From 16b794089cbffc63e81af66ae8fcb1cd118e607c Mon Sep 17 00:00:00 2001 From: Michael Mestnik Date: Sun, 18 Mar 2018 09:09:01 -0500 Subject: [PATCH] Initial commit --- .gitignore | 49 + .gitmodules | 6 + 0000tri/.gitignore | 6 + 0000tri/0_frag.glsl | 11 + 0000tri/0_vert.glsl | 15 + 0000tri/Makefile | 26 + 0000tri/data.h | 33 + 0000tri/data_bulk.c | 28 + 0000tri/data_dynamic.c.in | 10 + 0000tri/libdata.c | 18 + 0000tri/vulkan.c | 1136 + 0001uniform-buffer-object.diff | 682 + 0001uniform-buffer-object/.gitignore | 6 + 0001uniform-buffer-object/0_frag.glsl | 11 + 0001uniform-buffer-object/0_vert.glsl | 28 + 0001uniform-buffer-object/Makefile | 26 + 0001uniform-buffer-object/data.h | 79 + 0001uniform-buffer-object/data_bulk.c | 46 + 0001uniform-buffer-object/data_bulk.h | 16 + 0001uniform-buffer-object/data_dynamic.c.in | 10 + 0001uniform-buffer-object/libdata.c | 234 + 0001uniform-buffer-object/vulkan.c | 1339 + 0002lighting.diff | 194 + 0002lighting/.gitignore | 6 + 0002lighting/0_frag.glsl | 45 + 0002lighting/0_vert.glsl | 50 + 0002lighting/Makefile | 26 + 0002lighting/data.h | 82 + 0002lighting/data_bulk.c | 90 + 0002lighting/data_bulk.h | 16 + 0002lighting/data_dynamic.c.in | 10 + 0002lighting/libdata.c | 237 + 0002lighting/vulkan.c | 1339 + 0003index-buffer.diff | 193 + 0003index-buffer/.gitignore | 6 + 0003index-buffer/0_frag.glsl | 45 + 0003index-buffer/0_vert.glsl | 50 + 0003index-buffer/Makefile | 26 + 0003index-buffer/data.h | 85 + 0003index-buffer/data_bulk.c | 92 + 0003index-buffer/data_bulk.h | 16 + 0003index-buffer/data_dynamic.c.in | 10 + 0003index-buffer/libdata.c | 237 + 0003index-buffer/vulkan.c | 1417 + 0004cube.diff | 271 + 0004cube/.gitignore | 6 + 0004cube/0_frag.glsl | 45 + 0004cube/0_vert.glsl | 50 + 0004cube/Makefile | 26 + 0004cube/data.h | 85 + 0004cube/data_bulk.c | 258 + 0004cube/data_bulk.h | 16 + 0004cube/data_dynamic.c.in | 10 + 0004cube/libdata.c | 248 + 0004cube/vulkan.c | 1417 + 0005texture.diff | 991 + 0005texture/.gitignore | 6 + 0005texture/0_frag.glsl | 47 + 0005texture/0_vert.glsl | 50 + 0005texture/Makefile | 26 + 0005texture/data.h | 84 + 0005texture/data_bulk.c | 746 + 0005texture/data_bulk.h | 16 + 0005texture/data_dynamic.c.in | 10 + 0005texture/libdata.c | 248 + 0005texture/vulkan.c | 1637 + 0006multi-model.diff | 335 + 0006multi-model/.gitignore | 6 + 0006multi-model/0_frag.glsl | 47 + 0006multi-model/0_vert.glsl | 50 + 0006multi-model/Makefile | 26 + 0006multi-model/data.h | 87 + 0006multi-model/data_bulk.c | 771 + 0006multi-model/data_bulk.h | 16 + 0006multi-model/data_dynamic.c.in | 10 + 0006multi-model/libdata.c | 368 + 0006multi-model/vulkan.c | 1639 + 0007shared-ubo.diff | 453 + 0007shared-ubo/.gitignore | 6 + 0007shared-ubo/0_frag.glsl | 47 + 0007shared-ubo/0_vert.glsl | 54 + 0007shared-ubo/Makefile | 26 + 0007shared-ubo/data.h | 90 + 0007shared-ubo/data_bulk.c | 771 + 0007shared-ubo/data_bulk.h | 10 + 0007shared-ubo/data_dynamic.c.in | 10 + 0007shared-ubo/libdata.c | 374 + 0007shared-ubo/vulkan.c | 1658 + 0008multi-material.diff | 2553 + 0008multi-material/.gitignore | 6 + 0008multi-material/0_frag.glsl | 47 + 0008multi-material/0_vert.glsl | 54 + 0008multi-material/Makefile | 26 + 0008multi-material/data.h | 98 + 0008multi-material/data_bulk.c | 2899 + 0008multi-material/data_bulk.h | 17 + 0008multi-material/data_dynamic.c.in | 10 + 0008multi-material/libdata.c | 389 + 0008multi-material/vulkan.c | 1682 + 0009modify-instances-count.diff | 138 + 0009modify-instances-count/.gitignore | 6 + 0009modify-instances-count/0_frag.glsl | 47 + 0009modify-instances-count/0_vert.glsl | 54 + 0009modify-instances-count/Makefile | 26 + 0009modify-instances-count/data.h | 98 + 0009modify-instances-count/data_bulk.c | 2899 + 0009modify-instances-count/data_bulk.h | 17 + 0009modify-instances-count/data_dynamic.c.in | 10 + 0009modify-instances-count/libdata.c | 419 + 0009modify-instances-count/vulkan.c | 1682 + 0010tasks-during-render.diff | 394 + 0010tasks-during-render/.gitignore | 6 + 0010tasks-during-render/0_frag.glsl | 47 + 0010tasks-during-render/0_vert.glsl | 54 + 0010tasks-during-render/Makefile | 26 + 0010tasks-during-render/data.h | 100 + 0010tasks-during-render/data_bulk.c | 2901 + 0010tasks-during-render/data_bulk.h | 17 + 0010tasks-during-render/data_dynamic.c.in | 10 + 0010tasks-during-render/libdata.c | 656 + 0010tasks-during-render/vulkan.c | 1684 + 0011disappearing-instances.diff | 214 + 0011disappearing-instances/.gitignore | 6 + 0011disappearing-instances/0_frag.glsl | 47 + 0011disappearing-instances/0_vert.glsl | 54 + 0011disappearing-instances/Makefile | 26 + 0011disappearing-instances/data.h | 102 + 0011disappearing-instances/data_bulk.c | 2907 + 0011disappearing-instances/data_bulk.h | 17 + 0011disappearing-instances/data_dynamic.c.in | 10 + 0011disappearing-instances/libdata.c | 722 + 0011disappearing-instances/vulkan.c | 1684 + 0012raytrace.diff | 9 + 0012raytrace/.gitignore | 6 + 0012raytrace/0_frag.glsl | 47 + 0012raytrace/0_vert.glsl | 54 + 0012raytrace/Makefile | 26 + 0012raytrace/data.h | 102 + 0012raytrace/data_bulk.c | 2907 + 0012raytrace/data_bulk.h | 17 + 0012raytrace/data_dynamic.c.in | 10 + 0012raytrace/libdata.c | 723 + 0012raytrace/vulkan.c | 1684 + Makefile | 22 + archive/.gitignore | 1 + archive/cglm.min.js | 273 + include/cglm/affine-mat.h | 100 + include/cglm/affine.h | 409 + include/cglm/cam.h | 425 + include/cglm/cglm.h | 23 + include/cglm/common.h | 59 + include/cglm/euler.h | 378 + include/cglm/io.h | 174 + include/cglm/mat3.h | 291 + include/cglm/mat4.h | 572 + include/cglm/quat.h | 212 + include/cglm/simd/avx/affine.h | 63 + include/cglm/simd/avx/mat4.h | 65 + include/cglm/simd/intrin.h | 52 + include/cglm/simd/neon/mat4.h | 57 + include/cglm/simd/sse2/affine.h | 79 + include/cglm/simd/sse2/mat3.h | 61 + include/cglm/simd/sse2/mat4.h | 409 + include/cglm/simd/sse2/quat.h | 69 + include/cglm/types.h | 30 + include/cglm/util.h | 64 + include/cglm/vec3-ext.h | 163 + include/cglm/vec3.h | 538 + include/cglm/vec4-ext.h | 178 + include/cglm/vec4.h | 402 + include/cglm/version.h | 15 + include/cimgui.h | 1 + include/ctexteditor.h | 1 + include/duk_config.h | 3672 + include/duk_module_duktape.h | 1 + include/duktape.h | 1 + include/imgui_impl_glfw_vulkan.h | 1 + include/list.h | 520 + include/spirv/unified1/spirv.h | 1072 + include/whereami.h | 1 + lib/Makefile | 30 + lib/bin/.gitignore | 1 + lib/bin/Makefile | 14 + lib/bin/duk_cmdline.c | 1 + lib/bin/duk_cmdline.h | 1 + lib/bin/duk_print_alert.c | 1 + lib/bin/duk_print_alert.h | 1 + lib/cimgui | 1 + lib/cimgui-1.53.1/.gitignore | 38 + lib/cimgui-1.53.1/.gitmodules | 3 + lib/cimgui-1.53.1/.travis.yml | 12 + lib/cimgui-1.53.1/LICENSE | 22 + lib/cimgui-1.53.1/README.md | 26 + .../cimgui/.vscode/settings.json | 4 + lib/cimgui-1.53.1/cimgui/Makefile | 57 + lib/cimgui-1.53.1/cimgui/cimgui.cpp | 1892 + lib/cimgui-1.53.1/cimgui/cimgui.h | 1138 + lib/cimgui-1.53.1/cimgui/cimgui.sln | 28 + lib/cimgui-1.53.1/cimgui/cimgui.vcxproj | 161 + .../cimgui/cimgui.vcxproj.filters | 48 + lib/cimgui-1.53.1/cimgui/drawList.cpp | 293 + lib/cimgui-1.53.1/cimgui/fontAtlas.cpp | 328 + lib/cimgui-1.53.1/cimgui/listClipper.cpp | 27 + lib/cimgui-1.53.1/cimgui/test.c | 2 + lib/cimgui-1.53.1/imgui | 1 + lib/cimgui-1.53.1/imgui-1.53/.travis.yml | 18 + lib/cimgui-1.53.1/imgui-1.53/LICENSE.txt | 21 + lib/cimgui-1.53.1/imgui-1.53/README.md | 253 + lib/cimgui-1.53.1/imgui-1.53/TODO.txt | 259 + .../imgui-1.53/examples/.gitignore | 49 + .../imgui-1.53/examples/README.txt | 102 + .../examples/allegro5_example/README.md | 15 + .../allegro5_example/imgui_impl_a5.cpp | 298 + .../examples/allegro5_example/imgui_impl_a5.h | 22 + .../examples/allegro5_example/main.cpp | 116 + .../examples/apple_example/.gitignore | 3 + .../examples/apple_example/README.md | 41 + .../apple_example/imguiex-ios/AppDelegate.h | 13 + .../apple_example/imguiex-ios/AppDelegate.m | 41 + .../imguiex-ios/Base.lproj/LaunchScreen.xib | 32 + .../imguiex-ios/Base.lproj/Main.storyboard | 44 + .../imguiex-ios/GameViewController.h | 12 + .../imguiex-ios/GameViewController.m | 481 + .../AppIcon.appiconset/Contents.json | 77 + .../icon_imgui_60@2x~iphone.png | Bin 0 -> 3974 bytes .../icon_imgui_60@3x~iphone.png | Bin 0 -> 5953 bytes .../icon_imgui_76@2x~ipad.png | Bin 0 -> 4959 bytes .../AppIcon.appiconset/icon_imgui_76~ipad.png | Bin 0 -> 2576 bytes .../apple_example/imguiex-ios/Info.plist | 49 + .../imguiex-ios/Shaders/Shader.fsh | 10 + .../imguiex-ios/Shaders/Shader.vsh | 25 + .../apple_example/imguiex-ios/debug_hud.cpp | 44 + .../apple_example/imguiex-ios/debug_hud.h | 25 + .../imguiex-ios/imgui_ex_icon.png | Bin 0 -> 12653 bytes .../imguiex-ios/imgui_impl_ios.h | 22 + .../imguiex-ios/imgui_impl_ios.mm | 807 + .../examples/apple_example/imguiex-ios/main.m | 13 + .../apple_example/imguiex-osx/AppDelegate.h | 15 + .../apple_example/imguiex-osx/AppDelegate.m | 26 + .../AppIcon.appiconset/Contents.json | 64 + .../AppIcon.appiconset/icon_imgui_180x180.png | Bin 0 -> 5953 bytes .../imguiex-osx/Assets.xcassets/Contents.json | 6 + .../apple_example/imguiex-osx/Info.plist | 34 + .../examples/apple_example/imguiex-osx/main.m | 13 + .../imguiex.xcodeproj/project.pbxproj | 539 + .../directx10_example/build_win32.bat | 4 + .../directx10_example.vcxproj | 159 + .../directx10_example.vcxproj.filters | 45 + .../directx10_example/imgui_impl_dx10.cpp | 614 + .../directx10_example/imgui_impl_dx10.h | 24 + .../examples/directx10_example/main.cpp | 211 + .../directx11_example/build_win32.bat | 4 + .../directx11_example.vcxproj | 159 + .../directx11_example.vcxproj.filters | 45 + .../directx11_example/imgui_impl_dx11.cpp | 617 + .../directx11_example/imgui_impl_dx11.h | 25 + .../examples/directx11_example/main.cpp | 214 + .../examples/directx9_example/build_win32.bat | 3 + .../directx9_example/directx9_example.vcxproj | 159 + .../directx9_example.vcxproj.filters | 46 + .../directx9_example/imgui_impl_dx9.cpp | 391 + .../directx9_example/imgui_impl_dx9.h | 24 + .../examples/directx9_example/main.cpp | 181 + .../examples/imgui_examples_msvc2010.sln | 66 + .../imgui-1.53/examples/libs/gl3w/GL/gl3w.c | 1344 + .../imgui-1.53/examples/libs/gl3w/GL/gl3w.h | 1234 + .../examples/libs/gl3w/GL/glcorearb.h | 4533 + .../imgui-1.53/examples/libs/glfw/COPYING.txt | 22 + .../examples/libs/glfw/include/GLFW/glfw3.h | 4227 + .../libs/glfw/include/GLFW/glfw3native.h | 456 + .../examples/libs/usynergy/uSynergy.c | 636 + .../examples/libs/usynergy/uSynergy.h | 420 + .../examples/marmalade_example/data/app.icf | 32 + .../imgui_impl_marmalade.cpp | 312 + .../marmalade_example/imgui_impl_marmalade.h | 24 + .../examples/marmalade_example/main.cpp | 100 + .../marmalade_example/marmalade_example.mkb | 44 + .../examples/null_example/build_win32.bat | 3 + .../imgui-1.53/examples/null_example/main.cpp | 33 + .../examples/opengl2_example/Makefile | 60 + .../examples/opengl2_example/build_win32.bat | 3 + .../opengl2_example/imgui_impl_glfw.cpp | 307 + .../opengl2_example/imgui_impl_glfw.h | 29 + .../examples/opengl2_example/main.cpp | 111 + .../opengl2_example/opengl2_example.vcxproj | 169 + .../opengl2_example.vcxproj.filters | 46 + .../examples/opengl3_example/Makefile | 63 + .../examples/opengl3_example/build_win32.bat | 3 + .../opengl3_example/imgui_impl_glfw_gl3.cpp | 419 + .../opengl3_example/imgui_impl_glfw_gl3.h | 27 + .../examples/opengl3_example/main.cpp | 115 + .../opengl3_example/opengl3_example.vcxproj | 172 + .../opengl3_example.vcxproj.filters | 58 + .../examples/sdl_opengl2_example/README.md | 22 + .../sdl_opengl2_example/build_win32.bat | 3 + .../sdl_opengl2_example/imgui_impl_sdl.cpp | 296 + .../sdl_opengl2_example/imgui_impl_sdl.h | 24 + .../examples/sdl_opengl2_example/main.cpp | 124 + .../examples/sdl_opengl3_example/Makefile | 61 + .../examples/sdl_opengl3_example/README.md | 22 + .../sdl_opengl3_example/build_win32.bat | 3 + .../imgui_impl_sdl_gl3.cpp | 407 + .../sdl_opengl3_example/imgui_impl_sdl_gl3.h | 21 + .../examples/sdl_opengl3_example/main.cpp | 123 + .../examples/vulkan_example/build_win32.bat | 7 + .../examples/vulkan_example/build_win64.bat | 7 + .../examples/vulkan_example/gen_spv.sh | 3 + .../examples/vulkan_example/glsl_shader.frag | 14 + .../examples/vulkan_example/glsl_shader.vert | 25 + .../vulkan_example/imgui_impl_glfw_vulkan.cpp | 843 + .../vulkan_example/imgui_impl_glfw_vulkan.h | 45 + .../examples/vulkan_example/main.cpp | 744 + .../extra_fonts/Cousine-Regular.ttf | Bin 0 -> 43912 bytes .../imgui-1.53/extra_fonts/DroidSans.ttf | Bin 0 -> 190044 bytes .../imgui-1.53/extra_fonts/Karla-Regular.ttf | Bin 0 -> 16848 bytes .../imgui-1.53/extra_fonts/ProggyClean.ttf | Bin 0 -> 41208 bytes .../imgui-1.53/extra_fonts/ProggyTiny.ttf | Bin 0 -> 35656 bytes .../imgui-1.53/extra_fonts/README.txt | 255 + .../imgui-1.53/extra_fonts/Roboto-Medium.ttf | Bin 0 -> 162588 bytes .../extra_fonts/binary_to_compressed_c.cpp | 380 + lib/cimgui-1.53.1/imgui-1.53/imconfig.h | 61 + lib/cimgui-1.53.1/imgui-1.53/imgui.cpp | 11739 ++ lib/cimgui-1.53.1/imgui-1.53/imgui.h | 1684 + lib/cimgui-1.53.1/imgui-1.53/imgui_demo.cpp | 3067 + lib/cimgui-1.53.1/imgui-1.53/imgui_draw.cpp | 2906 + lib/cimgui-1.53.1/imgui-1.53/imgui_internal.h | 985 + lib/cimgui-1.53.1/imgui-1.53/stb_rect_pack.h | 583 + lib/cimgui-1.53.1/imgui-1.53/stb_textedit.h | 1322 + lib/cimgui-1.53.1/imgui-1.53/stb_truetype.h | 4018 + lib/cimgui-1.53.1/menus-api.gif | Bin 0 -> 199335 bytes lib/cimgui-1.53.1/screenshot.png | Bin 0 -> 66213 bytes lib/duktape | 1 + lib/duktape-2.2.1/AUTHORS.rst | 89 + lib/duktape-2.2.1/LICENSE.txt | 25 + lib/duktape-2.2.1/Makefile.cmdline | 47 + lib/duktape-2.2.1/Makefile.codepage | 4 + lib/duktape-2.2.1/Makefile.coffee | 4 + lib/duktape-2.2.1/Makefile.dukdebug | 41 + lib/duktape-2.2.1/Makefile.eval | 7 + lib/duktape-2.2.1/Makefile.eventloop | 22 + lib/duktape-2.2.1/Makefile.hello | 32 + lib/duktape-2.2.1/Makefile.jxpretty | 8 + lib/duktape-2.2.1/Makefile.sandbox | 7 + lib/duktape-2.2.1/Makefile.sharedlibrary | 71 + lib/duktape-2.2.1/README.rst | 138 + lib/duktape-2.2.1/config/README.rst | 19 + lib/duktape-2.2.1/config/architectures.yaml | 63 + .../architectures/architecture_arm32.h.in | 6 + .../architectures/architecture_arm64.h.in | 6 + .../architecture_emscripten.h.in | 8 + .../architectures/architecture_generic.h.in | 3 + .../architectures/architecture_m68k.h.in | 8 + .../architectures/architecture_mips32.h.in | 6 + .../architectures/architecture_mips64.h.in | 6 + .../architectures/architecture_powerpc32.h.in | 8 + .../architectures/architecture_powerpc64.h.in | 8 + .../architectures/architecture_sparc32.h.in | 6 + .../architectures/architecture_sparc64.h.in | 6 + .../architectures/architecture_superh.h.in | 9 + .../architectures/architecture_x32.h.in | 11 + .../architectures/architecture_x64.h.in | 11 + .../architectures/architecture_x86.h.in | 11 + lib/duktape-2.2.1/config/compilers.yaml | 35 + .../config/compilers/compiler_bcc.h.in | 24 + .../config/compilers/compiler_clang.h.in | 64 + .../config/compilers/compiler_emscripten.h.in | 45 + .../config/compilers/compiler_gcc.h.in | 84 + .../config/compilers/compiler_generic.h.in | 24 + .../config/compilers/compiler_msvc.h.in | 84 + .../config/compilers/compiler_tinyc.h.in | 18 + .../config/compilers/compiler_vbcc.h.in | 23 + .../config-options/DUK_USE_32BIT_PTRS.yaml | 8 + .../config-options/DUK_USE_64BIT_OPS.yaml | 9 + .../config-options/DUK_USE_ALIGN_4.yaml | 11 + .../config-options/DUK_USE_ALIGN_8.yaml | 11 + .../config-options/DUK_USE_ALIGN_BY.yaml | 8 + .../config-options/DUK_USE_ARCH_STRING.yaml | 9 + .../config-options/DUK_USE_ARRAY_BUILTIN.yaml | 7 + .../DUK_USE_ARRAY_FASTPATH.yaml | 15 + .../DUK_USE_ARRAY_PROP_FASTPATH.yaml | 14 + .../config-options/DUK_USE_ASSERTIONS.yaml | 9 + .../DUK_USE_ATAN2_WORKAROUNDS.yaml | 8 + .../DUK_USE_AUGMENT_ERROR_CREATE.yaml | 8 + .../DUK_USE_AUGMENT_ERROR_THROW.yaml | 8 + .../DUK_USE_AVOID_PLATFORM_FUNCPTRS.yaml | 13 + .../DUK_USE_BASE64_FASTPATH.yaml | 10 + .../DUK_USE_BOOLEAN_BUILTIN.yaml | 7 + .../config-options/DUK_USE_BRANCH_HINTS.yaml | 9 + .../config-options/DUK_USE_BROWSER_LIKE.yaml | 8 + .../DUK_USE_BUFFEROBJECT_SUPPORT.yaml | 15 + .../config-options/DUK_USE_BUFLEN16.yaml | 8 + .../DUK_USE_BUILTIN_INITJS.yaml | 12 + .../DUK_USE_BYTECODE_DUMP_SUPPORT.yaml | 7 + .../config-options/DUK_USE_BYTEORDER.yaml | 16 + .../DUK_USE_BYTEORDER_FORCED.yaml | 9 + .../DUK_USE_CACHE_ACTIVATION.yaml | 9 + .../config-options/DUK_USE_CACHE_CATCHER.yaml | 9 + .../DUK_USE_CALLSTACK_LIMIT.yaml | 10 + .../DUK_USE_COMMONJS_MODULES.yaml | 12 + .../DUK_USE_COMPILER_RECLIMIT.yaml | 8 + .../DUK_USE_COMPILER_STRING.yaml | 9 + .../DUK_USE_COMPUTED_INFINITY.yaml | 15 + .../config-options/DUK_USE_COMPUTED_NAN.yaml | 15 + .../DUK_USE_COROUTINE_SUPPORT.yaml | 7 + .../DUK_USE_CPP_EXCEPTIONS.yaml | 9 + .../config-options/DUK_USE_DATAPTR16.yaml | 21 + .../config-options/DUK_USE_DATAPTR_DEC16.yaml | 13 + .../config-options/DUK_USE_DATAPTR_ENC16.yaml | 15 + .../config-options/DUK_USE_DATE_BUILTIN.yaml | 7 + .../DUK_USE_DATE_FMT_STRFTIME.yaml | 13 + .../DUK_USE_DATE_FORMAT_STRING.yaml | 9 + .../DUK_USE_DATE_GET_LOCAL_TZOFFSET.yaml | 9 + .../config-options/DUK_USE_DATE_GET_NOW.yaml | 15 + .../DUK_USE_DATE_NOW_GETTIMEOFDAY.yaml | 12 + .../config-options/DUK_USE_DATE_NOW_TIME.yaml | 13 + .../DUK_USE_DATE_NOW_WINDOWS.yaml | 8 + .../DUK_USE_DATE_NOW_WINDOWS_SUBMS.yaml | 9 + .../DUK_USE_DATE_PARSE_STRING.yaml | 9 + .../DUK_USE_DATE_PRS_GETDATE.yaml | 14 + .../DUK_USE_DATE_PRS_STRPTIME.yaml | 12 + .../DUK_USE_DATE_TZO_GMTIME.yaml | 14 + .../DUK_USE_DATE_TZO_GMTIME_R.yaml | 12 + .../DUK_USE_DATE_TZO_GMTIME_S.yaml | 8 + .../DUK_USE_DATE_TZO_WINDOWS.yaml | 8 + .../DUK_USE_DATE_TZO_WINDOWS_NO_DST.yaml | 9 + .../config-options/DUK_USE_DDDPRINT.yaml | 9 + .../config-options/DUK_USE_DDPRINT.yaml | 8 + .../config/config-options/DUK_USE_DEBUG.yaml | 9 + .../DUK_USE_DEBUGGER_DUMPHEAP.yaml | 12 + .../DUK_USE_DEBUGGER_FWD_LOGGING.yaml | 14 + .../DUK_USE_DEBUGGER_FWD_PRINTALERT.yaml | 12 + .../DUK_USE_DEBUGGER_INSPECT.yaml | 13 + .../DUK_USE_DEBUGGER_PAUSE_UNCAUGHT.yaml | 17 + .../DUK_USE_DEBUGGER_SUPPORT.yaml | 13 + .../DUK_USE_DEBUGGER_THROW_NOTIFY.yaml | 14 + .../DUK_USE_DEBUGGER_TRANSPORT_TORTURE.yaml | 14 + .../config-options/DUK_USE_DEBUG_BUFSIZE.yaml | 12 + .../config-options/DUK_USE_DEBUG_LEVEL.yaml | 8 + .../config-options/DUK_USE_DEBUG_WRITE.yaml | 16 + .../config-options/DUK_USE_DEEP_C_STACK.yaml | 12 + .../config-options/DUK_USE_DOUBLE_BE.yaml | 11 + .../config-options/DUK_USE_DOUBLE_LE.yaml | 11 + .../DUK_USE_DOUBLE_LINKED_HEAP.yaml | 11 + .../config-options/DUK_USE_DOUBLE_ME.yaml | 13 + .../config/config-options/DUK_USE_DPRINT.yaml | 10 + .../config-options/DUK_USE_DPRINT_COLORS.yaml | 10 + .../config-options/DUK_USE_DPRINT_RDTSC.yaml | 8 + .../DUK_USE_DUKTAPE_BUILTIN.yaml | 7 + .../DUK_USE_ENCODING_BUILTINS.yaml | 13 + .../config-options/DUK_USE_ERRCREATE.yaml | 8 + .../config-options/DUK_USE_ERRTHROW.yaml | 8 + .../config/config-options/DUK_USE_ES6.yaml | 7 + .../DUK_USE_ES6_OBJECT_PROTO_PROPERTY.yaml | 7 + .../DUK_USE_ES6_OBJECT_SETPROTOTYPEOF.yaml | 7 + .../config-options/DUK_USE_ES6_PROXY.yaml | 7 + .../DUK_USE_ES6_REGEXP_BRACES.yaml | 8 + .../DUK_USE_ES6_REGEXP_SYNTAX.yaml | 14 + .../DUK_USE_ES6_UNICODE_ESCAPE.yaml | 8 + .../config/config-options/DUK_USE_ES7.yaml | 7 + .../DUK_USE_ES7_EXP_OPERATOR.yaml | 9 + .../config/config-options/DUK_USE_ES8.yaml | 7 + .../config/config-options/DUK_USE_ES9.yaml | 7 + .../config-options/DUK_USE_ESBC_LIMITS.yaml | 7 + .../DUK_USE_ESBC_MAX_BYTES.yaml | 9 + .../DUK_USE_ESBC_MAX_LINENUMBER.yaml | 9 + .../config-options/DUK_USE_EXAMPLE.yaml | 74 + .../DUK_USE_EXEC_FUN_LOCAL.yaml | 14 + .../DUK_USE_EXEC_INDIRECT_BOUND_CHECK.yaml | 11 + .../DUK_USE_EXEC_PREFER_SIZE.yaml | 7 + .../DUK_USE_EXEC_REGCONST_OPTIMIZE.yaml | 11 + .../DUK_USE_EXEC_TIMEOUT_CHECK.yaml | 31 + .../DUK_USE_EXPLICIT_NULL_INIT.yaml | 12 + .../config-options/DUK_USE_EXTSTR_FREE.yaml | 23 + .../DUK_USE_EXTSTR_INTERN_CHECK.yaml | 39 + .../config-options/DUK_USE_FASTINT.yaml | 14 + .../DUK_USE_FAST_REFCOUNT_DEFAULT.yaml | 10 + .../config-options/DUK_USE_FATAL_HANDLER.yaml | 23 + .../config-options/DUK_USE_FATAL_MAXLEN.yaml | 8 + .../config-options/DUK_USE_FILE_IO.yaml | 10 + .../DUK_USE_FINALIZER_SUPPORT.yaml | 7 + .../DUK_USE_FINALIZER_TORTURE.yaml | 11 + .../config-options/DUK_USE_FLEX_C99.yaml | 9 + .../config-options/DUK_USE_FLEX_ONESIZE.yaml | 11 + .../config-options/DUK_USE_FLEX_ZEROSIZE.yaml | 11 + .../config-options/DUK_USE_FULL_TVAL.yaml | 16 + .../config-options/DUK_USE_FUNCPTR16.yaml | 21 + .../config-options/DUK_USE_FUNCPTR_DEC16.yaml | 15 + .../config-options/DUK_USE_FUNCPTR_ENC16.yaml | 13 + .../DUK_USE_FUNCTION_BUILTIN.yaml | 7 + .../DUK_USE_FUNC_FILENAME_PROPERTY.yaml | 9 + .../DUK_USE_FUNC_NAME_PROPERTY.yaml | 10 + .../config-options/DUK_USE_GCC_PRAGMAS.yaml | 8 + .../config-options/DUK_USE_GC_TORTURE.yaml | 14 + .../DUK_USE_GET_MONOTONIC_TIME.yaml | 22 + ..._USE_GET_MONOTONIC_TIME_CLOCK_GETTIME.yaml | 8 + ...UK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC.yaml | 7 + .../DUK_USE_GET_RANDOM_DOUBLE.yaml | 16 + .../DUK_USE_GLOBAL_BINDING.yaml | 10 + .../DUK_USE_GLOBAL_BUILTIN.yaml | 9 + ...UK_USE_HASHBYTES_UNALIGNED_U32_ACCESS.yaml | 8 + .../config-options/DUK_USE_HEAPPTR16.yaml | 35 + .../config-options/DUK_USE_HEAPPTR_DEC16.yaml | 13 + .../config-options/DUK_USE_HEAPPTR_ENC16.yaml | 13 + .../config-options/DUK_USE_HEX_FASTPATH.yaml | 10 + .../DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT.yaml | 14 + ...K_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT.yaml | 13 + .../DUK_USE_HOBJECT_ARRAY_MINGROW_ADD.yaml | 8 + ...DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR.yaml | 8 + .../DUK_USE_HOBJECT_ENTRY_MINGROW_ADD.yaml | 8 + ...DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR.yaml | 8 + .../DUK_USE_HOBJECT_HASH_PART.yaml | 11 + .../DUK_USE_HOBJECT_HASH_PROP_LIMIT.yaml | 20 + .../DUK_USE_HOBJECT_LAYOUT_1.yaml | 10 + .../DUK_USE_HOBJECT_LAYOUT_2.yaml | 8 + .../DUK_USE_HOBJECT_LAYOUT_3.yaml | 9 + .../DUK_USE_HSTRING_ARRIDX.yaml | 12 + .../config-options/DUK_USE_HSTRING_CLEN.yaml | 13 + .../DUK_USE_HSTRING_EXTDATA.yaml | 12 + .../DUK_USE_HSTRING_LAZY_CLEN.yaml | 11 + .../config-options/DUK_USE_HTML_COMMENTS.yaml | 7 + .../DUK_USE_IDCHAR_FASTPATH.yaml | 10 + .../DUK_USE_INJECT_HEAP_ALLOC_ERROR.yaml | 7 + .../config-options/DUK_USE_INTEGER_BE.yaml | 11 + .../config-options/DUK_USE_INTEGER_LE.yaml | 11 + .../config-options/DUK_USE_INTEGER_ME.yaml | 14 + .../DUK_USE_INTERRUPT_COUNTER.yaml | 13 + .../DUK_USE_INTERRUPT_DEBUG_FIXUP.yaml | 10 + .../config/config-options/DUK_USE_JC.yaml | 7 + .../config-options/DUK_USE_JSON_BUILTIN.yaml | 7 + .../DUK_USE_JSON_DECNUMBER_FASTPATH.yaml | 10 + .../DUK_USE_JSON_DECSTRING_FASTPATH.yaml | 10 + .../DUK_USE_JSON_DEC_RECLIMIT.yaml | 8 + .../DUK_USE_JSON_EATWHITE_FASTPATH.yaml | 10 + .../DUK_USE_JSON_ENC_RECLIMIT.yaml | 11 + .../DUK_USE_JSON_QUOTESTRING_FASTPATH.yaml | 10 + .../DUK_USE_JSON_STRINGIFY_FASTPATH.yaml | 15 + .../config-options/DUK_USE_JSON_SUPPORT.yaml | 10 + .../config/config-options/DUK_USE_JX.yaml | 7 + .../DUK_USE_LEXER_SLIDING_WINDOW.yaml | 9 + .../DUK_USE_LIGHTFUNC_BUILTINS.yaml | 10 + ...UK_USE_MARKANDSWEEP_FINALIZER_TORTURE.yaml | 17 + .../DUK_USE_MARK_AND_SWEEP.yaml | 19 + .../DUK_USE_MARK_AND_SWEEP_RECLIMIT.yaml | 10 + .../config-options/DUK_USE_MATH_BUILTIN.yaml | 7 + .../config-options/DUK_USE_MATH_FMAX.yaml | 14 + .../config-options/DUK_USE_MATH_FMIN.yaml | 14 + .../config-options/DUK_USE_MATH_ROUND.yaml | 15 + .../DUK_USE_MS_STRINGTABLE_RESIZE.yaml | 13 + .../DUK_USE_NATIVE_CALL_RECLIMIT.yaml | 12 + .../DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER.yaml | 14 + .../DUK_USE_NONSTD_ARRAY_MAP_TRAILER.yaml | 14 + .../DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml | 15 + .../DUK_USE_NONSTD_FUNC_CALLER_PROPERTY.yaml | 16 + .../DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY.yaml | 12 + .../DUK_USE_NONSTD_FUNC_STMT.yaml | 13 + .../DUK_USE_NONSTD_GETTER_KEY_ARGUMENT.yaml | 11 + .../DUK_USE_NONSTD_JSON_ESC_U2028_U2029.yaml | 13 + .../DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE.yaml | 9 + .../DUK_USE_NONSTD_SETTER_KEY_ARGUMENT.yaml | 11 + ..._USE_NONSTD_STRING_FROMCHARCODE_32BIT.yaml | 12 + .../DUK_USE_NO_DOUBLE_ALIASING_SELFTEST.yaml | 12 + .../DUK_USE_NUMBER_BUILTIN.yaml | 7 + .../DUK_USE_OBJECT_BUILTIN.yaml | 7 + .../config-options/DUK_USE_OBJSIZES16.yaml | 12 + .../config-options/DUK_USE_OCTAL_SUPPORT.yaml | 10 + .../config-options/DUK_USE_OS_STRING.yaml | 9 + .../config-options/DUK_USE_PACKED_TVAL.yaml | 11 + .../DUK_USE_PACKED_TVAL_POSSIBLE.yaml | 8 + .../DUK_USE_PACK_CLANG_ATTR.yaml | 7 + .../DUK_USE_PACK_DUMMY_MEMBER.yaml | 7 + .../config-options/DUK_USE_PACK_GCC_ATTR.yaml | 7 + .../DUK_USE_PACK_MSVC_PRAGMA.yaml | 7 + .../config-options/DUK_USE_PANIC_ABORT.yaml | 8 + .../config-options/DUK_USE_PANIC_EXIT.yaml | 8 + .../config-options/DUK_USE_PANIC_HANDLER.yaml | 11 + .../DUK_USE_PANIC_SEGFAULT.yaml | 10 + .../DUK_USE_PARANOID_DATE_COMPUTATION.yaml | 15 + .../DUK_USE_PARANOID_ERRORS.yaml | 14 + .../config-options/DUK_USE_PARANOID_MATH.yaml | 11 + .../config-options/DUK_USE_PC2LINE.yaml | 11 + .../DUK_USE_PERFORMANCE_BUILTIN.yaml | 7 + .../DUK_USE_POW_NETBSD_WORKAROUND.yaml | 11 + .../DUK_USE_POW_WORKAROUNDS.yaml | 9 + .../config-options/DUK_USE_PREFER_SIZE.yaml | 9 + .../DUK_USE_PROMISE_BUILTIN.yaml | 9 + ...K_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS.yaml | 9 + .../config/config-options/DUK_USE_RDTSC.yaml | 8 + .../config-options/DUK_USE_REFCOUNT16.yaml | 9 + .../config-options/DUK_USE_REFCOUNT32.yaml | 12 + .../DUK_USE_REFERENCE_COUNTING.yaml | 7 + .../DUK_USE_REFLECT_BUILTIN.yaml | 8 + .../DUK_USE_REFZERO_FINALIZER_TORTURE.yaml | 15 + .../DUK_USE_REGEXP_CANON_BITMAP.yaml | 11 + .../DUK_USE_REGEXP_CANON_WORKAROUND.yaml | 13 + .../DUK_USE_REGEXP_COMPILER_RECLIMIT.yaml | 8 + .../DUK_USE_REGEXP_EXECUTOR_RECLIMIT.yaml | 8 + .../DUK_USE_REGEXP_SUPPORT.yaml | 15 + .../DUK_USE_REPL_FPCLASSIFY.yaml | 12 + .../config-options/DUK_USE_REPL_ISFINITE.yaml | 12 + .../config-options/DUK_USE_REPL_ISINF.yaml | 12 + .../config-options/DUK_USE_REPL_ISNAN.yaml | 12 + .../config-options/DUK_USE_REPL_SIGNBIT.yaml | 12 + .../DUK_USE_ROM_GLOBAL_CLONE.yaml | 18 + .../DUK_USE_ROM_GLOBAL_INHERIT.yaml | 23 + .../config-options/DUK_USE_ROM_OBJECTS.yaml | 22 + .../DUK_USE_ROM_PTRCOMP_FIRST.yaml | 16 + .../config-options/DUK_USE_ROM_STRINGS.yaml | 13 + .../config-options/DUK_USE_SECTION_B.yaml | 11 + .../config-options/DUK_USE_SELF_TESTS.yaml | 9 + .../config/config-options/DUK_USE_SETJMP.yaml | 17 + .../DUK_USE_SHEBANG_COMMENTS.yaml | 8 + .../DUK_USE_SHUFFLE_TORTURE.yaml | 12 + .../config-options/DUK_USE_SIGSETJMP.yaml | 12 + .../config-options/DUK_USE_SOURCE_NONBMP.yaml | 11 + .../config-options/DUK_USE_STRHASH16.yaml | 8 + .../config-options/DUK_USE_STRHASH_DENSE.yaml | 10 + .../DUK_USE_STRHASH_SKIP_SHIFT.yaml | 12 + .../config-options/DUK_USE_STRICT_DECL.yaml | 13 + .../DUK_USE_STRICT_UTF8_SOURCE.yaml | 11 + .../DUK_USE_STRING_BUILTIN.yaml | 7 + .../config-options/DUK_USE_STRLEN16.yaml | 8 + .../config-options/DUK_USE_STRTAB_CHAIN.yaml | 27 + .../DUK_USE_STRTAB_CHAIN_SIZE.yaml | 10 + .../DUK_USE_STRTAB_GROW_LIMIT.yaml | 10 + .../DUK_USE_STRTAB_MAXSIZE.yaml | 13 + .../DUK_USE_STRTAB_MINSIZE.yaml | 9 + .../config-options/DUK_USE_STRTAB_PROBE.yaml | 8 + .../DUK_USE_STRTAB_PTRCOMP.yaml | 14 + .../DUK_USE_STRTAB_RESIZE_CHECK_MASK.yaml | 16 + .../DUK_USE_STRTAB_SHRINK_LIMIT.yaml | 10 + .../DUK_USE_STRTAB_TORTURE.yaml | 9 + .../DUK_USE_SYMBOL_BUILTIN.yaml | 10 + .../config-options/DUK_USE_TAILCALL.yaml | 13 + .../config-options/DUK_USE_TARGET_INFO.yaml | 10 + .../config-options/DUK_USE_TRACEBACKS.yaml | 12 + .../DUK_USE_TRACEBACK_DEPTH.yaml | 13 + .../DUK_USE_UNALIGNED_ACCESSES_POSSIBLE.yaml | 9 + .../DUK_USE_UNDERSCORE_SETJMP.yaml | 13 + .../DUK_USE_UNION_INITIALIZERS.yaml | 11 + .../config-options/DUK_USE_USER_DECLARE.yaml | 18 + .../config-options/DUK_USE_USER_INITJS.yaml | 13 + .../DUK_USE_VALSTACK_GROW_SHIFT.yaml | 13 + .../DUK_USE_VALSTACK_LIMIT.yaml | 11 + .../DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT.yaml | 13 + .../DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT.yaml | 10 + .../DUK_USE_VALSTACK_UNSAFE.yaml | 11 + .../DUK_USE_VARIADIC_MACROS.yaml | 11 + .../DUK_USE_VERBOSE_ERRORS.yaml | 11 + .../DUK_USE_VERBOSE_EXECUTOR_ERRORS.yaml | 10 + .../config-options/DUK_USE_VOLUNTARY_GC.yaml | 16 + .../DUK_USE_ZERO_BUFFER_DATA.yaml | 11 + .../config/examples/compliance.yaml | 20 + .../config/examples/debugger_support.yaml | 24 + .../examples/disable_bufferobjects.yaml | 3 + .../config/examples/disable_es6.yaml | 5 + .../config/examples/enable_debug_print0.yaml | 3 + .../config/examples/enable_debug_print1.yaml | 3 + .../config/examples/enable_debug_print2.yaml | 3 + .../config/examples/enable_fastint.yaml | 3 + .../config/examples/low_memory.yaml | 139 + .../config/examples/low_memory_strip.yaml | 47 + .../examples/performance_sensitive.yaml | 26 + .../config/examples/rom_builtins.yaml | 19 + .../config/examples/security_sensitive.yaml | 17 + .../config/examples/shallow_c_stack.yaml | 10 + .../config/examples/timing_sensitive.yaml | 6 + .../feature-options/DUK_OPT_ASSERTIONS.yaml | 8 + .../DUK_OPT_BUFFEROBJECT_SUPPORT.yaml | 8 + .../feature-options/DUK_OPT_BUFLEN16.yaml | 7 + .../feature-options/DUK_OPT_DATAPTR16.yaml | 20 + .../DUK_OPT_DATAPTR_DEC16.yaml | 12 + .../DUK_OPT_DATAPTR_ENC16.yaml | 14 + .../feature-options/DUK_OPT_DDDPRINT.yaml | 9 + .../feature-options/DUK_OPT_DDPRINT.yaml | 8 + .../config/feature-options/DUK_OPT_DEBUG.yaml | 7 + .../DUK_OPT_DEBUGGER_DUMPHEAP.yaml | 10 + .../DUK_OPT_DEBUGGER_FWD_LOGGING.yaml | 11 + .../DUK_OPT_DEBUGGER_FWD_PRINTALERT.yaml | 9 + .../DUK_OPT_DEBUGGER_SUPPORT.yaml | 12 + .../DUK_OPT_DEBUGGER_TRANSPORT_TORTURE.yaml | 11 + .../DUK_OPT_DEBUG_BUFSIZE.yaml | 11 + .../feature-options/DUK_OPT_DECLARE.yaml | 10 + .../feature-options/DUK_OPT_DEEP_C_STACK.yaml | 15 + .../feature-options/DUK_OPT_DLL_BUILD.yaml | 12 + .../feature-options/DUK_OPT_DPRINT.yaml | 8 + .../DUK_OPT_DPRINT_COLORS.yaml | 8 + .../feature-options/DUK_OPT_DPRINT_RDTSC.yaml | 7 + .../feature-options/DUK_OPT_EXAMPLE.yaml | 52 + .../DUK_OPT_EXEC_TIMEOUT_CHECK.yaml | 30 + .../DUK_OPT_EXTERNAL_STRINGS.yaml | 11 + .../feature-options/DUK_OPT_EXTSTR_FREE.yaml | 22 + .../DUK_OPT_EXTSTR_INTERN_CHECK.yaml | 38 + .../feature-options/DUK_OPT_FASTINT.yaml | 10 + .../feature-options/DUK_OPT_FORCE_ALIGN.yaml | 8 + .../DUK_OPT_FORCE_BYTEORDER.yaml | 10 + .../feature-options/DUK_OPT_FUNCPTR16.yaml | 21 + .../DUK_OPT_FUNCPTR_DEC16.yaml | 12 + .../DUK_OPT_FUNCPTR_ENC16.yaml | 12 + .../DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY.yaml | 9 + .../DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY.yaml | 9 + .../feature-options/DUK_OPT_GC_TORTURE.yaml | 9 + .../DUK_OPT_HAVE_CUSTOM_H.yaml | 26 + .../feature-options/DUK_OPT_HEAPPTR16.yaml | 34 + .../DUK_OPT_HEAPPTR_DEC16.yaml | 12 + .../DUK_OPT_HEAPPTR_ENC16.yaml | 12 + .../DUK_OPT_INTERRUPT_COUNTER.yaml | 12 + .../DUK_OPT_JSON_STRINGIFY_FASTPATH.yaml | 9 + .../DUK_OPT_LIGHTFUNC_BUILTINS.yaml | 9 + .../DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY.yaml | 14 + .../DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY.yaml | 10 + ...K_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT.yaml | 9 + .../DUK_OPT_NO_AUGMENT_ERRORS.yaml | 10 + .../DUK_OPT_NO_BROWSER_LIKE.yaml | 9 + .../DUK_OPT_NO_BUFFEROBJECT_SUPPORT.yaml | 8 + .../DUK_OPT_NO_BYTECODE_DUMP_SUPPORT.yaml | 7 + .../DUK_OPT_NO_COMMONJS_MODULES.yaml | 6 + .../DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY.yaml | 8 + .../DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF.yaml | 8 + .../feature-options/DUK_OPT_NO_ES6_PROXY.yaml | 8 + .../feature-options/DUK_OPT_NO_FILE_IO.yaml | 10 + .../feature-options/DUK_OPT_NO_FUNC_STMT.yaml | 9 + .../config/feature-options/DUK_OPT_NO_JC.yaml | 7 + .../feature-options/DUK_OPT_NO_JSONC.yaml | 9 + .../feature-options/DUK_OPT_NO_JSONX.yaml | 9 + .../config/feature-options/DUK_OPT_NO_JX.yaml | 7 + .../DUK_OPT_NO_MARK_AND_SWEEP.yaml | 14 + .../DUK_OPT_NO_MS_STRINGTABLE_RESIZE.yaml | 9 + ...K_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT.yaml | 8 + ...UK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER.yaml | 12 + .../DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER.yaml | 12 + ...K_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml | 13 + .../DUK_OPT_NO_NONSTD_FUNC_STMT.yaml | 10 + ...UK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029.yaml | 10 + ...T_NO_NONSTD_STRING_FROMCHARCODE_32BIT.yaml | 9 + .../DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY.yaml | 10 + .../DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF.yaml | 10 + .../DUK_OPT_NO_OCTAL_SUPPORT.yaml | 7 + .../DUK_OPT_NO_PACKED_TVAL.yaml | 9 + .../feature-options/DUK_OPT_NO_PC2LINE.yaml | 9 + .../DUK_OPT_NO_REFERENCE_COUNTING.yaml | 9 + .../DUK_OPT_NO_REGEXP_SUPPORT.yaml | 11 + .../feature-options/DUK_OPT_NO_SECTION_B.yaml | 9 + .../DUK_OPT_NO_SOURCE_NONBMP.yaml | 7 + .../DUK_OPT_NO_STRICT_DECL.yaml | 8 + .../DUK_OPT_NO_TRACEBACKS.yaml | 8 + .../DUK_OPT_NO_VERBOSE_ERRORS.yaml | 8 + .../DUK_OPT_NO_VOLUNTARY_GC.yaml | 13 + .../DUK_OPT_NO_ZERO_BUFFER_DATA.yaml | 8 + .../feature-options/DUK_OPT_OBJSIZES16.yaml | 11 + .../DUK_OPT_PANIC_HANDLER.yaml | 6 + .../feature-options/DUK_OPT_REFCOUNT16.yaml | 7 + .../DUK_OPT_SEGFAULT_ON_PANIC.yaml | 8 + .../feature-options/DUK_OPT_SELF_TESTS.yaml | 8 + .../feature-options/DUK_OPT_SETJMP.yaml | 18 + .../DUK_OPT_SHUFFLE_TORTURE.yaml | 10 + .../feature-options/DUK_OPT_SIGSETJMP.yaml | 9 + .../feature-options/DUK_OPT_STRHASH16.yaml | 7 + .../DUK_OPT_STRICT_UTF8_SOURCE.yaml | 9 + .../feature-options/DUK_OPT_STRLEN16.yaml | 7 + .../feature-options/DUK_OPT_STRTAB_CHAIN.yaml | 25 + .../DUK_OPT_STRTAB_CHAIN_SIZE.yaml | 8 + .../feature-options/DUK_OPT_TARGET_INFO.yaml | 8 + .../DUK_OPT_TRACEBACK_DEPTH.yaml | 6 + .../DUK_OPT_UNDERSCORE_SETJMP.yaml | 10 + .../feature-options/DUK_OPT_USER_INITJS.yaml | 11 + .../config/header-snippets/64bitops.h.in | 11 + .../header-snippets/alignment_fillin.h.in | 23 + .../header-snippets/architecture_fillins.h.in | 0 .../header-snippets/byteorder_derived.h.in | 21 + .../header-snippets/byteorder_fillin.h.in | 109 + .../header-snippets/compiler_fillins.h.in | 172 + .../header-snippets/cpp_exception_sanity.h.in | 3 + .../config/header-snippets/date_provider.h.in | 66 + .../header-snippets/gcc_clang_visibility.h.in | 26 + .../header-snippets/inline_workaround.h.in | 11 + .../header-snippets/msvc_visibility.h.in | 19 + .../config/header-snippets/object_layout.h.in | 21 + .../header-snippets/packed_tval_fillin.h.in | 40 + .../header-snippets/platform_cppextras.h.in | 9 + .../header-snippets/platform_fillins.h.in | 327 + .../platform_sharedincludes.h.in | 26 + .../header-snippets/reject_fast_math.h.in | 6 + .../config/header-snippets/types1.h.in | 78 + .../config/header-snippets/types2.h.in | 132 + .../config/header-snippets/types_c99.h.in | 94 + .../config/header-snippets/types_legacy.h.in | 242 + .../config/helper-snippets/DUK_F_AIX.h.in | 5 + .../config/helper-snippets/DUK_F_AMIGAOS.h.in | 6 + .../config/helper-snippets/DUK_F_ANDROID.h.in | 3 + .../config/helper-snippets/DUK_F_APPLE.h.in | 4 + .../config/helper-snippets/DUK_F_ARM.h.in | 9 + .../config/helper-snippets/DUK_F_BCC.h.in | 4 + .../config/helper-snippets/DUK_F_BSD.h.in | 5 + .../config/helper-snippets/DUK_F_C99.h.in | 5 + .../config/helper-snippets/DUK_F_CLANG.h.in | 4 + .../config/helper-snippets/DUK_F_CPP.h.in | 5 + .../config/helper-snippets/DUK_F_CPP11.h.in | 5 + .../config/helper-snippets/DUK_F_CYGWIN.h.in | 4 + .../config/helper-snippets/DUK_F_DURANGO.h.in | 4 + .../helper-snippets/DUK_F_EMSCRIPTEN.h.in | 4 + .../helper-snippets/DUK_F_FLASHPLAYER.h.in | 4 + .../config/helper-snippets/DUK_F_FREEBSD.h.in | 4 + .../config/helper-snippets/DUK_F_GCC.h.in | 10 + .../config/helper-snippets/DUK_F_HPUX.h.in | 7 + .../config/helper-snippets/DUK_F_LINUX.h.in | 4 + .../config/helper-snippets/DUK_F_M68K.h.in | 6 + .../config/helper-snippets/DUK_F_MINGW.h.in | 4 + .../config/helper-snippets/DUK_F_MINT.h.in | 4 + .../config/helper-snippets/DUK_F_MIPS.h.in | 14 + .../config/helper-snippets/DUK_F_MSVC.h.in | 15 + .../config/helper-snippets/DUK_F_NETBSD.h.in | 4 + .../helper-snippets/DUK_F_NO_STDINT_H.h.in | 10 + .../config/helper-snippets/DUK_F_OPENBSD.h.in | 4 + .../config/helper-snippets/DUK_F_ORBIS.h.in | 4 + .../config/helper-snippets/DUK_F_POSIX.h.in | 4 + .../config/helper-snippets/DUK_F_PPC.h.in | 9 + .../config/helper-snippets/DUK_F_QNX.h.in | 4 + .../config/helper-snippets/DUK_F_SPARC.h.in | 9 + .../config/helper-snippets/DUK_F_SUN.h.in | 12 + .../config/helper-snippets/DUK_F_SUPERH.h.in | 9 + .../helper-snippets/DUK_F_TINSPIRE.h.in | 4 + .../config/helper-snippets/DUK_F_TINYC.h.in | 5 + .../config/helper-snippets/DUK_F_TOS.h.in | 6 + .../config/helper-snippets/DUK_F_UCLIBC.h.in | 4 + .../helper-snippets/DUK_F_ULL_CONSTS.h.in | 9 + .../config/helper-snippets/DUK_F_UNIX.h.in | 5 + .../config/helper-snippets/DUK_F_VBCC.h.in | 4 + .../config/helper-snippets/DUK_F_WINDOWS.h.in | 10 + .../config/helper-snippets/DUK_F_X86.h.in | 26 + .../config/other-defines/c_types.yaml | 175 + .../config/other-defines/other_defines.yaml | 32 + .../other-defines/platform_functions.yaml | 57 + lib/duktape-2.2.1/config/platforms.yaml | 85 + .../config/platforms/platform_aix.h.in | 12 + .../config/platforms/platform_amigaos.h.in | 26 + .../config/platforms/platform_apple.h.in | 25 + .../config/platforms/platform_cygwin.h.in | 15 + .../config/platforms/platform_durango.h.in | 32 + .../config/platforms/platform_emscripten.h.in | 29 + .../platforms/platform_flashplayer.h.in | 14 + .../config/platforms/platform_generic.h.in | 18 + .../config/platforms/platform_genericbsd.h.in | 11 + .../platforms/platform_genericunix.h.in | 7 + .../config/platforms/platform_hpux.h.in | 13 + .../config/platforms/platform_linux.h.in | 33 + .../config/platforms/platform_openbsd.h.in | 12 + .../config/platforms/platform_orbis.h.in | 12 + .../config/platforms/platform_posix.h.in | 11 + .../config/platforms/platform_qnx.h.in | 16 + .../config/platforms/platform_solaris.h.in | 21 + .../config/platforms/platform_tinspire.h.in | 14 + .../config/platforms/platform_tos.h.in | 12 + .../config/platforms/platform_windows.h.in | 59 + lib/duktape-2.2.1/config/tags.yaml | 96 + lib/duktape-2.2.1/debugger/Makefile | 101 + lib/duktape-2.2.1/debugger/README.rst | 383 + .../debugger/duk_classnames.yaml | 32 + lib/duktape-2.2.1/debugger/duk_debug.js | 2491 + .../debugger/duk_debug_meta.json | 1901 + lib/duktape-2.2.1/debugger/duk_debug_proxy.js | 1044 + .../debugger/duk_debugcommands.yaml | 52 + .../debugger/duk_debugerrors.yaml | 6 + lib/duktape-2.2.1/debugger/duk_opcodes.yaml | 1049 + lib/duktape-2.2.1/debugger/package.json | 27 + lib/duktape-2.2.1/debugger/static/index.html | 96 + lib/duktape-2.2.1/debugger/static/style.css | 517 + lib/duktape-2.2.1/debugger/static/webui.js | 808 + lib/duktape-2.2.1/duk_dist_meta.json | 9 + lib/duktape-2.2.1/examples/README.rst | 10 + .../examples/alloc-hybrid/README.rst | 10 + .../examples/alloc-hybrid/duk_alloc_hybrid.c | 294 + .../examples/alloc-hybrid/duk_alloc_hybrid.h | 11 + .../examples/alloc-logging/README.rst | 7 + .../alloc-logging/duk_alloc_logging.c | 139 + .../alloc-logging/duk_alloc_logging.h | 10 + .../examples/alloc-logging/log2gnuplot.py | 41 + .../examples/alloc-torture/README.rst | 10 + .../alloc-torture/duk_alloc_torture.c | 183 + .../alloc-torture/duk_alloc_torture.h | 10 + lib/duktape-2.2.1/examples/cmdline/README.rst | 6 + .../examples/cmdline/duk_cmdline.c | 1560 + .../examples/cmdline/duk_cmdline.h | 16 + .../examples/cmdline/duk_cmdline_lowmem.c | 1016 + .../examples/codepage-conv/README.rst | 8 + .../codepage-conv/duk_codepage_conv.c | 54 + .../codepage-conv/duk_codepage_conv.h | 8 + .../examples/codepage-conv/test.c | 298 + lib/duktape-2.2.1/examples/coffee/README.rst | 10 + .../examples/coffee/globals.coffee | 7 + .../examples/coffee/hello.coffee | 2 + .../examples/coffee/mandel.coffee | 28 + .../examples/cpp-exceptions/README.rst | 29 + .../cpp-exceptions/cpp_exceptions.cpp | 311 + .../examples/debug-trans-dvalue/Makefile | 16 + .../examples/debug-trans-dvalue/README.rst | 8 + .../debug-trans-dvalue/duk_trans_dvalue.c | 1241 + .../debug-trans-dvalue/duk_trans_dvalue.h | 113 + .../examples/debug-trans-dvalue/test.c | 248 + .../examples/debug-trans-socket/README.rst | 17 + .../debug-trans-socket/duk_trans_socket.h | 15 + .../duk_trans_socket_unix.c | 364 + .../duk_trans_socket_windows.c | 419 + .../examples/dummy-date-provider/README.rst | 5 + .../dummy-date-provider/dummy_date_provider.c | 27 + lib/duktape-2.2.1/examples/eval/README.rst | 5 + lib/duktape-2.2.1/examples/eval/eval.c | 62 + .../examples/eventloop/README.rst | 76 + .../examples/eventloop/basic-test.js | 17 + .../examples/eventloop/c_eventloop.c | 620 + .../examples/eventloop/c_eventloop.js | 179 + .../examples/eventloop/client-socket-test.js | 24 + .../examples/eventloop/curses-timers.js | 79 + .../examples/eventloop/ecma_eventloop.js | 466 + lib/duktape-2.2.1/examples/eventloop/fileio.c | 84 + lib/duktape-2.2.1/examples/eventloop/main.c | 276 + .../examples/eventloop/ncurses.c | 105 + lib/duktape-2.2.1/examples/eventloop/poll.c | 111 + .../examples/eventloop/server-socket-test.js | 34 + lib/duktape-2.2.1/examples/eventloop/socket.c | 286 + lib/duktape-2.2.1/examples/guide/README.rst | 5 + lib/duktape-2.2.1/examples/guide/fib.js | 16 + lib/duktape-2.2.1/examples/guide/prime.js | 32 + lib/duktape-2.2.1/examples/guide/primecheck.c | 81 + lib/duktape-2.2.1/examples/guide/process.js | 12 + .../examples/guide/processlines.c | 78 + lib/duktape-2.2.1/examples/guide/uppercase.c | 42 + lib/duktape-2.2.1/examples/hello/README.rst | 5 + lib/duktape-2.2.1/examples/hello/hello.c | 46 + .../examples/jxpretty/README.rst | 5 + .../examples/jxpretty/jxpretty.c | 76 + lib/duktape-2.2.1/examples/sandbox/README.rst | 5 + lib/duktape-2.2.1/examples/sandbox/sandbox.c | 266 + lib/duktape-2.2.1/extras/README.rst | 13 + lib/duktape-2.2.1/extras/alloc-pool/Makefile | 41 + .../extras/alloc-pool/README.rst | 38 + .../extras/alloc-pool/duk_alloc_pool.c | 612 + .../extras/alloc-pool/duk_alloc_pool.h | 223 + .../extras/alloc-pool/ptrcomp.yaml | 16 + .../extras/alloc-pool/ptrcomp_fixup.h | 2 + lib/duktape-2.2.1/extras/alloc-pool/test.c | 114 + lib/duktape-2.2.1/extras/console/Makefile | 11 + lib/duktape-2.2.1/extras/console/README.rst | 30 + .../extras/console/duk_console.c | 163 + .../extras/console/duk_console.h | 14 + lib/duktape-2.2.1/extras/console/test.c | 30 + .../extras/duk-v1-compat/Makefile | 6 + .../extras/duk-v1-compat/README.rst | 25 + .../extras/duk-v1-compat/duk_v1_compat.c | 131 + .../extras/duk-v1-compat/duk_v1_compat.h | 28 + lib/duktape-2.2.1/extras/duk-v1-compat/test.c | 104 + .../extras/duk-v1-compat/test_compile1.js | 3 + .../extras/duk-v1-compat/test_compile2.js | 3 + .../extras/duk-v1-compat/test_eval1.js | 4 + .../extras/duk-v1-compat/test_eval2.js | 4 + lib/duktape-2.2.1/extras/logging/Makefile | 12 + lib/duktape-2.2.1/extras/logging/README.rst | 33 + .../extras/logging/duk_logging.c | 380 + .../extras/logging/duk_logging.h | 20 + lib/duktape-2.2.1/extras/logging/test.c | 56 + .../extras/minimal-printf/Makefile | 5 + .../extras/minimal-printf/README.rst | 116 + .../minimal-printf/duk_minimal_printf.c | 312 + .../minimal-printf/duk_minimal_printf.h | 12 + .../extras/minimal-printf/test.c | 190 + .../extras/module-duktape/Makefile | 14 + .../extras/module-duktape/README.rst | 31 + .../module-duktape/duk_module_duktape.c | 471 + .../module-duktape/duk_module_duktape.h | 14 + .../extras/module-duktape/test.c | 55 + lib/duktape-2.2.1/extras/module-node/Makefile | 19 + .../extras/module-node/README.rst | 89 + .../extras/module-node/duk_module_node.c | 333 + .../extras/module-node/duk_module_node.h | 9 + lib/duktape-2.2.1/extras/module-node/test.c | 103 + lib/duktape-2.2.1/extras/print-alert/Makefile | 6 + .../extras/print-alert/README.rst | 27 + .../extras/print-alert/duk_print_alert.c | 127 + .../extras/print-alert/duk_print_alert.h | 10 + lib/duktape-2.2.1/extras/print-alert/test.c | 30 + lib/duktape-2.2.1/licenses/commonjs.txt | 2 + lib/duktape-2.2.1/licenses/lua.txt | 1 + lib/duktape-2.2.1/licenses/murmurhash2.txt | 21 + lib/duktape-2.2.1/licenses/splitmix64.txt | 7 + .../licenses/xoroshiro128plus.txt | 7 + lib/duktape-2.2.1/mandel.js | 53 + .../polyfills/console-minimal.js | 20 + lib/duktape-2.2.1/polyfills/duktape-buffer.js | 53 + .../duktape-error-setter-nonwritable.js | 20 + .../duktape-error-setter-writable.js | 19 + .../polyfills/duktape-isfastint.js | 38 + lib/duktape-2.2.1/polyfills/global.js | 15 + lib/duktape-2.2.1/polyfills/object-assign.js | 45 + .../object-prototype-definegetter.js | 14 + .../object-prototype-definesetter.js | 14 + .../polyfills/performance-now.js | 25 + .../src-input/SpecialCasing-8bit.txt | 1 + lib/duktape-2.2.1/src-input/SpecialCasing.txt | 281 + .../src-input/UnicodeData-8bit.txt | 256 + lib/duktape-2.2.1/src-input/UnicodeData.txt | 30592 +++++ lib/duktape-2.2.1/src-input/builtins.yaml | 5391 + .../src-input/duk_alloc_default.c | 34 + lib/duktape-2.2.1/src-input/duk_api_buffer.c | 70 + .../src-input/duk_api_bytecode.c | 765 + lib/duktape-2.2.1/src-input/duk_api_call.c | 519 + lib/duktape-2.2.1/src-input/duk_api_codec.c | 657 + lib/duktape-2.2.1/src-input/duk_api_compile.c | 171 + lib/duktape-2.2.1/src-input/duk_api_debug.c | 258 + lib/duktape-2.2.1/src-input/duk_api_heap.c | 205 + lib/duktape-2.2.1/src-input/duk_api_inspect.c | 229 + .../src-input/duk_api_internal.h | 348 + lib/duktape-2.2.1/src-input/duk_api_memory.c | 80 + lib/duktape-2.2.1/src-input/duk_api_object.c | 831 + lib/duktape-2.2.1/src-input/duk_api_stack.c | 6588 ++ lib/duktape-2.2.1/src-input/duk_api_string.c | 376 + lib/duktape-2.2.1/src-input/duk_api_time.c | 110 + lib/duktape-2.2.1/src-input/duk_bi_array.c | 1611 + lib/duktape-2.2.1/src-input/duk_bi_boolean.c | 69 + lib/duktape-2.2.1/src-input/duk_bi_buffer.c | 2908 + lib/duktape-2.2.1/src-input/duk_bi_date.c | 1724 + .../src-input/duk_bi_date_unix.c | 325 + .../src-input/duk_bi_date_windows.c | 183 + lib/duktape-2.2.1/src-input/duk_bi_duktape.c | 158 + lib/duktape-2.2.1/src-input/duk_bi_encoding.c | 531 + lib/duktape-2.2.1/src-input/duk_bi_error.c | 387 + lib/duktape-2.2.1/src-input/duk_bi_function.c | 442 + lib/duktape-2.2.1/src-input/duk_bi_global.c | 724 + lib/duktape-2.2.1/src-input/duk_bi_json.c | 3248 + lib/duktape-2.2.1/src-input/duk_bi_math.c | 518 + lib/duktape-2.2.1/src-input/duk_bi_number.c | 240 + lib/duktape-2.2.1/src-input/duk_bi_object.c | 805 + .../src-input/duk_bi_performance.c | 31 + lib/duktape-2.2.1/src-input/duk_bi_pointer.c | 75 + lib/duktape-2.2.1/src-input/duk_bi_promise.c | 44 + lib/duktape-2.2.1/src-input/duk_bi_protos.h | 81 + lib/duktape-2.2.1/src-input/duk_bi_proxy.c | 95 + lib/duktape-2.2.1/src-input/duk_bi_reflect.c | 97 + lib/duktape-2.2.1/src-input/duk_bi_regexp.c | 226 + lib/duktape-2.2.1/src-input/duk_bi_string.c | 1554 + lib/duktape-2.2.1/src-input/duk_bi_symbol.c | 170 + lib/duktape-2.2.1/src-input/duk_bi_thread.c | 312 + lib/duktape-2.2.1/src-input/duk_bi_thrower.c | 9 + lib/duktape-2.2.1/src-input/duk_dblunion.h | 423 + lib/duktape-2.2.1/src-input/duk_debug.h | 184 + .../src-input/duk_debug_fixedbuffer.c | 69 + .../src-input/duk_debug_macros.c | 88 + .../src-input/duk_debug_vsnprintf.c | 1041 + lib/duktape-2.2.1/src-input/duk_debugger.c | 2902 + lib/duktape-2.2.1/src-input/duk_debugger.h | 151 + lib/duktape-2.2.1/src-input/duk_error.h | 517 + .../src-input/duk_error_augment.c | 563 + .../src-input/duk_error_longjmp.c | 106 + .../src-input/duk_error_macros.c | 144 + lib/duktape-2.2.1/src-input/duk_error_misc.c | 174 + lib/duktape-2.2.1/src-input/duk_error_throw.c | 162 + lib/duktape-2.2.1/src-input/duk_exception.h | 18 + lib/duktape-2.2.1/src-input/duk_forwdecl.h | 132 + lib/duktape-2.2.1/src-input/duk_harray.h | 47 + lib/duktape-2.2.1/src-input/duk_hboundfunc.h | 40 + lib/duktape-2.2.1/src-input/duk_hbuffer.h | 325 + .../src-input/duk_hbuffer_alloc.c | 132 + lib/duktape-2.2.1/src-input/duk_hbuffer_ops.c | 76 + lib/duktape-2.2.1/src-input/duk_hbufobj.h | 142 + .../src-input/duk_hbufobj_misc.c | 20 + lib/duktape-2.2.1/src-input/duk_hcompfunc.h | 270 + lib/duktape-2.2.1/src-input/duk_heap.h | 686 + lib/duktape-2.2.1/src-input/duk_heap_alloc.c | 1195 + .../src-input/duk_heap_finalize.c | 445 + .../src-input/duk_heap_hashstring.c | 116 + .../src-input/duk_heap_markandsweep.c | 1374 + lib/duktape-2.2.1/src-input/duk_heap_memory.c | 363 + lib/duktape-2.2.1/src-input/duk_heap_misc.c | 181 + .../src-input/duk_heap_refcount.c | 829 + .../src-input/duk_heap_stringcache.c | 309 + .../src-input/duk_heap_stringtable.c | 983 + lib/duktape-2.2.1/src-input/duk_heaphdr.h | 305 + lib/duktape-2.2.1/src-input/duk_henv.h | 48 + lib/duktape-2.2.1/src-input/duk_hnatfunc.h | 32 + lib/duktape-2.2.1/src-input/duk_hobject.h | 998 + .../src-input/duk_hobject_alloc.c | 270 + .../src-input/duk_hobject_class.c | 129 + .../src-input/duk_hobject_enum.c | 699 + .../src-input/duk_hobject_misc.c | 52 + .../src-input/duk_hobject_pc2line.c | 244 + .../src-input/duk_hobject_props.c | 6087 + lib/duktape-2.2.1/src-input/duk_hproxy.h | 26 + lib/duktape-2.2.1/src-input/duk_hstring.h | 238 + .../src-input/duk_hstring_misc.c | 196 + lib/duktape-2.2.1/src-input/duk_hthread.h | 421 + .../src-input/duk_hthread_alloc.c | 59 + .../src-input/duk_hthread_builtins.c | 859 + .../src-input/duk_hthread_misc.c | 97 + .../src-input/duk_hthread_stacks.c | 407 + lib/duktape-2.2.1/src-input/duk_internal.h | 83 + lib/duktape-2.2.1/src-input/duk_jmpbuf.h | 24 + lib/duktape-2.2.1/src-input/duk_js.h | 110 + lib/duktape-2.2.1/src-input/duk_js_arith.c | 137 + lib/duktape-2.2.1/src-input/duk_js_bytecode.h | 482 + lib/duktape-2.2.1/src-input/duk_js_call.c | 2863 + lib/duktape-2.2.1/src-input/duk_js_compiler.c | 7981 ++ lib/duktape-2.2.1/src-input/duk_js_compiler.h | 227 + lib/duktape-2.2.1/src-input/duk_js_executor.c | 5176 + lib/duktape-2.2.1/src-input/duk_js_ops.c | 1431 + lib/duktape-2.2.1/src-input/duk_js_var.c | 1753 + lib/duktape-2.2.1/src-input/duk_json.h | 68 + lib/duktape-2.2.1/src-input/duk_lexer.c | 2437 + lib/duktape-2.2.1/src-input/duk_lexer.h | 438 + lib/duktape-2.2.1/src-input/duk_numconv.c | 2263 + lib/duktape-2.2.1/src-input/duk_numconv.h | 100 + lib/duktape-2.2.1/src-input/duk_refcount.h | 725 + lib/duktape-2.2.1/src-input/duk_regexp.h | 84 + .../src-input/duk_regexp_compiler.c | 1278 + .../src-input/duk_regexp_executor.c | 1024 + .../src-input/duk_replacements.c | 82 + .../src-input/duk_replacements.h | 29 + lib/duktape-2.2.1/src-input/duk_selftest.c | 636 + lib/duktape-2.2.1/src-input/duk_selftest.h | 15 + lib/duktape-2.2.1/src-input/duk_strings.h | 167 + lib/duktape-2.2.1/src-input/duk_tval.c | 142 + lib/duktape-2.2.1/src-input/duk_tval.h | 632 + lib/duktape-2.2.1/src-input/duk_unicode.h | 249 + .../src-input/duk_unicode_support.c | 1182 + .../src-input/duk_unicode_tables.c | 64 + lib/duktape-2.2.1/src-input/duk_util.h | 564 + .../src-input/duk_util_bitdecoder.c | 157 + .../src-input/duk_util_bitencoder.c | 43 + .../src-input/duk_util_bufwriter.c | 352 + .../src-input/duk_util_hashbytes.c | 57 + lib/duktape-2.2.1/src-input/duk_util_misc.c | 405 + .../src-input/duk_util_tinyrandom.c | 125 + lib/duktape-2.2.1/src-input/duktape.h.in | 1233 + lib/duktape-2.2.1/src-input/strings.yaml | 1237 + lib/duktape-2.2.1/src-noline/duk_config.h | 3672 + .../src-noline/duk_source_meta.json | 1821 + lib/duktape-2.2.1/src-noline/duktape.c | 95041 +++++++++++++++ lib/duktape-2.2.1/src-noline/duktape.h | 1349 + .../src-separate/duk_alloc_default.c | 34 + .../src-separate/duk_api_buffer.c | 70 + .../src-separate/duk_api_bytecode.c | 765 + lib/duktape-2.2.1/src-separate/duk_api_call.c | 519 + .../src-separate/duk_api_codec.c | 657 + .../src-separate/duk_api_compile.c | 171 + .../src-separate/duk_api_debug.c | 258 + lib/duktape-2.2.1/src-separate/duk_api_heap.c | 205 + .../src-separate/duk_api_inspect.c | 229 + .../src-separate/duk_api_internal.h | 348 + .../src-separate/duk_api_memory.c | 80 + .../src-separate/duk_api_object.c | 831 + .../src-separate/duk_api_stack.c | 6588 ++ .../src-separate/duk_api_string.c | 376 + lib/duktape-2.2.1/src-separate/duk_api_time.c | 110 + lib/duktape-2.2.1/src-separate/duk_bi_array.c | 1611 + .../src-separate/duk_bi_boolean.c | 69 + .../src-separate/duk_bi_buffer.c | 2908 + lib/duktape-2.2.1/src-separate/duk_bi_date.c | 1724 + .../src-separate/duk_bi_date_unix.c | 325 + .../src-separate/duk_bi_date_windows.c | 183 + .../src-separate/duk_bi_duktape.c | 158 + .../src-separate/duk_bi_encoding.c | 531 + lib/duktape-2.2.1/src-separate/duk_bi_error.c | 387 + .../src-separate/duk_bi_function.c | 442 + .../src-separate/duk_bi_global.c | 724 + lib/duktape-2.2.1/src-separate/duk_bi_json.c | 3248 + lib/duktape-2.2.1/src-separate/duk_bi_math.c | 518 + .../src-separate/duk_bi_number.c | 240 + .../src-separate/duk_bi_object.c | 805 + .../src-separate/duk_bi_performance.c | 31 + .../src-separate/duk_bi_pointer.c | 75 + .../src-separate/duk_bi_promise.c | 44 + .../src-separate/duk_bi_protos.h | 81 + lib/duktape-2.2.1/src-separate/duk_bi_proxy.c | 95 + .../src-separate/duk_bi_reflect.c | 97 + .../src-separate/duk_bi_regexp.c | 226 + .../src-separate/duk_bi_string.c | 1554 + .../src-separate/duk_bi_symbol.c | 170 + .../src-separate/duk_bi_thread.c | 312 + .../src-separate/duk_bi_thrower.c | 9 + lib/duktape-2.2.1/src-separate/duk_builtins.c | 800 + lib/duktape-2.2.1/src-separate/duk_builtins.h | 767 + lib/duktape-2.2.1/src-separate/duk_config.h | 3672 + lib/duktape-2.2.1/src-separate/duk_dblunion.h | 423 + lib/duktape-2.2.1/src-separate/duk_debug.h | 184 + .../src-separate/duk_debug_fixedbuffer.c | 69 + .../src-separate/duk_debug_macros.c | 88 + .../src-separate/duk_debug_vsnprintf.c | 1041 + lib/duktape-2.2.1/src-separate/duk_debugger.c | 2902 + lib/duktape-2.2.1/src-separate/duk_debugger.h | 151 + lib/duktape-2.2.1/src-separate/duk_error.h | 517 + .../src-separate/duk_error_augment.c | 563 + .../src-separate/duk_error_longjmp.c | 106 + .../src-separate/duk_error_macros.c | 144 + .../src-separate/duk_error_misc.c | 174 + .../src-separate/duk_error_throw.c | 162 + .../src-separate/duk_exception.h | 18 + lib/duktape-2.2.1/src-separate/duk_forwdecl.h | 132 + lib/duktape-2.2.1/src-separate/duk_harray.h | 47 + .../src-separate/duk_hboundfunc.h | 40 + lib/duktape-2.2.1/src-separate/duk_hbuffer.h | 325 + .../src-separate/duk_hbuffer_alloc.c | 132 + .../src-separate/duk_hbuffer_ops.c | 76 + lib/duktape-2.2.1/src-separate/duk_hbufobj.h | 142 + .../src-separate/duk_hbufobj_misc.c | 20 + .../src-separate/duk_hcompfunc.h | 270 + lib/duktape-2.2.1/src-separate/duk_heap.h | 686 + .../src-separate/duk_heap_alloc.c | 1195 + .../src-separate/duk_heap_finalize.c | 445 + .../src-separate/duk_heap_hashstring.c | 116 + .../src-separate/duk_heap_markandsweep.c | 1374 + .../src-separate/duk_heap_memory.c | 363 + .../src-separate/duk_heap_misc.c | 181 + .../src-separate/duk_heap_refcount.c | 829 + .../src-separate/duk_heap_stringcache.c | 309 + .../src-separate/duk_heap_stringtable.c | 983 + lib/duktape-2.2.1/src-separate/duk_heaphdr.h | 305 + lib/duktape-2.2.1/src-separate/duk_henv.h | 48 + lib/duktape-2.2.1/src-separate/duk_hnatfunc.h | 32 + lib/duktape-2.2.1/src-separate/duk_hobject.h | 998 + .../src-separate/duk_hobject_alloc.c | 270 + .../src-separate/duk_hobject_class.c | 129 + .../src-separate/duk_hobject_enum.c | 699 + .../src-separate/duk_hobject_misc.c | 52 + .../src-separate/duk_hobject_pc2line.c | 244 + .../src-separate/duk_hobject_props.c | 6087 + lib/duktape-2.2.1/src-separate/duk_hproxy.h | 26 + lib/duktape-2.2.1/src-separate/duk_hstring.h | 238 + .../src-separate/duk_hstring_misc.c | 196 + lib/duktape-2.2.1/src-separate/duk_hthread.h | 421 + .../src-separate/duk_hthread_alloc.c | 59 + .../src-separate/duk_hthread_builtins.c | 859 + .../src-separate/duk_hthread_misc.c | 97 + .../src-separate/duk_hthread_stacks.c | 407 + lib/duktape-2.2.1/src-separate/duk_internal.h | 83 + lib/duktape-2.2.1/src-separate/duk_jmpbuf.h | 24 + lib/duktape-2.2.1/src-separate/duk_js.h | 110 + lib/duktape-2.2.1/src-separate/duk_js_arith.c | 137 + .../src-separate/duk_js_bytecode.h | 482 + lib/duktape-2.2.1/src-separate/duk_js_call.c | 2863 + .../src-separate/duk_js_compiler.c | 7981 ++ .../src-separate/duk_js_compiler.h | 227 + .../src-separate/duk_js_executor.c | 5176 + lib/duktape-2.2.1/src-separate/duk_js_ops.c | 1431 + lib/duktape-2.2.1/src-separate/duk_js_var.c | 1753 + lib/duktape-2.2.1/src-separate/duk_json.h | 68 + lib/duktape-2.2.1/src-separate/duk_lexer.c | 2437 + lib/duktape-2.2.1/src-separate/duk_lexer.h | 438 + lib/duktape-2.2.1/src-separate/duk_numconv.c | 2263 + lib/duktape-2.2.1/src-separate/duk_numconv.h | 100 + lib/duktape-2.2.1/src-separate/duk_refcount.h | 725 + lib/duktape-2.2.1/src-separate/duk_regexp.h | 84 + .../src-separate/duk_regexp_compiler.c | 1278 + .../src-separate/duk_regexp_executor.c | 1024 + .../src-separate/duk_replacements.c | 82 + .../src-separate/duk_replacements.h | 29 + lib/duktape-2.2.1/src-separate/duk_selftest.c | 636 + lib/duktape-2.2.1/src-separate/duk_selftest.h | 15 + .../src-separate/duk_source_meta.json | 1149 + lib/duktape-2.2.1/src-separate/duk_strings.h | 167 + lib/duktape-2.2.1/src-separate/duk_tval.c | 142 + lib/duktape-2.2.1/src-separate/duk_tval.h | 632 + lib/duktape-2.2.1/src-separate/duk_unicode.h | 289 + .../src-separate/duk_unicode_support.c | 1182 + .../src-separate/duk_unicode_tables.c | 6164 + lib/duktape-2.2.1/src-separate/duk_util.h | 564 + .../src-separate/duk_util_bitdecoder.c | 157 + .../src-separate/duk_util_bitencoder.c | 43 + .../src-separate/duk_util_bufwriter.c | 352 + .../src-separate/duk_util_hashbytes.c | 57 + .../src-separate/duk_util_misc.c | 405 + .../src-separate/duk_util_tinyrandom.c | 125 + lib/duktape-2.2.1/src-separate/duktape.h | 1349 + lib/duktape-2.2.1/src/duk_config.h | 3672 + lib/duktape-2.2.1/src/duk_source_meta.json | 1821 + lib/duktape-2.2.1/src/duktape.c | 95175 ++++++++++++++++ lib/duktape-2.2.1/src/duktape.h | 1349 + lib/duktape-2.2.1/tools/combine_src.py | 271 + lib/duktape-2.2.1/tools/configure.py | 993 + .../tools/create_spdx_license.py | 246 + .../tools/duk_meta_to_strarray.py | 49 + lib/duktape-2.2.1/tools/dukutil.py | 300 + lib/duktape-2.2.1/tools/dump_bytecode.py | 133 + lib/duktape-2.2.1/tools/extract_caseconv.py | 733 + lib/duktape-2.2.1/tools/extract_chars.py | 385 + .../tools/extract_unique_options.py | 41 + lib/duktape-2.2.1/tools/genbuiltins.py | 3202 + lib/duktape-2.2.1/tools/genconfig.py | 1522 + lib/duktape-2.2.1/tools/json2yaml.py | 5 + lib/duktape-2.2.1/tools/merge_debug_meta.py | 48 + .../tools/prepare_unicode_data.py | 51 + .../tools/resolve_combined_lineno.py | 26 + lib/duktape-2.2.1/tools/scan_strings.py | 135 + .../tools/scan_used_stridx_bidx.py | 58 + lib/duktape-2.2.1/tools/yaml2json.py | 4 + lib/imguicolortextedit | 1 + lib/whereami | 1 + misc-targets.mk | 43 + 1294 files changed, 587126 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 0000tri/.gitignore create mode 100644 0000tri/0_frag.glsl create mode 100644 0000tri/0_vert.glsl create mode 100644 0000tri/Makefile create mode 100644 0000tri/data.h create mode 100644 0000tri/data_bulk.c create mode 100644 0000tri/data_dynamic.c.in create mode 100644 0000tri/libdata.c create mode 100644 0000tri/vulkan.c create mode 100644 0001uniform-buffer-object.diff create mode 100644 0001uniform-buffer-object/.gitignore create mode 100644 0001uniform-buffer-object/0_frag.glsl create mode 100644 0001uniform-buffer-object/0_vert.glsl create mode 100644 0001uniform-buffer-object/Makefile create mode 100644 0001uniform-buffer-object/data.h create mode 100644 0001uniform-buffer-object/data_bulk.c create mode 100644 0001uniform-buffer-object/data_bulk.h create mode 100644 0001uniform-buffer-object/data_dynamic.c.in create mode 100644 0001uniform-buffer-object/libdata.c create mode 100644 0001uniform-buffer-object/vulkan.c create mode 100644 0002lighting.diff create mode 100644 0002lighting/.gitignore create mode 100644 0002lighting/0_frag.glsl create mode 100644 0002lighting/0_vert.glsl create mode 100644 0002lighting/Makefile create mode 100644 0002lighting/data.h create mode 100644 0002lighting/data_bulk.c create mode 100644 0002lighting/data_bulk.h create mode 100644 0002lighting/data_dynamic.c.in create mode 100644 0002lighting/libdata.c create mode 100644 0002lighting/vulkan.c create mode 100644 0003index-buffer.diff create mode 100644 0003index-buffer/.gitignore create mode 100644 0003index-buffer/0_frag.glsl create mode 100644 0003index-buffer/0_vert.glsl create mode 100644 0003index-buffer/Makefile create mode 100644 0003index-buffer/data.h create mode 100644 0003index-buffer/data_bulk.c create mode 100644 0003index-buffer/data_bulk.h create mode 100644 0003index-buffer/data_dynamic.c.in create mode 100644 0003index-buffer/libdata.c create mode 100644 0003index-buffer/vulkan.c create mode 100644 0004cube.diff create mode 100644 0004cube/.gitignore create mode 100644 0004cube/0_frag.glsl create mode 100644 0004cube/0_vert.glsl create mode 100644 0004cube/Makefile create mode 100644 0004cube/data.h create mode 100644 0004cube/data_bulk.c create mode 100644 0004cube/data_bulk.h create mode 100644 0004cube/data_dynamic.c.in create mode 100644 0004cube/libdata.c create mode 100644 0004cube/vulkan.c create mode 100644 0005texture.diff create mode 100644 0005texture/.gitignore create mode 100644 0005texture/0_frag.glsl create mode 100644 0005texture/0_vert.glsl create mode 100644 0005texture/Makefile create mode 100644 0005texture/data.h create mode 100644 0005texture/data_bulk.c create mode 100644 0005texture/data_bulk.h create mode 100644 0005texture/data_dynamic.c.in create mode 100644 0005texture/libdata.c create mode 100644 0005texture/vulkan.c create mode 100644 0006multi-model.diff create mode 100644 0006multi-model/.gitignore create mode 100644 0006multi-model/0_frag.glsl create mode 100644 0006multi-model/0_vert.glsl create mode 100644 0006multi-model/Makefile create mode 100644 0006multi-model/data.h create mode 100644 0006multi-model/data_bulk.c create mode 100644 0006multi-model/data_bulk.h create mode 100644 0006multi-model/data_dynamic.c.in create mode 100644 0006multi-model/libdata.c create mode 100644 0006multi-model/vulkan.c create mode 100644 0007shared-ubo.diff create mode 100644 0007shared-ubo/.gitignore create mode 100644 0007shared-ubo/0_frag.glsl create mode 100644 0007shared-ubo/0_vert.glsl create mode 100644 0007shared-ubo/Makefile create mode 100644 0007shared-ubo/data.h create mode 100644 0007shared-ubo/data_bulk.c create mode 100644 0007shared-ubo/data_bulk.h create mode 100644 0007shared-ubo/data_dynamic.c.in create mode 100644 0007shared-ubo/libdata.c create mode 100644 0007shared-ubo/vulkan.c create mode 100644 0008multi-material.diff create mode 100644 0008multi-material/.gitignore create mode 100644 0008multi-material/0_frag.glsl create mode 100644 0008multi-material/0_vert.glsl create mode 100644 0008multi-material/Makefile create mode 100644 0008multi-material/data.h create mode 100644 0008multi-material/data_bulk.c create mode 100644 0008multi-material/data_bulk.h create mode 100644 0008multi-material/data_dynamic.c.in create mode 100644 0008multi-material/libdata.c create mode 100644 0008multi-material/vulkan.c create mode 100644 0009modify-instances-count.diff create mode 100644 0009modify-instances-count/.gitignore create mode 100644 0009modify-instances-count/0_frag.glsl create mode 100644 0009modify-instances-count/0_vert.glsl create mode 100644 0009modify-instances-count/Makefile create mode 100644 0009modify-instances-count/data.h create mode 100644 0009modify-instances-count/data_bulk.c create mode 100644 0009modify-instances-count/data_bulk.h create mode 100644 0009modify-instances-count/data_dynamic.c.in create mode 100644 0009modify-instances-count/libdata.c create mode 100644 0009modify-instances-count/vulkan.c create mode 100644 0010tasks-during-render.diff create mode 100644 0010tasks-during-render/.gitignore create mode 100644 0010tasks-during-render/0_frag.glsl create mode 100644 0010tasks-during-render/0_vert.glsl create mode 100644 0010tasks-during-render/Makefile create mode 100644 0010tasks-during-render/data.h create mode 100644 0010tasks-during-render/data_bulk.c create mode 100644 0010tasks-during-render/data_bulk.h create mode 100644 0010tasks-during-render/data_dynamic.c.in create mode 100644 0010tasks-during-render/libdata.c create mode 100644 0010tasks-during-render/vulkan.c create mode 100644 0011disappearing-instances.diff create mode 100644 0011disappearing-instances/.gitignore create mode 100644 0011disappearing-instances/0_frag.glsl create mode 100644 0011disappearing-instances/0_vert.glsl create mode 100644 0011disappearing-instances/Makefile create mode 100644 0011disappearing-instances/data.h create mode 100644 0011disappearing-instances/data_bulk.c create mode 100644 0011disappearing-instances/data_bulk.h create mode 100644 0011disappearing-instances/data_dynamic.c.in create mode 100644 0011disappearing-instances/libdata.c create mode 100644 0011disappearing-instances/vulkan.c create mode 100644 0012raytrace.diff create mode 100644 0012raytrace/.gitignore create mode 100644 0012raytrace/0_frag.glsl create mode 100644 0012raytrace/0_vert.glsl create mode 100644 0012raytrace/Makefile create mode 100644 0012raytrace/data.h create mode 100644 0012raytrace/data_bulk.c create mode 100644 0012raytrace/data_bulk.h create mode 100644 0012raytrace/data_dynamic.c.in create mode 100644 0012raytrace/libdata.c create mode 100644 0012raytrace/vulkan.c create mode 100644 Makefile create mode 100644 archive/.gitignore create mode 100644 archive/cglm.min.js create mode 100644 include/cglm/affine-mat.h create mode 100644 include/cglm/affine.h create mode 100644 include/cglm/cam.h create mode 100644 include/cglm/cglm.h create mode 100644 include/cglm/common.h create mode 100644 include/cglm/euler.h create mode 100644 include/cglm/io.h create mode 100644 include/cglm/mat3.h create mode 100644 include/cglm/mat4.h create mode 100644 include/cglm/quat.h create mode 100644 include/cglm/simd/avx/affine.h create mode 100644 include/cglm/simd/avx/mat4.h create mode 100644 include/cglm/simd/intrin.h create mode 100644 include/cglm/simd/neon/mat4.h create mode 100644 include/cglm/simd/sse2/affine.h create mode 100644 include/cglm/simd/sse2/mat3.h create mode 100644 include/cglm/simd/sse2/mat4.h create mode 100644 include/cglm/simd/sse2/quat.h create mode 100644 include/cglm/types.h create mode 100644 include/cglm/util.h create mode 100644 include/cglm/vec3-ext.h create mode 100644 include/cglm/vec3.h create mode 100644 include/cglm/vec4-ext.h create mode 100644 include/cglm/vec4.h create mode 100644 include/cglm/version.h create mode 120000 include/cimgui.h create mode 120000 include/ctexteditor.h create mode 100644 include/duk_config.h create mode 120000 include/duk_module_duktape.h create mode 120000 include/duktape.h create mode 120000 include/imgui_impl_glfw_vulkan.h create mode 100644 include/list.h create mode 100644 include/spirv/unified1/spirv.h create mode 120000 include/whereami.h create mode 100644 lib/Makefile create mode 100644 lib/bin/.gitignore create mode 100644 lib/bin/Makefile create mode 120000 lib/bin/duk_cmdline.c create mode 120000 lib/bin/duk_cmdline.h create mode 120000 lib/bin/duk_print_alert.c create mode 120000 lib/bin/duk_print_alert.h create mode 120000 lib/cimgui create mode 100644 lib/cimgui-1.53.1/.gitignore create mode 100644 lib/cimgui-1.53.1/.gitmodules create mode 100644 lib/cimgui-1.53.1/.travis.yml create mode 100644 lib/cimgui-1.53.1/LICENSE create mode 100644 lib/cimgui-1.53.1/README.md create mode 100644 lib/cimgui-1.53.1/cimgui/.vscode/settings.json create mode 100644 lib/cimgui-1.53.1/cimgui/Makefile create mode 100644 lib/cimgui-1.53.1/cimgui/cimgui.cpp create mode 100644 lib/cimgui-1.53.1/cimgui/cimgui.h create mode 100644 lib/cimgui-1.53.1/cimgui/cimgui.sln create mode 100644 lib/cimgui-1.53.1/cimgui/cimgui.vcxproj create mode 100644 lib/cimgui-1.53.1/cimgui/cimgui.vcxproj.filters create mode 100644 lib/cimgui-1.53.1/cimgui/drawList.cpp create mode 100644 lib/cimgui-1.53.1/cimgui/fontAtlas.cpp create mode 100644 lib/cimgui-1.53.1/cimgui/listClipper.cpp create mode 100644 lib/cimgui-1.53.1/cimgui/test.c create mode 120000 lib/cimgui-1.53.1/imgui create mode 100644 lib/cimgui-1.53.1/imgui-1.53/.travis.yml create mode 100644 lib/cimgui-1.53.1/imgui-1.53/LICENSE.txt create mode 100644 lib/cimgui-1.53.1/imgui-1.53/README.md create mode 100644 lib/cimgui-1.53.1/imgui-1.53/TODO.txt create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/.gitignore create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/README.txt create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/README.md create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/.gitignore create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/README.md create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.m create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/LaunchScreen.xib create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/Main.storyboard create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.m create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_60@2x~iphone.png create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_60@3x~iphone.png create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_76@2x~ipad.png create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_76~ipad.png create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Info.plist create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.fsh create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.vsh create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_ex_icon.png create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_impl_ios.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_impl_ios.mm create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/main.m create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.m create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/icon_imgui_180x180.png create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/Contents.json create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Info.plist create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/main.m create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex.xcodeproj/project.pbxproj create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj.filters create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj.filters create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj.filters create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/imgui_examples_msvc2010.sln create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.c create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/glcorearb.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/COPYING.txt create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3native.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.c create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/data/app.icf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/marmalade_example.mkb create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/null_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/null_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/Makefile create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj.filters create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/Makefile create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj.filters create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/README.md create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/Makefile create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/README.md create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win32.bat create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win64.bat create mode 100755 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/gen_spv.sh create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.frag create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.vert create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/main.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Cousine-Regular.ttf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/DroidSans.ttf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Karla-Regular.ttf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/ProggyClean.ttf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/ProggyTiny.ttf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/README.txt create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Roboto-Medium.ttf create mode 100644 lib/cimgui-1.53.1/imgui-1.53/extra_fonts/binary_to_compressed_c.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/imconfig.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/imgui.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/imgui.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/imgui_demo.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/imgui_draw.cpp create mode 100644 lib/cimgui-1.53.1/imgui-1.53/imgui_internal.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/stb_rect_pack.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/stb_textedit.h create mode 100644 lib/cimgui-1.53.1/imgui-1.53/stb_truetype.h create mode 100644 lib/cimgui-1.53.1/menus-api.gif create mode 100644 lib/cimgui-1.53.1/screenshot.png create mode 120000 lib/duktape create mode 100644 lib/duktape-2.2.1/AUTHORS.rst create mode 100644 lib/duktape-2.2.1/LICENSE.txt create mode 100644 lib/duktape-2.2.1/Makefile.cmdline create mode 100644 lib/duktape-2.2.1/Makefile.codepage create mode 100644 lib/duktape-2.2.1/Makefile.coffee create mode 100644 lib/duktape-2.2.1/Makefile.dukdebug create mode 100644 lib/duktape-2.2.1/Makefile.eval create mode 100644 lib/duktape-2.2.1/Makefile.eventloop create mode 100644 lib/duktape-2.2.1/Makefile.hello create mode 100644 lib/duktape-2.2.1/Makefile.jxpretty create mode 100644 lib/duktape-2.2.1/Makefile.sandbox create mode 100644 lib/duktape-2.2.1/Makefile.sharedlibrary create mode 100644 lib/duktape-2.2.1/README.rst create mode 100644 lib/duktape-2.2.1/config/README.rst create mode 100644 lib/duktape-2.2.1/config/architectures.yaml create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_arm32.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_arm64.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_emscripten.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_generic.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_m68k.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_mips32.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_mips64.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_powerpc32.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_powerpc64.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_sparc32.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_sparc64.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_superh.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_x32.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_x64.h.in create mode 100644 lib/duktape-2.2.1/config/architectures/architecture_x86.h.in create mode 100644 lib/duktape-2.2.1/config/compilers.yaml create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_bcc.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_clang.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_emscripten.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_gcc.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_generic.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_msvc.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_tinyc.h.in create mode 100644 lib/duktape-2.2.1/config/compilers/compiler_vbcc.h.in create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_32BIT_PTRS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_64BIT_OPS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_4.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_8.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_BY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ARCH_STRING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_PROP_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ASSERTIONS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ATAN2_WORKAROUNDS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_CREATE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_THROW.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_AVOID_PLATFORM_FUNCPTRS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BASE64_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BOOLEAN_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BRANCH_HINTS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BROWSER_LIKE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BUFFEROBJECT_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BUFLEN16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BUILTIN_INITJS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BYTECODE_DUMP_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER_FORCED.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_ACTIVATION.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_CATCHER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_CALLSTACK_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_COMMONJS_MODULES.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_STRING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_INFINITY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_NAN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_COROUTINE_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_CPP_EXCEPTIONS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_DEC16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_ENC16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FMT_STRFTIME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FORMAT_STRING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_LOCAL_TZOFFSET.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_NOW.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_GETTIMEOFDAY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_TIME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS_SUBMS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PARSE_STRING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_GETDATE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_STRPTIME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_R.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_S.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS_NO_DST.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DDDPRINT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DDPRINT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_DUMPHEAP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_LOGGING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_PRINTALERT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_INSPECT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_PAUSE_UNCAUGHT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_THROW_NOTIFY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_TRANSPORT_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_BUFSIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_LEVEL.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_WRITE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DEEP_C_STACK.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_BE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LINKED_HEAP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_ME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_COLORS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_RDTSC.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_DUKTAPE_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ENCODING_BUILTINS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ERRCREATE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ERRTHROW.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_PROTO_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_SETPROTOTYPEOF.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_PROXY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_BRACES.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_SYNTAX.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_UNICODE_ESCAPE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES7.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES7_EXP_OPERATOR.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES8.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ES9.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_LIMITS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_BYTES.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_LINENUMBER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXAMPLE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_FUN_LOCAL.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_INDIRECT_BOUND_CHECK.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_PREFER_SIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_REGCONST_OPTIMIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_TIMEOUT_CHECK.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXPLICIT_NULL_INIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_FREE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_INTERN_CHECK.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FASTINT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FAST_REFCOUNT_DEFAULT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_HANDLER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_MAXLEN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FILE_IO.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_C99.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ONESIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ZEROSIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FULL_TVAL.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_DEC16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_ENC16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCTION_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_FILENAME_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_NAME_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GCC_PRAGMAS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GC_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GET_RANDOM_DOUBLE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BINDING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_DEC16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_ENC16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HEX_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_ADD.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_ADD.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PART.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PROP_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_1.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_2.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_3.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_ARRIDX.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_CLEN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_EXTDATA.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_LAZY_CLEN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_HTML_COMMENTS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_IDCHAR_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_INJECT_HEAP_ALLOC_ERROR.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_BE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_LE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_ME.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_COUNTER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_DEBUG_FIXUP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JC.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECNUMBER_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECSTRING_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DEC_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_EATWHITE_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_ENC_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_QUOTESTRING_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_STRINGIFY_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_JX.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_LEXER_SLIDING_WINDOW.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_LIGHTFUNC_BUILTINS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMAX.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_ROUND.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_MS_STRINGTABLE_RESIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NATIVE_CALL_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_MAP_TRAILER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_CALLER_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_STMT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_GETTER_KEY_ARGUMENT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_JSON_ESC_U2028_U2029.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_SETTER_KEY_ARGUMENT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NO_DOUBLE_ALIASING_SELFTEST.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_NUMBER_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_OBJECT_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_OBJSIZES16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_OCTAL_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_OS_STRING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL_POSSIBLE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_CLANG_ATTR.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_DUMMY_MEMBER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_GCC_ATTR.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_MSVC_PRAGMA.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_ABORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_EXIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_HANDLER.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_SEGFAULT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_DATE_COMPUTATION.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_ERRORS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_MATH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PC2LINE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PERFORMANCE_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_POW_NETBSD_WORKAROUND.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_POW_WORKAROUNDS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PREFER_SIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PROMISE_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_RDTSC.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT32.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REFERENCE_COUNTING.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REFLECT_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REFZERO_FINALIZER_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_BITMAP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_WORKAROUND.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_COMPILER_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_EXECUTOR_RECLIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_FPCLASSIFY.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISFINITE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISINF.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISNAN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_SIGNBIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_CLONE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_INHERIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_OBJECTS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_PTRCOMP_FIRST.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_STRINGS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SECTION_B.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SELF_TESTS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SETJMP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SHEBANG_COMMENTS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SHUFFLE_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SIGSETJMP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SOURCE_NONBMP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_DENSE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_SKIP_SHIFT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_DECL.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_UTF8_SOURCE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRING_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRLEN16.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN_SIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_GROW_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MAXSIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MINSIZE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PROBE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PTRCOMP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_RESIZE_CHECK_MASK.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_SHRINK_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_SYMBOL_BUILTIN.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_TAILCALL.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_TARGET_INFO.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACKS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACK_DEPTH.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_UNALIGNED_ACCESSES_POSSIBLE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_UNDERSCORE_SETJMP.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_UNION_INITIALIZERS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_USER_DECLARE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_USER_INITJS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_GROW_SHIFT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_LIMIT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_UNSAFE.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VARIADIC_MACROS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_ERRORS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_EXECUTOR_ERRORS.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_VOLUNTARY_GC.yaml create mode 100644 lib/duktape-2.2.1/config/config-options/DUK_USE_ZERO_BUFFER_DATA.yaml create mode 100644 lib/duktape-2.2.1/config/examples/compliance.yaml create mode 100644 lib/duktape-2.2.1/config/examples/debugger_support.yaml create mode 100644 lib/duktape-2.2.1/config/examples/disable_bufferobjects.yaml create mode 100644 lib/duktape-2.2.1/config/examples/disable_es6.yaml create mode 100644 lib/duktape-2.2.1/config/examples/enable_debug_print0.yaml create mode 100644 lib/duktape-2.2.1/config/examples/enable_debug_print1.yaml create mode 100644 lib/duktape-2.2.1/config/examples/enable_debug_print2.yaml create mode 100644 lib/duktape-2.2.1/config/examples/enable_fastint.yaml create mode 100644 lib/duktape-2.2.1/config/examples/low_memory.yaml create mode 100644 lib/duktape-2.2.1/config/examples/low_memory_strip.yaml create mode 100644 lib/duktape-2.2.1/config/examples/performance_sensitive.yaml create mode 100644 lib/duktape-2.2.1/config/examples/rom_builtins.yaml create mode 100644 lib/duktape-2.2.1/config/examples/security_sensitive.yaml create mode 100644 lib/duktape-2.2.1/config/examples/shallow_c_stack.yaml create mode 100644 lib/duktape-2.2.1/config/examples/timing_sensitive.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_ASSERTIONS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFFEROBJECT_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFLEN16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_DEC16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_ENC16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDDPRINT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDPRINT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_DUMPHEAP.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_LOGGING.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_PRINTALERT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_TRANSPORT_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG_BUFSIZE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DECLARE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEEP_C_STACK.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DLL_BUILD.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_COLORS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_RDTSC.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXAMPLE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXEC_TIMEOUT_CHECK.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTERNAL_STRINGS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_FREE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_INTERN_CHECK.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FASTINT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_ALIGN.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_BYTEORDER.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_DEC16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_ENC16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_GC_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_HAVE_CUSTOM_H.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_DEC16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_ENC16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_INTERRUPT_COUNTER.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_JSON_STRINGIFY_FASTPATH.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_LIGHTFUNC_BUILTINS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_AUGMENT_ERRORS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BROWSER_LIKE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BUFFEROBJECT_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BYTECODE_DUMP_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_COMMONJS_MODULES.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_PROXY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FILE_IO.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FUNC_STMT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JC.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONC.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONX.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JX.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MARK_AND_SWEEP.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MS_STRINGTABLE_RESIZE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_FUNC_STMT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OCTAL_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PACKED_TVAL.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PC2LINE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REFERENCE_COUNTING.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REGEXP_SUPPORT.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SECTION_B.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SOURCE_NONBMP.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_STRICT_DECL.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_TRACEBACKS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VERBOSE_ERRORS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VOLUNTARY_GC.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ZERO_BUFFER_DATA.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_OBJSIZES16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_PANIC_HANDLER.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_REFCOUNT16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_SEGFAULT_ON_PANIC.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_SELF_TESTS.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_SETJMP.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_SHUFFLE_TORTURE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_SIGSETJMP.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRHASH16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRICT_UTF8_SOURCE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRLEN16.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN_SIZE.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_TARGET_INFO.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_TRACEBACK_DEPTH.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_UNDERSCORE_SETJMP.yaml create mode 100644 lib/duktape-2.2.1/config/feature-options/DUK_OPT_USER_INITJS.yaml create mode 100644 lib/duktape-2.2.1/config/header-snippets/64bitops.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/alignment_fillin.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/architecture_fillins.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/byteorder_derived.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/byteorder_fillin.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/compiler_fillins.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/cpp_exception_sanity.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/date_provider.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/gcc_clang_visibility.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/inline_workaround.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/msvc_visibility.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/object_layout.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/packed_tval_fillin.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/platform_cppextras.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/platform_fillins.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/platform_sharedincludes.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/reject_fast_math.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/types1.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/types2.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/types_c99.h.in create mode 100644 lib/duktape-2.2.1/config/header-snippets/types_legacy.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_AIX.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_AMIGAOS.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_ANDROID.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_APPLE.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_ARM.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_BCC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_BSD.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_C99.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_CLANG.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP11.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_CYGWIN.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_DURANGO.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_EMSCRIPTEN.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_FLASHPLAYER.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_FREEBSD.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_GCC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_HPUX.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_LINUX.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_M68K.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINGW.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINT.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_MIPS.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_MSVC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_NETBSD.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_NO_STDINT_H.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_OPENBSD.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_ORBIS.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_POSIX.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_PPC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_QNX.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_SPARC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUN.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUPERH.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINSPIRE.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINYC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_TOS.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_UCLIBC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_ULL_CONSTS.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_UNIX.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_VBCC.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_WINDOWS.h.in create mode 100644 lib/duktape-2.2.1/config/helper-snippets/DUK_F_X86.h.in create mode 100644 lib/duktape-2.2.1/config/other-defines/c_types.yaml create mode 100644 lib/duktape-2.2.1/config/other-defines/other_defines.yaml create mode 100644 lib/duktape-2.2.1/config/other-defines/platform_functions.yaml create mode 100644 lib/duktape-2.2.1/config/platforms.yaml create mode 100644 lib/duktape-2.2.1/config/platforms/platform_aix.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_amigaos.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_apple.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_cygwin.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_durango.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_emscripten.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_flashplayer.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_generic.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_genericbsd.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_genericunix.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_hpux.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_linux.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_openbsd.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_orbis.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_posix.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_qnx.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_solaris.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_tinspire.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_tos.h.in create mode 100644 lib/duktape-2.2.1/config/platforms/platform_windows.h.in create mode 100644 lib/duktape-2.2.1/config/tags.yaml create mode 100644 lib/duktape-2.2.1/debugger/Makefile create mode 100644 lib/duktape-2.2.1/debugger/README.rst create mode 100644 lib/duktape-2.2.1/debugger/duk_classnames.yaml create mode 100644 lib/duktape-2.2.1/debugger/duk_debug.js create mode 100644 lib/duktape-2.2.1/debugger/duk_debug_meta.json create mode 100644 lib/duktape-2.2.1/debugger/duk_debug_proxy.js create mode 100644 lib/duktape-2.2.1/debugger/duk_debugcommands.yaml create mode 100644 lib/duktape-2.2.1/debugger/duk_debugerrors.yaml create mode 100644 lib/duktape-2.2.1/debugger/duk_opcodes.yaml create mode 100644 lib/duktape-2.2.1/debugger/package.json create mode 100644 lib/duktape-2.2.1/debugger/static/index.html create mode 100644 lib/duktape-2.2.1/debugger/static/style.css create mode 100644 lib/duktape-2.2.1/debugger/static/webui.js create mode 100644 lib/duktape-2.2.1/duk_dist_meta.json create mode 100644 lib/duktape-2.2.1/examples/README.rst create mode 100644 lib/duktape-2.2.1/examples/alloc-hybrid/README.rst create mode 100644 lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.c create mode 100644 lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.h create mode 100644 lib/duktape-2.2.1/examples/alloc-logging/README.rst create mode 100644 lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.c create mode 100644 lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.h create mode 100644 lib/duktape-2.2.1/examples/alloc-logging/log2gnuplot.py create mode 100644 lib/duktape-2.2.1/examples/alloc-torture/README.rst create mode 100644 lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.c create mode 100644 lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.h create mode 100644 lib/duktape-2.2.1/examples/cmdline/README.rst create mode 100644 lib/duktape-2.2.1/examples/cmdline/duk_cmdline.c create mode 100644 lib/duktape-2.2.1/examples/cmdline/duk_cmdline.h create mode 100644 lib/duktape-2.2.1/examples/cmdline/duk_cmdline_lowmem.c create mode 100644 lib/duktape-2.2.1/examples/codepage-conv/README.rst create mode 100644 lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.c create mode 100644 lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.h create mode 100644 lib/duktape-2.2.1/examples/codepage-conv/test.c create mode 100644 lib/duktape-2.2.1/examples/coffee/README.rst create mode 100644 lib/duktape-2.2.1/examples/coffee/globals.coffee create mode 100644 lib/duktape-2.2.1/examples/coffee/hello.coffee create mode 100644 lib/duktape-2.2.1/examples/coffee/mandel.coffee create mode 100644 lib/duktape-2.2.1/examples/cpp-exceptions/README.rst create mode 100644 lib/duktape-2.2.1/examples/cpp-exceptions/cpp_exceptions.cpp create mode 100644 lib/duktape-2.2.1/examples/debug-trans-dvalue/Makefile create mode 100644 lib/duktape-2.2.1/examples/debug-trans-dvalue/README.rst create mode 100644 lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.c create mode 100644 lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.h create mode 100644 lib/duktape-2.2.1/examples/debug-trans-dvalue/test.c create mode 100644 lib/duktape-2.2.1/examples/debug-trans-socket/README.rst create mode 100644 lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket.h create mode 100644 lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_unix.c create mode 100644 lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_windows.c create mode 100644 lib/duktape-2.2.1/examples/dummy-date-provider/README.rst create mode 100644 lib/duktape-2.2.1/examples/dummy-date-provider/dummy_date_provider.c create mode 100644 lib/duktape-2.2.1/examples/eval/README.rst create mode 100644 lib/duktape-2.2.1/examples/eval/eval.c create mode 100644 lib/duktape-2.2.1/examples/eventloop/README.rst create mode 100644 lib/duktape-2.2.1/examples/eventloop/basic-test.js create mode 100644 lib/duktape-2.2.1/examples/eventloop/c_eventloop.c create mode 100644 lib/duktape-2.2.1/examples/eventloop/c_eventloop.js create mode 100644 lib/duktape-2.2.1/examples/eventloop/client-socket-test.js create mode 100644 lib/duktape-2.2.1/examples/eventloop/curses-timers.js create mode 100644 lib/duktape-2.2.1/examples/eventloop/ecma_eventloop.js create mode 100644 lib/duktape-2.2.1/examples/eventloop/fileio.c create mode 100644 lib/duktape-2.2.1/examples/eventloop/main.c create mode 100644 lib/duktape-2.2.1/examples/eventloop/ncurses.c create mode 100644 lib/duktape-2.2.1/examples/eventloop/poll.c create mode 100644 lib/duktape-2.2.1/examples/eventloop/server-socket-test.js create mode 100644 lib/duktape-2.2.1/examples/eventloop/socket.c create mode 100644 lib/duktape-2.2.1/examples/guide/README.rst create mode 100644 lib/duktape-2.2.1/examples/guide/fib.js create mode 100644 lib/duktape-2.2.1/examples/guide/prime.js create mode 100644 lib/duktape-2.2.1/examples/guide/primecheck.c create mode 100644 lib/duktape-2.2.1/examples/guide/process.js create mode 100644 lib/duktape-2.2.1/examples/guide/processlines.c create mode 100644 lib/duktape-2.2.1/examples/guide/uppercase.c create mode 100644 lib/duktape-2.2.1/examples/hello/README.rst create mode 100644 lib/duktape-2.2.1/examples/hello/hello.c create mode 100644 lib/duktape-2.2.1/examples/jxpretty/README.rst create mode 100644 lib/duktape-2.2.1/examples/jxpretty/jxpretty.c create mode 100644 lib/duktape-2.2.1/examples/sandbox/README.rst create mode 100644 lib/duktape-2.2.1/examples/sandbox/sandbox.c create mode 100644 lib/duktape-2.2.1/extras/README.rst create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/Makefile create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/README.rst create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.c create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.h create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/ptrcomp.yaml create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/ptrcomp_fixup.h create mode 100644 lib/duktape-2.2.1/extras/alloc-pool/test.c create mode 100644 lib/duktape-2.2.1/extras/console/Makefile create mode 100644 lib/duktape-2.2.1/extras/console/README.rst create mode 100644 lib/duktape-2.2.1/extras/console/duk_console.c create mode 100644 lib/duktape-2.2.1/extras/console/duk_console.h create mode 100644 lib/duktape-2.2.1/extras/console/test.c create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/Makefile create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/README.rst create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.c create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.h create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/test.c create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/test_compile1.js create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/test_compile2.js create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/test_eval1.js create mode 100644 lib/duktape-2.2.1/extras/duk-v1-compat/test_eval2.js create mode 100644 lib/duktape-2.2.1/extras/logging/Makefile create mode 100644 lib/duktape-2.2.1/extras/logging/README.rst create mode 100644 lib/duktape-2.2.1/extras/logging/duk_logging.c create mode 100644 lib/duktape-2.2.1/extras/logging/duk_logging.h create mode 100644 lib/duktape-2.2.1/extras/logging/test.c create mode 100644 lib/duktape-2.2.1/extras/minimal-printf/Makefile create mode 100644 lib/duktape-2.2.1/extras/minimal-printf/README.rst create mode 100644 lib/duktape-2.2.1/extras/minimal-printf/duk_minimal_printf.c create mode 100644 lib/duktape-2.2.1/extras/minimal-printf/duk_minimal_printf.h create mode 100644 lib/duktape-2.2.1/extras/minimal-printf/test.c create mode 100644 lib/duktape-2.2.1/extras/module-duktape/Makefile create mode 100644 lib/duktape-2.2.1/extras/module-duktape/README.rst create mode 100644 lib/duktape-2.2.1/extras/module-duktape/duk_module_duktape.c create mode 100644 lib/duktape-2.2.1/extras/module-duktape/duk_module_duktape.h create mode 100644 lib/duktape-2.2.1/extras/module-duktape/test.c create mode 100644 lib/duktape-2.2.1/extras/module-node/Makefile create mode 100644 lib/duktape-2.2.1/extras/module-node/README.rst create mode 100644 lib/duktape-2.2.1/extras/module-node/duk_module_node.c create mode 100644 lib/duktape-2.2.1/extras/module-node/duk_module_node.h create mode 100644 lib/duktape-2.2.1/extras/module-node/test.c create mode 100644 lib/duktape-2.2.1/extras/print-alert/Makefile create mode 100644 lib/duktape-2.2.1/extras/print-alert/README.rst create mode 100644 lib/duktape-2.2.1/extras/print-alert/duk_print_alert.c create mode 100644 lib/duktape-2.2.1/extras/print-alert/duk_print_alert.h create mode 100644 lib/duktape-2.2.1/extras/print-alert/test.c create mode 100644 lib/duktape-2.2.1/licenses/commonjs.txt create mode 100644 lib/duktape-2.2.1/licenses/lua.txt create mode 100644 lib/duktape-2.2.1/licenses/murmurhash2.txt create mode 100644 lib/duktape-2.2.1/licenses/splitmix64.txt create mode 100644 lib/duktape-2.2.1/licenses/xoroshiro128plus.txt create mode 100644 lib/duktape-2.2.1/mandel.js create mode 100644 lib/duktape-2.2.1/polyfills/console-minimal.js create mode 100644 lib/duktape-2.2.1/polyfills/duktape-buffer.js create mode 100644 lib/duktape-2.2.1/polyfills/duktape-error-setter-nonwritable.js create mode 100644 lib/duktape-2.2.1/polyfills/duktape-error-setter-writable.js create mode 100644 lib/duktape-2.2.1/polyfills/duktape-isfastint.js create mode 100644 lib/duktape-2.2.1/polyfills/global.js create mode 100644 lib/duktape-2.2.1/polyfills/object-assign.js create mode 100644 lib/duktape-2.2.1/polyfills/object-prototype-definegetter.js create mode 100644 lib/duktape-2.2.1/polyfills/object-prototype-definesetter.js create mode 100644 lib/duktape-2.2.1/polyfills/performance-now.js create mode 100644 lib/duktape-2.2.1/src-input/SpecialCasing-8bit.txt create mode 100644 lib/duktape-2.2.1/src-input/SpecialCasing.txt create mode 100644 lib/duktape-2.2.1/src-input/UnicodeData-8bit.txt create mode 100644 lib/duktape-2.2.1/src-input/UnicodeData.txt create mode 100644 lib/duktape-2.2.1/src-input/builtins.yaml create mode 100644 lib/duktape-2.2.1/src-input/duk_alloc_default.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_buffer.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_bytecode.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_call.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_codec.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_compile.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_debug.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_heap.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_inspect.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_internal.h create mode 100644 lib/duktape-2.2.1/src-input/duk_api_memory.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_object.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_stack.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_string.c create mode 100644 lib/duktape-2.2.1/src-input/duk_api_time.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_array.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_boolean.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_buffer.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_date.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_date_unix.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_date_windows.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_duktape.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_encoding.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_error.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_function.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_global.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_json.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_math.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_number.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_object.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_performance.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_pointer.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_promise.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_protos.h create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_proxy.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_reflect.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_regexp.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_string.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_symbol.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_thread.c create mode 100644 lib/duktape-2.2.1/src-input/duk_bi_thrower.c create mode 100644 lib/duktape-2.2.1/src-input/duk_dblunion.h create mode 100644 lib/duktape-2.2.1/src-input/duk_debug.h create mode 100644 lib/duktape-2.2.1/src-input/duk_debug_fixedbuffer.c create mode 100644 lib/duktape-2.2.1/src-input/duk_debug_macros.c create mode 100644 lib/duktape-2.2.1/src-input/duk_debug_vsnprintf.c create mode 100644 lib/duktape-2.2.1/src-input/duk_debugger.c create mode 100644 lib/duktape-2.2.1/src-input/duk_debugger.h create mode 100644 lib/duktape-2.2.1/src-input/duk_error.h create mode 100644 lib/duktape-2.2.1/src-input/duk_error_augment.c create mode 100644 lib/duktape-2.2.1/src-input/duk_error_longjmp.c create mode 100644 lib/duktape-2.2.1/src-input/duk_error_macros.c create mode 100644 lib/duktape-2.2.1/src-input/duk_error_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_error_throw.c create mode 100644 lib/duktape-2.2.1/src-input/duk_exception.h create mode 100644 lib/duktape-2.2.1/src-input/duk_forwdecl.h create mode 100644 lib/duktape-2.2.1/src-input/duk_harray.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hboundfunc.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hbuffer.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hbuffer_alloc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hbuffer_ops.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hbufobj.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hbufobj_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hcompfunc.h create mode 100644 lib/duktape-2.2.1/src-input/duk_heap.h create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_alloc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_finalize.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_hashstring.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_markandsweep.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_memory.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_refcount.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_stringcache.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heap_stringtable.c create mode 100644 lib/duktape-2.2.1/src-input/duk_heaphdr.h create mode 100644 lib/duktape-2.2.1/src-input/duk_henv.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hnatfunc.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject_alloc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject_class.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject_enum.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject_pc2line.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hobject_props.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hproxy.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hstring.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hstring_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hthread.h create mode 100644 lib/duktape-2.2.1/src-input/duk_hthread_alloc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hthread_builtins.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hthread_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_hthread_stacks.c create mode 100644 lib/duktape-2.2.1/src-input/duk_internal.h create mode 100644 lib/duktape-2.2.1/src-input/duk_jmpbuf.h create mode 100644 lib/duktape-2.2.1/src-input/duk_js.h create mode 100644 lib/duktape-2.2.1/src-input/duk_js_arith.c create mode 100644 lib/duktape-2.2.1/src-input/duk_js_bytecode.h create mode 100644 lib/duktape-2.2.1/src-input/duk_js_call.c create mode 100644 lib/duktape-2.2.1/src-input/duk_js_compiler.c create mode 100644 lib/duktape-2.2.1/src-input/duk_js_compiler.h create mode 100644 lib/duktape-2.2.1/src-input/duk_js_executor.c create mode 100644 lib/duktape-2.2.1/src-input/duk_js_ops.c create mode 100644 lib/duktape-2.2.1/src-input/duk_js_var.c create mode 100644 lib/duktape-2.2.1/src-input/duk_json.h create mode 100644 lib/duktape-2.2.1/src-input/duk_lexer.c create mode 100644 lib/duktape-2.2.1/src-input/duk_lexer.h create mode 100644 lib/duktape-2.2.1/src-input/duk_numconv.c create mode 100644 lib/duktape-2.2.1/src-input/duk_numconv.h create mode 100644 lib/duktape-2.2.1/src-input/duk_refcount.h create mode 100644 lib/duktape-2.2.1/src-input/duk_regexp.h create mode 100644 lib/duktape-2.2.1/src-input/duk_regexp_compiler.c create mode 100644 lib/duktape-2.2.1/src-input/duk_regexp_executor.c create mode 100644 lib/duktape-2.2.1/src-input/duk_replacements.c create mode 100644 lib/duktape-2.2.1/src-input/duk_replacements.h create mode 100644 lib/duktape-2.2.1/src-input/duk_selftest.c create mode 100644 lib/duktape-2.2.1/src-input/duk_selftest.h create mode 100644 lib/duktape-2.2.1/src-input/duk_strings.h create mode 100644 lib/duktape-2.2.1/src-input/duk_tval.c create mode 100644 lib/duktape-2.2.1/src-input/duk_tval.h create mode 100644 lib/duktape-2.2.1/src-input/duk_unicode.h create mode 100644 lib/duktape-2.2.1/src-input/duk_unicode_support.c create mode 100644 lib/duktape-2.2.1/src-input/duk_unicode_tables.c create mode 100644 lib/duktape-2.2.1/src-input/duk_util.h create mode 100644 lib/duktape-2.2.1/src-input/duk_util_bitdecoder.c create mode 100644 lib/duktape-2.2.1/src-input/duk_util_bitencoder.c create mode 100644 lib/duktape-2.2.1/src-input/duk_util_bufwriter.c create mode 100644 lib/duktape-2.2.1/src-input/duk_util_hashbytes.c create mode 100644 lib/duktape-2.2.1/src-input/duk_util_misc.c create mode 100644 lib/duktape-2.2.1/src-input/duk_util_tinyrandom.c create mode 100644 lib/duktape-2.2.1/src-input/duktape.h.in create mode 100644 lib/duktape-2.2.1/src-input/strings.yaml create mode 100644 lib/duktape-2.2.1/src-noline/duk_config.h create mode 100644 lib/duktape-2.2.1/src-noline/duk_source_meta.json create mode 100644 lib/duktape-2.2.1/src-noline/duktape.c create mode 100644 lib/duktape-2.2.1/src-noline/duktape.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_alloc_default.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_buffer.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_bytecode.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_call.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_codec.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_compile.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_debug.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_heap.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_inspect.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_internal.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_memory.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_object.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_stack.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_string.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_api_time.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_array.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_boolean.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_buffer.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_date.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_date_unix.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_date_windows.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_duktape.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_encoding.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_error.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_function.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_global.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_json.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_math.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_number.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_object.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_performance.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_pointer.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_promise.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_protos.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_proxy.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_reflect.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_regexp.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_string.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_symbol.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_thread.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_bi_thrower.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_builtins.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_builtins.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_config.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_dblunion.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_debug.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_debug_fixedbuffer.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_debug_macros.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_debug_vsnprintf.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_debugger.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_debugger.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_error.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_error_augment.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_error_longjmp.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_error_macros.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_error_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_error_throw.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_exception.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_forwdecl.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_harray.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hboundfunc.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hbuffer.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hbuffer_alloc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hbuffer_ops.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hbufobj.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hbufobj_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hcompfunc.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_alloc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_finalize.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_hashstring.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_markandsweep.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_memory.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_refcount.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_stringcache.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heap_stringtable.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_heaphdr.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_henv.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hnatfunc.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject_alloc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject_class.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject_enum.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject_pc2line.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hobject_props.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hproxy.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hstring.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hstring_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hthread.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_hthread_alloc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hthread_builtins.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hthread_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_hthread_stacks.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_internal.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_jmpbuf.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_js.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_arith.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_bytecode.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_call.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_compiler.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_compiler.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_executor.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_ops.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_js_var.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_json.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_lexer.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_lexer.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_numconv.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_numconv.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_refcount.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_regexp.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_regexp_compiler.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_regexp_executor.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_replacements.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_replacements.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_selftest.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_selftest.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_source_meta.json create mode 100644 lib/duktape-2.2.1/src-separate/duk_strings.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_tval.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_tval.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_unicode.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_unicode_support.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_unicode_tables.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_util.h create mode 100644 lib/duktape-2.2.1/src-separate/duk_util_bitdecoder.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_util_bitencoder.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_util_bufwriter.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_util_hashbytes.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_util_misc.c create mode 100644 lib/duktape-2.2.1/src-separate/duk_util_tinyrandom.c create mode 100644 lib/duktape-2.2.1/src-separate/duktape.h create mode 100644 lib/duktape-2.2.1/src/duk_config.h create mode 100644 lib/duktape-2.2.1/src/duk_source_meta.json create mode 100644 lib/duktape-2.2.1/src/duktape.c create mode 100644 lib/duktape-2.2.1/src/duktape.h create mode 100644 lib/duktape-2.2.1/tools/combine_src.py create mode 100644 lib/duktape-2.2.1/tools/configure.py create mode 100644 lib/duktape-2.2.1/tools/create_spdx_license.py create mode 100644 lib/duktape-2.2.1/tools/duk_meta_to_strarray.py create mode 100644 lib/duktape-2.2.1/tools/dukutil.py create mode 100644 lib/duktape-2.2.1/tools/dump_bytecode.py create mode 100644 lib/duktape-2.2.1/tools/extract_caseconv.py create mode 100644 lib/duktape-2.2.1/tools/extract_chars.py create mode 100644 lib/duktape-2.2.1/tools/extract_unique_options.py create mode 100644 lib/duktape-2.2.1/tools/genbuiltins.py create mode 100644 lib/duktape-2.2.1/tools/genconfig.py create mode 100644 lib/duktape-2.2.1/tools/json2yaml.py create mode 100644 lib/duktape-2.2.1/tools/merge_debug_meta.py create mode 100644 lib/duktape-2.2.1/tools/prepare_unicode_data.py create mode 100644 lib/duktape-2.2.1/tools/resolve_combined_lineno.py create mode 100644 lib/duktape-2.2.1/tools/scan_strings.py create mode 100644 lib/duktape-2.2.1/tools/scan_used_stridx_bidx.py create mode 100644 lib/duktape-2.2.1/tools/yaml2json.py create mode 160000 lib/imguicolortextedit create mode 160000 lib/whereami create mode 100644 misc-targets.mk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7147daf --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +imgui.ini +/nbproject +/.settings +core +*~ +*.bak +*.log +*.orig +*.rej + +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ + +# Eclipse +/.project +/.cproject + +# VSCode +/.vscode diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f49cd37 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "lib/imguicolortextedit"] + path = lib/imguicolortextedit + url = https://github.com/cheako/ImGuiColorTextEdit.git +[submodule "lib/whereami"] + path = lib/whereami + url = https://github.com/gpakosz/whereami diff --git a/0000tri/.gitignore b/0000tri/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0000tri/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0000tri/0_frag.glsl b/0000tri/0_frag.glsl new file mode 100644 index 0000000..b373bdb --- /dev/null +++ b/0000tri/0_frag.glsl @@ -0,0 +1,11 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + outFragColor = vec4(0.0, 0.0, 0.059, 1.0); +} diff --git a/0000tri/0_vert.glsl b/0000tri/0_vert.glsl new file mode 100644 index 0000000..a541624 --- /dev/null +++ b/0000tri/0_vert.glsl @@ -0,0 +1,15 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + gl_Position = vec4(inPos, 1.0); +} diff --git a/0000tri/Makefile b/0000tri/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0000tri/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0000tri/data.h b/0000tri/data.h new file mode 100644 index 0000000..317815b --- /dev/null +++ b/0000tri/data.h @@ -0,0 +1,33 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +extern const void *data_model_vertex; +extern const size_t data_model_vertex_count; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +#endif diff --git a/0000tri/data_bulk.c b/0000tri/data_bulk.c new file mode 100644 index 0000000..196a883 --- /dev/null +++ b/0000tri/data_bulk.c @@ -0,0 +1,28 @@ +#include "data.h" + +typedef struct +{ + vec3 position; +} vertex_t; +const vertex_t model_vertex[] = { + {{0.0f, -0.5f, 0.5f}}, + {{0.5f, 0.5f, 0.5f}}, + {{-0.5f, 0.5f, 0.5f}}, +}; +const void *data_model_vertex = model_vertex; +const size_t data_model_vertex_count = + sizeof(model_vertex) / sizeof(vertex_t); +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, +}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); diff --git a/0000tri/data_dynamic.c.in b/0000tri/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0000tri/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0000tri/libdata.c b/0000tri/libdata.c new file mode 100644 index 0000000..b19e3a2 --- /dev/null +++ b/0000tri/libdata.c @@ -0,0 +1,18 @@ +#include "data.h" + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; diff --git a/0000tri/vulkan.c b/0000tri/vulkan.c new file mode 100644 index 0000000..93e25db --- /dev/null +++ b/0000tri/vulkan.c @@ -0,0 +1,1136 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[0]); + + vkCmdDraw(command_buffer, data_model_vertex_count, 1, 0, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void clean_up(VkPipeline *graphics_pipelines, + VkShaderModule *frag_modules, + VkShaderModule *vert_modules, + uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + create_pipeline_layout(); + + setup_vertex_buffer(gpu_memory_properties); + + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(vert_modules, frag_modules, graphics_pipelines); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, graphics_pipelines); + + clean_up(graphics_pipelines, frag_modules, vert_modules, + swapchain_image_count); + exit(0); +} diff --git a/0001uniform-buffer-object.diff b/0001uniform-buffer-object.diff new file mode 100644 index 0000000..ad5abf2 --- /dev/null +++ b/0001uniform-buffer-object.diff @@ -0,0 +1,682 @@ +diff -bNur 0000tri/0_vert.glsl 0001uniform-buffer-object/0_vert.glsl +--- 0000tri/0_vert.glsl 2019-03-02 19:55:02.545357702 -0600 ++++ 0001uniform-buffer-object/0_vert.glsl 2019-03-02 19:55:02.545357702 -0600 +@@ -5,11 +5,24 @@ + + layout (location = 0) in vec3 inPos; + ++#define MAX_BONES 64 ++ ++layout (binding = 0) uniform UBO ++{ ++ mat4 model; ++ mat4 bones[MAX_BONES]; ++ mat4 vp; ++ vec3 lightPos; ++ float pada; ++ vec3 viewPos; ++ float padb; ++} ubo; ++ + out gl_PerVertex + { + vec4 gl_Position; + }; + + void main() { +- gl_Position = vec4(inPos, 1.0); ++ gl_Position = ubo.vp * ubo.model * vec4(inPos, 1.0); + } +diff -bNur 0000tri/data_bulk.c 0001uniform-buffer-object/data_bulk.c +--- 0000tri/data_bulk.c 2019-03-02 20:06:22.809345166 -0600 ++++ 0001uniform-buffer-object/data_bulk.c 2019-03-02 20:06:22.813345353 -0600 +@@ -1,17 +1,18 @@ +-#include "data.h" ++#include "data_bulk.h" + + typedef struct + { + vec3 position; + } vertex_t; + const vertex_t model_vertex[] = { +- {{0.0f, -0.5f, 0.5f}}, +- {{0.5f, 0.5f, 0.5f}}, +- {{-0.5f, 0.5f, 0.5f}}, ++ {{0.5f, -0.5f, -0.5f}}, ++ {{0.5f, 0.5f, -0.5f}}, ++ {{-0.5f, 0.5f, -0.5f}}, ++ {{0.5f, -0.5f, -0.5f}}, ++ {{-0.5f, 0.5f, -0.5f}}, ++ {{-0.5f, -0.5f, -0.5f}}, + }; + const void *data_model_vertex = model_vertex; +-const size_t data_model_vertex_count = +- sizeof(model_vertex) / sizeof(vertex_t); + const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); + const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, +@@ -26,3 +27,20 @@ + const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); ++ ++data_model_t data_models[] = { ++ { ++ "Square", ++ 0, ++ sizeof(model_vertex) / sizeof(uint32_t), ++ 0, ++ }, ++}; ++ ++const data_material_t data_materials[] = { ++ { ++ "Example", ++ 0, ++ sizeof(material_0_ubo_t), ++ }, ++}; +diff -bNur 0000tri/data_bulk.h 0001uniform-buffer-object/data_bulk.h +--- 0000tri/data_bulk.h 1969-12-31 18:00:00.000000000 -0600 ++++ 0001uniform-buffer-object/data_bulk.h 2019-03-02 19:55:02.545357702 -0600 +@@ -0,0 +1,16 @@ ++#include "data.h" ++ ++// Maximum number of bones per mesh ++// Must not be higher than same const in skinning shader ++#define MAX_BONES 64 ++ ++typedef struct ++{ ++ mat4 model; ++ mat4 bones[MAX_BONES]; ++ mat4 vp; ++ vec3 lightPos; ++ float pada; ++ vec3 viewPos; ++ float padb; ++} material_0_ubo_t; +diff -bNur 0000tri/data.h 0001uniform-buffer-object/data.h +--- 0000tri/data.h 2019-03-02 19:55:02.545357702 -0600 ++++ 0001uniform-buffer-object/data.h 2019-03-02 19:55:02.549357804 -0600 +@@ -1,5 +1,6 @@ + #ifndef HAND_DATA_H__ + #define HAND_DATA_H__ ++#include "list.h" + + #define GLFW_INCLUDE_VULKAN + #include +@@ -12,8 +13,12 @@ + #endif + #include + ++void data_init(VkExtent2D extent); ++void data_update(); ++ ++extern uintptr_t data_uniform_ptr; ++ + extern const void *data_model_vertex; +-extern const size_t data_model_vertex_count; + extern const VkDeviceSize data_model_vertex_size; + + extern const VkVertexInputBindingDescription data_binding_description; +@@ -22,6 +27,39 @@ + + typedef struct + { ++ char *name; ++ uint32_t first; ++ uint32_t count; ++ size_t material; ++} data_model_t; ++extern data_model_t data_models[]; ++ ++#define UNIFORM_ALIGN (sizeof(float) * 4) ++#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) ++#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) ++#define UNIFORM_SIZE (4096 * 4096) ++typedef struct ++{ ++ VkDescriptorSet descriptor_set; ++ size_t offset; ++ size_t range; ++ size_t width; ++ struct list_head list; ++} uniform_map_t; ++extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); ++ ++typedef struct data_model_instance ++{ ++ char *name; ++ size_t model; ++ struct list_head list; ++ void *ubo; ++ uniform_map_t *uniform_map; ++} data_model_instance_t; ++extern struct list_head data_model_instances; ++ ++typedef struct ++{ + struct + { + const void *spv; +@@ -30,4 +68,12 @@ + } data_material_shader_t; + extern const data_material_shader_t data_material_shaders[]; + ++typedef struct ++{ ++ char *name; ++ size_t shader; ++ VkDeviceSize ubo_vertex_shader_size; ++} data_material_t; ++extern const data_material_t data_materials[]; ++ + #endif +diff -bNur 0000tri/libdata.c 0001uniform-buffer-object/libdata.c +--- 0000tri/libdata.c 2019-03-02 20:06:22.809345166 -0600 ++++ 0001uniform-buffer-object/libdata.c 2019-03-02 20:06:22.813345353 -0600 +@@ -1,4 +1,19 @@ +-#include "data.h" ++#include "data_bulk.h" ++#include ++#include ++ ++void key_callback(GLFWwindow *window, int key, int scancode, int action, ++ int mods) ++{ ++ switch (key) ++ { ++ case GLFW_KEY_ESCAPE: ++ glfwSetWindowShouldClose(window, true); ++ break; ++ } ++} ++ ++float center_dir = 0; + + GLFWwindow *data_window = NULL; + +@@ -16,3 +31,204 @@ + &material_shader_0_frag_size, + }}, + }; ++ ++struct list_head data_model_instances; ++struct ++{ ++ data_model_instance_t obj; ++} model_instance = { ++ {"Object", ++ 0, ++ {&(data_model_instances), &(data_model_instances)}, ++ NULL, ++ NULL}, ++}; ++struct list_head data_model_instances = {&(model_instance.obj.list), ++ &(model_instance.obj.list)}; ++ ++uniform_map_t starting_map; ++struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; ++uniform_map_t starting_map = { ++ VK_NULL_HANDLE, ++ 0, ++ 0, ++ TO_UNIFORM_ALLOC(UNIFORM_SIZE), ++ {&(uniform_maps), &(uniform_maps)}, ++}; ++ ++inline static void split_map(size_t size, uniform_map_t *map, ++ uniform_map_t **ptr) ++{ ++ uniform_map_t *this_map; ++ this_map = malloc(sizeof(uniform_map_t)); ++ assert(this_map && "malloc(sizeof(uniform_map_t))"); ++ this_map->descriptor_set = VK_NULL_HANDLE; ++ if (map->range) ++ { ++ this_map->offset = map->offset + map->range; ++ this_map->range = size; ++ this_map->width = map->width - map->range; ++ map->width = map->range; ++ list_add(&this_map->list, map->list.next); ++ *ptr = this_map; ++ } ++ else ++ { ++ this_map->offset = map->offset; ++ map->offset += this_map->width = this_map->range = size; ++ map->width -= size; ++ list_add(&this_map->list, &map->list); ++ *ptr = this_map; ++ } ++} ++ ++uintptr_t data_uniform_ptr = 0; ++void (*data_setup_model_instance)(uniform_map_t *uniform_map); ++inline static void setup_model_instance(data_model_instance_t *inst) ++{ ++ size_t size = TO_UNIFORM_ALLOC( ++ data_materials[data_models[inst->model].material].ubo_vertex_shader_size); ++ size_t contigious = 0; ++ size_t count = 0; ++ inst->uniform_map = NULL; ++ uniform_map_t *map; ++ list_for_each_entry(map, &uniform_maps, list) ++ { ++ if (map->range) ++ { ++ contigious = 0; ++ count = 0; ++ } ++ size_t free = map->width - map->range; ++ if (free) ++ { ++ contigious += free; ++ count++; ++ if ((!map->range) && (free >= size) && (size * 2 > free)) ++ { ++ map->range = size; ++ inst->uniform_map = map; ++ data_setup_model_instance(inst->uniform_map); ++ break; ++ } ++ else if (size < free) ++ { ++ split_map(size, map, &inst->uniform_map); ++ data_setup_model_instance(inst->uniform_map); ++ break; ++ } ++ else if (size < free + contigious) ++ { ++ assert(!count && 0 && "TODO: Support for combining uniform maps."); ++ } ++ } ++ } ++ assert(inst->uniform_map && "Out of uniform space."); ++ inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + ++ data_uniform_ptr); ++} ++ ++mat4 projection; ++mat4 view; ++inline static void update_vp(material_0_ubo_t *ubo_0) ++{ ++ glm_lookat(ubo_0->viewPos, ++ (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], ++ ubo_0->viewPos[2] + cosf(center_dir)}, ++ GLM_YUP, view); ++ glm_mat4_mul(projection, view, ubo_0->vp); ++} ++ ++/* ++ * This code uses a float point frame counter. To make your code easier ++ * u may want to resolve this to an integer. One frame is the set of all ++ * player's turns. ++ */ ++double previous_frame; ++ ++void data_init(VkExtent2D extent) ++{ ++ material_0_ubo_t *ubo_0; ++ data_model_instance_t *inst = ++ list_entry(data_model_instances.next, data_model_instance_t, list); ++ ++ setup_model_instance(inst); ++ ubo_0 = inst->ubo; ++ ++ glfwSetKeyCallback(data_window, key_callback); ++ ++ { ++ static const material_0_ubo_t empty_data_material_ubo_s; ++ *ubo_0 = empty_data_material_ubo_s; ++ } ++ glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); ++ ubo_0->viewPos[0] = 0.0f; ++ ubo_0->viewPos[1] = 0.0f; ++ ubo_0->viewPos[2] = -2.0f; ++ ++ glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); ++ ++#ifdef NEWER_CGLM ++ glm_perspective_default((float)extent.width / (float)extent.height, ++ projection); ++#else ++ mat4 oglproj; ++ glm_perspective_default((float)extent.width / (float)extent.height, oglproj); ++ /* This is for Vulkan, cglm is for OpenGL. */ ++ glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, ++ {0.0f, -1.0f, 0.0f, 0.0f}, ++ {0.0f, 0.0f, 0.5f, 0.5f}, ++ {0.0f, 0.0f, 0.0f, 1.0f}}, ++ oglproj, projection); ++#endif ++ ++ update_vp(ubo_0); ++ ++ previous_frame = glfwGetTime(); ++} ++ ++inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) ++{ ++ bool need_lookat = false; ++ ++#define GET_KEY(key) glfwGetKey(data_window, (key)) ++#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) ++ if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) ++ { ++ double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame ++ : previous_frame - this_frame); ++ ubo_0->viewPos[0] += sinf(center_dir) * dist; ++ ubo_0->viewPos[2] += cosf(center_dir) * dist; ++ need_lookat = true; ++ } ++ ++ if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) ++ { ++ center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame ++ : previous_frame - this_frame; ++ need_lookat = true; ++ } ++ ++ if (need_lookat) ++ update_vp(ubo_0); ++} ++ ++void data_update() ++{ ++ material_0_ubo_t *ubo_0 = ++ list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; ++ double this_frame = glfwGetTime(); ++ ++ handle_input(this_frame, ubo_0); ++ ++ /* TODO: Take turns. */ ++ ++ if (0) ++ { ++ mat4 model; ++ glm_mat4_copy(ubo_0->model, model); ++ glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); ++ } ++ ++ previous_frame = this_frame; ++} +diff -bNur 0000tri/vulkan.c 0001uniform-buffer-object/vulkan.c +--- 0000tri/vulkan.c 2019-03-03 14:31:34.815871615 -0600 ++++ 0001uniform-buffer-object/vulkan.c 2019-03-02 20:06:22.813345353 -0600 +@@ -20,6 +20,10 @@ + VkRenderPass render_pass = VK_NULL_HANDLE; + VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; ++VkBuffer uniform_buffer = VK_NULL_HANDLE; ++VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; ++VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; ++VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; + VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; + VkBuffer vertex_buffer = VK_NULL_HANDLE; + VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +@@ -516,6 +520,167 @@ + } + } + ++inline static void create_uniform_buffer() ++{ ++ VkBufferCreateInfo buffer_info_create; ++ static const VkBufferCreateInfo EmptyVkBufferCreateInfo; ++ buffer_info_create = EmptyVkBufferCreateInfo; ++ buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; ++ buffer_info_create.size = UNIFORM_SIZE; ++ buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; ++ buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; ++ ++ VkResult err; ++ err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); ++ assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); ++} ++ ++inline static void allocate_uniform_buffer( ++ VkPhysicalDeviceMemoryProperties gpu_memory_properties) ++{ ++ VkMemoryRequirements mememory_requirements; ++ vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); ++ ++ VkMemoryAllocateInfo allocate_info; ++ static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; ++ allocate_info = EmptyVkMemoryAllocateInfo; ++ allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ++ allocate_info.allocationSize = mememory_requirements.size; ++ ++ allocate_info.memoryTypeIndex = UINT32_MAX; ++ for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) ++ { ++ if ((mememory_requirements.memoryTypeBits & (1 << i)) && ++ ((gpu_memory_properties.memoryTypes[i].propertyFlags & ++ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | ++ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == ++ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | ++ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) ++ { ++ allocate_info.memoryTypeIndex = i; ++ break; ++ } ++ } ++ assert((allocate_info.memoryTypeIndex != UINT32_MAX) && ++ "Failed to find suitable memory type for uniform."); ++ ++ VkResult err; ++ err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); ++ assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); ++ ++ err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); ++ assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); ++} ++ ++inline static void ++setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) ++{ ++ create_uniform_buffer(); ++ allocate_uniform_buffer(gpu_memory_properties); ++ ++ VkResult err; ++ err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, ++ (void **)&data_uniform_ptr); ++ assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); ++} ++ ++inline static void create_descriptor_set_layout() ++{ ++ VkDescriptorSetLayoutBinding set_layout_bindings[1]; ++ static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; ++ set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; ++ set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; ++ set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; ++ set_layout_bindings[0].binding = 0; ++ set_layout_bindings[0].descriptorCount = 1; ++ ++ VkDescriptorSetLayoutCreateInfo set_layout_create_info; ++ static const VkDescriptorSetLayoutCreateInfo ++ EmptyVkDescriptorSetLayoutCreateInfo; ++ set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; ++ set_layout_create_info.sType = ++ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; ++ set_layout_create_info.pBindings = set_layout_bindings; ++ set_layout_create_info.bindingCount = 1; ++ ++ VkResult err; ++ err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, ++ &descriptor_set_layout); ++ assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); ++} ++ ++inline static void create_descriptor_pool() ++{ ++ VkDescriptorPoolSize pool_sizes[] = { ++ {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, ++ {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, ++ {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, ++ {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, ++ {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, ++ {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, ++ {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, ++ {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, ++ {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, ++ {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, ++ {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; ++ ++ VkDescriptorPoolCreateInfo pool_info; ++ static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; ++ pool_info = EmptyVkDescriptorPoolCreateInfo; ++ pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; ++ pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); ++ pool_info.pPoolSizes = pool_sizes; ++ pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; ++ ++ VkResult err; ++ err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); ++ assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); ++} ++ ++inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) ++{ ++ VkDescriptorSetAllocateInfo alloc_info; ++ static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; ++ alloc_info = EmptyVkDescriptorSetAllocateInfo; ++ alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; ++ alloc_info.descriptorPool = descriptor_pool; ++ alloc_info.pSetLayouts = &descriptor_set_layout; ++ alloc_info.descriptorSetCount = 1; ++ ++ VkResult err; ++ err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); ++ assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); ++} ++ ++inline static void update_descriptor_set(uniform_map_t *map) ++{ ++ VkDescriptorBufferInfo uniform_descriptors[1]; ++ static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; ++ uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; ++ uniform_descriptors[0].buffer = uniform_buffer; ++ uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); ++ uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); ++ ++ VkWriteDescriptorSet write_descriptor_sets[1]; ++ static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; ++ write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; ++ write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; ++ write_descriptor_sets[0].dstSet = map->descriptor_set; ++ write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; ++ write_descriptor_sets[0].dstBinding = 0; ++ write_descriptor_sets[0].pBufferInfo = uniform_descriptors; ++ write_descriptor_sets[0].descriptorCount = 1; ++ ++ vkUpdateDescriptorSets(device, 1, write_descriptor_sets, 0, NULL); ++} ++ ++void setup_model_instance(uniform_map_t *uniform_map) ++{ ++ if (uniform_map->descriptor_set == VK_NULL_HANDLE) ++ allocate_descriptor_set(&uniform_map->descriptor_set); ++ update_descriptor_set(uniform_map); ++} ++ + inline static void create_pipeline_layout() + { + VkPipelineLayoutCreateInfo pipeline_layout_create_info; +@@ -523,6 +688,8 @@ + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; ++ pipeline_layout_create_info.setLayoutCount = 1; ++ pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, +@@ -530,6 +697,13 @@ + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); + } + ++inline static void setup_descriptor_set() ++{ ++ create_descriptor_set_layout(); ++ create_descriptor_pool(); ++ create_pipeline_layout(); ++} ++ + inline static void create_vertex_buffer() + { + VkBufferCreateInfo buffer_info_create; +@@ -946,10 +1120,20 @@ + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + +- vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, +- graphics_pipelines[0]); ++ data_model_instance_t *ptr = ++ list_entry(data_model_instances.next, data_model_instance_t, list); ++ vkCmdBindPipeline( ++ command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ++ graphics_pipelines[data_materials[data_models[ptr->model].material] ++ .shader]); ++ ++ vkCmdBindDescriptorSets( ++ command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, ++ &ptr->uniform_map->descriptor_set, ++ 0, NULL); + +- vkCmdDraw(command_buffer, data_model_vertex_count, 1, 0, 0); ++ vkCmdDraw(command_buffer, data_models[ptr->model].count, 1, ++ data_models[ptr->model].first, 0); + + vkCmdEndRenderPass(command_buffer); + +@@ -1023,6 +1207,8 @@ + { + glfwPollEvents(); + ++ data_update(); ++ + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + +@@ -1068,6 +1254,19 @@ + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; ++ vkDestroyDescriptorPool(device, descriptor_pool, NULL); ++ descriptor_pool = VK_NULL_HANDLE; ++ list_entry(data_model_instances.next, data_model_instance_t, list) ++ ->uniform_map->descriptor_set = VK_NULL_HANDLE; ++ vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); ++ descriptor_set_layout = VK_NULL_HANDLE; ++ vkUnmapMemory(device, uniform_buffer_memmory); ++ list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = ++ NULL; ++ vkFreeMemory(device, uniform_buffer_memmory, NULL); ++ uniform_buffer_memmory = VK_NULL_HANDLE; ++ vkDestroyBuffer(device, uniform_buffer, NULL); ++ uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); +@@ -1118,7 +1317,8 @@ + + create_framebuffers(swapchain_image_count); + +- create_pipeline_layout(); ++ setup_uniform_buffer(gpu_memory_properties); ++ setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + +@@ -1127,6 +1327,9 @@ + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(vert_modules, frag_modules, graphics_pipelines); + ++ data_setup_model_instance = setup_model_instance; ++ data_init(extent); ++ + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, graphics_pipelines); + diff --git a/0001uniform-buffer-object/.gitignore b/0001uniform-buffer-object/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0001uniform-buffer-object/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0001uniform-buffer-object/0_frag.glsl b/0001uniform-buffer-object/0_frag.glsl new file mode 100644 index 0000000..b373bdb --- /dev/null +++ b/0001uniform-buffer-object/0_frag.glsl @@ -0,0 +1,11 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + outFragColor = vec4(0.0, 0.0, 0.059, 1.0); +} diff --git a/0001uniform-buffer-object/0_vert.glsl b/0001uniform-buffer-object/0_vert.glsl new file mode 100644 index 0000000..fdf8b2b --- /dev/null +++ b/0001uniform-buffer-object/0_vert.glsl @@ -0,0 +1,28 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} ubo; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + gl_Position = ubo.vp * ubo.model * vec4(inPos, 1.0); +} diff --git a/0001uniform-buffer-object/Makefile b/0001uniform-buffer-object/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0001uniform-buffer-object/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0001uniform-buffer-object/data.h b/0001uniform-buffer-object/data.h new file mode 100644 index 0000000..6f0fc50 --- /dev/null +++ b/0001uniform-buffer-object/data.h @@ -0,0 +1,79 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; +extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +typedef struct data_model_instance +{ + char *name; + size_t model; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#endif diff --git a/0001uniform-buffer-object/data_bulk.c b/0001uniform-buffer-object/data_bulk.c new file mode 100644 index 0000000..c7a4820 --- /dev/null +++ b/0001uniform-buffer-object/data_bulk.c @@ -0,0 +1,46 @@ +#include "data_bulk.h" + +typedef struct +{ + vec3 position; +} vertex_t; +const vertex_t model_vertex[] = { + {{0.5f, -0.5f, -0.5f}}, + {{0.5f, 0.5f, -0.5f}}, + {{-0.5f, 0.5f, -0.5f}}, + {{0.5f, -0.5f, -0.5f}}, + {{-0.5f, 0.5f, -0.5f}}, + {{-0.5f, -0.5f, -0.5f}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, +}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +data_model_t data_models[] = { + { + "Square", + 0, + sizeof(model_vertex) / sizeof(uint32_t), + 0, + }, +}; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + }, +}; diff --git a/0001uniform-buffer-object/data_bulk.h b/0001uniform-buffer-object/data_bulk.h new file mode 100644 index 0000000..58330e4 --- /dev/null +++ b/0001uniform-buffer-object/data_bulk.h @@ -0,0 +1,16 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} material_0_ubo_t; diff --git a/0001uniform-buffer-object/data_dynamic.c.in b/0001uniform-buffer-object/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0001uniform-buffer-object/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0001uniform-buffer-object/libdata.c b/0001uniform-buffer-object/libdata.c new file mode 100644 index 0000000..c57192d --- /dev/null +++ b/0001uniform-buffer-object/libdata.c @@ -0,0 +1,234 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +struct list_head data_model_instances; +struct +{ + data_model_instance_t obj; +} model_instance = { + {"Object", + 0, + {&(data_model_instances), &(data_model_instances)}, + NULL, + NULL}, +}; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + uniform_map_t **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = this_map; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = this_map; + } +} + +uintptr_t data_uniform_ptr = 0; +void (*data_setup_model_instance)(uniform_map_t *uniform_map); +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = map; + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp(material_0_ubo_t *ubo_0) +{ + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + + setup_model_instance(inst); + ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(ubo_0); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) +{ + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + ubo_0->viewPos[0] += sinf(center_dir) * dist; + ubo_0->viewPos[2] += cosf(center_dir) * dist; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (need_lookat) + update_vp(ubo_0); +} + +void data_update() +{ + material_0_ubo_t *ubo_0 = + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; + double this_frame = glfwGetTime(); + + handle_input(this_frame, ubo_0); + + /* TODO: Take turns. */ + + if (0) + { + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0001uniform-buffer-object/vulkan.c b/0001uniform-buffer-object/vulkan.c new file mode 100644 index 0000000..cc8df44 --- /dev/null +++ b/0001uniform-buffer-object/vulkan.c @@ -0,0 +1,1339 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[1]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = 1; + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[1]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + VkWriteDescriptorSet write_descriptor_sets[1]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + + vkUpdateDescriptorSets(device, 1, write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(uniform_map_t *uniform_map) +{ + if (uniform_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&uniform_map->descriptor_set); + update_descriptor_set(uniform_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[ptr->model].material] + .shader]); + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &ptr->uniform_map->descriptor_set, + 0, NULL); + + vkCmdDraw(command_buffer, data_models[ptr->model].count, 1, + data_models[ptr->model].first, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void clean_up(VkPipeline *graphics_pipelines, + VkShaderModule *frag_modules, + VkShaderModule *vert_modules, + uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + list_entry(data_model_instances.next, data_model_instance_t, list) + ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = + NULL; + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, graphics_pipelines); + + clean_up(graphics_pipelines, frag_modules, vert_modules, + swapchain_image_count); + exit(0); +} diff --git a/0002lighting.diff b/0002lighting.diff new file mode 100644 index 0000000..e02a788 --- /dev/null +++ b/0002lighting.diff @@ -0,0 +1,194 @@ +diff -bNur 0001uniform-buffer-object/0_frag.glsl 0002lighting/0_frag.glsl +--- 0001uniform-buffer-object/0_frag.glsl 2019-03-02 19:55:02.545357702 -0600 ++++ 0002lighting/0_frag.glsl 2019-03-02 19:55:02.549357804 -0600 +@@ -3,9 +3,43 @@ + #extension GL_ARB_separate_shader_objects : enable + #extension GL_ARB_shading_language_420pack : enable + ++layout (location = 0) in vec2 inUV; ++layout (location = 1) in vec3 inNormal; ++layout (location = 2) in vec3 inViewVec; ++layout (location = 3) in vec3 inLightVec; ++ + layout (location = 0) out vec4 outFragColor; + + void main() + { +- outFragColor = vec4(0.0, 0.0, 0.059, 1.0); ++ vec4 color = vec4(0.0, 0.0, 0.059, 1.0); ++ ++ vec3 normal = normalize(inNormal); ++ vec3 surfaceToLight = normalize(inLightVec); ++ vec3 surfaceToCamera = normalize(inViewVec); ++ ++ //ambient ++ vec3 ambient = color.rgb / 150.0; ++ ++ //diffuse ++ float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); ++ vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; ++ ++ //specular ++ float specularCoefficient = 0.0; ++ if(diffuseCoefficient > 0.0) ++ specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); ++ vec3 specular = specularCoefficient * vec3(255,255,255); ++ ++ //attenuation ++ float distanceToLight = length(inLightVec); ++ float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); ++ ++ //linear color (color before gamma correction) ++ vec3 linearColor = ambient + attenuation*(diffuse + specular); ++ ++ //final color (after gamma correction) ++ vec3 gamma = vec3(1.0/2.2); ++ ++ outFragColor = vec4(pow(linearColor, gamma), color.a); + } +diff -bNur 0001uniform-buffer-object/0_vert.glsl 0002lighting/0_vert.glsl +--- 0001uniform-buffer-object/0_vert.glsl 2019-03-02 19:55:02.545357702 -0600 ++++ 0002lighting/0_vert.glsl 2019-03-02 19:55:02.549357804 -0600 +@@ -4,6 +4,10 @@ + #extension GL_ARB_shading_language_420pack : enable + + layout (location = 0) in vec3 inPos; ++layout (location = 1) in vec3 inNormal; ++layout (location = 2) in vec2 inUV; ++layout (location = 3) in vec4 inBoneWeights; ++layout (location = 4) in ivec4 inBoneIDs; + + #define MAX_BONES 64 + +@@ -18,11 +22,29 @@ + float padb; + } ubo; + ++layout (location = 0) out vec2 outUV; ++layout (location = 1) out vec3 outNormal; ++layout (location = 2) out vec3 outViewVec; ++layout (location = 3) out vec3 outLightVec; ++ + out gl_PerVertex + { + vec4 gl_Position; + }; + + void main() { +- gl_Position = ubo.vp * ubo.model * vec4(inPos, 1.0); ++ mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; ++ boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; ++ boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; ++ boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; ++ ++ outUV = inUV; ++ ++ mat4 skinPos = ubo.model * boneTransform; ++ gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); ++ ++ vec4 pos = skinPos * vec4(inPos, 1.0); ++ outNormal = inverse(transpose(mat3(skinPos))) * inNormal; ++ outLightVec = ubo.lightPos - pos.xyz; ++ outViewVec = ubo.viewPos - pos.xyz; + } +diff -bNur 0001uniform-buffer-object/data_bulk.c 0002lighting/data_bulk.c +--- 0001uniform-buffer-object/data_bulk.c 2019-03-02 20:06:22.813345353 -0600 ++++ 0002lighting/data_bulk.c 2019-03-02 20:06:22.813345353 -0600 +@@ -3,14 +3,42 @@ + typedef struct + { + vec3 position; ++ vec3 normal; ++ float uv[2]; ++ float boneWeights[MAX_BONES_PER_VERTEX]; ++ uint32_t boneIDs[MAX_BONES_PER_VERTEX]; + } vertex_t; + const vertex_t model_vertex[] = { +- {{0.5f, -0.5f, -0.5f}}, +- {{0.5f, 0.5f, -0.5f}}, +- {{-0.5f, 0.5f, -0.5f}}, +- {{0.5f, -0.5f, -0.5f}}, +- {{-0.5f, 0.5f, -0.5f}}, +- {{-0.5f, -0.5f, -0.5f}}, ++ {{-0.5f, 0.5f, -0.5f}, ++ {0.0f, 0.0f, -1.0f}, ++ {0.0f, 2.0f / 3.0f}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {{-0.5f, -0.5f, -0.5f}, ++ {0.0f, 0.0f, -1.0f}, ++ {0.25f, 1.0f / 3.0f}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {{0.5f, -0.5f, -0.5f}, ++ {0.0f, 0.0f, -1.0f}, ++ {0.0f, 1.0f / 3.0f}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {{-0.5f, 0.5f, -0.5f}, ++ {0.0f, 0.0f, -1.0f}, ++ {0.0f, 2.0f / 3.0f}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {{0.5f, -0.5f, -0.5f}, ++ {0.0f, 0.0f, -1.0f}, ++ {0.25f, 1.0f / 3.0f}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {{0.5f, 0.5f, -0.5f}, ++ {0.0f, 0.0f, -1.0f}, ++ {0.25f, 2.0f / 3.0f}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, + }; + const void *data_model_vertex = model_vertex; + const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +@@ -23,6 +51,22 @@ + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, ++ {.location = 1, ++ .binding = 0, ++ .format = VK_FORMAT_R32G32B32_SFLOAT, ++ .offset = offsetof(vertex_t, normal)}, ++ {.location = 2, ++ .binding = 0, ++ .format = VK_FORMAT_R32G32_SFLOAT, ++ .offset = offsetof(vertex_t, uv)}, ++ {.location = 3, ++ .binding = 0, ++ .format = VK_FORMAT_R32G32B32A32_SFLOAT, ++ .offset = offsetof(vertex_t, boneWeights)}, ++ {.location = 4, ++ .binding = 0, ++ .format = VK_FORMAT_R32G32B32A32_SINT, ++ .offset = offsetof(vertex_t, boneIDs)}, + }; + const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / +diff -bNur 0001uniform-buffer-object/data.h 0002lighting/data.h +--- 0001uniform-buffer-object/data.h 2019-03-02 19:55:02.549357804 -0600 ++++ 0002lighting/data.h 2019-03-02 19:55:02.549357804 -0600 +@@ -16,6 +16,9 @@ + void data_init(VkExtent2D extent); + void data_update(); + ++// Maximum number of bones per vertex ++#define MAX_BONES_PER_VERTEX 4 ++ + extern uintptr_t data_uniform_ptr; + + extern const void *data_model_vertex; +diff -bNur 0001uniform-buffer-object/libdata.c 0002lighting/libdata.c +--- 0001uniform-buffer-object/libdata.c 2019-03-02 20:06:22.813345353 -0600 ++++ 0002lighting/libdata.c 2019-03-02 20:06:22.813345353 -0600 +@@ -162,6 +162,9 @@ + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); ++ ubo_0->lightPos[0] = 0.0f; ++ ubo_0->lightPos[1] = 250.0f; ++ ubo_0->lightPos[2] = -250.0f; + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; diff --git a/0002lighting/.gitignore b/0002lighting/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0002lighting/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0002lighting/0_frag.glsl b/0002lighting/0_frag.glsl new file mode 100644 index 0000000..f104a26 --- /dev/null +++ b/0002lighting/0_frag.glsl @@ -0,0 +1,45 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = vec4(0.0, 0.0, 0.059, 1.0); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0002lighting/0_vert.glsl b/0002lighting/0_vert.glsl new file mode 100644 index 0000000..be62be1 --- /dev/null +++ b/0002lighting/0_vert.glsl @@ -0,0 +1,50 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} ubo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = ubo.lightPos - pos.xyz; + outViewVec = ubo.viewPos - pos.xyz; +} diff --git a/0002lighting/Makefile b/0002lighting/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0002lighting/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0002lighting/data.h b/0002lighting/data.h new file mode 100644 index 0000000..48c9b9b --- /dev/null +++ b/0002lighting/data.h @@ -0,0 +1,82 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; +extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +typedef struct data_model_instance +{ + char *name; + size_t model; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#endif diff --git a/0002lighting/data_bulk.c b/0002lighting/data_bulk.c new file mode 100644 index 0000000..ebdb43d --- /dev/null +++ b/0002lighting/data_bulk.c @@ -0,0 +1,90 @@ +#include "data_bulk.h" + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; +const vertex_t model_vertex[] = { + {{-0.5f, 0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 2.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{-0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.25f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{-0.5f, 0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 2.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.25f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{0.5f, 0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.25f, 2.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}, +}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +data_model_t data_models[] = { + { + "Square", + 0, + sizeof(model_vertex) / sizeof(uint32_t), + 0, + }, +}; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + }, +}; diff --git a/0002lighting/data_bulk.h b/0002lighting/data_bulk.h new file mode 100644 index 0000000..58330e4 --- /dev/null +++ b/0002lighting/data_bulk.h @@ -0,0 +1,16 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} material_0_ubo_t; diff --git a/0002lighting/data_dynamic.c.in b/0002lighting/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0002lighting/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0002lighting/libdata.c b/0002lighting/libdata.c new file mode 100644 index 0000000..8aedbc3 --- /dev/null +++ b/0002lighting/libdata.c @@ -0,0 +1,237 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +struct list_head data_model_instances; +struct +{ + data_model_instance_t obj; +} model_instance = { + {"Object", + 0, + {&(data_model_instances), &(data_model_instances)}, + NULL, + NULL}, +}; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + uniform_map_t **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = this_map; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = this_map; + } +} + +uintptr_t data_uniform_ptr = 0; +void (*data_setup_model_instance)(uniform_map_t *uniform_map); +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = map; + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp(material_0_ubo_t *ubo_0) +{ + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + + setup_model_instance(inst); + ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + ubo_0->lightPos[0] = 0.0f; + ubo_0->lightPos[1] = 250.0f; + ubo_0->lightPos[2] = -250.0f; + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(ubo_0); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) +{ + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + ubo_0->viewPos[0] += sinf(center_dir) * dist; + ubo_0->viewPos[2] += cosf(center_dir) * dist; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (need_lookat) + update_vp(ubo_0); +} + +void data_update() +{ + material_0_ubo_t *ubo_0 = + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; + double this_frame = glfwGetTime(); + + handle_input(this_frame, ubo_0); + + /* TODO: Take turns. */ + + if (0) + { + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0002lighting/vulkan.c b/0002lighting/vulkan.c new file mode 100644 index 0000000..cc8df44 --- /dev/null +++ b/0002lighting/vulkan.c @@ -0,0 +1,1339 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[1]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = 1; + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[1]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + VkWriteDescriptorSet write_descriptor_sets[1]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + + vkUpdateDescriptorSets(device, 1, write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(uniform_map_t *uniform_map) +{ + if (uniform_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&uniform_map->descriptor_set); + update_descriptor_set(uniform_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[ptr->model].material] + .shader]); + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &ptr->uniform_map->descriptor_set, + 0, NULL); + + vkCmdDraw(command_buffer, data_models[ptr->model].count, 1, + data_models[ptr->model].first, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void clean_up(VkPipeline *graphics_pipelines, + VkShaderModule *frag_modules, + VkShaderModule *vert_modules, + uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + list_entry(data_model_instances.next, data_model_instance_t, list) + ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = + NULL; + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, graphics_pipelines); + + clean_up(graphics_pipelines, frag_modules, vert_modules, + swapchain_image_count); + exit(0); +} diff --git a/0003index-buffer.diff b/0003index-buffer.diff new file mode 100644 index 0000000..ad08415 --- /dev/null +++ b/0003index-buffer.diff @@ -0,0 +1,193 @@ +diff -bNur 0002lighting/data_bulk.c 0003index-buffer/data_bulk.c +--- 0002lighting/data_bulk.c 2019-03-02 20:06:22.813345353 -0600 ++++ 0003index-buffer/data_bulk.c 2019-03-02 20:06:22.813345353 -0600 +@@ -14,22 +14,12 @@ + {0.0f, 2.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +- {{-0.5f, -0.5f, -0.5f}, +- {0.0f, 0.0f, -1.0f}, +- {0.25f, 1.0f / 3.0f}, +- {1.0f, 0.0f, 0.0f, 0.0f}, +- {0, 0, 0, 0}}, + {{0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +- {{-0.5f, 0.5f, -0.5f}, +- {0.0f, 0.0f, -1.0f}, +- {0.0f, 2.0f / 3.0f}, +- {1.0f, 0.0f, 0.0f, 0.0f}, +- {0, 0, 0, 0}}, +- {{0.5f, -0.5f, -0.5f}, ++ {{-0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.25f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, +@@ -72,11 +62,23 @@ + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + ++const struct data_model_index ++{ ++ struct ++ { ++ uint32_t first, second, third; ++ } square[2]; ++} *data_model_index = &(struct data_model_index){{ ++ {0, 2, 1}, ++ {0, 1, 3}, ++}}; ++const VkDeviceSize data_model_index_size = sizeof(*data_model_index); ++ + data_model_t data_models[] = { + { + "Square", +- 0, +- sizeof(model_vertex) / sizeof(uint32_t), ++ offsetof(struct data_model_index, square) / sizeof(uint32_t), ++ sizeof(data_model_index->square) / sizeof(uint32_t), + 0, + }, + }; +diff -bNur 0002lighting/data.h 0003index-buffer/data.h +--- 0002lighting/data.h 2019-03-02 19:55:02.549357804 -0600 ++++ 0003index-buffer/data.h 2019-03-02 19:55:02.553357906 -0600 +@@ -28,6 +28,9 @@ + extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; + extern const uint32_t data_attribute_descriptions_count; + ++extern const struct data_model_index *data_model_index; ++extern const VkDeviceSize data_model_index_size; ++ + typedef struct + { + char *name; +diff -bNur 0002lighting/vulkan.c 0003index-buffer/vulkan.c +--- 0002lighting/vulkan.c 2019-03-02 20:06:22.813345353 -0600 ++++ 0003index-buffer/vulkan.c 2019-03-02 20:06:22.817345540 -0600 +@@ -27,6 +27,8 @@ + VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; + VkBuffer vertex_buffer = VK_NULL_HANDLE; + VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; ++VkBuffer index_buffer = VK_NULL_HANDLE; ++VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; + VkCommandPool command_pool = VK_NULL_HANDLE; + VkSemaphore wait_semaphore = VK_NULL_HANDLE; + VkFence queue_submit_fence = VK_NULL_HANDLE; +@@ -773,6 +775,75 @@ + vkUnmapMemory(device, vertex_buffer_memmory); + } + ++inline static void create_index_buffer() ++{ ++ VkBufferCreateInfo buffer_info_create; ++ static const VkBufferCreateInfo EmptyVkBufferCreateInfo; ++ buffer_info_create = EmptyVkBufferCreateInfo; ++ buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; ++ buffer_info_create.size = data_model_index_size; ++ buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; ++ buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; ++ ++ VkResult err; ++ err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); ++ assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); ++} ++ ++inline static void ++allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) ++{ ++ VkMemoryRequirements mememory_requirements; ++ vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); ++ ++ VkMemoryAllocateInfo allocate_info; ++ static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; ++ allocate_info = EmptyVkMemoryAllocateInfo; ++ allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ++ allocate_info.allocationSize = mememory_requirements.size; ++ ++ allocate_info.memoryTypeIndex = UINT32_MAX; ++ for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) ++ { ++ if ((mememory_requirements.memoryTypeBits & (1 << i)) && ++ ((gpu_memory_properties.memoryTypes[i].propertyFlags & ++ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | ++ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == ++ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | ++ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) ++ { ++ allocate_info.memoryTypeIndex = i; ++ break; ++ } ++ } ++ assert((allocate_info.memoryTypeIndex != UINT32_MAX) && ++ "Failed to find suitable memory type for index."); ++ ++ VkResult err; ++ err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); ++ assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); ++ ++ err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); ++ assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); ++} ++ ++inline static void ++setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) ++{ ++ create_index_buffer(); ++ allocate_index_buffer(gpu_memory_properties); ++ ++ void *data; ++ VkResult err; ++ err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, ++ &data); ++ assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); ++ ++ memcpy(data, data_model_index, data_model_index_size); ++ ++ vkUnmapMemory(device, index_buffer_memmory); ++} ++ + inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) + { +@@ -1120,6 +1191,8 @@ + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + ++ vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); ++ + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( +@@ -1132,8 +1205,8 @@ + &ptr->uniform_map->descriptor_set, + 0, NULL); + +- vkCmdDraw(command_buffer, data_models[ptr->model].count, 1, +- data_models[ptr->model].first, 0); ++ vkCmdDrawIndexed(command_buffer, data_models[ptr->model].count, 1, ++ data_models[ptr->model].first, 0, 0); + + vkCmdEndRenderPass(command_buffer); + +@@ -1248,6 +1321,10 @@ + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; ++ vkFreeMemory(device, index_buffer_memmory, NULL); ++ index_buffer_memmory = VK_NULL_HANDLE; ++ vkDestroyBuffer(device, index_buffer, NULL); ++ index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); +@@ -1321,6 +1398,7 @@ + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); ++ setup_index_buffer(gpu_memory_properties); + + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; diff --git a/0003index-buffer/.gitignore b/0003index-buffer/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0003index-buffer/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0003index-buffer/0_frag.glsl b/0003index-buffer/0_frag.glsl new file mode 100644 index 0000000..f104a26 --- /dev/null +++ b/0003index-buffer/0_frag.glsl @@ -0,0 +1,45 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = vec4(0.0, 0.0, 0.059, 1.0); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0003index-buffer/0_vert.glsl b/0003index-buffer/0_vert.glsl new file mode 100644 index 0000000..be62be1 --- /dev/null +++ b/0003index-buffer/0_vert.glsl @@ -0,0 +1,50 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} ubo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = ubo.lightPos - pos.xyz; + outViewVec = ubo.viewPos - pos.xyz; +} diff --git a/0003index-buffer/Makefile b/0003index-buffer/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0003index-buffer/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0003index-buffer/data.h b/0003index-buffer/data.h new file mode 100644 index 0000000..874218a --- /dev/null +++ b/0003index-buffer/data.h @@ -0,0 +1,85 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; +extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +typedef struct data_model_instance +{ + char *name; + size_t model; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#endif diff --git a/0003index-buffer/data_bulk.c b/0003index-buffer/data_bulk.c new file mode 100644 index 0000000..f02a2fd --- /dev/null +++ b/0003index-buffer/data_bulk.c @@ -0,0 +1,92 @@ +#include "data_bulk.h" + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; +const vertex_t model_vertex[] = { + {{-0.5f, 0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 2.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{-0.5f, -0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.25f, 1.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {{0.5f, 0.5f, -0.5f}, + {0.0f, 0.0f, -1.0f}, + {0.25f, 2.0f / 3.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}, +}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } square[2]; +} *data_model_index = &(struct data_model_index){{ + {0, 2, 1}, + {0, 1, 3}, +}}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Square", + offsetof(struct data_model_index, square) / sizeof(uint32_t), + sizeof(data_model_index->square) / sizeof(uint32_t), + 0, + }, +}; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + }, +}; diff --git a/0003index-buffer/data_bulk.h b/0003index-buffer/data_bulk.h new file mode 100644 index 0000000..58330e4 --- /dev/null +++ b/0003index-buffer/data_bulk.h @@ -0,0 +1,16 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} material_0_ubo_t; diff --git a/0003index-buffer/data_dynamic.c.in b/0003index-buffer/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0003index-buffer/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0003index-buffer/libdata.c b/0003index-buffer/libdata.c new file mode 100644 index 0000000..8aedbc3 --- /dev/null +++ b/0003index-buffer/libdata.c @@ -0,0 +1,237 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +struct list_head data_model_instances; +struct +{ + data_model_instance_t obj; +} model_instance = { + {"Object", + 0, + {&(data_model_instances), &(data_model_instances)}, + NULL, + NULL}, +}; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + uniform_map_t **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = this_map; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = this_map; + } +} + +uintptr_t data_uniform_ptr = 0; +void (*data_setup_model_instance)(uniform_map_t *uniform_map); +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = map; + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp(material_0_ubo_t *ubo_0) +{ + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + + setup_model_instance(inst); + ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + ubo_0->lightPos[0] = 0.0f; + ubo_0->lightPos[1] = 250.0f; + ubo_0->lightPos[2] = -250.0f; + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(ubo_0); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) +{ + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + ubo_0->viewPos[0] += sinf(center_dir) * dist; + ubo_0->viewPos[2] += cosf(center_dir) * dist; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (need_lookat) + update_vp(ubo_0); +} + +void data_update() +{ + material_0_ubo_t *ubo_0 = + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; + double this_frame = glfwGetTime(); + + handle_input(this_frame, ubo_0); + + /* TODO: Take turns. */ + + if (0) + { + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0003index-buffer/vulkan.c b/0003index-buffer/vulkan.c new file mode 100644 index 0000000..ef27244 --- /dev/null +++ b/0003index-buffer/vulkan.c @@ -0,0 +1,1417 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[1]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = 1; + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[1]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + VkWriteDescriptorSet write_descriptor_sets[1]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + + vkUpdateDescriptorSets(device, 1, write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(uniform_map_t *uniform_map) +{ + if (uniform_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&uniform_map->descriptor_set); + update_descriptor_set(uniform_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[ptr->model].material] + .shader]); + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &ptr->uniform_map->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[ptr->model].count, 1, + data_models[ptr->model].first, 0, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void clean_up(VkPipeline *graphics_pipelines, + VkShaderModule *frag_modules, + VkShaderModule *vert_modules, + uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + list_entry(data_model_instances.next, data_model_instance_t, list) + ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = + NULL; + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, graphics_pipelines); + + clean_up(graphics_pipelines, frag_modules, vert_modules, + swapchain_image_count); + exit(0); +} diff --git a/0004cube.diff b/0004cube.diff new file mode 100644 index 0000000..a7facfb --- /dev/null +++ b/0004cube.diff @@ -0,0 +1,271 @@ +diff -bNur 0003index-buffer/data_bulk.c 0004cube/data_bulk.c +--- 0003index-buffer/data_bulk.c 2019-03-02 20:06:22.813345353 -0600 ++++ 0004cube/data_bulk.c 2019-03-02 20:06:22.817345540 -0600 +@@ -8,25 +8,181 @@ + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; + } vertex_t; ++ ++/* Texture ++ ####0AA1######## ++ ####AAAA######## ++ ####AAAA######## ++ ####2AA3######## ++ 4BB56CC78DD9aEEb ++ BBBBCCCCDDDDEEEE ++ BBBBCCCCDDDDEEEE ++ cBBdeCCfgDDhEEEi ++ ####jFFk######## ++ ####FFFF######## ++ ####FFFF######## ++ ####lFFm######## ++ */ ++ ++#define DMVPFR -0.5f ++#define DMVPBA 0.5f ++#define DMVPBO -0.5f ++#define DMVPTO 0.5f ++#define DMVPRI -0.5f ++#define DMVPLE 0.5f ++ ++#define DMVUXONE 0.0f ++#define DMVUXTWO 0.25f ++#define DMVUXTHR 0.5f ++#define DMVUXFOR 0.75f ++#define DMVUXFIV 1.0f ++#define DMVUYONE 0.0f ++#define DMVUYTWO 1.0f / 3.0f ++#define DMVUYTHR 2.0f / 3.0f ++#define DMVUYFOR 1.0f + const vertex_t model_vertex[] = { +- {{-0.5f, 0.5f, -0.5f}, +- {0.0f, 0.0f, -1.0f}, +- {0.0f, 2.0f / 3.0f}, ++ {// 0 ++ {DMVPLE, DMVPTO, DMVPBA}, ++ {0.0f, DMVPTO * 2, 0.0f}, ++ {DMVUXTWO, DMVUYONE}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {// 1 ++ {DMVPRI, DMVPTO, DMVPBA}, ++ {0.0f, DMVPTO * 2, 0.0f}, ++ {DMVUXTHR, DMVUYONE}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {// 2 ++ {DMVPLE, DMVPTO, DMVPFR}, ++ {0.0f, DMVPTO * 2, 0.0f}, ++ {DMVUXTWO, DMVUYTWO}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {// 3 ++ {DMVPRI, DMVPTO, DMVPFR}, ++ {0.0f, DMVPTO * 2, 0.0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V, DMVUYTHR}, ++ {1.0f, 0.0f, 0.0f, 0.0f}, ++ {0, 0, 0, 0}}, ++ {// k ++ {DMVPLE, DMVPBO, DMVPFR}, ++ {0.0f, DMVPBO * 2, 0.0f}, ++ {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +- {{0.5f, -0.5f, -0.5f}, +- {0.0f, 0.0f, -1.0f}, +- {0.0f, 1.0f / 3.0f}, ++ {// k ++ {DMVPRI, DMVPBO, DMVPFR}, ++ {0.0f, DMVPBO * 2, 0.0f}, ++ {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +- {{-0.5f, -0.5f, -0.5f}, +- {0.0f, 0.0f, -1.0f}, +- {0.25f, 1.0f / 3.0f}, ++ {// m ++ {DMVPLE, DMVPBO, DMVPBA}, ++ {0.0f, DMVPBO * 2, 0.0f}, ++ {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +- {{0.5f, 0.5f, -0.5f}, +- {0.0f, 0.0f, -1.0f}, +- {0.25f, 2.0f / 3.0f}, ++ {// n ++ {DMVPRI, DMVPBO, DMVPBA}, ++ {0.0f, DMVPBO * 2, 0.0f}, ++ {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + }; +@@ -67,18 +223,28 @@ + struct + { + uint32_t first, second, third; +- } square[2]; ++ } cube[12]; + } *data_model_index = &(struct data_model_index){{ +- {0, 2, 1}, +- {0, 1, 3}, ++ {2, 0, 1}, // A ++ {2, 1, 3}, ++ {12, 4, 5}, // B ++ {12, 5, 13}, ++ {14, 6, 7}, // C ++ {14, 7, 15}, ++ {16, 8, 9}, // D ++ {16, 9, 17}, ++ {18, 10, 11}, // E ++ {18, 11, 19}, ++ {22, 20, 21}, // F ++ {22, 21, 23}, + }}; + const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + + data_model_t data_models[] = { + { +- "Square", +- offsetof(struct data_model_index, square) / sizeof(uint32_t), +- sizeof(data_model_index->square) / sizeof(uint32_t), ++ "Cube", ++ offsetof(struct data_model_index, cube) / sizeof(uint32_t), ++ sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, + }; +diff -bNur 0003index-buffer/libdata.c 0004cube/libdata.c +--- 0003index-buffer/libdata.c 2019-03-02 20:06:22.813345353 -0600 ++++ 0004cube/libdata.c 2019-03-02 20:06:22.817345540 -0600 +@@ -192,6 +192,7 @@ + + inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) + { ++ float diagnal2 = 1; + bool need_lookat = false; + + #define GET_KEY(key) glfwGetKey(data_window, (key)) +@@ -200,8 +201,10 @@ + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); +- ubo_0->viewPos[0] += sinf(center_dir) * dist; +- ubo_0->viewPos[2] += cosf(center_dir) * dist; ++ if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) ++ diagnal2 = 0.70710678119f; ++ ubo_0->viewPos[0] += sinf(center_dir) * dist * diagnal2; ++ ubo_0->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + +@@ -212,6 +215,14 @@ + need_lookat = true; + } + ++ if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) ++ { ++ double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame ++ : previous_frame - this_frame); ++ ubo_0->viewPos[1] += dist * diagnal2; ++ need_lookat = true; ++ } ++ + if (need_lookat) + update_vp(ubo_0); + } diff --git a/0004cube/.gitignore b/0004cube/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0004cube/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0004cube/0_frag.glsl b/0004cube/0_frag.glsl new file mode 100644 index 0000000..f104a26 --- /dev/null +++ b/0004cube/0_frag.glsl @@ -0,0 +1,45 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = vec4(0.0, 0.0, 0.059, 1.0); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0004cube/0_vert.glsl b/0004cube/0_vert.glsl new file mode 100644 index 0000000..be62be1 --- /dev/null +++ b/0004cube/0_vert.glsl @@ -0,0 +1,50 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} ubo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = ubo.lightPos - pos.xyz; + outViewVec = ubo.viewPos - pos.xyz; +} diff --git a/0004cube/Makefile b/0004cube/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0004cube/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0004cube/data.h b/0004cube/data.h new file mode 100644 index 0000000..874218a --- /dev/null +++ b/0004cube/data.h @@ -0,0 +1,85 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; +extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +typedef struct data_model_instance +{ + char *name; + size_t model; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#endif diff --git a/0004cube/data_bulk.c b/0004cube/data_bulk.c new file mode 100644 index 0000000..e980dd6 --- /dev/null +++ b/0004cube/data_bulk.c @@ -0,0 +1,258 @@ +#include "data_bulk.h" + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}, +}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12]; +} *data_model_index = &(struct data_model_index){{ + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, +}}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, +}; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + }, +}; diff --git a/0004cube/data_bulk.h b/0004cube/data_bulk.h new file mode 100644 index 0000000..58330e4 --- /dev/null +++ b/0004cube/data_bulk.h @@ -0,0 +1,16 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} material_0_ubo_t; diff --git a/0004cube/data_dynamic.c.in b/0004cube/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0004cube/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0004cube/libdata.c b/0004cube/libdata.c new file mode 100644 index 0000000..0cb3254 --- /dev/null +++ b/0004cube/libdata.c @@ -0,0 +1,248 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +struct list_head data_model_instances; +struct +{ + data_model_instance_t obj; +} model_instance = { + {"Object", + 0, + {&(data_model_instances), &(data_model_instances)}, + NULL, + NULL}, +}; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + uniform_map_t **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = this_map; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = this_map; + } +} + +uintptr_t data_uniform_ptr = 0; +void (*data_setup_model_instance)(uniform_map_t *uniform_map); +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = map; + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp(material_0_ubo_t *ubo_0) +{ + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + + setup_model_instance(inst); + ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + ubo_0->lightPos[0] = 0.0f; + ubo_0->lightPos[1] = 250.0f; + ubo_0->lightPos[2] = -250.0f; + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(ubo_0); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + ubo_0->viewPos[0] += sinf(center_dir) * dist * diagnal2; + ubo_0->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + ubo_0->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(ubo_0); +} + +void data_update() +{ + material_0_ubo_t *ubo_0 = + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; + double this_frame = glfwGetTime(); + + handle_input(this_frame, ubo_0); + + /* TODO: Take turns. */ + + if (0) + { + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0004cube/vulkan.c b/0004cube/vulkan.c new file mode 100644 index 0000000..ef27244 --- /dev/null +++ b/0004cube/vulkan.c @@ -0,0 +1,1417 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[1]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = 1; + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[1]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + VkWriteDescriptorSet write_descriptor_sets[1]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + + vkUpdateDescriptorSets(device, 1, write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(uniform_map_t *uniform_map) +{ + if (uniform_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&uniform_map->descriptor_set); + update_descriptor_set(uniform_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[ptr->model].material] + .shader]); + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &ptr->uniform_map->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[ptr->model].count, 1, + data_models[ptr->model].first, 0, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void clean_up(VkPipeline *graphics_pipelines, + VkShaderModule *frag_modules, + VkShaderModule *vert_modules, + uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + list_entry(data_model_instances.next, data_model_instance_t, list) + ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = + NULL; + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, graphics_pipelines); + + clean_up(graphics_pipelines, frag_modules, vert_modules, + swapchain_image_count); + exit(0); +} diff --git a/0005texture.diff b/0005texture.diff new file mode 100644 index 0000000..e78a73d --- /dev/null +++ b/0005texture.diff @@ -0,0 +1,991 @@ +diff -bNur 0004cube/0_frag.glsl 0005texture/0_frag.glsl +--- 0004cube/0_frag.glsl 2019-03-02 19:55:02.553357906 -0600 ++++ 0005texture/0_frag.glsl 2019-03-02 19:55:02.557358008 -0600 +@@ -3,6 +3,8 @@ + #extension GL_ARB_separate_shader_objects : enable + #extension GL_ARB_shading_language_420pack : enable + ++layout (binding = 1) uniform sampler2D samplerColorMap; ++ + layout (location = 0) in vec2 inUV; + layout (location = 1) in vec3 inNormal; + layout (location = 2) in vec3 inViewVec; +@@ -12,7 +14,7 @@ + + void main() + { +- vec4 color = vec4(0.0, 0.0, 0.059, 1.0); ++ vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); +diff -bNur 0004cube/data_bulk.c 0005texture/data_bulk.c +--- 0004cube/data_bulk.c 2019-03-02 20:06:22.817345540 -0600 ++++ 0005texture/data_bulk.c 2019-03-02 20:06:22.817345540 -0600 +@@ -1,4 +1,5 @@ + #include "data_bulk.h" ++#include + + typedef struct + { +@@ -212,8 +213,7 @@ + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, +- .offset = offsetof(vertex_t, boneIDs)}, +-}; ++ .offset = offsetof(vertex_t, boneIDs)}}; + const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); +@@ -249,10 +249,498 @@ + }, + }; + ++#define DMTCLEAR \ ++ { \ ++ {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ ++ {0, 0, 0, 0}, {0, 0, 0, 0}, \ ++ { \ ++ 0, 0, 0, 0 \ ++ } \ ++ } ++#define DMTCONE 0xff ++#define DMTCTWO 0xf0 ++#define DMTCTHR 0xe0 ++#define DMTCFOR 0xd0 ++#define DMTCFIV 0xc0 ++#define DMTCSIX 0xb0 ++#define DMTCSEV 0xa0 ++#define DMTCEIG 0x90 ++#define DMTCNIN 0x80 ++#define DMTCTEN 0x70 ++#define DMTCELE 0x60 ++#define DMTCTWE 0x50 ++#define DMTCTHT 0x40 ++#define DMTCFOT 0x30 ++#define DMTCFIT 0x20 ++#define DMTCSIT 0x10 ++typedef struct ++{ ++ struct ++ { ++ struct ++ { ++ struct ++ { ++ struct ++ { ++ uint8_t red, green, blue, alpha; ++ } one, two, three, four, five, six, seven, eight; ++ } one, two, three, four; ++ } one, two, three, four, five, six, seven, eight; ++ } one, two, three; ++} texture_0_t; ++ + const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), ++ VK_FORMAT_R8G8B8A8_UNORM, ++ 8 * 4, ++ 8 * 3, ++ (void *)&(texture_0_t){{{DMTCLEAR, ++ { ++ {DMTCONE, 0, DMTCONE, 0xff}, ++ {DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}, ++ }, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFIV, 0, DMTCONE, 0xff}, ++ {DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}, ++ {0, DMTCFIV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}}, ++ {{{{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++#if 1 ++ {0xff, 0xff, 0xff, 0xff}, ++#else ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++#endif ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}}, ++ {{{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++#if 1 ++ {{0xff, 0xff, 0xff, 0xff}, ++ {0xff, 0xff, 0xff, 0xff}, ++#else ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++#endif ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}, ++ {{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}}, ++ {{{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}, ++ {{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}}, ++ {{{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}, ++ {{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}}, ++ {{{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}, ++ {{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}}, ++ {{{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}, ++ {{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}}, ++ {{{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}, ++ {{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}}, ++ {{{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}}}, ++ {{DMTCLEAR, ++ {{DMTCONE, 0, DMTCONE, 0xff}, ++ {DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFIV, 0, DMTCONE, 0xff}, ++ {DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}, ++ {0, DMTCFIV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}}}, ++ sizeof(texture_0_t), + }, + }; +diff -bNur 0004cube/data.h 0005texture/data.h +--- 0004cube/data.h 2019-03-02 19:55:02.557358008 -0600 ++++ 0005texture/data.h 2019-03-02 19:55:02.557358008 -0600 +@@ -31,8 +31,7 @@ + extern const struct data_model_index *data_model_index; + extern const VkDeviceSize data_model_index_size; + +-typedef struct +-{ ++typedef struct { + char *name; + uint32_t first; + uint32_t count; +@@ -44,8 +43,7 @@ + #define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) + #define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) + #define UNIFORM_SIZE (4096 * 4096) +-typedef struct +-{ ++typedef struct { + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; +@@ -54,8 +52,7 @@ + } uniform_map_t; + extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +-typedef struct data_model_instance +-{ ++typedef struct data_model_instance { + char *name; + size_t model; + struct list_head list; +@@ -64,21 +61,23 @@ + } data_model_instance_t; + extern struct list_head data_model_instances; + +-typedef struct +-{ +- struct +- { ++typedef struct { ++ struct { + const void *spv; + const size_t *size; + } vert, frag; + } data_material_shader_t; + extern const data_material_shader_t data_material_shaders[]; + +-typedef struct +-{ ++typedef struct { + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; ++ VkFormat texture_format; ++ uint32_t texture_width; ++ uint32_t texture_height; ++ void *texture; ++ VkDeviceSize texture_size; + } data_material_t; + extern const data_material_t data_materials[]; + +diff -bNur 0004cube/vulkan.c 0005texture/vulkan.c +--- 0004cube/vulkan.c 2019-03-02 20:06:22.817345540 -0600 ++++ 0005texture/vulkan.c 2019-03-03 15:05:42.770226379 -0600 +@@ -25,10 +25,12 @@ + VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; + VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; + VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; ++VkSampler texture_image_sampler; + VkBuffer vertex_buffer = VK_NULL_HANDLE; + VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; + VkBuffer index_buffer = VK_NULL_HANDLE; + VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; ++VkImageView *texture_image_views; + VkCommandPool command_pool = VK_NULL_HANDLE; + VkSemaphore wait_semaphore = VK_NULL_HANDLE; + VkFence queue_submit_fence = VK_NULL_HANDLE; +@@ -588,7 +590,7 @@ + + inline static void create_descriptor_set_layout() + { +- VkDescriptorSetLayoutBinding set_layout_bindings[1]; ++ VkDescriptorSetLayoutBinding set_layout_bindings[2]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; +@@ -596,6 +598,13 @@ + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + ++ set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; ++ set_layout_bindings[1].descriptorType = ++ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; ++ set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; ++ set_layout_bindings[1].binding = 1; ++ set_layout_bindings[1].descriptorCount = 1; ++ + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; +@@ -603,7 +612,8 @@ + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; +- set_layout_create_info.bindingCount = 1; ++ set_layout_create_info.bindingCount = ++ sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, +@@ -663,7 +673,7 @@ + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + +- VkWriteDescriptorSet write_descriptor_sets[1]; ++ VkWriteDescriptorSet write_descriptor_sets[2]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; +@@ -673,7 +683,25 @@ + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + +- vkUpdateDescriptorSets(device, 1, write_descriptor_sets, 0, NULL); ++ VkDescriptorImageInfo image_info; ++ static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; ++ image_info = EmptyVkDescriptorImageInfo; ++ image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; ++ image_info.imageView = texture_image_views[0]; ++ image_info.sampler = texture_image_sampler; ++ ++ write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; ++ write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; ++ write_descriptor_sets[1].dstSet = map->descriptor_set; ++ write_descriptor_sets[1].descriptorType = ++ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; ++ write_descriptor_sets[1].dstBinding = 1; ++ write_descriptor_sets[1].pImageInfo = &image_info; ++ write_descriptor_sets[1].descriptorCount = 1; ++ ++ vkUpdateDescriptorSets( ++ device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), ++ write_descriptor_sets, 0, NULL); + } + + void setup_model_instance(uniform_map_t *uniform_map) +@@ -699,11 +727,39 @@ + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); + } + ++inline static void create_texture_image_sampler() ++{ ++ VkSamplerCreateInfo sampler_info; ++ static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; ++ sampler_info = EmptyVkSamplerCreateInfo; ++ sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; ++ sampler_info.magFilter = VK_FILTER_LINEAR; ++ sampler_info.minFilter = VK_FILTER_LINEAR; ++ sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; ++ sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; ++ sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; ++ sampler_info.anisotropyEnable = VK_FALSE; ++ sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; ++ sampler_info.unnormalizedCoordinates = VK_FALSE; ++ sampler_info.compareEnable = VK_FALSE; ++ sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; ++ sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; ++ sampler_info.mipLodBias = 0.0f; ++ sampler_info.minLod = 0.0f; ++ sampler_info.maxLod = 0.0f; ++ ++ VkResult err; ++ err = ++ vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); ++ assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); ++} ++ + inline static void setup_descriptor_set() + { + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); ++ create_texture_image_sampler(); + } + + inline static void create_vertex_buffer() +@@ -844,6 +900,124 @@ + vkUnmapMemory(device, index_buffer_memmory); + } + ++inline static void create_texture_images(VkImage *texture_images) ++{ ++ VkImageCreateInfo image_create_info; ++ static const VkImageCreateInfo EmptyVkImageViewCreateInfo; ++ image_create_info = EmptyVkImageViewCreateInfo; ++ image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; ++ image_create_info.imageType = VK_IMAGE_TYPE_2D; ++ image_create_info.format = data_materials[0].texture_format; ++ image_create_info.extent.width = data_materials[0].texture_width; ++ image_create_info.extent.height = data_materials[0].texture_height; ++ image_create_info.extent.depth = 1; ++ image_create_info.mipLevels = 1; ++ image_create_info.arrayLayers = 1; ++ image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; ++ image_create_info.tiling = VK_IMAGE_TILING_LINEAR; ++ image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; ++ image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; ++ image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; ++ image_create_info.pQueueFamilyIndices = NULL; ++ image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; ++ ++ VkResult err; ++ err = vkCreateImage(device, &image_create_info, NULL, &texture_images[0]); ++ assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); ++} ++ ++inline static void ++allocate_texture_image(VkImage texture_image, ++ VkPhysicalDeviceMemoryProperties gpu_memory_properties, ++ VkDeviceMemory *texture_image_memory) ++{ ++ VkMemoryAllocateInfo memory_allocate_info; ++ static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; ++ memory_allocate_info = EmptyVkMemoryAllocateInfo; ++ memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ++ ++ VkMemoryRequirements image_memory_requirements; ++ vkGetImageMemoryRequirements(device, texture_image, ++ &image_memory_requirements); ++ memory_allocate_info.allocationSize = image_memory_requirements.size; ++ ++ memory_allocate_info.memoryTypeIndex = UINT32_MAX; ++ for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) ++ { ++ if ((image_memory_requirements.memoryTypeBits & (1 << i)) && ++ ((gpu_memory_properties.memoryTypes[i].propertyFlags & ++ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | ++ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == ++ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | ++ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) ++ { ++ memory_allocate_info.memoryTypeIndex = i; ++ break; ++ } ++ } ++ assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && ++ "Couldn't locate texture memory."); ++ ++ VkResult err; ++ err = vkAllocateMemory(device, &memory_allocate_info, NULL, ++ texture_image_memory); ++ assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); ++ err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); ++ assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); ++} ++ ++inline static void ++setup_texture_images(VkImage *texture_images, ++ VkPhysicalDeviceMemoryProperties gpu_memory_properties, ++ VkDeviceMemory *texture_image_memorys) ++{ ++ create_texture_images(texture_images); ++ allocate_texture_image(texture_images[0], gpu_memory_properties, ++ &texture_image_memorys[0]); ++ ++ void *data; ++ vkMapMemory(device, texture_image_memorys[0], 0, ++ data_materials[0].texture_size, 0, &data); ++ memcpy(data, data_materials[0].texture, data_materials[0].texture_size); ++ vkUnmapMemory(device, texture_image_memorys[0]); ++} ++ ++inline static void create_image_views(VkImage *texture_images) ++{ ++ VkImageViewCreateInfo image_view_create_info; ++ static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; ++ image_view_create_info = EmptyVkImageViewCreateInfo; ++ image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; ++ image_view_create_info.image = texture_images[0]; ++ image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; ++ image_view_create_info.format = data_materials[0].texture_format; ++ image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; ++ image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; ++ image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; ++ image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; ++ image_view_create_info.subresourceRange.aspectMask = ++ VK_IMAGE_ASPECT_COLOR_BIT; ++ image_view_create_info.subresourceRange.baseMipLevel = 0; ++ image_view_create_info.subresourceRange.levelCount = 1; ++ image_view_create_info.subresourceRange.baseArrayLayer = 0; ++ image_view_create_info.subresourceRange.layerCount = 1; ++ ++ VkResult err; ++ err = vkCreateImageView(device, &image_view_create_info, NULL, ++ &texture_image_views[0]); ++ assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); ++} ++ ++inline static void ++setup_textures(VkImage *texture_images, ++ VkPhysicalDeviceMemoryProperties gpu_memory_properties, ++ VkDeviceMemory *texture_image_memorys) ++{ ++ setup_texture_images(texture_images, gpu_memory_properties, ++ texture_image_memorys); ++ create_image_views(texture_images); ++} ++ + inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) + { +@@ -1027,10 +1201,14 @@ + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); + } + +-inline static void setup_materials(VkShaderModule *vert_modules, ++inline static void setup_materials(VkImage *texture_images, ++ VkPhysicalDeviceMemoryProperties gpu_memory_properties, ++ VkDeviceMemory *texture_image_memorys, ++ VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) + { ++ setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); + } +@@ -1130,6 +1308,28 @@ + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); + } + ++inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) ++{ ++ VkImageMemoryBarrier barriers[1]; ++ static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; ++ barriers[0] = EmptyVkImageMemoryBarrier; ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; ++ barriers[0].image = texture_images[0]; ++ barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; ++ ++ vkCmdPipelineBarrier( ++ command_buffer, ++ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ++ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, ++ 0, ++ 0, VK_NULL_HANDLE, ++ 0, VK_NULL_HANDLE, ++ 1, barriers); ++} ++ + inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) + { +@@ -1179,11 +1379,17 @@ + vkCmdSetViewport(command_buffer, 0, 1, &viewport); + } + +-inline static void record_commands(VkCommandBuffer command_buffer, ++inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) + { + begin_command_buffer(command_buffer); ++ ++ static bool init = true; ++ if (init) ++ image_barriers(command_buffer, texture_images); ++ init = false; ++ + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + +@@ -1265,6 +1471,7 @@ + } + + inline static void blocking_render_loop(uint32_t queue_family_index, ++ VkImage *texture_images, + VkPipeline *graphics_pipelines) + { + VkCommandBuffer command_buffer; +@@ -1288,7 +1495,8 @@ + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); +- record_commands(command_buffer, active_swapchain_image_id, ++ record_commands(command_buffer, texture_images, ++ active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); +@@ -1300,10 +1508,10 @@ + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); + } + +-inline static void clean_up(VkPipeline *graphics_pipelines, +- VkShaderModule *frag_modules, +- VkShaderModule *vert_modules, +- uint32_t swapchain_image_count) ++inline static void ++clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, ++ VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, ++ VkShaderModule *vert_modules, uint32_t swapchain_image_count) + { + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; +@@ -1337,6 +1545,14 @@ + ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; ++ vkDestroySampler(device, texture_image_sampler, NULL); ++ texture_image_sampler = VK_NULL_HANDLE; ++ vkDestroyImageView(device, texture_image_views[0], NULL); ++ texture_image_views[0] = VK_NULL_HANDLE; ++ vkFreeMemory(device, texture_image_memorys[0], NULL); ++ texture_image_memorys[0] = VK_NULL_HANDLE; ++ vkDestroyImage(device, texture_images[0], NULL); ++ texture_images[0] = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = + NULL; +@@ -1400,18 +1616,22 @@ + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + ++ VkImage texture_images[] = {VK_NULL_HANDLE}; ++ VkDeviceMemory texture_image_memorys[] = {VK_NULL_HANDLE}; ++ VkImageView _texture_image_views[] = {VK_NULL_HANDLE}; ++ texture_image_views = _texture_image_views; + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; +- setup_materials(vert_modules, frag_modules, graphics_pipelines); ++ setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); +- blocking_render_loop(queue_family_index, graphics_pipelines); ++ blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + +- clean_up(graphics_pipelines, frag_modules, vert_modules, +- swapchain_image_count); ++ clean_up(texture_images, texture_image_memorys, graphics_pipelines, ++ frag_modules, vert_modules, swapchain_image_count); + exit(0); + } diff --git a/0005texture/.gitignore b/0005texture/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0005texture/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0005texture/0_frag.glsl b/0005texture/0_frag.glsl new file mode 100644 index 0000000..4f29a5c --- /dev/null +++ b/0005texture/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0005texture/0_vert.glsl b/0005texture/0_vert.glsl new file mode 100644 index 0000000..be62be1 --- /dev/null +++ b/0005texture/0_vert.glsl @@ -0,0 +1,50 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} ubo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = ubo.lightPos - pos.xyz; + outViewVec = ubo.viewPos - pos.xyz; +} diff --git a/0005texture/Makefile b/0005texture/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0005texture/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0005texture/data.h b/0005texture/data.h new file mode 100644 index 0000000..8f72907 --- /dev/null +++ b/0005texture/data.h @@ -0,0 +1,84 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +typedef struct { + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +typedef struct { + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; +extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +typedef struct data_model_instance { + char *name; + size_t model; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; + +typedef struct { + struct { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct { + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#endif diff --git a/0005texture/data_bulk.c b/0005texture/data_bulk.c new file mode 100644 index 0000000..812f77b --- /dev/null +++ b/0005texture/data_bulk.c @@ -0,0 +1,746 @@ +#include "data_bulk.h" +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12]; +} *data_model_index = &(struct data_model_index){{ + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, +}}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, +}; + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; diff --git a/0005texture/data_bulk.h b/0005texture/data_bulk.h new file mode 100644 index 0000000..58330e4 --- /dev/null +++ b/0005texture/data_bulk.h @@ -0,0 +1,16 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} material_0_ubo_t; diff --git a/0005texture/data_dynamic.c.in b/0005texture/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0005texture/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0005texture/libdata.c b/0005texture/libdata.c new file mode 100644 index 0000000..0cb3254 --- /dev/null +++ b/0005texture/libdata.c @@ -0,0 +1,248 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +struct list_head data_model_instances; +struct +{ + data_model_instance_t obj; +} model_instance = { + {"Object", + 0, + {&(data_model_instances), &(data_model_instances)}, + NULL, + NULL}, +}; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + uniform_map_t **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = this_map; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = this_map; + } +} + +uintptr_t data_uniform_ptr = 0; +void (*data_setup_model_instance)(uniform_map_t *uniform_map); +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = map; + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp(material_0_ubo_t *ubo_0) +{ + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + + setup_model_instance(inst); + ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + ubo_0->lightPos[0] = 0.0f; + ubo_0->lightPos[1] = 250.0f; + ubo_0->lightPos[2] = -250.0f; + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(ubo_0); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + ubo_0->viewPos[0] += sinf(center_dir) * dist * diagnal2; + ubo_0->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + ubo_0->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(ubo_0); +} + +void data_update() +{ + material_0_ubo_t *ubo_0 = + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; + double this_frame = glfwGetTime(); + + handle_input(this_frame, ubo_0); + + /* TODO: Take turns. */ + + if (0) + { + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0005texture/vulkan.c b/0005texture/vulkan.c new file mode 100644 index 0000000..7e14159 --- /dev/null +++ b/0005texture/vulkan.c @@ -0,0 +1,1637 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[2]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[1]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + VkWriteDescriptorSet write_descriptor_sets[2]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + image_info.imageView = texture_image_views[0]; + image_info.sampler = texture_image_sampler; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(uniform_map_t *uniform_map) +{ + if (uniform_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&uniform_map->descriptor_set); + update_descriptor_set(uniform_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = data_materials[0].texture_format; + image_create_info.extent.width = data_materials[0].texture_width; + image_create_info.extent.height = data_materials[0].texture_height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[0]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + allocate_texture_image(texture_images[0], gpu_memory_properties, + &texture_image_memorys[0]); + + void *data; + vkMapMemory(device, texture_image_memorys[0], 0, + data_materials[0].texture_size, 0, &data); + memcpy(data, data_materials[0].texture, data_materials[0].texture_size); + vkUnmapMemory(device, texture_image_memorys[0]); +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = texture_images[0]; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = data_materials[0].texture_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[0]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[ptr->model].material] + .shader]); + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &ptr->uniform_map->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[ptr->model].count, 1, + data_models[ptr->model].first, 0, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + list_entry(data_model_instances.next, data_model_instance_t, list) + ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + vkDestroyImageView(device, texture_image_views[0], NULL); + texture_image_views[0] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[0], NULL); + texture_image_memorys[0] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[0], NULL); + texture_images[0] = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = + NULL; + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[] = {VK_NULL_HANDLE}; + VkDeviceMemory texture_image_memorys[] = {VK_NULL_HANDLE}; + VkImageView _texture_image_views[] = {VK_NULL_HANDLE}; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0006multi-model.diff b/0006multi-model.diff new file mode 100644 index 0000000..509a0cc --- /dev/null +++ b/0006multi-model.diff @@ -0,0 +1,335 @@ +diff -bNur 0005texture/data_bulk.c 0006multi-model/data_bulk.c +--- 0005texture/data_bulk.c 2019-03-02 20:06:22.817345540 -0600 ++++ 0006multi-model/data_bulk.c 2019-03-02 20:06:22.821345727 -0600 +@@ -223,8 +223,9 @@ + struct + { + uint32_t first, second, third; +- } cube[12]; +-} *data_model_index = &(struct data_model_index){{ ++ } cube[12], other_cube[12]; ++} *data_model_index = &(struct data_model_index){ ++ { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B +@@ -237,7 +238,22 @@ + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, +-}}; ++ }, ++ { ++ {2, 0, 1}, // A ++ {2, 1, 3}, ++ {12, 4, 5}, // B ++ {12, 5, 13}, ++ {14, 6, 7}, // C ++ {14, 7, 15}, ++ {16, 8, 9}, // D ++ {16, 9, 17}, ++ {18, 10, 11}, // E ++ {18, 11, 19}, ++ {22, 20, 21}, // F ++ {22, 21, 23}, ++ }, ++}; + const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + + data_model_t data_models[] = { +@@ -247,8 +263,16 @@ + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, ++ { ++ "Other Cube", ++ offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), ++ sizeof(data_model_index->other_cube) / sizeof(uint32_t), ++ 0, ++ }, + }; + ++mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } ++ + #define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ +@@ -295,6 +319,7 @@ + "Example", + 0, + sizeof(material_0_ubo_t), ++ get_model_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, +diff -bNur 0005texture/data.h 0006multi-model/data.h +--- 0005texture/data.h 2019-03-02 19:55:02.557358008 -0600 ++++ 0006multi-model/data.h 2019-03-02 19:55:02.561358109 -0600 +@@ -55,6 +55,8 @@ + typedef struct data_model_instance { + char *name; + size_t model; ++ void (*update)(struct data_model_instance *, double); ++ void *closure; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +@@ -73,6 +75,7 @@ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; ++ mat4 *(*get_model)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; +diff -bNur 0005texture/libdata.c 0006multi-model/libdata.c +--- 0005texture/libdata.c 2019-03-02 20:06:22.817345540 -0600 ++++ 0006multi-model/libdata.c 2019-03-02 20:06:22.821345727 -0600 +@@ -32,19 +32,43 @@ + }}, + }; + +-struct list_head data_model_instances; +-struct ++void shoot_forward(data_model_instance_t *ptr, double t) + { +- data_model_instance_t obj; +-} model_instance = { +- {"Object", ++ mat4 rot0, ++ *model = ++ data_materials[data_models[ptr->model].material].get_model(ptr->ubo); ++ glm_translate_z(*model, 3 * t); ++ glm_rotate_z(*model, t, rot0); ++ glm_mat4_copy(rot0, *model); ++} ++ ++typedef struct ++{ ++ data_model_instance_t obj, other_obj; ++} model_instance_t; ++model_instance_t model_instance; ++struct list_head data_model_instances = {&(model_instance.obj.list), ++ &(model_instance.other_obj.list)}; ++model_instance_t model_instance = { ++ { ++ "Object", + 0, +- {&(data_model_instances), &(data_model_instances)}, + NULL, +- NULL}, ++ NULL, ++ {&(model_instance.other_obj.list), &(data_model_instances)}, ++ NULL, ++ VK_NULL_HANDLE, ++ }, ++ { ++ "Other Object", ++ 1, ++ shoot_forward, ++ NULL, ++ {&(data_model_instances), &(model_instance.obj.list)}, ++ NULL, ++ VK_NULL_HANDLE, ++ }, + }; +-struct list_head data_model_instances = {&(model_instance.obj.list), +- &(model_instance.obj.list)}; + + uniform_map_t starting_map; + struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +@@ -130,13 +154,16 @@ + + mat4 projection; + mat4 view; +-inline static void update_vp(material_0_ubo_t *ubo_0) ++inline static void update_vp(material_0_ubo_t *ubo_0, material_0_ubo_t *ubo_1) + { ++ glm_vec_copy(ubo_0->viewPos, ubo_1->viewPos); ++ + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); ++ glm_mat4_copy(ubo_0->vp, ubo_1->vp); + } + + /* +@@ -148,12 +175,12 @@ + + void data_init(VkExtent2D extent) + { +- material_0_ubo_t *ubo_0; +- data_model_instance_t *inst = +- list_entry(data_model_instances.next, data_model_instance_t, list); +- ++ material_0_ubo_t *ubo_0, *ubo_1; ++ data_model_instance_t *inst; ++ list_for_each_entry(inst, &data_model_instances, list) + setup_model_instance(inst); +- ubo_0 = inst->ubo; ++ ubo_0 = (list_entry(data_model_instances.next, data_model_instance_t, list))->ubo; ++ ubo_1 = (list_entry(data_model_instances.prev, data_model_instance_t, list))->ubo; + + glfwSetKeyCallback(data_window, key_callback); + +@@ -185,12 +212,16 @@ + oglproj, projection); + #endif + +- update_vp(ubo_0); ++ update_vp(ubo_0, ubo_1); ++ ++ *ubo_1 = *ubo_0; ++ glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model); + + previous_frame = glfwGetTime(); + } + +-inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0) ++inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0, ++ material_0_ubo_t *ubo_1) + { + float diagnal2 = 1; + bool need_lookat = false; +@@ -224,18 +255,107 @@ + } + + if (need_lookat) +- update_vp(ubo_0); ++ update_vp(ubo_0, ubo_1); ++} ++ ++void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) ++{ ++ rot[0] = atan2f(zvec[1], zvec[2]); ++ rot[1] = atan2f(zvec[0], fabsf(zvec[2])); ++ rot[2] = atan2f(zopposite, zadjacent); ++} ++ ++void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, ++ float *zadjacent) ++{ ++ mat4 rot0, rot1; ++ vec4 mul1, mul2; ++ if (pos) ++ { ++ vec4 mul0; ++ glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); ++ glm_vec_copy(mul0, pos); ++ } ++ glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); ++ glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); ++ glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); ++ glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); ++ if (rot) ++ _glm_atan3(mul1, mul2[2], mul2[1], rot); ++ if (zvec) ++ glm_vec_copy(mul1, zvec); ++ if (zopposite && zadjacent) ++ { ++ *zopposite = mul2[2]; ++ *zadjacent = mul2[1]; ++ } ++} ++ ++inline static void take_turn(data_model_instance_t *ptr, double this_frame) ++{ ++ if (ptr->update) ++ { ++ ptr->update(ptr, this_frame - previous_frame); ++ /* Check out of bounds and reflect. */ ++ { ++ vec3 pos, rot; ++ mat4 *model = ++ data_materials[data_models[ptr->model].material].get_model(ptr->ubo); ++ _glm_decompose(*model, pos, rot, NULL, NULL, NULL); ++ bool new_model = false; ++ for (size_t i = 0; i < 3; i++) ++ { ++#define BOUND 7.0f ++ if (pos[i] < -BOUND || pos[i] > BOUND) ++ { ++ switch (i) ++ { ++ case 0: ++ rot[1] = -rot[1]; ++ break; ++ case 1: ++ rot[0] = -rot[0]; ++ break; ++ case 2: ++ rot[1] = CGLM_PI - rot[1]; ++ break; ++ default: ++ assert(0 && "Out of bounds."); ++ } ++ pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f ++ : (pos[i] - BOUND) * -2.0f; ++ new_model = true; ++ } ++ } ++ if (new_model) ++ { ++ mat4 rot0, rot1, trans0; ++ glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); ++ glm_rotate_y(rot0, rot[1], rot1); ++ glm_rotate_z(rot1, rot[2], rot0); ++ glm_translate_make(trans0, pos); ++ glm_mat4_mul(trans0, rot0, *model); ++ } ++ } ++ } + } + + void data_update() + { +- material_0_ubo_t *ubo_0 = +- list_entry(data_model_instances.next, data_model_instance_t, list)->ubo; ++ material_0_ubo_t *ubo_0 = list_entry(data_model_instances.next, ++ data_model_instance_t, list) ++ ->ubo, ++ *ubo_1 = list_entry(data_model_instances.next->next, ++ data_model_instance_t, list) ++ ->ubo; ++ + double this_frame = glfwGetTime(); + +- handle_input(this_frame, ubo_0); ++ handle_input(this_frame, ubo_0, ubo_1); + +- /* TODO: Take turns. */ ++ data_model_instance_t *ptr; ++ list_for_each_entry(ptr, &data_model_instances, list) ++ take_turn(ptr, this_frame); + + if (0) + { +diff -bNur 0005texture/vulkan.c 0006multi-model/vulkan.c +--- 0005texture/vulkan.c 2019-03-03 15:05:42.770226379 -0600 ++++ 0006multi-model/vulkan.c 2019-03-03 15:07:42.139278966 -0600 +@@ -1541,8 +1541,6 @@ + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; +- list_entry(data_model_instances.next, data_model_instance_t, list) +- ->uniform_map->descriptor_set = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkDestroySampler(device, texture_image_sampler, NULL); +@@ -1554,8 +1552,12 @@ + vkDestroyImage(device, texture_images[0], NULL); + texture_images[0] = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); +- list_entry(data_model_instances.next, data_model_instance_t, list)->ubo = +- NULL; ++ data_model_instance_t *ptr; ++ list_for_each_entry(ptr, &data_model_instances, list) ++ { ++ ptr->ubo = NULL; ++ ptr->uniform_map->descriptor_set = VK_NULL_HANDLE; ++ } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); diff --git a/0006multi-model/.gitignore b/0006multi-model/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0006multi-model/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0006multi-model/0_frag.glsl b/0006multi-model/0_frag.glsl new file mode 100644 index 0000000..4f29a5c --- /dev/null +++ b/0006multi-model/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0006multi-model/0_vert.glsl b/0006multi-model/0_vert.glsl new file mode 100644 index 0000000..be62be1 --- /dev/null +++ b/0006multi-model/0_vert.glsl @@ -0,0 +1,50 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} ubo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = ubo.lightPos - pos.xyz; + outViewVec = ubo.viewPos - pos.xyz; +} diff --git a/0006multi-model/Makefile b/0006multi-model/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0006multi-model/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0006multi-model/data.h b/0006multi-model/data.h new file mode 100644 index 0000000..5237b18 --- /dev/null +++ b/0006multi-model/data.h @@ -0,0 +1,87 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +typedef struct { + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +typedef struct { + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; +extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); + +typedef struct data_model_instance { + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void *closure; + struct list_head list; + void *ubo; + uniform_map_t *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; + +typedef struct { + struct { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct { + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#endif diff --git a/0006multi-model/data_bulk.c b/0006multi-model/data_bulk.c new file mode 100644 index 0000000..b1c4615 --- /dev/null +++ b/0006multi-model/data_bulk.c @@ -0,0 +1,771 @@ +#include "data_bulk.h" +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, + { + "Other Cube", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 0, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; diff --git a/0006multi-model/data_bulk.h b/0006multi-model/data_bulk.h new file mode 100644 index 0000000..58330e4 --- /dev/null +++ b/0006multi-model/data_bulk.h @@ -0,0 +1,16 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} material_0_ubo_t; diff --git a/0006multi-model/data_dynamic.c.in b/0006multi-model/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0006multi-model/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0006multi-model/libdata.c b/0006multi-model/libdata.c new file mode 100644 index 0000000..ba537f5 --- /dev/null +++ b/0006multi-model/libdata.c @@ -0,0 +1,368 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, 3 * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +typedef struct +{ + data_model_instance_t obj, other_obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.other_obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + NULL, + {&(model_instance.other_obj.list), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, + { + "Other Object", + 1, + shoot_forward, + NULL, + {&(data_model_instances), &(model_instance.obj.list)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + uniform_map_t **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = this_map; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = this_map; + } +} + +uintptr_t data_uniform_ptr = 0; +void (*data_setup_model_instance)(uniform_map_t *uniform_map); +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = map; + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst->uniform_map); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp(material_0_ubo_t *ubo_0, material_0_ubo_t *ubo_1) +{ + glm_vec_copy(ubo_0->viewPos, ubo_1->viewPos); + + glm_lookat(ubo_0->viewPos, + (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], + ubo_0->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, ubo_0->vp); + glm_mat4_copy(ubo_0->vp, ubo_1->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0, *ubo_1; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + setup_model_instance(inst); + ubo_0 = (list_entry(data_model_instances.next, data_model_instance_t, list))->ubo; + ubo_1 = (list_entry(data_model_instances.prev, data_model_instance_t, list))->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + ubo_0->lightPos[0] = 0.0f; + ubo_0->lightPos[1] = 250.0f; + ubo_0->lightPos[2] = -250.0f; + ubo_0->viewPos[0] = 0.0f; + ubo_0->viewPos[1] = 0.0f; + ubo_0->viewPos[2] = -2.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(ubo_0, ubo_1); + + *ubo_1 = *ubo_0; + glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0, + material_0_ubo_t *ubo_1) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + ubo_0->viewPos[0] += sinf(center_dir) * dist * diagnal2; + ubo_0->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + ubo_0->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(ubo_0, ubo_1); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 rot0, rot1, trans0; + glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +void data_update() +{ + material_0_ubo_t *ubo_0 = list_entry(data_model_instances.next, + data_model_instance_t, list) + ->ubo, + *ubo_1 = list_entry(data_model_instances.next->next, + data_model_instance_t, list) + ->ubo; + + double this_frame = glfwGetTime(); + + handle_input(this_frame, ubo_0, ubo_1); + + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0006multi-model/vulkan.c b/0006multi-model/vulkan.c new file mode 100644 index 0000000..21ea85e --- /dev/null +++ b/0006multi-model/vulkan.c @@ -0,0 +1,1639 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[2]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[1]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + VkWriteDescriptorSet write_descriptor_sets[2]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = uniform_descriptors; + write_descriptor_sets[0].descriptorCount = 1; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + image_info.imageView = texture_image_views[0]; + image_info.sampler = texture_image_sampler; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(uniform_map_t *uniform_map) +{ + if (uniform_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&uniform_map->descriptor_set); + update_descriptor_set(uniform_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = data_materials[0].texture_format; + image_create_info.extent.width = data_materials[0].texture_width; + image_create_info.extent.height = data_materials[0].texture_height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[0]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + allocate_texture_image(texture_images[0], gpu_memory_properties, + &texture_image_memorys[0]); + + void *data; + vkMapMemory(device, texture_image_memorys[0], 0, + data_materials[0].texture_size, 0, &data); + memcpy(data, data_materials[0].texture, data_materials[0].texture_size); + vkUnmapMemory(device, texture_image_memorys[0]); +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = texture_images[0]; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = data_materials[0].texture_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[0]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + data_model_instance_t *ptr = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[ptr->model].material] + .shader]); + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &ptr->uniform_map->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[ptr->model].count, 1, + data_models[ptr->model].first, 0, 0); + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + vkDestroyImageView(device, texture_image_views[0], NULL); + texture_image_views[0] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[0], NULL); + texture_image_memorys[0] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[0], NULL); + texture_images[0] = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + ptr->uniform_map->descriptor_set = VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[] = {VK_NULL_HANDLE}; + VkDeviceMemory texture_image_memorys[] = {VK_NULL_HANDLE}; + VkImageView _texture_image_views[] = {VK_NULL_HANDLE}; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0007shared-ubo.diff b/0007shared-ubo.diff new file mode 100644 index 0000000..2208979 --- /dev/null +++ b/0007shared-ubo.diff @@ -0,0 +1,453 @@ +diff -bNur 0006multi-model/0_vert.glsl 0007shared-ubo/0_vert.glsl +--- 0006multi-model/0_vert.glsl 2019-03-02 19:55:02.561358109 -0600 ++++ 0007shared-ubo/0_vert.glsl 2019-03-02 19:55:02.561358109 -0600 +@@ -15,12 +15,16 @@ + { + mat4 model; + mat4 bones[MAX_BONES]; ++} ubo; ++ ++layout (binding = 2) uniform SUBO ++{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +-} ubo; ++} subo; + + layout (location = 0) out vec2 outUV; + layout (location = 1) out vec3 outNormal; +@@ -41,10 +45,10 @@ + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; +- gl_Position = ubo.vp * skinPos * vec4(inPos, 1.0); ++ gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; +- outLightVec = ubo.lightPos - pos.xyz; +- outViewVec = ubo.viewPos - pos.xyz; ++ outLightVec = subo.lightPos - pos.xyz; ++ outViewVec = subo.viewPos - pos.xyz; + } +diff -bNur 0006multi-model/data_bulk.h 0007shared-ubo/data_bulk.h +--- 0006multi-model/data_bulk.h 2019-03-02 19:55:02.561358109 -0600 ++++ 0007shared-ubo/data_bulk.h 2019-03-02 19:55:02.561358109 -0600 +@@ -4,13 +4,7 @@ + // Must not be higher than same const in skinning shader + #define MAX_BONES 64 + +-typedef struct +-{ ++typedef struct { + mat4 model; + mat4 bones[MAX_BONES]; +- mat4 vp; +- vec3 lightPos; +- float pada; +- vec3 viewPos; +- float padb; + } material_0_ubo_t; +diff -bNur 0006multi-model/data.h 0007shared-ubo/data.h +--- 0006multi-model/data.h 2019-03-02 19:55:02.561358109 -0600 ++++ 0007shared-ubo/data.h 2019-03-02 19:55:02.561358109 -0600 +@@ -31,6 +31,8 @@ + extern const struct data_model_index *data_model_index; + extern const VkDeviceSize data_model_index_size; + ++extern struct shared_ubo *data_model_shared_ubo; ++ + typedef struct { + char *name; + uint32_t first; +@@ -39,19 +41,6 @@ + } data_model_t; + extern data_model_t data_models[]; + +-#define UNIFORM_ALIGN (sizeof(float) * 4) +-#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +-#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +-#define UNIFORM_SIZE (4096 * 4096) +-typedef struct { +- VkDescriptorSet descriptor_set; +- size_t offset; +- size_t range; +- size_t width; +- struct list_head list; +-} uniform_map_t; +-extern void (*data_setup_model_instance)(uniform_map_t *uniform_map); +- + typedef struct data_model_instance { + char *name; + size_t model; +@@ -59,9 +48,10 @@ + void *closure; + struct list_head list; + void *ubo; +- uniform_map_t *uniform_map; ++ struct list_head *uniform_map; + } data_model_instance_t; + extern struct list_head data_model_instances; ++extern void (*data_setup_model_instance)(data_model_instance_t *inst); + + typedef struct { + struct { +@@ -84,4 +74,17 @@ + } data_material_t; + extern const data_material_t data_materials[]; + ++#define UNIFORM_ALIGN (sizeof(float) * 4) ++#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) ++#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) ++#define UNIFORM_SIZE (4096 * 4096) ++#define SHARED_UNIFORM_SIZE (4096 * 32) ++typedef struct { ++ VkDescriptorSet descriptor_set; ++ size_t offset; ++ size_t range; ++ size_t width; ++ struct list_head list; ++} uniform_map_t; ++ + #endif +diff -bNur 0006multi-model/libdata.c 0007shared-ubo/libdata.c +--- 0006multi-model/libdata.c 2019-03-02 20:06:22.821345727 -0600 ++++ 0007shared-ubo/libdata.c 2019-03-02 20:06:22.821345727 -0600 +@@ -13,6 +13,15 @@ + } + } + ++typedef struct shared_ubo ++{ ++ mat4 vp; ++ vec3 lightPos; ++ float pada; ++ vec3 viewPos; ++ float padb; ++} shared_ubo_t; ++ + float center_dir = 0; + + GLFWwindow *data_window = NULL; +@@ -42,6 +51,9 @@ + glm_mat4_copy(rot0, *model); + } + ++#define SUBO data_model_shared_ubo ++struct shared_ubo *SUBO = NULL; ++ + typedef struct + { + data_model_instance_t obj, other_obj; +@@ -81,7 +93,7 @@ + }; + + inline static void split_map(size_t size, uniform_map_t *map, +- uniform_map_t **ptr) ++ struct list_head **ptr) + { + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); +@@ -94,7 +106,7 @@ + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); +- *ptr = this_map; ++ *ptr = &this_map->list; + } + else + { +@@ -102,12 +114,12 @@ + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); +- *ptr = this_map; ++ *ptr = &this_map->list; + } + } + ++void (*data_setup_model_instance)(data_model_instance_t *inst); + uintptr_t data_uniform_ptr = 0; +-void (*data_setup_model_instance)(uniform_map_t *uniform_map); + inline static void setup_model_instance(data_model_instance_t *inst) + { + size_t size = TO_UNIFORM_ALLOC( +@@ -131,14 +143,14 @@ + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; +- inst->uniform_map = map; +- data_setup_model_instance(inst->uniform_map); ++ inst->uniform_map = &map->list; ++ data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); +- data_setup_model_instance(inst->uniform_map); ++ data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) +@@ -148,22 +160,21 @@ + } + } + assert(inst->uniform_map && "Out of uniform space."); +- inst->ubo = (void *)(FROM_UNIFORM_ALLOC(inst->uniform_map->offset) + ++ inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, ++ uniform_map_t, list) ++ ->offset) + + data_uniform_ptr); + } + + mat4 projection; + mat4 view; +-inline static void update_vp(material_0_ubo_t *ubo_0, material_0_ubo_t *ubo_1) ++inline static void update_vp() + { +- glm_vec_copy(ubo_0->viewPos, ubo_1->viewPos); +- +- glm_lookat(ubo_0->viewPos, +- (vec3){ubo_0->viewPos[0] + sinf(center_dir), ubo_0->viewPos[1], +- ubo_0->viewPos[2] + cosf(center_dir)}, ++ glm_lookat(SUBO->viewPos, ++ (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], ++ SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); +- glm_mat4_mul(projection, view, ubo_0->vp); +- glm_mat4_copy(ubo_0->vp, ubo_1->vp); ++ glm_mat4_mul(projection, view, SUBO->vp); + } + + /* +@@ -187,14 +198,16 @@ + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; ++ static const shared_ubo_t empty_shared_ubo_s; ++ *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); +- ubo_0->lightPos[0] = 0.0f; +- ubo_0->lightPos[1] = 250.0f; +- ubo_0->lightPos[2] = -250.0f; +- ubo_0->viewPos[0] = 0.0f; +- ubo_0->viewPos[1] = 0.0f; +- ubo_0->viewPos[2] = -2.0f; ++ SUBO->lightPos[0] = 0.0f; ++ SUBO->lightPos[1] = 250.0f; ++ SUBO->lightPos[2] = -250.0f; ++ SUBO->viewPos[0] = 0.0f; ++ SUBO->viewPos[1] = 0.0f; ++ SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +@@ -212,7 +225,7 @@ + oglproj, projection); + #endif + +- update_vp(ubo_0, ubo_1); ++ update_vp(); + + *ubo_1 = *ubo_0; + glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model); +@@ -220,8 +233,7 @@ + previous_frame = glfwGetTime(); + } + +-inline static void handle_input(double this_frame, material_0_ubo_t *ubo_0, +- material_0_ubo_t *ubo_1) ++inline static void handle_input(double this_frame) + { + float diagnal2 = 1; + bool need_lookat = false; +@@ -234,8 +246,8 @@ + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; +- ubo_0->viewPos[0] += sinf(center_dir) * dist * diagnal2; +- ubo_0->viewPos[2] += cosf(center_dir) * dist * diagnal2; ++ SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; ++ SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + +@@ -250,12 +262,12 @@ + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); +- ubo_0->viewPos[1] += dist * diagnal2; ++ SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) +- update_vp(ubo_0, ubo_1); ++ update_vp(); + } + + void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +@@ -342,16 +354,9 @@ + + void data_update() + { +- material_0_ubo_t *ubo_0 = list_entry(data_model_instances.next, +- data_model_instance_t, list) +- ->ubo, +- *ubo_1 = list_entry(data_model_instances.next->next, +- data_model_instance_t, list) +- ->ubo; +- + double this_frame = glfwGetTime(); + +- handle_input(this_frame, ubo_0, ubo_1); ++ handle_input(this_frame); + + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) +@@ -359,6 +364,7 @@ + + if (0) + { ++ material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); +diff -bNur 0006multi-model/vulkan.c 0007shared-ubo/vulkan.c +--- 0006multi-model/vulkan.c 2019-03-03 15:07:42.139278966 -0600 ++++ 0007shared-ubo/vulkan.c 2019-03-03 15:07:51.304459958 -0600 +@@ -530,7 +530,7 @@ + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; +- buffer_info_create.size = UNIFORM_SIZE; ++ buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + +@@ -583,14 +583,16 @@ + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; +- err = vkMapMemory(device, uniform_buffer_memmory, 0, UNIFORM_SIZE, 0, ++ err = vkMapMemory(device, uniform_buffer_memmory, 0, ++ UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); ++ data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); + } + + inline static void create_descriptor_set_layout() + { +- VkDescriptorSetLayoutBinding set_layout_bindings[2]; ++ VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; +@@ -598,6 +600,9 @@ + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + ++ set_layout_bindings[2] = set_layout_bindings[0]; ++ set_layout_bindings[2].binding = 2; ++ + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; +@@ -666,23 +671,31 @@ + + inline static void update_descriptor_set(uniform_map_t *map) + { +- VkDescriptorBufferInfo uniform_descriptors[1]; ++ VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + +- VkWriteDescriptorSet write_descriptor_sets[2]; ++ uniform_descriptors[1] = uniform_descriptors[0]; ++ uniform_descriptors[1].offset = UNIFORM_SIZE; ++ uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; ++ ++ VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; +- write_descriptor_sets[0].pBufferInfo = uniform_descriptors; ++ write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + ++ write_descriptor_sets[2] = write_descriptor_sets[0]; ++ write_descriptor_sets[2].dstBinding = 2; ++ write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; ++ + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; +@@ -704,11 +717,13 @@ + write_descriptor_sets, 0, NULL); + } + +-void setup_model_instance(uniform_map_t *uniform_map) ++void setup_model_instance(data_model_instance_t *inst) + { +- if (uniform_map->descriptor_set == VK_NULL_HANDLE) +- allocate_descriptor_set(&uniform_map->descriptor_set); +- update_descriptor_set(uniform_map); ++ uniform_map_t *this_map; ++ this_map = list_entry(inst->uniform_map, uniform_map_t, list); ++ if (this_map->descriptor_set == VK_NULL_HANDLE) ++ allocate_descriptor_set(&this_map->descriptor_set); ++ update_descriptor_set(this_map); + } + + inline static void create_pipeline_layout() +@@ -1399,20 +1414,23 @@ + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + +- data_model_instance_t *ptr = ++ data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, +- graphics_pipelines[data_materials[data_models[ptr->model].material] ++ graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + ++ list_for_each_entry(inst, &data_model_instances, list) ++ { + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, +- &ptr->uniform_map->descriptor_set, ++ &list_entry(inst->uniform_map, uniform_map_t, list)->descriptor_set, + 0, NULL); + +- vkCmdDrawIndexed(command_buffer, data_models[ptr->model].count, 1, +- data_models[ptr->model].first, 0, 0); ++ vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, ++ data_models[inst->model].first, 0, 0); ++ } + + vkCmdEndRenderPass(command_buffer); + +@@ -1556,7 +1574,8 @@ + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; +- ptr->uniform_map->descriptor_set = VK_NULL_HANDLE; ++ list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = ++ VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; diff --git a/0007shared-ubo/.gitignore b/0007shared-ubo/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0007shared-ubo/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0007shared-ubo/0_frag.glsl b/0007shared-ubo/0_frag.glsl new file mode 100644 index 0000000..4f29a5c --- /dev/null +++ b/0007shared-ubo/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0007shared-ubo/0_vert.glsl b/0007shared-ubo/0_vert.glsl new file mode 100644 index 0000000..f8339a6 --- /dev/null +++ b/0007shared-ubo/0_vert.glsl @@ -0,0 +1,54 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; +} ubo; + +layout (binding = 2) uniform SUBO +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} subo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = subo.lightPos - pos.xyz; + outViewVec = subo.viewPos - pos.xyz; +} diff --git a/0007shared-ubo/Makefile b/0007shared-ubo/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0007shared-ubo/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0007shared-ubo/data.h b/0007shared-ubo/data.h new file mode 100644 index 0000000..dde3493 --- /dev/null +++ b/0007shared-ubo/data.h @@ -0,0 +1,90 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +extern struct shared_ubo *data_model_shared_ubo; + +typedef struct { + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +typedef struct data_model_instance { + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void *closure; + struct list_head list; + void *ubo; + struct list_head *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; +extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +typedef struct { + struct { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; + +typedef struct { + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +#define SHARED_UNIFORM_SIZE (4096 * 32) +typedef struct { + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; + +#endif diff --git a/0007shared-ubo/data_bulk.c b/0007shared-ubo/data_bulk.c new file mode 100644 index 0000000..b1c4615 --- /dev/null +++ b/0007shared-ubo/data_bulk.c @@ -0,0 +1,771 @@ +#include "data_bulk.h" +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, + { + "Other Cube", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 0, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; diff --git a/0007shared-ubo/data_bulk.h b/0007shared-ubo/data_bulk.h new file mode 100644 index 0000000..ee68faf --- /dev/null +++ b/0007shared-ubo/data_bulk.h @@ -0,0 +1,10 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct { + mat4 model; + mat4 bones[MAX_BONES]; +} material_0_ubo_t; diff --git a/0007shared-ubo/data_dynamic.c.in b/0007shared-ubo/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0007shared-ubo/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0007shared-ubo/libdata.c b/0007shared-ubo/libdata.c new file mode 100644 index 0000000..75ae2a4 --- /dev/null +++ b/0007shared-ubo/libdata.c @@ -0,0 +1,374 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +typedef struct shared_ubo +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} shared_ubo_t; + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, +}; + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, 3 * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +#define SUBO data_model_shared_ubo +struct shared_ubo *SUBO = NULL; + +typedef struct +{ + data_model_instance_t obj, other_obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.other_obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + NULL, + {&(model_instance.other_obj.list), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, + { + "Other Object", + 1, + shoot_forward, + NULL, + {&(data_model_instances), &(model_instance.obj.list)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + struct list_head **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = &this_map->list; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = &this_map->list; + } +} + +void (*data_setup_model_instance)(data_model_instance_t *inst); +uintptr_t data_uniform_ptr = 0; +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = &map->list; + data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, + uniform_map_t, list) + ->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp() +{ + glm_lookat(SUBO->viewPos, + (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], + SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, SUBO->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0, *ubo_1; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + setup_model_instance(inst); + ubo_0 = (list_entry(data_model_instances.next, data_model_instance_t, list))->ubo; + ubo_1 = (list_entry(data_model_instances.prev, data_model_instance_t, list))->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + static const shared_ubo_t empty_shared_ubo_s; + *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + SUBO->lightPos[0] = 0.0f; + SUBO->lightPos[1] = 250.0f; + SUBO->lightPos[2] = -250.0f; + SUBO->viewPos[0] = 0.0f; + SUBO->viewPos[1] = 0.0f; + SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(); + + *ubo_1 = *ubo_0; + glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 rot0, rot1, trans0; + glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +void data_update() +{ + double this_frame = glfwGetTime(); + + handle_input(this_frame); + + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0007shared-ubo/vulkan.c b/0007shared-ubo/vulkan.c new file mode 100644 index 0000000..ef7569c --- /dev/null +++ b/0007shared-ubo/vulkan.c @@ -0,0 +1,1658 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, + UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); + data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[2] = set_layout_bindings[0]; + set_layout_bindings[2].binding = 2; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map) +{ + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + uniform_descriptors[1] = uniform_descriptors[0]; + uniform_descriptors[1].offset = UNIFORM_SIZE; + uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; + + VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + + write_descriptor_sets[2] = write_descriptor_sets[0]; + write_descriptor_sets[2].dstBinding = 2; + write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + image_info.imageView = texture_image_views[0]; + image_info.sampler = texture_image_sampler; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(data_model_instance_t *inst) +{ + uniform_map_t *this_map; + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); + update_descriptor_set(this_map); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = data_materials[0].texture_format; + image_create_info.extent.width = data_materials[0].texture_width; + image_create_info.extent.height = data_materials[0].texture_height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[0]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + allocate_texture_image(texture_images[0], gpu_memory_properties, + &texture_image_memorys[0]); + + void *data; + vkMapMemory(device, texture_image_memorys[0], 0, + data_materials[0].texture_size, 0, &data); + memcpy(data, data_materials[0].texture, data_materials[0].texture_size); + vkUnmapMemory(device, texture_image_memorys[0]); +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = texture_images[0]; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = data_materials[0].texture_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[0]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[0].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[0]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].module = vert_modules[0]; + shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[0]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + data_model_instance_t *inst = + list_entry(data_model_instances.next, data_model_instance_t, list); + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + + list_for_each_entry(inst, &data_model_instances, list) + { + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &list_entry(inst->uniform_map, uniform_map_t, list)->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } + + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + vkDestroyPipeline(device, graphics_pipelines[0], NULL); + graphics_pipelines[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[0], NULL); + frag_modules[0] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[0], NULL); + vert_modules[0] = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + vkDestroyImageView(device, texture_image_views[0], NULL); + texture_image_views[0] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[0], NULL); + texture_image_memorys[0] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[0], NULL); + texture_images[0] = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = + VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[] = {VK_NULL_HANDLE}; + VkDeviceMemory texture_image_memorys[] = {VK_NULL_HANDLE}; + VkImageView _texture_image_views[] = {VK_NULL_HANDLE}; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; + VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; + VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0008multi-material.diff b/0008multi-material.diff new file mode 100644 index 0000000..6fe25d4 --- /dev/null +++ b/0008multi-material.diff @@ -0,0 +1,2553 @@ +diff -bNur 0007shared-ubo/data_bulk.c 0008multi-material/data_bulk.c +--- 0007shared-ubo/data_bulk.c 2019-03-02 20:06:22.821345727 -0600 ++++ 0008multi-material/data_bulk.c 2019-03-02 20:06:22.825345914 -0600 +@@ -1,4 +1,5 @@ + #include "data_bulk.h" ++#include + #include + + typedef struct +@@ -267,12 +268,14 @@ + "Other Cube", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), +- 0, ++ 1, + }, + }; + + mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + ++mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } ++ + #define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ +@@ -768,4 +771,2129 @@ + DMTCLEAR}}}, + sizeof(texture_0_t), + }, ++ { ++ "Other Example", ++ 1, ++ sizeof(material_1_ubo_t), ++ get_model_1, ++ VK_FORMAT_R8G8B8A8_UNORM, ++ 8 * 4, ++ 8 * 3, ++ (void *)&(texture_0_t){{{DMTCLEAR, ++ { ++ {DMTCONE, 0, DMTCONE, 0xff}, ++ {DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}, ++ }, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFIV, 0, DMTCONE, 0xff}, ++ {DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}, ++ {0, DMTCFIV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}}, ++ {{{{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++#if 1 ++ {0xff, 0xff, 0xff, 0xff}, ++#else ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++#endif ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}}, ++ {{{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++#if 1 ++ {{0xff, 0xff, 0xff, 0xff}, ++ {0xff, 0xff, 0xff, 0xff}, ++#else ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++#endif ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}, ++ {{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}}, ++ {{{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}, ++ {{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}}, ++ {{{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}, ++ {{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}}, ++ {{{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}, ++ {{DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}}, ++ {{DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}}}, ++ {{{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}, ++ {{DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}}, ++ {{DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}}}, ++ {{{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}, ++ {{DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}}, ++ {{DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}}}, ++ {{{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCONE, DMTCTWO, 0, 0xff}, ++ {DMTCONE, DMTCTHR, 0, 0xff}, ++ {DMTCONE, DMTCFOR, 0, 0xff}, ++ {DMTCONE, 0, DMTCFOR, 0xff}, ++ {DMTCONE, 0, DMTCTHR, 0xff}, ++ {DMTCONE, 0, DMTCTWO, 0xff}, ++ {DMTCONE, 0, DMTCONE, 0xff}}, ++ {{DMTCONE, DMTCONE, 0, 0xff}, ++ {DMTCTWO, DMTCONE, 0, 0xff}, ++ {DMTCTHR, DMTCONE, 0, 0xff}, ++ {DMTCFOR, DMTCONE, 0, 0xff}, ++ {0, DMTCONE, DMTCFOR, 0xff}, ++ {0, DMTCONE, DMTCTHR, 0xff}, ++ {0, DMTCONE, DMTCTWO, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}}}, ++ {{DMTCLEAR, ++ {{DMTCONE, 0, DMTCONE, 0xff}, ++ {DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}, ++ {0, DMTCONE, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTWO, 0, DMTCONE, 0xff}, ++ {DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}, ++ {0, DMTCTWO, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCTHR, 0, DMTCONE, 0xff}, ++ {DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}, ++ {0, DMTCTHR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFOR, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCFOR, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}, ++ {DMTCLEAR, ++ {{DMTCFIV, 0, DMTCONE, 0xff}, ++ {DMTCSIX, 0, DMTCONE, 0xff}, ++ {DMTCSEV, 0, DMTCONE, 0xff}, ++ {DMTCEIG, 0, DMTCONE, 0xff}, ++ {0, DMTCEIG, DMTCONE, 0xff}, ++ {0, DMTCSEV, DMTCONE, 0xff}, ++ {0, DMTCSIX, DMTCONE, 0xff}, ++ {0, DMTCFIV, DMTCONE, 0xff}}, ++ DMTCLEAR, ++ DMTCLEAR}}}, ++ sizeof(texture_0_t), ++ }, ++}; ++const size_t data_materials_count = ++ sizeof(data_materials) / sizeof(data_materials[0]); ++const uint32_t material_shader_1_vert_spv[] = { ++ 0x07230203, ++ SPV_VERSION, ++ (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, ++ 183, ++ 0, ++ 131089, ++ 1, ++ 393227, ++ 1, ++ 1280527431, ++ 1685353262, ++ 808793134, ++ 0, ++ 196622, ++ 0, ++ 1, ++ 983055, ++ 0, ++ 4, ++ 1852399981, ++ 0, ++ 21, ++ 30, ++ 103, ++ 105, ++ 109, ++ 123, ++ 144, ++ 166, ++ 169, ++ 176, ++ 196611, ++ 2, ++ 400, ++ 589828, ++ 1096764487, ++ 1935622738, ++ 1918988389, ++ 1600484449, ++ 1684105331, ++ 1868526181, ++ 1667590754, ++ 29556, ++ 589828, ++ 1096764487, ++ 1935622738, ++ 1768186216, ++ 1818191726, ++ 1969712737, ++ 1600481121, ++ 1882206772, ++ 7037793, ++ 262149, ++ 4, ++ 1852399981, ++ 0, ++ 393221, ++ 10, ++ 1701736290, ++ 1851880020, ++ 1919903347, ++ 109, ++ 196613, ++ 14, ++ 5194325, ++ 327686, ++ 14, ++ 0, ++ 1701080941, ++ 108, ++ 327686, ++ 14, ++ 1, ++ 1701736290, ++ 115, ++ 196613, ++ 16, ++ 7299701, ++ 327685, ++ 21, ++ 1866624617, ++ 1145660782, ++ 115, ++ 393221, ++ 30, ++ 1866624617, ++ 1700226414, ++ 1952999273, ++ 115, ++ 262149, ++ 103, ++ 1433695599, ++ 86, ++ 262149, ++ 105, ++ 1448439401, ++ 0, ++ 393221, ++ 107, ++ 1348430951, ++ 1700164197, ++ 2019914866, ++ 0, ++ 393222, ++ 107, ++ 0, ++ 1348430951, ++ 1953067887, ++ 7237481, ++ 196613, ++ 109, ++ 0, ++ 262149, ++ 112, ++ 1329747283, ++ 0, ++ 262150, ++ 112, ++ 0, ++ 28790, ++ 393222, ++ 112, ++ 1, ++ 1751607660, ++ 1936674932, ++ 0, ++ 327686, ++ 112, ++ 2, ++ 1633968496, ++ 0, ++ 327686, ++ 112, ++ 3, ++ 2003134838, ++ 7565136, ++ 327686, ++ 112, ++ 4, ++ 1650745712, ++ 0, ++ 262149, ++ 114, ++ 1868723571, ++ 0, ++ 262149, ++ 123, ++ 1867542121, ++ 115, ++ 196613, ++ 134, ++ 7565168, ++ 327685, ++ 144, ++ 1316255087, ++ 1634562671, ++ 108, ++ 327685, ++ 166, ++ 1867411049, ++ 1818324338, ++ 0, ++ 327685, ++ 169, ++ 1282700655, ++ 1952999273, ++ 6514006, ++ 327685, ++ 176, ++ 1450472815, ++ 1450665321, ++ 25445, ++ 262215, ++ 13, ++ 6, ++ 64, ++ 262216, ++ 14, ++ 0, ++ 5, ++ 327752, ++ 14, ++ 0, ++ 35, ++ 0, ++ 327752, ++ 14, ++ 0, ++ 7, ++ 16, ++ 262216, ++ 14, ++ 1, ++ 5, ++ 327752, ++ 14, ++ 1, ++ 35, ++ 64, ++ 327752, ++ 14, ++ 1, ++ 7, ++ 16, ++ 196679, ++ 14, ++ 2, ++ 262215, ++ 16, ++ 34, ++ 0, ++ 262215, ++ 16, ++ 33, ++ 0, ++ 262215, ++ 21, ++ 30, ++ 4, ++ 262215, ++ 30, ++ 30, ++ 3, ++ 262215, ++ 103, ++ 30, ++ 0, ++ 262215, ++ 105, ++ 30, ++ 2, ++ 327752, ++ 107, ++ 0, ++ 11, ++ 0, ++ 196679, ++ 107, ++ 2, ++ 262216, ++ 112, ++ 0, ++ 5, ++ 327752, ++ 112, ++ 0, ++ 35, ++ 0, ++ 327752, ++ 112, ++ 0, ++ 7, ++ 16, ++ 327752, ++ 112, ++ 1, ++ 35, ++ 64, ++ 327752, ++ 112, ++ 2, ++ 35, ++ 76, ++ 327752, ++ 112, ++ 3, ++ 35, ++ 80, ++ 327752, ++ 112, ++ 4, ++ 35, ++ 92, ++ 196679, ++ 112, ++ 2, ++ 262215, ++ 114, ++ 34, ++ 0, ++ 262215, ++ 114, ++ 33, ++ 2, ++ 262215, ++ 123, ++ 30, ++ 0, ++ 262215, ++ 144, ++ 30, ++ 1, ++ 262215, ++ 166, ++ 30, ++ 1, ++ 262215, ++ 169, ++ 30, ++ 3, ++ 262215, ++ 176, ++ 30, ++ 2, ++ 131091, ++ 2, ++ 196641, ++ 3, ++ 2, ++ 196630, ++ 6, ++ 32, ++ 262167, ++ 7, ++ 6, ++ 4, ++ 262168, ++ 8, ++ 7, ++ 4, ++ 262176, ++ 9, ++ 7, ++ 8, ++ 262165, ++ 11, ++ 32, ++ 0, ++ 262187, ++ 11, ++ 12, ++ 64, ++ 262172, ++ 13, ++ 8, ++ 12, ++ 262174, ++ 14, ++ 8, ++ 13, ++ 262176, ++ 15, ++ 2, ++ 14, ++ 262203, ++ 15, ++ 16, ++ 2, ++ 262165, ++ 17, ++ 32, ++ 1, ++ 262187, ++ 17, ++ 18, ++ 1, ++ 262167, ++ 19, ++ 17, ++ 4, ++ 262176, ++ 20, ++ 1, ++ 19, ++ 262203, ++ 20, ++ 21, ++ 1, ++ 262187, ++ 11, ++ 22, ++ 0, ++ 262176, ++ 23, ++ 1, ++ 17, ++ 262176, ++ 26, ++ 2, ++ 8, ++ 262176, ++ 29, ++ 1, ++ 7, ++ 262203, ++ 29, ++ 30, ++ 1, ++ 262176, ++ 31, ++ 1, ++ 6, ++ 262187, ++ 11, ++ 35, ++ 1, ++ 262187, ++ 11, ++ 57, ++ 2, ++ 262187, ++ 11, ++ 79, ++ 3, ++ 262167, ++ 101, ++ 6, ++ 2, ++ 262176, ++ 102, ++ 3, ++ 101, ++ 262203, ++ 102, ++ 103, ++ 3, ++ 262176, ++ 104, ++ 1, ++ 101, ++ 262203, ++ 104, ++ 105, ++ 1, ++ 196638, ++ 107, ++ 7, ++ 262176, ++ 108, ++ 3, ++ 107, ++ 262203, ++ 108, ++ 109, ++ 3, ++ 262187, ++ 17, ++ 110, ++ 0, ++ 262167, ++ 111, ++ 6, ++ 3, ++ 458782, ++ 112, ++ 8, ++ 111, ++ 6, ++ 111, ++ 6, ++ 262176, ++ 113, ++ 2, ++ 112, ++ 262203, ++ 113, ++ 114, ++ 2, ++ 262176, ++ 122, ++ 1, ++ 111, ++ 262203, ++ 122, ++ 123, ++ 1, ++ 262187, ++ 6, ++ 125, ++ 1065353216, ++ 262176, ++ 131, ++ 3, ++ 7, ++ 262176, ++ 133, ++ 7, ++ 7, ++ 262176, ++ 143, ++ 3, ++ 111, ++ 262203, ++ 143, ++ 144, ++ 3, ++ 262168, ++ 151, ++ 111, ++ 3, ++ 262187, ++ 6, ++ 152, ++ 0, ++ 262203, ++ 122, ++ 166, ++ 1, ++ 262203, ++ 143, ++ 169, ++ 3, ++ 262176, ++ 170, ++ 2, ++ 111, ++ 262203, ++ 143, ++ 176, ++ 3, ++ 262187, ++ 17, ++ 177, ++ 3, ++ 327734, ++ 2, ++ 4, ++ 0, ++ 3, ++ 131320, ++ 5, ++ 262203, ++ 9, ++ 10, ++ 7, ++ 262203, ++ 133, ++ 134, ++ 7, ++ 327745, ++ 23, ++ 24, ++ 21, ++ 22, ++ 262205, ++ 17, ++ 25, ++ 24, ++ 393281, ++ 26, ++ 27, ++ 16, ++ 18, ++ 25, ++ 262205, ++ 8, ++ 28, ++ 27, ++ 327745, ++ 31, ++ 32, ++ 30, ++ 22, ++ 262205, ++ 6, ++ 33, ++ 32, ++ 327823, ++ 8, ++ 34, ++ 28, ++ 33, ++ 196670, ++ 10, ++ 34, ++ 327745, ++ 23, ++ 36, ++ 21, ++ 35, ++ 262205, ++ 17, ++ 37, ++ 36, ++ 393281, ++ 26, ++ 38, ++ 16, ++ 18, ++ 37, ++ 262205, ++ 8, ++ 39, ++ 38, ++ 327745, ++ 31, ++ 40, ++ 30, ++ 35, ++ 262205, ++ 6, ++ 41, ++ 40, ++ 327823, ++ 8, ++ 42, ++ 39, ++ 41, ++ 262205, ++ 8, ++ 43, ++ 10, ++ 327761, ++ 7, ++ 44, ++ 43, ++ 0, ++ 327761, ++ 7, ++ 45, ++ 42, ++ 0, ++ 327809, ++ 7, ++ 46, ++ 44, ++ 45, ++ 327761, ++ 7, ++ 47, ++ 43, ++ 1, ++ 327761, ++ 7, ++ 48, ++ 42, ++ 1, ++ 327809, ++ 7, ++ 49, ++ 47, ++ 48, ++ 327761, ++ 7, ++ 50, ++ 43, ++ 2, ++ 327761, ++ 7, ++ 51, ++ 42, ++ 2, ++ 327809, ++ 7, ++ 52, ++ 50, ++ 51, ++ 327761, ++ 7, ++ 53, ++ 43, ++ 3, ++ 327761, ++ 7, ++ 54, ++ 42, ++ 3, ++ 327809, ++ 7, ++ 55, ++ 53, ++ 54, ++ 458832, ++ 8, ++ 56, ++ 46, ++ 49, ++ 52, ++ 55, ++ 196670, ++ 10, ++ 56, ++ 327745, ++ 23, ++ 58, ++ 21, ++ 57, ++ 262205, ++ 17, ++ 59, ++ 58, ++ 393281, ++ 26, ++ 60, ++ 16, ++ 18, ++ 59, ++ 262205, ++ 8, ++ 61, ++ 60, ++ 327745, ++ 31, ++ 62, ++ 30, ++ 57, ++ 262205, ++ 6, ++ 63, ++ 62, ++ 327823, ++ 8, ++ 64, ++ 61, ++ 63, ++ 262205, ++ 8, ++ 65, ++ 10, ++ 327761, ++ 7, ++ 66, ++ 65, ++ 0, ++ 327761, ++ 7, ++ 67, ++ 64, ++ 0, ++ 327809, ++ 7, ++ 68, ++ 66, ++ 67, ++ 327761, ++ 7, ++ 69, ++ 65, ++ 1, ++ 327761, ++ 7, ++ 70, ++ 64, ++ 1, ++ 327809, ++ 7, ++ 71, ++ 69, ++ 70, ++ 327761, ++ 7, ++ 72, ++ 65, ++ 2, ++ 327761, ++ 7, ++ 73, ++ 64, ++ 2, ++ 327809, ++ 7, ++ 74, ++ 72, ++ 73, ++ 327761, ++ 7, ++ 75, ++ 65, ++ 3, ++ 327761, ++ 7, ++ 76, ++ 64, ++ 3, ++ 327809, ++ 7, ++ 77, ++ 75, ++ 76, ++ 458832, ++ 8, ++ 78, ++ 68, ++ 71, ++ 74, ++ 77, ++ 196670, ++ 10, ++ 78, ++ 327745, ++ 23, ++ 80, ++ 21, ++ 79, ++ 262205, ++ 17, ++ 81, ++ 80, ++ 393281, ++ 26, ++ 82, ++ 16, ++ 18, ++ 81, ++ 262205, ++ 8, ++ 83, ++ 82, ++ 327745, ++ 31, ++ 84, ++ 30, ++ 79, ++ 262205, ++ 6, ++ 85, ++ 84, ++ 327823, ++ 8, ++ 86, ++ 83, ++ 85, ++ 262205, ++ 8, ++ 87, ++ 10, ++ 327761, ++ 7, ++ 88, ++ 87, ++ 0, ++ 327761, ++ 7, ++ 89, ++ 86, ++ 0, ++ 327809, ++ 7, ++ 90, ++ 88, ++ 89, ++ 327761, ++ 7, ++ 91, ++ 87, ++ 1, ++ 327761, ++ 7, ++ 92, ++ 86, ++ 1, ++ 327809, ++ 7, ++ 93, ++ 91, ++ 92, ++ 327761, ++ 7, ++ 94, ++ 87, ++ 2, ++ 327761, ++ 7, ++ 95, ++ 86, ++ 2, ++ 327809, ++ 7, ++ 96, ++ 94, ++ 95, ++ 327761, ++ 7, ++ 97, ++ 87, ++ 3, ++ 327761, ++ 7, ++ 98, ++ 86, ++ 3, ++ 327809, ++ 7, ++ 99, ++ 97, ++ 98, ++ 458832, ++ 8, ++ 100, ++ 90, ++ 93, ++ 96, ++ 99, ++ 196670, ++ 10, ++ 100, ++ 262205, ++ 101, ++ 106, ++ 105, ++ 196670, ++ 103, ++ 106, ++ 327745, ++ 26, ++ 115, ++ 114, ++ 110, ++ 262205, ++ 8, ++ 116, ++ 115, ++ 327745, ++ 26, ++ 117, ++ 16, ++ 110, ++ 262205, ++ 8, ++ 118, ++ 117, ++ 327826, ++ 8, ++ 119, ++ 116, ++ 118, ++ 262205, ++ 8, ++ 120, ++ 10, ++ 327826, ++ 8, ++ 121, ++ 119, ++ 120, ++ 262205, ++ 111, ++ 124, ++ 123, ++ 327761, ++ 6, ++ 126, ++ 124, ++ 0, ++ 327761, ++ 6, ++ 127, ++ 124, ++ 1, ++ 327761, ++ 6, ++ 128, ++ 124, ++ 2, ++ 458832, ++ 7, ++ 129, ++ 126, ++ 127, ++ 128, ++ 125, ++ 327825, ++ 7, ++ 130, ++ 121, ++ 129, ++ 327745, ++ 131, ++ 132, ++ 109, ++ 110, ++ 196670, ++ 132, ++ 130, ++ 327745, ++ 26, ++ 135, ++ 16, ++ 110, ++ 262205, ++ 8, ++ 136, ++ 135, ++ 262205, ++ 111, ++ 137, ++ 123, ++ 327761, ++ 6, ++ 138, ++ 137, ++ 0, ++ 327761, ++ 6, ++ 139, ++ 137, ++ 1, ++ 327761, ++ 6, ++ 140, ++ 137, ++ 2, ++ 458832, ++ 7, ++ 141, ++ 138, ++ 139, ++ 140, ++ 125, ++ 327825, ++ 7, ++ 142, ++ 136, ++ 141, ++ 196670, ++ 134, ++ 142, ++ 327745, ++ 26, ++ 145, ++ 16, ++ 110, ++ 262205, ++ 8, ++ 146, ++ 145, ++ 262205, ++ 8, ++ 147, ++ 10, ++ 327826, ++ 8, ++ 148, ++ 146, ++ 147, ++ 262228, ++ 8, ++ 149, ++ 148, ++ 393228, ++ 8, ++ 150, ++ 1, ++ 34, ++ 149, ++ 393297, ++ 6, ++ 153, ++ 150, ++ 0, ++ 0, ++ 393297, ++ 6, ++ 154, ++ 150, ++ 0, ++ 1, ++ 393297, ++ 6, ++ 155, ++ 150, ++ 0, ++ 2, ++ 393297, ++ 6, ++ 156, ++ 150, ++ 1, ++ 0, ++ 393297, ++ 6, ++ 157, ++ 150, ++ 1, ++ 1, ++ 393297, ++ 6, ++ 158, ++ 150, ++ 1, ++ 2, ++ 393297, ++ 6, ++ 159, ++ 150, ++ 2, ++ 0, ++ 393297, ++ 6, ++ 160, ++ 150, ++ 2, ++ 1, ++ 393297, ++ 6, ++ 161, ++ 150, ++ 2, ++ 2, ++ 393296, ++ 111, ++ 162, ++ 153, ++ 154, ++ 155, ++ 393296, ++ 111, ++ 163, ++ 156, ++ 157, ++ 158, ++ 393296, ++ 111, ++ 164, ++ 159, ++ 160, ++ 161, ++ 393296, ++ 151, ++ 165, ++ 162, ++ 163, ++ 164, ++ 262205, ++ 111, ++ 167, ++ 166, ++ 327825, ++ 111, ++ 168, ++ 165, ++ 167, ++ 196670, ++ 144, ++ 168, ++ 327745, ++ 170, ++ 171, ++ 114, ++ 18, ++ 262205, ++ 111, ++ 172, ++ 171, ++ 262205, ++ 7, ++ 173, ++ 134, ++ 524367, ++ 111, ++ 174, ++ 173, ++ 173, ++ 0, ++ 1, ++ 2, ++ 327811, ++ 111, ++ 175, ++ 172, ++ 174, ++ 196670, ++ 169, ++ 175, ++ 327745, ++ 170, ++ 178, ++ 114, ++ 177, ++ 262205, ++ 111, ++ 179, ++ 178, ++ 262205, ++ 7, ++ 180, ++ 134, ++ 524367, ++ 111, ++ 181, ++ 180, ++ 180, ++ 0, ++ 1, ++ 2, ++ 327811, ++ 111, ++ 182, ++ 179, ++ 181, ++ 196670, ++ 176, ++ 182, ++ 65789, ++ 65592, ++}; ++ ++const uint32_t material_shader_1_frag_spv[] = { ++ 0x07230203, ++ SPV_VERSION, ++ (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, ++ 71, ++ 0, ++ 131089, ++ 1, ++ 393227, ++ 1, ++ 1280527431, ++ 1685353262, ++ 808793134, ++ 0, ++ 196622, ++ 0, ++ 1, ++ 655375, ++ 4, ++ 4, ++ 1852399981, ++ 0, ++ 17, ++ 24, ++ 53, ++ 69, ++ 70, ++ 196624, ++ 4, ++ 7, ++ 196611, ++ 2, ++ 400, ++ 589828, ++ 1096764487, ++ 1935622738, ++ 1918988389, ++ 1600484449, ++ 1684105331, ++ 1868526181, ++ 1667590754, ++ 29556, ++ 589828, ++ 1096764487, ++ 1935622738, ++ 1768186216, ++ 1818191726, ++ 1969712737, ++ 1600481121, ++ 1882206772, ++ 7037793, ++ 262149, ++ 4, ++ 1852399981, ++ 0, ++ 262149, ++ 9, ++ 1869377379, ++ 114, ++ 393221, ++ 13, ++ 1886216563, ++ 1131570540, ++ 1919904879, ++ 7364941, ++ 262149, ++ 17, ++ 1448439401, ++ 0, ++ 262149, ++ 21, ++ 1953720676, ++ 7500115, ++ 327685, ++ 24, ++ 1766616681, ++ 1450469479, ++ 25445, ++ 262149, ++ 29, ++ 1667585644, ++ 0, ++ 262149, ++ 34, ++ 1702130785, ++ 110, ++ 327685, ++ 44, ++ 1886351972, ++ 1684105331, ++ 30575, ++ 393221, ++ 53, ++ 1182037359, ++ 1130848626, ++ 1919904879, ++ 0, ++ 327685, ++ 69, ++ 1867411049, ++ 1818324338, ++ 0, ++ 327685, ++ 70, ++ 1767272041, ++ 1700165477, ++ 99, ++ 262215, ++ 13, ++ 34, ++ 0, ++ 262215, ++ 13, ++ 33, ++ 1, ++ 262215, ++ 17, ++ 30, ++ 0, ++ 262215, ++ 24, ++ 30, ++ 3, ++ 262215, ++ 53, ++ 30, ++ 0, ++ 262215, ++ 69, ++ 30, ++ 1, ++ 262215, ++ 70, ++ 30, ++ 2, ++ 131091, ++ 2, ++ 196641, ++ 3, ++ 2, ++ 196630, ++ 6, ++ 32, ++ 262167, ++ 7, ++ 6, ++ 4, ++ 262176, ++ 8, ++ 7, ++ 7, ++ 589849, ++ 10, ++ 6, ++ 1, ++ 0, ++ 0, ++ 0, ++ 1, ++ 0, ++ 196635, ++ 11, ++ 10, ++ 262176, ++ 12, ++ 0, ++ 11, ++ 262203, ++ 12, ++ 13, ++ 0, ++ 262167, ++ 15, ++ 6, ++ 2, ++ 262176, ++ 16, ++ 1, ++ 15, ++ 262203, ++ 16, ++ 17, ++ 1, ++ 262176, ++ 20, ++ 7, ++ 6, ++ 262167, ++ 22, ++ 6, ++ 3, ++ 262176, ++ 23, ++ 1, ++ 22, ++ 262203, ++ 23, ++ 24, ++ 1, ++ 262176, ++ 28, ++ 7, ++ 22, ++ 262187, ++ 6, ++ 35, ++ 1065353216, ++ 262187, ++ 6, ++ 36, ++ 961656599, ++ 262187, ++ 6, ++ 41, ++ 0, ++ 262187, ++ 6, ++ 45, ++ 998445679, ++ 262176, ++ 52, ++ 3, ++ 7, ++ 262203, ++ 52, ++ 53, ++ 3, ++ 262203, ++ 23, ++ 69, ++ 1, ++ 262203, ++ 23, ++ 70, ++ 1, ++ 327734, ++ 2, ++ 4, ++ 0, ++ 3, ++ 131320, ++ 5, ++ 262203, ++ 8, ++ 9, ++ 7, ++ 262203, ++ 20, ++ 21, ++ 7, ++ 262203, ++ 28, ++ 29, ++ 7, ++ 262203, ++ 20, ++ 34, ++ 7, ++ 262203, ++ 20, ++ 44, ++ 7, ++ 262205, ++ 11, ++ 14, ++ 13, ++ 262205, ++ 15, ++ 18, ++ 17, ++ 327767, ++ 7, ++ 19, ++ 14, ++ 18, ++ 196670, ++ 9, ++ 19, ++ 262205, ++ 22, ++ 25, ++ 24, ++ 262205, ++ 22, ++ 26, ++ 24, ++ 327828, ++ 6, ++ 27, ++ 25, ++ 26, ++ 196670, ++ 21, ++ 27, ++ 262205, ++ 22, ++ 30, ++ 24, ++ 262205, ++ 6, ++ 31, ++ 21, ++ 393228, ++ 6, ++ 32, ++ 1, ++ 32, ++ 31, ++ 327822, ++ 22, ++ 33, ++ 30, ++ 32, ++ 196670, ++ 29, ++ 33, ++ 262205, ++ 6, ++ 37, ++ 21, ++ 393228, ++ 6, ++ 38, ++ 1, ++ 31, ++ 37, ++ 327813, ++ 6, ++ 39, ++ 36, ++ 38, ++ 327811, ++ 6, ++ 40, ++ 35, ++ 39, ++ 524300, ++ 6, ++ 42, ++ 1, ++ 43, ++ 40, ++ 41, ++ 35, ++ 458764, ++ 6, ++ 43, ++ 1, ++ 40, ++ 42, ++ 41, ++ 196670, ++ 34, ++ 43, ++ 262205, ++ 6, ++ 46, ++ 21, ++ 393228, ++ 6, ++ 47, ++ 1, ++ 31, ++ 46, ++ 327813, ++ 6, ++ 48, ++ 45, ++ 47, ++ 327811, ++ 6, ++ 49, ++ 35, ++ 48, ++ 524300, ++ 6, ++ 50, ++ 1, ++ 43, ++ 49, ++ 41, ++ 35, ++ 458764, ++ 6, ++ 51, ++ 1, ++ 40, ++ 50, ++ 41, ++ 196670, ++ 44, ++ 51, ++ 262205, ++ 7, ++ 54, ++ 9, ++ 262205, ++ 6, ++ 55, ++ 44, ++ 327811, ++ 6, ++ 56, ++ 35, ++ 55, ++ 327822, ++ 7, ++ 57, ++ 54, ++ 56, ++ 327761, ++ 6, ++ 58, ++ 57, ++ 0, ++ 327761, ++ 6, ++ 59, ++ 57, ++ 1, ++ 327761, ++ 6, ++ 60, ++ 57, ++ 2, ++ 327761, ++ 6, ++ 61, ++ 57, ++ 3, ++ 458832, ++ 7, ++ 62, ++ 58, ++ 59, ++ 60, ++ 61, ++ 196670, ++ 53, ++ 62, ++ 262205, ++ 6, ++ 63, ++ 34, ++ 262205, ++ 7, ++ 64, ++ 53, ++ 524367, ++ 22, ++ 65, ++ 64, ++ 64, ++ 0, ++ 1, ++ 2, ++ 327822, ++ 22, ++ 66, ++ 65, ++ 63, ++ 262205, ++ 7, ++ 67, ++ 53, ++ 589903, ++ 7, ++ 68, ++ 67, ++ 66, ++ 4, ++ 5, ++ 6, ++ 3, ++ 196670, ++ 53, ++ 68, ++ 65789, ++ 65592, + }; ++const size_t material_shader_1_vert_size = sizeof(material_shader_1_vert_spv); ++const size_t material_shader_1_frag_size = sizeof(material_shader_1_frag_spv); +diff -bNur 0007shared-ubo/data_bulk.h 0008multi-material/data_bulk.h +--- 0007shared-ubo/data_bulk.h 2019-03-02 19:55:02.561358109 -0600 ++++ 0008multi-material/data_bulk.h 2019-03-02 19:55:02.565358211 -0600 +@@ -4,7 +4,14 @@ + // Must not be higher than same const in skinning shader + #define MAX_BONES 64 + +-typedef struct { ++typedef struct ++{ + mat4 model; + mat4 bones[MAX_BONES]; + } material_0_ubo_t; ++ ++typedef struct ++{ ++ mat4 model; ++ mat4 bones[MAX_BONES]; ++} material_1_ubo_t; +diff -bNur 0007shared-ubo/data.h 0008multi-material/data.h +--- 0007shared-ubo/data.h 2019-03-02 19:55:02.561358109 -0600 ++++ 0008multi-material/data.h 2019-03-02 19:55:02.565358211 -0600 +@@ -33,7 +33,8 @@ + + extern struct shared_ubo *data_model_shared_ubo; + +-typedef struct { ++typedef struct ++{ + char *name; + uint32_t first; + uint32_t count; +@@ -41,7 +42,8 @@ + } data_model_t; + extern data_model_t data_models[]; + +-typedef struct data_model_instance { ++typedef struct data_model_instance ++{ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); +@@ -53,15 +55,19 @@ + extern struct list_head data_model_instances; + extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +-typedef struct { +- struct { ++typedef struct ++{ ++ struct ++ { + const void *spv; + const size_t *size; + } vert, frag; + } data_material_shader_t; + extern const data_material_shader_t data_material_shaders[]; ++extern const size_t data_material_shaders_count; + +-typedef struct { ++typedef struct ++{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; +@@ -73,13 +79,15 @@ + VkDeviceSize texture_size; + } data_material_t; + extern const data_material_t data_materials[]; ++extern const size_t data_materials_count; + + #define UNIFORM_ALIGN (sizeof(float) * 4) + #define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) + #define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) + #define UNIFORM_SIZE (4096 * 4096) + #define SHARED_UNIFORM_SIZE (4096 * 32) +-typedef struct { ++typedef struct ++{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; +diff -bNur 0007shared-ubo/libdata.c 0008multi-material/libdata.c +--- 0007shared-ubo/libdata.c 2019-03-02 20:06:22.821345727 -0600 ++++ 0008multi-material/libdata.c 2019-03-02 20:06:22.825345914 -0600 +@@ -30,6 +30,10 @@ + const size_t material_shader_0_vert_size; + const uint8_t material_shader_0_frag_spv[1]; + const size_t material_shader_0_frag_size; ++const uint8_t material_shader_1_vert_spv[1]; ++const size_t material_shader_1_vert_size; ++const uint8_t material_shader_1_frag_spv[1]; ++const size_t material_shader_1_frag_size; + const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, +@@ -39,7 +43,17 @@ + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, ++ {{ ++ material_shader_1_vert_spv, ++ &material_shader_1_vert_size, ++ }, ++ { ++ material_shader_1_frag_spv, ++ &material_shader_1_frag_size, ++ }}, + }; ++const size_t data_material_shaders_count = ++ sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + + void shoot_forward(data_model_instance_t *ptr, double t) + { +@@ -56,7 +70,8 @@ + + typedef struct + { +- data_model_instance_t obj, other_obj; ++ data_model_instance_t obj; ++ data_model_instance_t other_obj; + } model_instance_t; + model_instance_t model_instance; + struct list_head data_model_instances = {&(model_instance.obj.list), +diff -bNur 0007shared-ubo/vulkan.c 0008multi-material/vulkan.c +--- 0007shared-ubo/vulkan.c 2019-03-03 15:07:51.304459958 -0600 ++++ 0008multi-material/vulkan.c 2019-03-03 15:07:57.262704289 -0600 +@@ -669,7 +669,7 @@ + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); + } + +-inline static void update_descriptor_set(uniform_map_t *map) ++inline static void update_descriptor_set(uniform_map_t *map, size_t material) + { + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; +@@ -699,9 +699,9 @@ + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; +- image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; +- image_info.imageView = texture_image_views[0]; ++ image_info.imageView = texture_image_views[material]; + image_info.sampler = texture_image_sampler; ++ image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; +@@ -723,7 +723,7 @@ + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); +- update_descriptor_set(this_map); ++ update_descriptor_set(this_map, data_models[inst->model].material); + } + + inline static void create_pipeline_layout() +@@ -922,9 +922,6 @@ + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; +- image_create_info.format = data_materials[0].texture_format; +- image_create_info.extent.width = data_materials[0].texture_width; +- image_create_info.extent.height = data_materials[0].texture_height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; +@@ -936,9 +933,15 @@ + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + ++ for (size_t i = 0; i < data_materials_count; i++) ++ { ++ image_create_info.format = data_materials[i].texture_format; ++ image_create_info.extent.width = data_materials[i].texture_width; ++ image_create_info.extent.height = data_materials[i].texture_height; + VkResult err; +- err = vkCreateImage(device, &image_create_info, NULL, &texture_images[0]); ++ err = vkCreateImage(device, &image_create_info, NULL, &texture_images[i]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); ++ } + } + + inline static void +@@ -987,14 +990,17 @@ + VkDeviceMemory *texture_image_memorys) + { + create_texture_images(texture_images); +- allocate_texture_image(texture_images[0], gpu_memory_properties, +- &texture_image_memorys[0]); ++ for (size_t i = 0; i < data_materials_count; i++) ++ { ++ allocate_texture_image(texture_images[i], gpu_memory_properties, ++ &texture_image_memorys[i]); + + void *data; +- vkMapMemory(device, texture_image_memorys[0], 0, +- data_materials[0].texture_size, 0, &data); +- memcpy(data, data_materials[0].texture, data_materials[0].texture_size); +- vkUnmapMemory(device, texture_image_memorys[0]); ++ vkMapMemory(device, texture_image_memorys[i], 0, ++ data_materials[i].texture_size, 0, &data); ++ memcpy(data, data_materials[i].texture, data_materials[i].texture_size); ++ vkUnmapMemory(device, texture_image_memorys[i]); ++ } + } + + inline static void create_image_views(VkImage *texture_images) +@@ -1003,9 +1009,7 @@ + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; +- image_view_create_info.image = texture_images[0]; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; +- image_view_create_info.format = data_materials[0].texture_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; +@@ -1017,10 +1021,15 @@ + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + ++ for (size_t i = 0; i < data_materials_count; i++) ++ { ++ image_view_create_info.image = texture_images[i]; ++ image_view_create_info.format = data_materials[i].texture_format; + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, +- &texture_image_views[0]); ++ &texture_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); ++ } + } + + inline static void +@@ -1041,20 +1050,23 @@ + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + +- shader_module_create_info.codeSize = *data_material_shaders[0].vert.size; ++ for (size_t i = 0; i < data_material_shaders_count; i++) ++ { ++ shader_module_create_info.codeSize = *data_material_shaders[i].vert.size; + shader_module_create_info.pCode = +- (uint32_t *)data_material_shaders[0].vert.spv; ++ (uint32_t *)data_material_shaders[i].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, +- &vert_modules[0]); ++ &vert_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + +- shader_module_create_info.codeSize = *data_material_shaders[0].frag.size; ++ shader_module_create_info.codeSize = *data_material_shaders[i].frag.size; + shader_module_create_info.pCode = +- (uint32_t *)data_material_shaders[0].frag.spv; ++ (uint32_t *)data_material_shaders[i].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, +- &frag_modules[0]); ++ &frag_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); ++ } + } + + inline static void create_graphice_pipelines(VkShaderModule *vert_modules, +@@ -1070,8 +1082,6 @@ + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; +- shader_stages_create_info[0].module = vert_modules[0]; +- shader_stages_create_info[1].module = frag_modules[0]; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + +@@ -1209,11 +1219,16 @@ + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + ++ for (size_t i = 0; i < data_material_shaders_count; i++) ++ { ++ shader_stages_create_info[0].module = vert_modules[i]; ++ shader_stages_create_info[1].module = frag_modules[i]; + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, +- &graphics_pipelines[0]); ++ &graphics_pipelines[i]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); ++ } + } + + inline static void setup_materials(VkImage *texture_images, +@@ -1414,24 +1429,29 @@ + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + +- data_model_instance_t *inst = +- list_entry(data_model_instances.next, data_model_instance_t, list); ++ size_t bound_shaders = SIZE_MAX; ++ data_model_instance_t *inst; ++ list_for_each_entry(inst, &data_model_instances, list) ++ { ++ if (bound_shaders != ++ data_materials[data_models[inst->model].material].shader) ++ { + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); ++ bound_shaders = data_materials[data_models[inst->model].material].shader; ++ } + +- list_for_each_entry(inst, &data_model_instances, list) +- { + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, +- &list_entry(inst->uniform_map, uniform_map_t, list)->descriptor_set, ++ &list_entry(inst->uniform_map, uniform_map_t, list) ++ ->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } +- + vkCmdEndRenderPass(command_buffer); + + VkResult err; +@@ -1539,14 +1559,26 @@ + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; +- vkDestroyPipeline(device, graphics_pipelines[0], NULL); +- graphics_pipelines[0] = VK_NULL_HANDLE; +- vkDestroyShaderModule(device, frag_modules[0], NULL); +- frag_modules[0] = VK_NULL_HANDLE; +- vkDestroyShaderModule(device, vert_modules[0], NULL); +- vert_modules[0] = VK_NULL_HANDLE; +- vkDestroyPipelineLayout(device, pipeline_layout, NULL); +- pipeline_layout = VK_NULL_HANDLE; ++ for (size_t i = 0; i < data_material_shaders_count; i++) ++ { ++ vkDestroyPipeline(device, graphics_pipelines[i], NULL); ++ graphics_pipelines[i] = VK_NULL_HANDLE; ++ vkDestroyShaderModule(device, frag_modules[i], NULL); ++ frag_modules[i] = VK_NULL_HANDLE; ++ vkDestroyShaderModule(device, vert_modules[i], NULL); ++ vert_modules[i] = VK_NULL_HANDLE; ++ } ++ vkDestroySampler(device, texture_image_sampler, NULL); ++ texture_image_sampler = VK_NULL_HANDLE; ++ for (size_t i = 0; i < data_materials_count; i++) ++ { ++ vkDestroyImageView(device, texture_image_views[i], NULL); ++ texture_image_views[i] = VK_NULL_HANDLE; ++ vkFreeMemory(device, texture_image_memorys[i], NULL); ++ texture_image_memorys[i] = VK_NULL_HANDLE; ++ vkDestroyImage(device, texture_images[i], NULL); ++ texture_images[i] = VK_NULL_HANDLE; ++ } + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); +@@ -1561,14 +1593,6 @@ + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; +- vkDestroySampler(device, texture_image_sampler, NULL); +- texture_image_sampler = VK_NULL_HANDLE; +- vkDestroyImageView(device, texture_image_views[0], NULL); +- texture_image_views[0] = VK_NULL_HANDLE; +- vkFreeMemory(device, texture_image_memorys[0], NULL); +- texture_image_memorys[0] = VK_NULL_HANDLE; +- vkDestroyImage(device, texture_images[0], NULL); +- texture_images[0] = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) +@@ -1637,13 +1661,13 @@ + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + +- VkImage texture_images[] = {VK_NULL_HANDLE}; +- VkDeviceMemory texture_image_memorys[] = {VK_NULL_HANDLE}; +- VkImageView _texture_image_views[] = {VK_NULL_HANDLE}; ++ VkImage texture_images[data_materials_count]; ++ VkDeviceMemory texture_image_memorys[data_materials_count]; ++ VkImageView _texture_image_views[data_materials_count]; + texture_image_views = _texture_image_views; +- VkShaderModule vert_modules[] = {VK_NULL_HANDLE}; +- VkShaderModule frag_modules[] = {VK_NULL_HANDLE}; +- VkPipeline graphics_pipelines[] = {VK_NULL_HANDLE}; ++ VkShaderModule vert_modules[data_material_shaders_count]; ++ VkShaderModule frag_modules[data_material_shaders_count]; ++ VkPipeline graphics_pipelines[data_material_shaders_count]; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; diff --git a/0008multi-material/.gitignore b/0008multi-material/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0008multi-material/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0008multi-material/0_frag.glsl b/0008multi-material/0_frag.glsl new file mode 100644 index 0000000..b877549 --- /dev/null +++ b/0008multi-material/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0008multi-material/0_vert.glsl b/0008multi-material/0_vert.glsl new file mode 100644 index 0000000..f8339a6 --- /dev/null +++ b/0008multi-material/0_vert.glsl @@ -0,0 +1,54 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; +} ubo; + +layout (binding = 2) uniform SUBO +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} subo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = subo.lightPos - pos.xyz; + outViewVec = subo.viewPos - pos.xyz; +} diff --git a/0008multi-material/Makefile b/0008multi-material/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0008multi-material/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0008multi-material/data.h b/0008multi-material/data.h new file mode 100644 index 0000000..be8206a --- /dev/null +++ b/0008multi-material/data.h @@ -0,0 +1,98 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +extern struct shared_ubo *data_model_shared_ubo; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +typedef struct data_model_instance +{ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void *closure; + struct list_head list; + void *ubo; + struct list_head *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; +extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; +extern const size_t data_material_shaders_count; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; +extern const size_t data_materials_count; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +#define SHARED_UNIFORM_SIZE (4096 * 32) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; + +#endif diff --git a/0008multi-material/data_bulk.c b/0008multi-material/data_bulk.c new file mode 100644 index 0000000..70db7a6 --- /dev/null +++ b/0008multi-material/data_bulk.c @@ -0,0 +1,2899 @@ +#include "data_bulk.h" +#include +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, + { + "Other Cube", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, + { + "Other Example", + 1, + sizeof(material_1_ubo_t), + get_model_1, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; +const size_t data_materials_count = + sizeof(data_materials) / sizeof(data_materials[0]); +const uint32_t material_shader_1_vert_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 183, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 983055, + 0, + 4, + 1852399981, + 0, + 21, + 30, + 103, + 105, + 109, + 123, + 144, + 166, + 169, + 176, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 393221, + 10, + 1701736290, + 1851880020, + 1919903347, + 109, + 196613, + 14, + 5194325, + 327686, + 14, + 0, + 1701080941, + 108, + 327686, + 14, + 1, + 1701736290, + 115, + 196613, + 16, + 7299701, + 327685, + 21, + 1866624617, + 1145660782, + 115, + 393221, + 30, + 1866624617, + 1700226414, + 1952999273, + 115, + 262149, + 103, + 1433695599, + 86, + 262149, + 105, + 1448439401, + 0, + 393221, + 107, + 1348430951, + 1700164197, + 2019914866, + 0, + 393222, + 107, + 0, + 1348430951, + 1953067887, + 7237481, + 196613, + 109, + 0, + 262149, + 112, + 1329747283, + 0, + 262150, + 112, + 0, + 28790, + 393222, + 112, + 1, + 1751607660, + 1936674932, + 0, + 327686, + 112, + 2, + 1633968496, + 0, + 327686, + 112, + 3, + 2003134838, + 7565136, + 327686, + 112, + 4, + 1650745712, + 0, + 262149, + 114, + 1868723571, + 0, + 262149, + 123, + 1867542121, + 115, + 196613, + 134, + 7565168, + 327685, + 144, + 1316255087, + 1634562671, + 108, + 327685, + 166, + 1867411049, + 1818324338, + 0, + 327685, + 169, + 1282700655, + 1952999273, + 6514006, + 327685, + 176, + 1450472815, + 1450665321, + 25445, + 262215, + 13, + 6, + 64, + 262216, + 14, + 0, + 5, + 327752, + 14, + 0, + 35, + 0, + 327752, + 14, + 0, + 7, + 16, + 262216, + 14, + 1, + 5, + 327752, + 14, + 1, + 35, + 64, + 327752, + 14, + 1, + 7, + 16, + 196679, + 14, + 2, + 262215, + 16, + 34, + 0, + 262215, + 16, + 33, + 0, + 262215, + 21, + 30, + 4, + 262215, + 30, + 30, + 3, + 262215, + 103, + 30, + 0, + 262215, + 105, + 30, + 2, + 327752, + 107, + 0, + 11, + 0, + 196679, + 107, + 2, + 262216, + 112, + 0, + 5, + 327752, + 112, + 0, + 35, + 0, + 327752, + 112, + 0, + 7, + 16, + 327752, + 112, + 1, + 35, + 64, + 327752, + 112, + 2, + 35, + 76, + 327752, + 112, + 3, + 35, + 80, + 327752, + 112, + 4, + 35, + 92, + 196679, + 112, + 2, + 262215, + 114, + 34, + 0, + 262215, + 114, + 33, + 2, + 262215, + 123, + 30, + 0, + 262215, + 144, + 30, + 1, + 262215, + 166, + 30, + 1, + 262215, + 169, + 30, + 3, + 262215, + 176, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262168, + 8, + 7, + 4, + 262176, + 9, + 7, + 8, + 262165, + 11, + 32, + 0, + 262187, + 11, + 12, + 64, + 262172, + 13, + 8, + 12, + 262174, + 14, + 8, + 13, + 262176, + 15, + 2, + 14, + 262203, + 15, + 16, + 2, + 262165, + 17, + 32, + 1, + 262187, + 17, + 18, + 1, + 262167, + 19, + 17, + 4, + 262176, + 20, + 1, + 19, + 262203, + 20, + 21, + 1, + 262187, + 11, + 22, + 0, + 262176, + 23, + 1, + 17, + 262176, + 26, + 2, + 8, + 262176, + 29, + 1, + 7, + 262203, + 29, + 30, + 1, + 262176, + 31, + 1, + 6, + 262187, + 11, + 35, + 1, + 262187, + 11, + 57, + 2, + 262187, + 11, + 79, + 3, + 262167, + 101, + 6, + 2, + 262176, + 102, + 3, + 101, + 262203, + 102, + 103, + 3, + 262176, + 104, + 1, + 101, + 262203, + 104, + 105, + 1, + 196638, + 107, + 7, + 262176, + 108, + 3, + 107, + 262203, + 108, + 109, + 3, + 262187, + 17, + 110, + 0, + 262167, + 111, + 6, + 3, + 458782, + 112, + 8, + 111, + 6, + 111, + 6, + 262176, + 113, + 2, + 112, + 262203, + 113, + 114, + 2, + 262176, + 122, + 1, + 111, + 262203, + 122, + 123, + 1, + 262187, + 6, + 125, + 1065353216, + 262176, + 131, + 3, + 7, + 262176, + 133, + 7, + 7, + 262176, + 143, + 3, + 111, + 262203, + 143, + 144, + 3, + 262168, + 151, + 111, + 3, + 262187, + 6, + 152, + 0, + 262203, + 122, + 166, + 1, + 262203, + 143, + 169, + 3, + 262176, + 170, + 2, + 111, + 262203, + 143, + 176, + 3, + 262187, + 17, + 177, + 3, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 9, + 10, + 7, + 262203, + 133, + 134, + 7, + 327745, + 23, + 24, + 21, + 22, + 262205, + 17, + 25, + 24, + 393281, + 26, + 27, + 16, + 18, + 25, + 262205, + 8, + 28, + 27, + 327745, + 31, + 32, + 30, + 22, + 262205, + 6, + 33, + 32, + 327823, + 8, + 34, + 28, + 33, + 196670, + 10, + 34, + 327745, + 23, + 36, + 21, + 35, + 262205, + 17, + 37, + 36, + 393281, + 26, + 38, + 16, + 18, + 37, + 262205, + 8, + 39, + 38, + 327745, + 31, + 40, + 30, + 35, + 262205, + 6, + 41, + 40, + 327823, + 8, + 42, + 39, + 41, + 262205, + 8, + 43, + 10, + 327761, + 7, + 44, + 43, + 0, + 327761, + 7, + 45, + 42, + 0, + 327809, + 7, + 46, + 44, + 45, + 327761, + 7, + 47, + 43, + 1, + 327761, + 7, + 48, + 42, + 1, + 327809, + 7, + 49, + 47, + 48, + 327761, + 7, + 50, + 43, + 2, + 327761, + 7, + 51, + 42, + 2, + 327809, + 7, + 52, + 50, + 51, + 327761, + 7, + 53, + 43, + 3, + 327761, + 7, + 54, + 42, + 3, + 327809, + 7, + 55, + 53, + 54, + 458832, + 8, + 56, + 46, + 49, + 52, + 55, + 196670, + 10, + 56, + 327745, + 23, + 58, + 21, + 57, + 262205, + 17, + 59, + 58, + 393281, + 26, + 60, + 16, + 18, + 59, + 262205, + 8, + 61, + 60, + 327745, + 31, + 62, + 30, + 57, + 262205, + 6, + 63, + 62, + 327823, + 8, + 64, + 61, + 63, + 262205, + 8, + 65, + 10, + 327761, + 7, + 66, + 65, + 0, + 327761, + 7, + 67, + 64, + 0, + 327809, + 7, + 68, + 66, + 67, + 327761, + 7, + 69, + 65, + 1, + 327761, + 7, + 70, + 64, + 1, + 327809, + 7, + 71, + 69, + 70, + 327761, + 7, + 72, + 65, + 2, + 327761, + 7, + 73, + 64, + 2, + 327809, + 7, + 74, + 72, + 73, + 327761, + 7, + 75, + 65, + 3, + 327761, + 7, + 76, + 64, + 3, + 327809, + 7, + 77, + 75, + 76, + 458832, + 8, + 78, + 68, + 71, + 74, + 77, + 196670, + 10, + 78, + 327745, + 23, + 80, + 21, + 79, + 262205, + 17, + 81, + 80, + 393281, + 26, + 82, + 16, + 18, + 81, + 262205, + 8, + 83, + 82, + 327745, + 31, + 84, + 30, + 79, + 262205, + 6, + 85, + 84, + 327823, + 8, + 86, + 83, + 85, + 262205, + 8, + 87, + 10, + 327761, + 7, + 88, + 87, + 0, + 327761, + 7, + 89, + 86, + 0, + 327809, + 7, + 90, + 88, + 89, + 327761, + 7, + 91, + 87, + 1, + 327761, + 7, + 92, + 86, + 1, + 327809, + 7, + 93, + 91, + 92, + 327761, + 7, + 94, + 87, + 2, + 327761, + 7, + 95, + 86, + 2, + 327809, + 7, + 96, + 94, + 95, + 327761, + 7, + 97, + 87, + 3, + 327761, + 7, + 98, + 86, + 3, + 327809, + 7, + 99, + 97, + 98, + 458832, + 8, + 100, + 90, + 93, + 96, + 99, + 196670, + 10, + 100, + 262205, + 101, + 106, + 105, + 196670, + 103, + 106, + 327745, + 26, + 115, + 114, + 110, + 262205, + 8, + 116, + 115, + 327745, + 26, + 117, + 16, + 110, + 262205, + 8, + 118, + 117, + 327826, + 8, + 119, + 116, + 118, + 262205, + 8, + 120, + 10, + 327826, + 8, + 121, + 119, + 120, + 262205, + 111, + 124, + 123, + 327761, + 6, + 126, + 124, + 0, + 327761, + 6, + 127, + 124, + 1, + 327761, + 6, + 128, + 124, + 2, + 458832, + 7, + 129, + 126, + 127, + 128, + 125, + 327825, + 7, + 130, + 121, + 129, + 327745, + 131, + 132, + 109, + 110, + 196670, + 132, + 130, + 327745, + 26, + 135, + 16, + 110, + 262205, + 8, + 136, + 135, + 262205, + 111, + 137, + 123, + 327761, + 6, + 138, + 137, + 0, + 327761, + 6, + 139, + 137, + 1, + 327761, + 6, + 140, + 137, + 2, + 458832, + 7, + 141, + 138, + 139, + 140, + 125, + 327825, + 7, + 142, + 136, + 141, + 196670, + 134, + 142, + 327745, + 26, + 145, + 16, + 110, + 262205, + 8, + 146, + 145, + 262205, + 8, + 147, + 10, + 327826, + 8, + 148, + 146, + 147, + 262228, + 8, + 149, + 148, + 393228, + 8, + 150, + 1, + 34, + 149, + 393297, + 6, + 153, + 150, + 0, + 0, + 393297, + 6, + 154, + 150, + 0, + 1, + 393297, + 6, + 155, + 150, + 0, + 2, + 393297, + 6, + 156, + 150, + 1, + 0, + 393297, + 6, + 157, + 150, + 1, + 1, + 393297, + 6, + 158, + 150, + 1, + 2, + 393297, + 6, + 159, + 150, + 2, + 0, + 393297, + 6, + 160, + 150, + 2, + 1, + 393297, + 6, + 161, + 150, + 2, + 2, + 393296, + 111, + 162, + 153, + 154, + 155, + 393296, + 111, + 163, + 156, + 157, + 158, + 393296, + 111, + 164, + 159, + 160, + 161, + 393296, + 151, + 165, + 162, + 163, + 164, + 262205, + 111, + 167, + 166, + 327825, + 111, + 168, + 165, + 167, + 196670, + 144, + 168, + 327745, + 170, + 171, + 114, + 18, + 262205, + 111, + 172, + 171, + 262205, + 7, + 173, + 134, + 524367, + 111, + 174, + 173, + 173, + 0, + 1, + 2, + 327811, + 111, + 175, + 172, + 174, + 196670, + 169, + 175, + 327745, + 170, + 178, + 114, + 177, + 262205, + 111, + 179, + 178, + 262205, + 7, + 180, + 134, + 524367, + 111, + 181, + 180, + 180, + 0, + 1, + 2, + 327811, + 111, + 182, + 179, + 181, + 196670, + 176, + 182, + 65789, + 65592, +}; + +const uint32_t material_shader_1_frag_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 71, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 655375, + 4, + 4, + 1852399981, + 0, + 17, + 24, + 53, + 69, + 70, + 196624, + 4, + 7, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 262149, + 9, + 1869377379, + 114, + 393221, + 13, + 1886216563, + 1131570540, + 1919904879, + 7364941, + 262149, + 17, + 1448439401, + 0, + 262149, + 21, + 1953720676, + 7500115, + 327685, + 24, + 1766616681, + 1450469479, + 25445, + 262149, + 29, + 1667585644, + 0, + 262149, + 34, + 1702130785, + 110, + 327685, + 44, + 1886351972, + 1684105331, + 30575, + 393221, + 53, + 1182037359, + 1130848626, + 1919904879, + 0, + 327685, + 69, + 1867411049, + 1818324338, + 0, + 327685, + 70, + 1767272041, + 1700165477, + 99, + 262215, + 13, + 34, + 0, + 262215, + 13, + 33, + 1, + 262215, + 17, + 30, + 0, + 262215, + 24, + 30, + 3, + 262215, + 53, + 30, + 0, + 262215, + 69, + 30, + 1, + 262215, + 70, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262176, + 8, + 7, + 7, + 589849, + 10, + 6, + 1, + 0, + 0, + 0, + 1, + 0, + 196635, + 11, + 10, + 262176, + 12, + 0, + 11, + 262203, + 12, + 13, + 0, + 262167, + 15, + 6, + 2, + 262176, + 16, + 1, + 15, + 262203, + 16, + 17, + 1, + 262176, + 20, + 7, + 6, + 262167, + 22, + 6, + 3, + 262176, + 23, + 1, + 22, + 262203, + 23, + 24, + 1, + 262176, + 28, + 7, + 22, + 262187, + 6, + 35, + 1065353216, + 262187, + 6, + 36, + 961656599, + 262187, + 6, + 41, + 0, + 262187, + 6, + 45, + 998445679, + 262176, + 52, + 3, + 7, + 262203, + 52, + 53, + 3, + 262203, + 23, + 69, + 1, + 262203, + 23, + 70, + 1, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 8, + 9, + 7, + 262203, + 20, + 21, + 7, + 262203, + 28, + 29, + 7, + 262203, + 20, + 34, + 7, + 262203, + 20, + 44, + 7, + 262205, + 11, + 14, + 13, + 262205, + 15, + 18, + 17, + 327767, + 7, + 19, + 14, + 18, + 196670, + 9, + 19, + 262205, + 22, + 25, + 24, + 262205, + 22, + 26, + 24, + 327828, + 6, + 27, + 25, + 26, + 196670, + 21, + 27, + 262205, + 22, + 30, + 24, + 262205, + 6, + 31, + 21, + 393228, + 6, + 32, + 1, + 32, + 31, + 327822, + 22, + 33, + 30, + 32, + 196670, + 29, + 33, + 262205, + 6, + 37, + 21, + 393228, + 6, + 38, + 1, + 31, + 37, + 327813, + 6, + 39, + 36, + 38, + 327811, + 6, + 40, + 35, + 39, + 524300, + 6, + 42, + 1, + 43, + 40, + 41, + 35, + 458764, + 6, + 43, + 1, + 40, + 42, + 41, + 196670, + 34, + 43, + 262205, + 6, + 46, + 21, + 393228, + 6, + 47, + 1, + 31, + 46, + 327813, + 6, + 48, + 45, + 47, + 327811, + 6, + 49, + 35, + 48, + 524300, + 6, + 50, + 1, + 43, + 49, + 41, + 35, + 458764, + 6, + 51, + 1, + 40, + 50, + 41, + 196670, + 44, + 51, + 262205, + 7, + 54, + 9, + 262205, + 6, + 55, + 44, + 327811, + 6, + 56, + 35, + 55, + 327822, + 7, + 57, + 54, + 56, + 327761, + 6, + 58, + 57, + 0, + 327761, + 6, + 59, + 57, + 1, + 327761, + 6, + 60, + 57, + 2, + 327761, + 6, + 61, + 57, + 3, + 458832, + 7, + 62, + 58, + 59, + 60, + 61, + 196670, + 53, + 62, + 262205, + 6, + 63, + 34, + 262205, + 7, + 64, + 53, + 524367, + 22, + 65, + 64, + 64, + 0, + 1, + 2, + 327822, + 22, + 66, + 65, + 63, + 262205, + 7, + 67, + 53, + 589903, + 7, + 68, + 67, + 66, + 4, + 5, + 6, + 3, + 196670, + 53, + 68, + 65789, + 65592, +}; +const size_t material_shader_1_vert_size = sizeof(material_shader_1_vert_spv); +const size_t material_shader_1_frag_size = sizeof(material_shader_1_frag_spv); diff --git a/0008multi-material/data_bulk.h b/0008multi-material/data_bulk.h new file mode 100644 index 0000000..ed7d5a4 --- /dev/null +++ b/0008multi-material/data_bulk.h @@ -0,0 +1,17 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_0_ubo_t; + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_1_ubo_t; diff --git a/0008multi-material/data_dynamic.c.in b/0008multi-material/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0008multi-material/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0008multi-material/libdata.c b/0008multi-material/libdata.c new file mode 100644 index 0000000..b1e4db2 --- /dev/null +++ b/0008multi-material/libdata.c @@ -0,0 +1,389 @@ +#include "data_bulk.h" +#include +#include + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } +} + +typedef struct shared_ubo +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} shared_ubo_t; + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const uint8_t material_shader_1_vert_spv[1]; +const size_t material_shader_1_vert_size; +const uint8_t material_shader_1_frag_spv[1]; +const size_t material_shader_1_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, + {{ + material_shader_1_vert_spv, + &material_shader_1_vert_size, + }, + { + material_shader_1_frag_spv, + &material_shader_1_frag_size, + }}, +}; +const size_t data_material_shaders_count = + sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, 3 * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +#define SUBO data_model_shared_ubo +struct shared_ubo *SUBO = NULL; + +typedef struct +{ + data_model_instance_t obj; + data_model_instance_t other_obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.other_obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + NULL, + {&(model_instance.other_obj.list), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, + { + "Other Object", + 1, + shoot_forward, + NULL, + {&(data_model_instances), &(model_instance.obj.list)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + struct list_head **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = &this_map->list; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = &this_map->list; + } +} + +void (*data_setup_model_instance)(data_model_instance_t *inst); +uintptr_t data_uniform_ptr = 0; +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = &map->list; + data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, + uniform_map_t, list) + ->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp() +{ + glm_lookat(SUBO->viewPos, + (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], + SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, SUBO->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0, *ubo_1; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + setup_model_instance(inst); + ubo_0 = (list_entry(data_model_instances.next, data_model_instance_t, list))->ubo; + ubo_1 = (list_entry(data_model_instances.prev, data_model_instance_t, list))->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + static const shared_ubo_t empty_shared_ubo_s; + *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + SUBO->lightPos[0] = 0.0f; + SUBO->lightPos[1] = 250.0f; + SUBO->lightPos[2] = -250.0f; + SUBO->viewPos[0] = 0.0f; + SUBO->viewPos[1] = 0.0f; + SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(); + + *ubo_1 = *ubo_0; + glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 rot0, rot1, trans0; + glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +void data_update() +{ + double this_frame = glfwGetTime(); + + handle_input(this_frame); + + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0008multi-material/vulkan.c b/0008multi-material/vulkan.c new file mode 100644 index 0000000..6b2b2ac --- /dev/null +++ b/0008multi-material/vulkan.c @@ -0,0 +1,1682 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, + UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); + data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[2] = set_layout_bindings[0]; + set_layout_bindings[2].binding = 2; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map, size_t material) +{ + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + uniform_descriptors[1] = uniform_descriptors[0]; + uniform_descriptors[1].offset = UNIFORM_SIZE; + uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; + + VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + + write_descriptor_sets[2] = write_descriptor_sets[0]; + write_descriptor_sets[2].dstBinding = 2; + write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageView = texture_image_views[material]; + image_info.sampler = texture_image_sampler; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(data_model_instance_t *inst) +{ + uniform_map_t *this_map; + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); + update_descriptor_set(this_map, data_models[inst->model].material); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_create_info.format = data_materials[i].texture_format; + image_create_info.extent.width = data_materials[i].texture_width; + image_create_info.extent.height = data_materials[i].texture_height; + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[i]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); + } +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + for (size_t i = 0; i < data_materials_count; i++) + { + allocate_texture_image(texture_images[i], gpu_memory_properties, + &texture_image_memorys[i]); + + void *data; + vkMapMemory(device, texture_image_memorys[i], 0, + data_materials[i].texture_size, 0, &data); + memcpy(data, data_materials[i].texture, data_materials[i].texture_size); + vkUnmapMemory(device, texture_image_memorys[i]); + } +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_view_create_info.image = texture_images[i]; + image_view_create_info.format = data_materials[i].texture_format; + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); + } +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_module_create_info.codeSize = *data_material_shaders[i].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[i].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); + } +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_stages_create_info[0].module = vert_modules[i]; + shader_stages_create_info[1].module = frag_modules[i]; + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[i]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); + } +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + size_t bound_shaders = SIZE_MAX; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + { + if (bound_shaders != + data_materials[data_models[inst->model].material].shader) + { + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + bound_shaders = data_materials[data_models[inst->model].material].shader; + } + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &list_entry(inst->uniform_map, uniform_map_t, list) + ->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + for (size_t i = 0; i < data_material_shaders_count; i++) + { + vkDestroyPipeline(device, graphics_pipelines[i], NULL); + graphics_pipelines[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[i], NULL); + frag_modules[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[i], NULL); + vert_modules[i] = VK_NULL_HANDLE; + } + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + for (size_t i = 0; i < data_materials_count; i++) + { + vkDestroyImageView(device, texture_image_views[i], NULL); + texture_image_views[i] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[i], NULL); + texture_image_memorys[i] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[i], NULL); + texture_images[i] = VK_NULL_HANDLE; + } + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = + VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[data_materials_count]; + VkDeviceMemory texture_image_memorys[data_materials_count]; + VkImageView _texture_image_views[data_materials_count]; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[data_material_shaders_count]; + VkShaderModule frag_modules[data_material_shaders_count]; + VkPipeline graphics_pipelines[data_material_shaders_count]; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0009modify-instances-count.diff b/0009modify-instances-count.diff new file mode 100644 index 0000000..edecf57 --- /dev/null +++ b/0009modify-instances-count.diff @@ -0,0 +1,138 @@ +diff -bNur 0008multi-material/data_bulk.c 0009modify-instances-count/data_bulk.c +--- 0008multi-material/data_bulk.c 2019-03-02 20:06:22.825345914 -0600 ++++ 0009modify-instances-count/data_bulk.c 2019-03-02 20:06:22.829346100 -0600 +@@ -265,7 +265,7 @@ + 0, + }, + { +- "Other Cube", ++ "Bullet", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, +diff -bNur 0008multi-material/libdata.c 0009modify-instances-count/libdata.c +--- 0008multi-material/libdata.c 2019-03-02 20:06:22.825345914 -0600 ++++ 0009modify-instances-count/libdata.c 2019-03-02 20:06:22.829346100 -0600 +@@ -1,15 +1,23 @@ + #include "data_bulk.h" ++#include + #include + #include ++#include ++ ++inline static void player_shoot(); + + void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) + { ++ if (action == GLFW_PRESS) + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; ++ case GLFW_KEY_X: ++ player_shoot(); ++ break; + } + } + +@@ -65,33 +73,60 @@ + glm_mat4_copy(rot0, *model); + } + ++inline static void setup_model_instance(data_model_instance_t *inst); + #define SUBO data_model_shared_ubo + struct shared_ubo *SUBO = NULL; ++inline static void player_shoot() ++{ ++ data_model_instance_t *this_instance = NULL, ++ bullet_instance = { ++ "Bullet Object", ++ 1, ++ shoot_forward, ++ NULL, ++ {NULL, NULL}, ++ NULL, ++ VK_NULL_HANDLE, ++ }; ++ ++ this_instance = malloc(sizeof(bullet_instance)); ++ assert(this_instance && "Out of memory."); ++ *this_instance = bullet_instance; ++ setup_model_instance(this_instance); ++ ++ { ++ material_1_ubo_t *this_ubo = this_instance->ubo; ++ { ++ static const material_1_ubo_t empty_data_material_ubo_s; ++ *this_ubo = empty_data_material_ubo_s; ++ } ++ glm_mat4_copy(GLM_MAT4_IDENTITY, this_ubo->bones[0]); ++ ++ { ++ mat4 trans0; ++ glm_translate_to(GLM_MAT4_IDENTITY, SUBO->viewPos, trans0); ++ glm_rotate_y(trans0, center_dir, this_ubo->model); ++ glm_translate_z(this_ubo->model, 1.25f); ++ } ++ } ++ ++ list_add_tail(&this_instance->list, &data_model_instances); ++} + + typedef struct + { + data_model_instance_t obj; +- data_model_instance_t other_obj; + } model_instance_t; + model_instance_t model_instance; + struct list_head data_model_instances = {&(model_instance.obj.list), +- &(model_instance.other_obj.list)}; ++ &(model_instance.obj.list)}; + model_instance_t model_instance = { + { + "Object", + 0, + NULL, + NULL, +- {&(model_instance.other_obj.list), &(data_model_instances)}, +- NULL, +- VK_NULL_HANDLE, +- }, +- { +- "Other Object", +- 1, +- shoot_forward, +- NULL, +- {&(data_model_instances), &(model_instance.obj.list)}, ++ {&(data_model_instances), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, +@@ -201,12 +236,10 @@ + + void data_init(VkExtent2D extent) + { +- material_0_ubo_t *ubo_0, *ubo_1; +- data_model_instance_t *inst; +- list_for_each_entry(inst, &data_model_instances, list) ++ material_0_ubo_t *ubo_0; ++ data_model_instance_t *inst = list_entry(data_model_instances.next, data_model_instance_t, list); + setup_model_instance(inst); +- ubo_0 = (list_entry(data_model_instances.next, data_model_instance_t, list))->ubo; +- ubo_1 = (list_entry(data_model_instances.prev, data_model_instance_t, list))->ubo; ++ ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + +@@ -242,9 +275,6 @@ + + update_vp(); + +- *ubo_1 = *ubo_0; +- glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model); +- + previous_frame = glfwGetTime(); + } + diff --git a/0009modify-instances-count/.gitignore b/0009modify-instances-count/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0009modify-instances-count/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0009modify-instances-count/0_frag.glsl b/0009modify-instances-count/0_frag.glsl new file mode 100644 index 0000000..b877549 --- /dev/null +++ b/0009modify-instances-count/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0009modify-instances-count/0_vert.glsl b/0009modify-instances-count/0_vert.glsl new file mode 100644 index 0000000..f8339a6 --- /dev/null +++ b/0009modify-instances-count/0_vert.glsl @@ -0,0 +1,54 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; +} ubo; + +layout (binding = 2) uniform SUBO +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} subo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = subo.lightPos - pos.xyz; + outViewVec = subo.viewPos - pos.xyz; +} diff --git a/0009modify-instances-count/Makefile b/0009modify-instances-count/Makefile new file mode 100644 index 0000000..4345d67 --- /dev/null +++ b/0009modify-instances-count/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0009modify-instances-count/data.h b/0009modify-instances-count/data.h new file mode 100644 index 0000000..be8206a --- /dev/null +++ b/0009modify-instances-count/data.h @@ -0,0 +1,98 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +extern struct shared_ubo *data_model_shared_ubo; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; +} data_model_t; +extern data_model_t data_models[]; + +typedef struct data_model_instance +{ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void *closure; + struct list_head list; + void *ubo; + struct list_head *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; +extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; +extern const size_t data_material_shaders_count; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; +extern const size_t data_materials_count; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +#define SHARED_UNIFORM_SIZE (4096 * 32) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; + +#endif diff --git a/0009modify-instances-count/data_bulk.c b/0009modify-instances-count/data_bulk.c new file mode 100644 index 0000000..a6f165b --- /dev/null +++ b/0009modify-instances-count/data_bulk.c @@ -0,0 +1,2899 @@ +#include "data_bulk.h" +#include +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + }, + { + "Bullet", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, + { + "Other Example", + 1, + sizeof(material_1_ubo_t), + get_model_1, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; +const size_t data_materials_count = + sizeof(data_materials) / sizeof(data_materials[0]); +const uint32_t material_shader_1_vert_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 183, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 983055, + 0, + 4, + 1852399981, + 0, + 21, + 30, + 103, + 105, + 109, + 123, + 144, + 166, + 169, + 176, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 393221, + 10, + 1701736290, + 1851880020, + 1919903347, + 109, + 196613, + 14, + 5194325, + 327686, + 14, + 0, + 1701080941, + 108, + 327686, + 14, + 1, + 1701736290, + 115, + 196613, + 16, + 7299701, + 327685, + 21, + 1866624617, + 1145660782, + 115, + 393221, + 30, + 1866624617, + 1700226414, + 1952999273, + 115, + 262149, + 103, + 1433695599, + 86, + 262149, + 105, + 1448439401, + 0, + 393221, + 107, + 1348430951, + 1700164197, + 2019914866, + 0, + 393222, + 107, + 0, + 1348430951, + 1953067887, + 7237481, + 196613, + 109, + 0, + 262149, + 112, + 1329747283, + 0, + 262150, + 112, + 0, + 28790, + 393222, + 112, + 1, + 1751607660, + 1936674932, + 0, + 327686, + 112, + 2, + 1633968496, + 0, + 327686, + 112, + 3, + 2003134838, + 7565136, + 327686, + 112, + 4, + 1650745712, + 0, + 262149, + 114, + 1868723571, + 0, + 262149, + 123, + 1867542121, + 115, + 196613, + 134, + 7565168, + 327685, + 144, + 1316255087, + 1634562671, + 108, + 327685, + 166, + 1867411049, + 1818324338, + 0, + 327685, + 169, + 1282700655, + 1952999273, + 6514006, + 327685, + 176, + 1450472815, + 1450665321, + 25445, + 262215, + 13, + 6, + 64, + 262216, + 14, + 0, + 5, + 327752, + 14, + 0, + 35, + 0, + 327752, + 14, + 0, + 7, + 16, + 262216, + 14, + 1, + 5, + 327752, + 14, + 1, + 35, + 64, + 327752, + 14, + 1, + 7, + 16, + 196679, + 14, + 2, + 262215, + 16, + 34, + 0, + 262215, + 16, + 33, + 0, + 262215, + 21, + 30, + 4, + 262215, + 30, + 30, + 3, + 262215, + 103, + 30, + 0, + 262215, + 105, + 30, + 2, + 327752, + 107, + 0, + 11, + 0, + 196679, + 107, + 2, + 262216, + 112, + 0, + 5, + 327752, + 112, + 0, + 35, + 0, + 327752, + 112, + 0, + 7, + 16, + 327752, + 112, + 1, + 35, + 64, + 327752, + 112, + 2, + 35, + 76, + 327752, + 112, + 3, + 35, + 80, + 327752, + 112, + 4, + 35, + 92, + 196679, + 112, + 2, + 262215, + 114, + 34, + 0, + 262215, + 114, + 33, + 2, + 262215, + 123, + 30, + 0, + 262215, + 144, + 30, + 1, + 262215, + 166, + 30, + 1, + 262215, + 169, + 30, + 3, + 262215, + 176, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262168, + 8, + 7, + 4, + 262176, + 9, + 7, + 8, + 262165, + 11, + 32, + 0, + 262187, + 11, + 12, + 64, + 262172, + 13, + 8, + 12, + 262174, + 14, + 8, + 13, + 262176, + 15, + 2, + 14, + 262203, + 15, + 16, + 2, + 262165, + 17, + 32, + 1, + 262187, + 17, + 18, + 1, + 262167, + 19, + 17, + 4, + 262176, + 20, + 1, + 19, + 262203, + 20, + 21, + 1, + 262187, + 11, + 22, + 0, + 262176, + 23, + 1, + 17, + 262176, + 26, + 2, + 8, + 262176, + 29, + 1, + 7, + 262203, + 29, + 30, + 1, + 262176, + 31, + 1, + 6, + 262187, + 11, + 35, + 1, + 262187, + 11, + 57, + 2, + 262187, + 11, + 79, + 3, + 262167, + 101, + 6, + 2, + 262176, + 102, + 3, + 101, + 262203, + 102, + 103, + 3, + 262176, + 104, + 1, + 101, + 262203, + 104, + 105, + 1, + 196638, + 107, + 7, + 262176, + 108, + 3, + 107, + 262203, + 108, + 109, + 3, + 262187, + 17, + 110, + 0, + 262167, + 111, + 6, + 3, + 458782, + 112, + 8, + 111, + 6, + 111, + 6, + 262176, + 113, + 2, + 112, + 262203, + 113, + 114, + 2, + 262176, + 122, + 1, + 111, + 262203, + 122, + 123, + 1, + 262187, + 6, + 125, + 1065353216, + 262176, + 131, + 3, + 7, + 262176, + 133, + 7, + 7, + 262176, + 143, + 3, + 111, + 262203, + 143, + 144, + 3, + 262168, + 151, + 111, + 3, + 262187, + 6, + 152, + 0, + 262203, + 122, + 166, + 1, + 262203, + 143, + 169, + 3, + 262176, + 170, + 2, + 111, + 262203, + 143, + 176, + 3, + 262187, + 17, + 177, + 3, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 9, + 10, + 7, + 262203, + 133, + 134, + 7, + 327745, + 23, + 24, + 21, + 22, + 262205, + 17, + 25, + 24, + 393281, + 26, + 27, + 16, + 18, + 25, + 262205, + 8, + 28, + 27, + 327745, + 31, + 32, + 30, + 22, + 262205, + 6, + 33, + 32, + 327823, + 8, + 34, + 28, + 33, + 196670, + 10, + 34, + 327745, + 23, + 36, + 21, + 35, + 262205, + 17, + 37, + 36, + 393281, + 26, + 38, + 16, + 18, + 37, + 262205, + 8, + 39, + 38, + 327745, + 31, + 40, + 30, + 35, + 262205, + 6, + 41, + 40, + 327823, + 8, + 42, + 39, + 41, + 262205, + 8, + 43, + 10, + 327761, + 7, + 44, + 43, + 0, + 327761, + 7, + 45, + 42, + 0, + 327809, + 7, + 46, + 44, + 45, + 327761, + 7, + 47, + 43, + 1, + 327761, + 7, + 48, + 42, + 1, + 327809, + 7, + 49, + 47, + 48, + 327761, + 7, + 50, + 43, + 2, + 327761, + 7, + 51, + 42, + 2, + 327809, + 7, + 52, + 50, + 51, + 327761, + 7, + 53, + 43, + 3, + 327761, + 7, + 54, + 42, + 3, + 327809, + 7, + 55, + 53, + 54, + 458832, + 8, + 56, + 46, + 49, + 52, + 55, + 196670, + 10, + 56, + 327745, + 23, + 58, + 21, + 57, + 262205, + 17, + 59, + 58, + 393281, + 26, + 60, + 16, + 18, + 59, + 262205, + 8, + 61, + 60, + 327745, + 31, + 62, + 30, + 57, + 262205, + 6, + 63, + 62, + 327823, + 8, + 64, + 61, + 63, + 262205, + 8, + 65, + 10, + 327761, + 7, + 66, + 65, + 0, + 327761, + 7, + 67, + 64, + 0, + 327809, + 7, + 68, + 66, + 67, + 327761, + 7, + 69, + 65, + 1, + 327761, + 7, + 70, + 64, + 1, + 327809, + 7, + 71, + 69, + 70, + 327761, + 7, + 72, + 65, + 2, + 327761, + 7, + 73, + 64, + 2, + 327809, + 7, + 74, + 72, + 73, + 327761, + 7, + 75, + 65, + 3, + 327761, + 7, + 76, + 64, + 3, + 327809, + 7, + 77, + 75, + 76, + 458832, + 8, + 78, + 68, + 71, + 74, + 77, + 196670, + 10, + 78, + 327745, + 23, + 80, + 21, + 79, + 262205, + 17, + 81, + 80, + 393281, + 26, + 82, + 16, + 18, + 81, + 262205, + 8, + 83, + 82, + 327745, + 31, + 84, + 30, + 79, + 262205, + 6, + 85, + 84, + 327823, + 8, + 86, + 83, + 85, + 262205, + 8, + 87, + 10, + 327761, + 7, + 88, + 87, + 0, + 327761, + 7, + 89, + 86, + 0, + 327809, + 7, + 90, + 88, + 89, + 327761, + 7, + 91, + 87, + 1, + 327761, + 7, + 92, + 86, + 1, + 327809, + 7, + 93, + 91, + 92, + 327761, + 7, + 94, + 87, + 2, + 327761, + 7, + 95, + 86, + 2, + 327809, + 7, + 96, + 94, + 95, + 327761, + 7, + 97, + 87, + 3, + 327761, + 7, + 98, + 86, + 3, + 327809, + 7, + 99, + 97, + 98, + 458832, + 8, + 100, + 90, + 93, + 96, + 99, + 196670, + 10, + 100, + 262205, + 101, + 106, + 105, + 196670, + 103, + 106, + 327745, + 26, + 115, + 114, + 110, + 262205, + 8, + 116, + 115, + 327745, + 26, + 117, + 16, + 110, + 262205, + 8, + 118, + 117, + 327826, + 8, + 119, + 116, + 118, + 262205, + 8, + 120, + 10, + 327826, + 8, + 121, + 119, + 120, + 262205, + 111, + 124, + 123, + 327761, + 6, + 126, + 124, + 0, + 327761, + 6, + 127, + 124, + 1, + 327761, + 6, + 128, + 124, + 2, + 458832, + 7, + 129, + 126, + 127, + 128, + 125, + 327825, + 7, + 130, + 121, + 129, + 327745, + 131, + 132, + 109, + 110, + 196670, + 132, + 130, + 327745, + 26, + 135, + 16, + 110, + 262205, + 8, + 136, + 135, + 262205, + 111, + 137, + 123, + 327761, + 6, + 138, + 137, + 0, + 327761, + 6, + 139, + 137, + 1, + 327761, + 6, + 140, + 137, + 2, + 458832, + 7, + 141, + 138, + 139, + 140, + 125, + 327825, + 7, + 142, + 136, + 141, + 196670, + 134, + 142, + 327745, + 26, + 145, + 16, + 110, + 262205, + 8, + 146, + 145, + 262205, + 8, + 147, + 10, + 327826, + 8, + 148, + 146, + 147, + 262228, + 8, + 149, + 148, + 393228, + 8, + 150, + 1, + 34, + 149, + 393297, + 6, + 153, + 150, + 0, + 0, + 393297, + 6, + 154, + 150, + 0, + 1, + 393297, + 6, + 155, + 150, + 0, + 2, + 393297, + 6, + 156, + 150, + 1, + 0, + 393297, + 6, + 157, + 150, + 1, + 1, + 393297, + 6, + 158, + 150, + 1, + 2, + 393297, + 6, + 159, + 150, + 2, + 0, + 393297, + 6, + 160, + 150, + 2, + 1, + 393297, + 6, + 161, + 150, + 2, + 2, + 393296, + 111, + 162, + 153, + 154, + 155, + 393296, + 111, + 163, + 156, + 157, + 158, + 393296, + 111, + 164, + 159, + 160, + 161, + 393296, + 151, + 165, + 162, + 163, + 164, + 262205, + 111, + 167, + 166, + 327825, + 111, + 168, + 165, + 167, + 196670, + 144, + 168, + 327745, + 170, + 171, + 114, + 18, + 262205, + 111, + 172, + 171, + 262205, + 7, + 173, + 134, + 524367, + 111, + 174, + 173, + 173, + 0, + 1, + 2, + 327811, + 111, + 175, + 172, + 174, + 196670, + 169, + 175, + 327745, + 170, + 178, + 114, + 177, + 262205, + 111, + 179, + 178, + 262205, + 7, + 180, + 134, + 524367, + 111, + 181, + 180, + 180, + 0, + 1, + 2, + 327811, + 111, + 182, + 179, + 181, + 196670, + 176, + 182, + 65789, + 65592, +}; + +const uint32_t material_shader_1_frag_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 71, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 655375, + 4, + 4, + 1852399981, + 0, + 17, + 24, + 53, + 69, + 70, + 196624, + 4, + 7, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 262149, + 9, + 1869377379, + 114, + 393221, + 13, + 1886216563, + 1131570540, + 1919904879, + 7364941, + 262149, + 17, + 1448439401, + 0, + 262149, + 21, + 1953720676, + 7500115, + 327685, + 24, + 1766616681, + 1450469479, + 25445, + 262149, + 29, + 1667585644, + 0, + 262149, + 34, + 1702130785, + 110, + 327685, + 44, + 1886351972, + 1684105331, + 30575, + 393221, + 53, + 1182037359, + 1130848626, + 1919904879, + 0, + 327685, + 69, + 1867411049, + 1818324338, + 0, + 327685, + 70, + 1767272041, + 1700165477, + 99, + 262215, + 13, + 34, + 0, + 262215, + 13, + 33, + 1, + 262215, + 17, + 30, + 0, + 262215, + 24, + 30, + 3, + 262215, + 53, + 30, + 0, + 262215, + 69, + 30, + 1, + 262215, + 70, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262176, + 8, + 7, + 7, + 589849, + 10, + 6, + 1, + 0, + 0, + 0, + 1, + 0, + 196635, + 11, + 10, + 262176, + 12, + 0, + 11, + 262203, + 12, + 13, + 0, + 262167, + 15, + 6, + 2, + 262176, + 16, + 1, + 15, + 262203, + 16, + 17, + 1, + 262176, + 20, + 7, + 6, + 262167, + 22, + 6, + 3, + 262176, + 23, + 1, + 22, + 262203, + 23, + 24, + 1, + 262176, + 28, + 7, + 22, + 262187, + 6, + 35, + 1065353216, + 262187, + 6, + 36, + 961656599, + 262187, + 6, + 41, + 0, + 262187, + 6, + 45, + 998445679, + 262176, + 52, + 3, + 7, + 262203, + 52, + 53, + 3, + 262203, + 23, + 69, + 1, + 262203, + 23, + 70, + 1, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 8, + 9, + 7, + 262203, + 20, + 21, + 7, + 262203, + 28, + 29, + 7, + 262203, + 20, + 34, + 7, + 262203, + 20, + 44, + 7, + 262205, + 11, + 14, + 13, + 262205, + 15, + 18, + 17, + 327767, + 7, + 19, + 14, + 18, + 196670, + 9, + 19, + 262205, + 22, + 25, + 24, + 262205, + 22, + 26, + 24, + 327828, + 6, + 27, + 25, + 26, + 196670, + 21, + 27, + 262205, + 22, + 30, + 24, + 262205, + 6, + 31, + 21, + 393228, + 6, + 32, + 1, + 32, + 31, + 327822, + 22, + 33, + 30, + 32, + 196670, + 29, + 33, + 262205, + 6, + 37, + 21, + 393228, + 6, + 38, + 1, + 31, + 37, + 327813, + 6, + 39, + 36, + 38, + 327811, + 6, + 40, + 35, + 39, + 524300, + 6, + 42, + 1, + 43, + 40, + 41, + 35, + 458764, + 6, + 43, + 1, + 40, + 42, + 41, + 196670, + 34, + 43, + 262205, + 6, + 46, + 21, + 393228, + 6, + 47, + 1, + 31, + 46, + 327813, + 6, + 48, + 45, + 47, + 327811, + 6, + 49, + 35, + 48, + 524300, + 6, + 50, + 1, + 43, + 49, + 41, + 35, + 458764, + 6, + 51, + 1, + 40, + 50, + 41, + 196670, + 44, + 51, + 262205, + 7, + 54, + 9, + 262205, + 6, + 55, + 44, + 327811, + 6, + 56, + 35, + 55, + 327822, + 7, + 57, + 54, + 56, + 327761, + 6, + 58, + 57, + 0, + 327761, + 6, + 59, + 57, + 1, + 327761, + 6, + 60, + 57, + 2, + 327761, + 6, + 61, + 57, + 3, + 458832, + 7, + 62, + 58, + 59, + 60, + 61, + 196670, + 53, + 62, + 262205, + 6, + 63, + 34, + 262205, + 7, + 64, + 53, + 524367, + 22, + 65, + 64, + 64, + 0, + 1, + 2, + 327822, + 22, + 66, + 65, + 63, + 262205, + 7, + 67, + 53, + 589903, + 7, + 68, + 67, + 66, + 4, + 5, + 6, + 3, + 196670, + 53, + 68, + 65789, + 65592, +}; +const size_t material_shader_1_vert_size = sizeof(material_shader_1_vert_spv); +const size_t material_shader_1_frag_size = sizeof(material_shader_1_frag_spv); diff --git a/0009modify-instances-count/data_bulk.h b/0009modify-instances-count/data_bulk.h new file mode 100644 index 0000000..ed7d5a4 --- /dev/null +++ b/0009modify-instances-count/data_bulk.h @@ -0,0 +1,17 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_0_ubo_t; + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_1_ubo_t; diff --git a/0009modify-instances-count/data_dynamic.c.in b/0009modify-instances-count/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0009modify-instances-count/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0009modify-instances-count/libdata.c b/0009modify-instances-count/libdata.c new file mode 100644 index 0000000..e40446a --- /dev/null +++ b/0009modify-instances-count/libdata.c @@ -0,0 +1,419 @@ +#include "data_bulk.h" +#include +#include +#include +#include + +inline static void player_shoot(); + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + if (action == GLFW_PRESS) + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + case GLFW_KEY_X: + player_shoot(); + break; + } +} + +typedef struct shared_ubo +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} shared_ubo_t; + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const uint8_t material_shader_1_vert_spv[1]; +const size_t material_shader_1_vert_size; +const uint8_t material_shader_1_frag_spv[1]; +const size_t material_shader_1_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, + {{ + material_shader_1_vert_spv, + &material_shader_1_vert_size, + }, + { + material_shader_1_frag_spv, + &material_shader_1_frag_size, + }}, +}; +const size_t data_material_shaders_count = + sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, 3 * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +inline static void setup_model_instance(data_model_instance_t *inst); +#define SUBO data_model_shared_ubo +struct shared_ubo *SUBO = NULL; +inline static void player_shoot() +{ + data_model_instance_t *this_instance = NULL, + bullet_instance = { + "Bullet Object", + 1, + shoot_forward, + NULL, + {NULL, NULL}, + NULL, + VK_NULL_HANDLE, + }; + + this_instance = malloc(sizeof(bullet_instance)); + assert(this_instance && "Out of memory."); + *this_instance = bullet_instance; + setup_model_instance(this_instance); + + { + material_1_ubo_t *this_ubo = this_instance->ubo; + { + static const material_1_ubo_t empty_data_material_ubo_s; + *this_ubo = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, this_ubo->bones[0]); + + { + mat4 trans0; + glm_translate_to(GLM_MAT4_IDENTITY, SUBO->viewPos, trans0); + glm_rotate_y(trans0, center_dir, this_ubo->model); + glm_translate_z(this_ubo->model, 1.25f); + } + } + + list_add_tail(&this_instance->list, &data_model_instances); +} + +typedef struct +{ + data_model_instance_t obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + NULL, + {&(data_model_instances), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + struct list_head **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = &this_map->list; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = &this_map->list; + } +} + +void (*data_setup_model_instance)(data_model_instance_t *inst); +uintptr_t data_uniform_ptr = 0; +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = &map->list; + data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, + uniform_map_t, list) + ->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp() +{ + glm_lookat(SUBO->viewPos, + (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], + SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, SUBO->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = list_entry(data_model_instances.next, data_model_instance_t, list); + setup_model_instance(inst); + ubo_0 = inst->ubo; + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + static const shared_ubo_t empty_shared_ubo_s; + *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + SUBO->lightPos[0] = 0.0f; + SUBO->lightPos[1] = 250.0f; + SUBO->lightPos[2] = -250.0f; + SUBO->viewPos[0] = 0.0f; + SUBO->viewPos[1] = 0.0f; + SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(); + + previous_frame = glfwGetTime(); +} + +inline static void handle_input(double this_frame) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 rot0, rot1, trans0; + glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +void data_update() +{ + double this_frame = glfwGetTime(); + + handle_input(this_frame); + + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; +} diff --git a/0009modify-instances-count/vulkan.c b/0009modify-instances-count/vulkan.c new file mode 100644 index 0000000..6b2b2ac --- /dev/null +++ b/0009modify-instances-count/vulkan.c @@ -0,0 +1,1682 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, + UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); + data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[2] = set_layout_bindings[0]; + set_layout_bindings[2].binding = 2; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map, size_t material) +{ + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + uniform_descriptors[1] = uniform_descriptors[0]; + uniform_descriptors[1].offset = UNIFORM_SIZE; + uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; + + VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + + write_descriptor_sets[2] = write_descriptor_sets[0]; + write_descriptor_sets[2].dstBinding = 2; + write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageView = texture_image_views[material]; + image_info.sampler = texture_image_sampler; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(data_model_instance_t *inst) +{ + uniform_map_t *this_map; + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); + update_descriptor_set(this_map, data_models[inst->model].material); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_create_info.format = data_materials[i].texture_format; + image_create_info.extent.width = data_materials[i].texture_width; + image_create_info.extent.height = data_materials[i].texture_height; + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[i]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); + } +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + for (size_t i = 0; i < data_materials_count; i++) + { + allocate_texture_image(texture_images[i], gpu_memory_properties, + &texture_image_memorys[i]); + + void *data; + vkMapMemory(device, texture_image_memorys[i], 0, + data_materials[i].texture_size, 0, &data); + memcpy(data, data_materials[i].texture, data_materials[i].texture_size); + vkUnmapMemory(device, texture_image_memorys[i]); + } +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_view_create_info.image = texture_images[i]; + image_view_create_info.format = data_materials[i].texture_format; + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); + } +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_module_create_info.codeSize = *data_material_shaders[i].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[i].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); + } +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_stages_create_info[0].module = vert_modules[i]; + shader_stages_create_info[1].module = frag_modules[i]; + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[i]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); + } +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + size_t bound_shaders = SIZE_MAX; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + { + if (bound_shaders != + data_materials[data_models[inst->model].material].shader) + { + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + bound_shaders = data_materials[data_models[inst->model].material].shader; + } + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &list_entry(inst->uniform_map, uniform_map_t, list) + ->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + for (size_t i = 0; i < data_material_shaders_count; i++) + { + vkDestroyPipeline(device, graphics_pipelines[i], NULL); + graphics_pipelines[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[i], NULL); + frag_modules[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[i], NULL); + vert_modules[i] = VK_NULL_HANDLE; + } + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + for (size_t i = 0; i < data_materials_count; i++) + { + vkDestroyImageView(device, texture_image_views[i], NULL); + texture_image_views[i] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[i], NULL); + texture_image_memorys[i] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[i], NULL); + texture_images[i] = VK_NULL_HANDLE; + } + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = + VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[data_materials_count]; + VkDeviceMemory texture_image_memorys[data_materials_count]; + VkImageView _texture_image_views[data_materials_count]; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[data_material_shaders_count]; + VkShaderModule frag_modules[data_material_shaders_count]; + VkPipeline graphics_pipelines[data_material_shaders_count]; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0010tasks-during-render.diff b/0010tasks-during-render.diff new file mode 100644 index 0000000..b6a1eae --- /dev/null +++ b/0010tasks-during-render.diff @@ -0,0 +1,394 @@ +diff -bNur 0009modify-instances-count/data_bulk.c 0010tasks-during-render/data_bulk.c +--- 0009modify-instances-count/data_bulk.c 2019-03-02 20:06:22.829346100 -0600 ++++ 0010tasks-during-render/data_bulk.c 2019-03-02 20:06:22.829346100 -0600 +@@ -263,12 +263,14 @@ + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, ++ 0.5f, + }, + { + "Bullet", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, ++ 0.5f, + }, + }; + +diff -bNur 0009modify-instances-count/data.h 0010tasks-during-render/data.h +--- 0009modify-instances-count/data.h 2019-03-02 19:55:02.565358211 -0600 ++++ 0010tasks-during-render/data.h 2019-03-02 19:55:02.569358313 -0600 +@@ -15,6 +15,7 @@ + + void data_init(VkExtent2D extent); + void data_update(); ++void data_exit(); + + // Maximum number of bones per vertex + #define MAX_BONES_PER_VERTEX 4 +@@ -39,6 +40,7 @@ + uint32_t first; + uint32_t count; + size_t material; ++ float radius; + } data_model_t; + extern data_model_t data_models[]; + +diff -bNur 0009modify-instances-count/libdata.c 0010tasks-during-render/libdata.c +--- 0009modify-instances-count/libdata.c 2019-03-02 20:06:22.829346100 -0600 ++++ 0010tasks-during-render/libdata.c 2019-03-02 20:06:22.829346100 -0600 +@@ -1,7 +1,10 @@ + #include "data_bulk.h" ++#include + #include + #include ++#include + #include ++#include + #include + + inline static void player_shoot(); +@@ -63,12 +66,19 @@ + const size_t data_material_shaders_count = + sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + ++typedef struct ++{ ++ float mass; ++ float speed; ++ bool solid; ++} instance_closure_t; ++ + void shoot_forward(data_model_instance_t *ptr, double t) + { + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); +- glm_translate_z(*model, 3 * t); ++ glm_translate_z(*model, ((instance_closure_t *)ptr->closure)->speed * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); + } +@@ -76,14 +86,21 @@ + inline static void setup_model_instance(data_model_instance_t *inst); + #define SUBO data_model_shared_ubo + struct shared_ubo *SUBO = NULL; ++pthread_mutex_t data_data_mutex = PTHREAD_MUTEX_INITIALIZER; + inline static void player_shoot() + { ++ static const instance_closure_t bullet_closure = { ++ 0.02f, ++ 3.0f, ++ true, ++ }; ++ + data_model_instance_t *this_instance = NULL, + bullet_instance = { + "Bullet Object", + 1, + shoot_forward, +- NULL, ++ &bullet_closure, + {NULL, NULL}, + NULL, + VK_NULL_HANDLE, +@@ -110,7 +127,9 @@ + } + } + ++ assert((!pthread_mutex_lock(&data_data_mutex)) && "Player Shoot"); + list_add_tail(&this_instance->list, &data_model_instances); ++ assert((!pthread_mutex_unlock(&data_data_mutex)) && "Player Shoot"); + } + + typedef struct +@@ -125,13 +144,120 @@ + "Object", + 0, + NULL, +- NULL, ++ &(instance_closure_t){ ++ 1.0f, ++ 0.0f, ++ true, ++ }, + {&(data_model_instances), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, + }; + ++bool intersect(vec3 amin, vec3 amax, vec3 bmin, vec3 bmax) ++{ ++ return (amin[0] <= bmax[0] && amax[0] >= bmin[0]) && ++ (amin[1] <= bmax[1] && amax[1] >= bmin[1]) && ++ (amin[2] <= bmax[2] && amax[2] >= bmin[2]); ++} ++ ++pthread_t while_rendering_0; ++pthread_cond_t data_data_cond = PTHREAD_COND_INITIALIZER; ++#define MAX_COLLISIONS (64 * 64) ++typedef struct ++{ ++ data_model_instance_t *x, *y; ++} collision_t; ++collision_t collisions[MAX_COLLISIONS]; ++size_t collisions_count = 0; ++pthread_mutex_t collisions_mutex = PTHREAD_MUTEX_INITIALIZER; ++void *while_rendering_0_func(void *vargp) ++{ ++ while (!glfwWindowShouldClose(data_window)) ++ { ++ ++ assert((!pthread_mutex_lock(&data_data_mutex)) && "While Rendering 0"); ++ pthread_cond_wait(&data_data_cond, &data_data_mutex); ++ ++ size_t instance_count = 0; ++ struct list_head *ptr; ++ list_for_each(ptr, &data_model_instances) instance_count++; ++ { ++ struct ++ { ++ data_model_instance_t *id; ++ mat4 model; ++ float radius; ++ vec4 pos; ++ vec3 pos_high; ++ vec3 pos_low; ++ } _data[instance_count]; ++ ++ { ++ size_t i = 0; ++ data_model_instance_t *ptr; ++ list_for_each_entry(ptr, &data_model_instances, list) ++ { ++ if (!((instance_closure_t *)ptr->closure)->solid) ++ { ++ --instance_count; ++ continue; ++ } ++ _data[i].id = ptr; ++ glm_mat4_copy( ++ *(data_materials[data_models[ptr->model].material].get_model( ++ ptr->ubo)), ++ _data[i].model); ++ _data[i++].radius = data_models[ptr->model].radius; ++ } ++ } ++ ++ assert((!pthread_mutex_unlock(&data_data_mutex)) && "While Rendering 0"); ++ ++ for (size_t i = 0; i < instance_count; i++) ++ { ++ glm_mat4_mulv(_data[i].model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, ++ _data[i].pos); ++ for (size_t a = 0; a < 3; a++) ++ { ++ _data[i].pos_high[a] = _data[i].pos[a] + _data[i].radius; ++ _data[i].pos_low[a] = _data[i].pos[a] - _data[i].radius; ++ } ++ } ++ ++ assert((!pthread_mutex_lock(&collisions_mutex)) && "While Rendering 0"); ++ ++ collisions_count = 0; ++ ++ for (size_t x = 0; x < instance_count; x++) ++ { ++ if (x + 1 < instance_count) ++ { ++ for (size_t y = x + 1; y < instance_count; y++) ++ { ++ if (intersect(_data[x].pos_low, _data[x].pos_high, _data[y].pos_low, ++ _data[y].pos_high)) ++ { ++ if (glm_vec_distance(_data[x].pos, _data[y].pos) - ++ _data[x].radius - _data[y].radius < ++ 0) ++ { ++ assert((++collisions_count < MAX_COLLISIONS) && ++ "Overflow collisions"); ++ collisions[collisions_count - 1] = ++ (collision_t){_data[x].id, _data[y].id}; ++ } ++ } ++ } ++ } ++ } ++ } ++ assert((!pthread_mutex_unlock(&collisions_mutex)) && "While Rendering 0"); ++ } ++ return (NULL); ++} ++ + uniform_map_t starting_map; + struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; + uniform_map_t starting_map = { +@@ -241,6 +367,9 @@ + setup_model_instance(inst); + ubo_0 = inst->ubo; + ++ assert( ++ !pthread_create(&while_rendering_0, NULL, while_rendering_0_func, NULL)); ++ + glfwSetKeyCallback(data_window, key_callback); + + { +@@ -276,6 +405,10 @@ + update_vp(); + + previous_frame = glfwGetTime(); ++ ++ assert((!pthread_mutex_lock(&data_data_mutex)) && "Init"); ++ assert((!pthread_cond_broadcast(&data_data_cond)) && "Init"); ++ assert((!pthread_mutex_unlock(&data_data_mutex)) && "Init"); + } + + inline static void handle_input(double this_frame) +@@ -397,12 +530,88 @@ + } + } + ++inline static void process_collisions() ++{ ++ for (size_t i = 0; i < collisions_count; i++) ++ { ++ data_model_instance_t *ids[2]; ++ vec3 pos[2], zrot[2]; ++ float zop[2], zadj[2]; ++ mat4 *model[2]; ++ ids[0] = collisions[i].x; ++ ids[1] = collisions[i].y; ++ for (size_t a = 0; a < 2; a++) ++ { ++ /* TODO: Skip no-longer available objects */ ++ model[a] = data_materials[data_models[ids[a]->model].material].get_model( ++ ids[a]->ubo); ++ _glm_decompose(*model[a], pos[a], NULL, zrot[a], &zop[a], &zadj[a]); ++ } ++ { ++ vec3 N /* Collision */, add0[2] /* overlapping points */; ++ glm_vec_sub(pos[0], pos[1], N); ++ for (size_t a = 0; a < 2; a++) ++ { ++ vec3 scale0; ++ float table[] = { ++ -data_models[ids[a]->model].radius, ++ data_models[ids[a]->model].radius, ++ }; ++ glm_vec_scale_as(N, table[a], scale0); ++ glm_vec_add(scale0, pos[a], add0[a]); ++ } ++ vec3 sub1 /* overlapping influence */; ++ glm_vec_sub(add0[0], add0[1], sub1); ++ { ++#define MASS(x) ((instance_closure_t *)ids[x]->closure)->mass ++#define SPEED(x) ((instance_closure_t *)ids[x]->closure)->speed ++ vec3 scale0, scale1, add0[2]; ++ float div0 = 1 / (MASS(0) + MASS(1)); ++ glm_vec_scale(zrot[0], SPEED(0) * (MASS(0) - MASS(1)), scale0); ++ glm_vec_scale(zrot[1], SPEED(1) * 2 * MASS(1), scale1); ++ glm_vec_add(scale0, scale1, add0[0]); ++ glm_vec_scale(zrot[1], SPEED(1) * (MASS(1) - MASS(0)), scale0); ++ glm_vec_scale(zrot[0], SPEED(0) * 2 * MASS(0), scale1); ++ glm_vec_scale(add0[0], div0, zrot[0]); ++ glm_vec_add(scale0, scale1, add0[1]); ++ glm_vec_scale(add0[1], div0, zrot[1]); ++ } ++ for (size_t a = 0; a < 2; a++) ++ { ++ vec3 scale1, add1, rot; ++ float table[] = { ++ -1.2f * MASS(0) / (MASS(0) + MASS(1)), ++ 1.2f * MASS(1) / (MASS(0) + MASS(1)), ++ }; ++#undef MASS ++#undef SPEED ++ glm_vec_scale(sub1, table[a], scale1); ++ glm_vec_add(scale1, pos[a], add1); ++ glm_vec_copy(add1, pos[a]); ++ ++ _glm_atan3(zrot[a], zop[a], zadj[a], rot); ++ ++ { ++ mat4 trans0, rot0, rot1, rot2; ++ glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); ++ glm_rotate_y(rot0, rot[1], rot1); ++ glm_rotate_z(rot1, rot[2], rot2); ++ glm_translate_make(trans0, pos[a]); ++ glm_mat4_mul(trans0, rot2, *model[a]); ++ } ++ } ++ } ++ } ++ collisions_count = 0; ++} ++ + void data_update() + { + double this_frame = glfwGetTime(); + + handle_input(this_frame); + ++ assert((!pthread_mutex_lock(&data_data_mutex)) && "Update"); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); +@@ -416,4 +625,32 @@ + } + + previous_frame = this_frame; ++ ++ int err; ++ err = pthread_mutex_trylock(&collisions_mutex); ++ switch (err) ++ { ++ case 0: ++ if (collisions_count) ++ process_collisions(); ++ ++ assert((!pthread_cond_broadcast(&data_data_cond)) && "Update"); ++ assert((!pthread_mutex_unlock(&collisions_mutex)) && "Update"); ++ ++ break; ++ case EBUSY: ++ break; ++ default: ++ assert((!err) && "pthread_mutex_trylock(&collisions_mutex): Update"); ++ } ++ ++ assert((!pthread_mutex_unlock(&data_data_mutex)) && "Update"); ++} ++ ++void data_exit() ++{ ++ assert((!pthread_mutex_lock(&collisions_mutex)) && "Exit"); ++ assert((!pthread_cond_broadcast(&data_data_cond)) && "Exit"); ++ assert((!pthread_mutex_unlock(&collisions_mutex)) && "Exit"); ++ assert(!pthread_join(while_rendering_0, NULL)); + } +diff -bNur 0009modify-instances-count/Makefile 0010tasks-during-render/Makefile +--- 0009modify-instances-count/Makefile 2019-03-02 19:55:02.569358313 -0600 ++++ 0010tasks-during-render/Makefile 2019-03-02 19:55:02.569358313 -0600 +@@ -8,7 +8,7 @@ + include ../misc-targets.mk + + DEPENDS = libdata.so +-vulkan: $(MYLDLIBS) $(DEPENDS) ++vulkan: -lpthread $(MYLDLIBS) $(DEPENDS) + LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv + data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h + LIBDEPENDS = data_bulk.o data_dynamic.o +diff -bNur 0009modify-instances-count/vulkan.c 0010tasks-during-render/vulkan.c +--- 0009modify-instances-count/vulkan.c 2019-03-03 15:08:03.352969091 -0600 ++++ 0010tasks-during-render/vulkan.c 2019-03-03 15:08:12.034593587 -0600 +@@ -1629,6 +1629,8 @@ + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + ++ data_exit(); ++ + glfwDestroyWindow(data_window); + + glfwTerminate(); diff --git a/0010tasks-during-render/.gitignore b/0010tasks-during-render/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0010tasks-during-render/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0010tasks-during-render/0_frag.glsl b/0010tasks-during-render/0_frag.glsl new file mode 100644 index 0000000..b877549 --- /dev/null +++ b/0010tasks-during-render/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0010tasks-during-render/0_vert.glsl b/0010tasks-during-render/0_vert.glsl new file mode 100644 index 0000000..f8339a6 --- /dev/null +++ b/0010tasks-during-render/0_vert.glsl @@ -0,0 +1,54 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; +} ubo; + +layout (binding = 2) uniform SUBO +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} subo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = subo.lightPos - pos.xyz; + outViewVec = subo.viewPos - pos.xyz; +} diff --git a/0010tasks-during-render/Makefile b/0010tasks-during-render/Makefile new file mode 100644 index 0000000..47acdd4 --- /dev/null +++ b/0010tasks-during-render/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: -lpthread $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0010tasks-during-render/data.h b/0010tasks-during-render/data.h new file mode 100644 index 0000000..1bf4e4f --- /dev/null +++ b/0010tasks-during-render/data.h @@ -0,0 +1,100 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); +void data_exit(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +extern struct shared_ubo *data_model_shared_ubo; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; + float radius; +} data_model_t; +extern data_model_t data_models[]; + +typedef struct data_model_instance +{ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void *closure; + struct list_head list; + void *ubo; + struct list_head *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; +extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; +extern const size_t data_material_shaders_count; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; +extern const size_t data_materials_count; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +#define SHARED_UNIFORM_SIZE (4096 * 32) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; + +#endif diff --git a/0010tasks-during-render/data_bulk.c b/0010tasks-during-render/data_bulk.c new file mode 100644 index 0000000..bed3bec --- /dev/null +++ b/0010tasks-during-render/data_bulk.c @@ -0,0 +1,2901 @@ +#include "data_bulk.h" +#include +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + 0.5f, + }, + { + "Bullet", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, + 0.5f, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, + { + "Other Example", + 1, + sizeof(material_1_ubo_t), + get_model_1, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; +const size_t data_materials_count = + sizeof(data_materials) / sizeof(data_materials[0]); +const uint32_t material_shader_1_vert_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 183, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 983055, + 0, + 4, + 1852399981, + 0, + 21, + 30, + 103, + 105, + 109, + 123, + 144, + 166, + 169, + 176, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 393221, + 10, + 1701736290, + 1851880020, + 1919903347, + 109, + 196613, + 14, + 5194325, + 327686, + 14, + 0, + 1701080941, + 108, + 327686, + 14, + 1, + 1701736290, + 115, + 196613, + 16, + 7299701, + 327685, + 21, + 1866624617, + 1145660782, + 115, + 393221, + 30, + 1866624617, + 1700226414, + 1952999273, + 115, + 262149, + 103, + 1433695599, + 86, + 262149, + 105, + 1448439401, + 0, + 393221, + 107, + 1348430951, + 1700164197, + 2019914866, + 0, + 393222, + 107, + 0, + 1348430951, + 1953067887, + 7237481, + 196613, + 109, + 0, + 262149, + 112, + 1329747283, + 0, + 262150, + 112, + 0, + 28790, + 393222, + 112, + 1, + 1751607660, + 1936674932, + 0, + 327686, + 112, + 2, + 1633968496, + 0, + 327686, + 112, + 3, + 2003134838, + 7565136, + 327686, + 112, + 4, + 1650745712, + 0, + 262149, + 114, + 1868723571, + 0, + 262149, + 123, + 1867542121, + 115, + 196613, + 134, + 7565168, + 327685, + 144, + 1316255087, + 1634562671, + 108, + 327685, + 166, + 1867411049, + 1818324338, + 0, + 327685, + 169, + 1282700655, + 1952999273, + 6514006, + 327685, + 176, + 1450472815, + 1450665321, + 25445, + 262215, + 13, + 6, + 64, + 262216, + 14, + 0, + 5, + 327752, + 14, + 0, + 35, + 0, + 327752, + 14, + 0, + 7, + 16, + 262216, + 14, + 1, + 5, + 327752, + 14, + 1, + 35, + 64, + 327752, + 14, + 1, + 7, + 16, + 196679, + 14, + 2, + 262215, + 16, + 34, + 0, + 262215, + 16, + 33, + 0, + 262215, + 21, + 30, + 4, + 262215, + 30, + 30, + 3, + 262215, + 103, + 30, + 0, + 262215, + 105, + 30, + 2, + 327752, + 107, + 0, + 11, + 0, + 196679, + 107, + 2, + 262216, + 112, + 0, + 5, + 327752, + 112, + 0, + 35, + 0, + 327752, + 112, + 0, + 7, + 16, + 327752, + 112, + 1, + 35, + 64, + 327752, + 112, + 2, + 35, + 76, + 327752, + 112, + 3, + 35, + 80, + 327752, + 112, + 4, + 35, + 92, + 196679, + 112, + 2, + 262215, + 114, + 34, + 0, + 262215, + 114, + 33, + 2, + 262215, + 123, + 30, + 0, + 262215, + 144, + 30, + 1, + 262215, + 166, + 30, + 1, + 262215, + 169, + 30, + 3, + 262215, + 176, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262168, + 8, + 7, + 4, + 262176, + 9, + 7, + 8, + 262165, + 11, + 32, + 0, + 262187, + 11, + 12, + 64, + 262172, + 13, + 8, + 12, + 262174, + 14, + 8, + 13, + 262176, + 15, + 2, + 14, + 262203, + 15, + 16, + 2, + 262165, + 17, + 32, + 1, + 262187, + 17, + 18, + 1, + 262167, + 19, + 17, + 4, + 262176, + 20, + 1, + 19, + 262203, + 20, + 21, + 1, + 262187, + 11, + 22, + 0, + 262176, + 23, + 1, + 17, + 262176, + 26, + 2, + 8, + 262176, + 29, + 1, + 7, + 262203, + 29, + 30, + 1, + 262176, + 31, + 1, + 6, + 262187, + 11, + 35, + 1, + 262187, + 11, + 57, + 2, + 262187, + 11, + 79, + 3, + 262167, + 101, + 6, + 2, + 262176, + 102, + 3, + 101, + 262203, + 102, + 103, + 3, + 262176, + 104, + 1, + 101, + 262203, + 104, + 105, + 1, + 196638, + 107, + 7, + 262176, + 108, + 3, + 107, + 262203, + 108, + 109, + 3, + 262187, + 17, + 110, + 0, + 262167, + 111, + 6, + 3, + 458782, + 112, + 8, + 111, + 6, + 111, + 6, + 262176, + 113, + 2, + 112, + 262203, + 113, + 114, + 2, + 262176, + 122, + 1, + 111, + 262203, + 122, + 123, + 1, + 262187, + 6, + 125, + 1065353216, + 262176, + 131, + 3, + 7, + 262176, + 133, + 7, + 7, + 262176, + 143, + 3, + 111, + 262203, + 143, + 144, + 3, + 262168, + 151, + 111, + 3, + 262187, + 6, + 152, + 0, + 262203, + 122, + 166, + 1, + 262203, + 143, + 169, + 3, + 262176, + 170, + 2, + 111, + 262203, + 143, + 176, + 3, + 262187, + 17, + 177, + 3, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 9, + 10, + 7, + 262203, + 133, + 134, + 7, + 327745, + 23, + 24, + 21, + 22, + 262205, + 17, + 25, + 24, + 393281, + 26, + 27, + 16, + 18, + 25, + 262205, + 8, + 28, + 27, + 327745, + 31, + 32, + 30, + 22, + 262205, + 6, + 33, + 32, + 327823, + 8, + 34, + 28, + 33, + 196670, + 10, + 34, + 327745, + 23, + 36, + 21, + 35, + 262205, + 17, + 37, + 36, + 393281, + 26, + 38, + 16, + 18, + 37, + 262205, + 8, + 39, + 38, + 327745, + 31, + 40, + 30, + 35, + 262205, + 6, + 41, + 40, + 327823, + 8, + 42, + 39, + 41, + 262205, + 8, + 43, + 10, + 327761, + 7, + 44, + 43, + 0, + 327761, + 7, + 45, + 42, + 0, + 327809, + 7, + 46, + 44, + 45, + 327761, + 7, + 47, + 43, + 1, + 327761, + 7, + 48, + 42, + 1, + 327809, + 7, + 49, + 47, + 48, + 327761, + 7, + 50, + 43, + 2, + 327761, + 7, + 51, + 42, + 2, + 327809, + 7, + 52, + 50, + 51, + 327761, + 7, + 53, + 43, + 3, + 327761, + 7, + 54, + 42, + 3, + 327809, + 7, + 55, + 53, + 54, + 458832, + 8, + 56, + 46, + 49, + 52, + 55, + 196670, + 10, + 56, + 327745, + 23, + 58, + 21, + 57, + 262205, + 17, + 59, + 58, + 393281, + 26, + 60, + 16, + 18, + 59, + 262205, + 8, + 61, + 60, + 327745, + 31, + 62, + 30, + 57, + 262205, + 6, + 63, + 62, + 327823, + 8, + 64, + 61, + 63, + 262205, + 8, + 65, + 10, + 327761, + 7, + 66, + 65, + 0, + 327761, + 7, + 67, + 64, + 0, + 327809, + 7, + 68, + 66, + 67, + 327761, + 7, + 69, + 65, + 1, + 327761, + 7, + 70, + 64, + 1, + 327809, + 7, + 71, + 69, + 70, + 327761, + 7, + 72, + 65, + 2, + 327761, + 7, + 73, + 64, + 2, + 327809, + 7, + 74, + 72, + 73, + 327761, + 7, + 75, + 65, + 3, + 327761, + 7, + 76, + 64, + 3, + 327809, + 7, + 77, + 75, + 76, + 458832, + 8, + 78, + 68, + 71, + 74, + 77, + 196670, + 10, + 78, + 327745, + 23, + 80, + 21, + 79, + 262205, + 17, + 81, + 80, + 393281, + 26, + 82, + 16, + 18, + 81, + 262205, + 8, + 83, + 82, + 327745, + 31, + 84, + 30, + 79, + 262205, + 6, + 85, + 84, + 327823, + 8, + 86, + 83, + 85, + 262205, + 8, + 87, + 10, + 327761, + 7, + 88, + 87, + 0, + 327761, + 7, + 89, + 86, + 0, + 327809, + 7, + 90, + 88, + 89, + 327761, + 7, + 91, + 87, + 1, + 327761, + 7, + 92, + 86, + 1, + 327809, + 7, + 93, + 91, + 92, + 327761, + 7, + 94, + 87, + 2, + 327761, + 7, + 95, + 86, + 2, + 327809, + 7, + 96, + 94, + 95, + 327761, + 7, + 97, + 87, + 3, + 327761, + 7, + 98, + 86, + 3, + 327809, + 7, + 99, + 97, + 98, + 458832, + 8, + 100, + 90, + 93, + 96, + 99, + 196670, + 10, + 100, + 262205, + 101, + 106, + 105, + 196670, + 103, + 106, + 327745, + 26, + 115, + 114, + 110, + 262205, + 8, + 116, + 115, + 327745, + 26, + 117, + 16, + 110, + 262205, + 8, + 118, + 117, + 327826, + 8, + 119, + 116, + 118, + 262205, + 8, + 120, + 10, + 327826, + 8, + 121, + 119, + 120, + 262205, + 111, + 124, + 123, + 327761, + 6, + 126, + 124, + 0, + 327761, + 6, + 127, + 124, + 1, + 327761, + 6, + 128, + 124, + 2, + 458832, + 7, + 129, + 126, + 127, + 128, + 125, + 327825, + 7, + 130, + 121, + 129, + 327745, + 131, + 132, + 109, + 110, + 196670, + 132, + 130, + 327745, + 26, + 135, + 16, + 110, + 262205, + 8, + 136, + 135, + 262205, + 111, + 137, + 123, + 327761, + 6, + 138, + 137, + 0, + 327761, + 6, + 139, + 137, + 1, + 327761, + 6, + 140, + 137, + 2, + 458832, + 7, + 141, + 138, + 139, + 140, + 125, + 327825, + 7, + 142, + 136, + 141, + 196670, + 134, + 142, + 327745, + 26, + 145, + 16, + 110, + 262205, + 8, + 146, + 145, + 262205, + 8, + 147, + 10, + 327826, + 8, + 148, + 146, + 147, + 262228, + 8, + 149, + 148, + 393228, + 8, + 150, + 1, + 34, + 149, + 393297, + 6, + 153, + 150, + 0, + 0, + 393297, + 6, + 154, + 150, + 0, + 1, + 393297, + 6, + 155, + 150, + 0, + 2, + 393297, + 6, + 156, + 150, + 1, + 0, + 393297, + 6, + 157, + 150, + 1, + 1, + 393297, + 6, + 158, + 150, + 1, + 2, + 393297, + 6, + 159, + 150, + 2, + 0, + 393297, + 6, + 160, + 150, + 2, + 1, + 393297, + 6, + 161, + 150, + 2, + 2, + 393296, + 111, + 162, + 153, + 154, + 155, + 393296, + 111, + 163, + 156, + 157, + 158, + 393296, + 111, + 164, + 159, + 160, + 161, + 393296, + 151, + 165, + 162, + 163, + 164, + 262205, + 111, + 167, + 166, + 327825, + 111, + 168, + 165, + 167, + 196670, + 144, + 168, + 327745, + 170, + 171, + 114, + 18, + 262205, + 111, + 172, + 171, + 262205, + 7, + 173, + 134, + 524367, + 111, + 174, + 173, + 173, + 0, + 1, + 2, + 327811, + 111, + 175, + 172, + 174, + 196670, + 169, + 175, + 327745, + 170, + 178, + 114, + 177, + 262205, + 111, + 179, + 178, + 262205, + 7, + 180, + 134, + 524367, + 111, + 181, + 180, + 180, + 0, + 1, + 2, + 327811, + 111, + 182, + 179, + 181, + 196670, + 176, + 182, + 65789, + 65592, +}; + +const uint32_t material_shader_1_frag_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 71, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 655375, + 4, + 4, + 1852399981, + 0, + 17, + 24, + 53, + 69, + 70, + 196624, + 4, + 7, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 262149, + 9, + 1869377379, + 114, + 393221, + 13, + 1886216563, + 1131570540, + 1919904879, + 7364941, + 262149, + 17, + 1448439401, + 0, + 262149, + 21, + 1953720676, + 7500115, + 327685, + 24, + 1766616681, + 1450469479, + 25445, + 262149, + 29, + 1667585644, + 0, + 262149, + 34, + 1702130785, + 110, + 327685, + 44, + 1886351972, + 1684105331, + 30575, + 393221, + 53, + 1182037359, + 1130848626, + 1919904879, + 0, + 327685, + 69, + 1867411049, + 1818324338, + 0, + 327685, + 70, + 1767272041, + 1700165477, + 99, + 262215, + 13, + 34, + 0, + 262215, + 13, + 33, + 1, + 262215, + 17, + 30, + 0, + 262215, + 24, + 30, + 3, + 262215, + 53, + 30, + 0, + 262215, + 69, + 30, + 1, + 262215, + 70, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262176, + 8, + 7, + 7, + 589849, + 10, + 6, + 1, + 0, + 0, + 0, + 1, + 0, + 196635, + 11, + 10, + 262176, + 12, + 0, + 11, + 262203, + 12, + 13, + 0, + 262167, + 15, + 6, + 2, + 262176, + 16, + 1, + 15, + 262203, + 16, + 17, + 1, + 262176, + 20, + 7, + 6, + 262167, + 22, + 6, + 3, + 262176, + 23, + 1, + 22, + 262203, + 23, + 24, + 1, + 262176, + 28, + 7, + 22, + 262187, + 6, + 35, + 1065353216, + 262187, + 6, + 36, + 961656599, + 262187, + 6, + 41, + 0, + 262187, + 6, + 45, + 998445679, + 262176, + 52, + 3, + 7, + 262203, + 52, + 53, + 3, + 262203, + 23, + 69, + 1, + 262203, + 23, + 70, + 1, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 8, + 9, + 7, + 262203, + 20, + 21, + 7, + 262203, + 28, + 29, + 7, + 262203, + 20, + 34, + 7, + 262203, + 20, + 44, + 7, + 262205, + 11, + 14, + 13, + 262205, + 15, + 18, + 17, + 327767, + 7, + 19, + 14, + 18, + 196670, + 9, + 19, + 262205, + 22, + 25, + 24, + 262205, + 22, + 26, + 24, + 327828, + 6, + 27, + 25, + 26, + 196670, + 21, + 27, + 262205, + 22, + 30, + 24, + 262205, + 6, + 31, + 21, + 393228, + 6, + 32, + 1, + 32, + 31, + 327822, + 22, + 33, + 30, + 32, + 196670, + 29, + 33, + 262205, + 6, + 37, + 21, + 393228, + 6, + 38, + 1, + 31, + 37, + 327813, + 6, + 39, + 36, + 38, + 327811, + 6, + 40, + 35, + 39, + 524300, + 6, + 42, + 1, + 43, + 40, + 41, + 35, + 458764, + 6, + 43, + 1, + 40, + 42, + 41, + 196670, + 34, + 43, + 262205, + 6, + 46, + 21, + 393228, + 6, + 47, + 1, + 31, + 46, + 327813, + 6, + 48, + 45, + 47, + 327811, + 6, + 49, + 35, + 48, + 524300, + 6, + 50, + 1, + 43, + 49, + 41, + 35, + 458764, + 6, + 51, + 1, + 40, + 50, + 41, + 196670, + 44, + 51, + 262205, + 7, + 54, + 9, + 262205, + 6, + 55, + 44, + 327811, + 6, + 56, + 35, + 55, + 327822, + 7, + 57, + 54, + 56, + 327761, + 6, + 58, + 57, + 0, + 327761, + 6, + 59, + 57, + 1, + 327761, + 6, + 60, + 57, + 2, + 327761, + 6, + 61, + 57, + 3, + 458832, + 7, + 62, + 58, + 59, + 60, + 61, + 196670, + 53, + 62, + 262205, + 6, + 63, + 34, + 262205, + 7, + 64, + 53, + 524367, + 22, + 65, + 64, + 64, + 0, + 1, + 2, + 327822, + 22, + 66, + 65, + 63, + 262205, + 7, + 67, + 53, + 589903, + 7, + 68, + 67, + 66, + 4, + 5, + 6, + 3, + 196670, + 53, + 68, + 65789, + 65592, +}; +const size_t material_shader_1_vert_size = sizeof(material_shader_1_vert_spv); +const size_t material_shader_1_frag_size = sizeof(material_shader_1_frag_spv); diff --git a/0010tasks-during-render/data_bulk.h b/0010tasks-during-render/data_bulk.h new file mode 100644 index 0000000..ed7d5a4 --- /dev/null +++ b/0010tasks-during-render/data_bulk.h @@ -0,0 +1,17 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_0_ubo_t; + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_1_ubo_t; diff --git a/0010tasks-during-render/data_dynamic.c.in b/0010tasks-during-render/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0010tasks-during-render/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0010tasks-during-render/libdata.c b/0010tasks-during-render/libdata.c new file mode 100644 index 0000000..89a3adf --- /dev/null +++ b/0010tasks-during-render/libdata.c @@ -0,0 +1,656 @@ +#include "data_bulk.h" +#include +#include +#include +#include +#include +#include +#include + +inline static void player_shoot(); + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + if (action == GLFW_PRESS) + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + case GLFW_KEY_X: + player_shoot(); + break; + } +} + +typedef struct shared_ubo +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} shared_ubo_t; + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const uint8_t material_shader_1_vert_spv[1]; +const size_t material_shader_1_vert_size; +const uint8_t material_shader_1_frag_spv[1]; +const size_t material_shader_1_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, + {{ + material_shader_1_vert_spv, + &material_shader_1_vert_size, + }, + { + material_shader_1_frag_spv, + &material_shader_1_frag_size, + }}, +}; +const size_t data_material_shaders_count = + sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + +typedef struct +{ + float mass; + float speed; + bool solid; +} instance_closure_t; + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, ((instance_closure_t *)ptr->closure)->speed * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +inline static void setup_model_instance(data_model_instance_t *inst); +#define SUBO data_model_shared_ubo +struct shared_ubo *SUBO = NULL; +pthread_mutex_t data_data_mutex = PTHREAD_MUTEX_INITIALIZER; +inline static void player_shoot() +{ + static const instance_closure_t bullet_closure = { + 0.02f, + 3.0f, + true, + }; + + data_model_instance_t *this_instance = NULL, + bullet_instance = { + "Bullet Object", + 1, + shoot_forward, + &bullet_closure, + {NULL, NULL}, + NULL, + VK_NULL_HANDLE, + }; + + this_instance = malloc(sizeof(bullet_instance)); + assert(this_instance && "Out of memory."); + *this_instance = bullet_instance; + setup_model_instance(this_instance); + + { + material_1_ubo_t *this_ubo = this_instance->ubo; + { + static const material_1_ubo_t empty_data_material_ubo_s; + *this_ubo = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, this_ubo->bones[0]); + + { + mat4 trans0; + glm_translate_to(GLM_MAT4_IDENTITY, SUBO->viewPos, trans0); + glm_rotate_y(trans0, center_dir, this_ubo->model); + glm_translate_z(this_ubo->model, 1.25f); + } + } + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Player Shoot"); + list_add_tail(&this_instance->list, &data_model_instances); + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Player Shoot"); +} + +typedef struct +{ + data_model_instance_t obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + &(instance_closure_t){ + 1.0f, + 0.0f, + true, + }, + {&(data_model_instances), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +bool intersect(vec3 amin, vec3 amax, vec3 bmin, vec3 bmax) +{ + return (amin[0] <= bmax[0] && amax[0] >= bmin[0]) && + (amin[1] <= bmax[1] && amax[1] >= bmin[1]) && + (amin[2] <= bmax[2] && amax[2] >= bmin[2]); +} + +pthread_t while_rendering_0; +pthread_cond_t data_data_cond = PTHREAD_COND_INITIALIZER; +#define MAX_COLLISIONS (64 * 64) +typedef struct +{ + data_model_instance_t *x, *y; +} collision_t; +collision_t collisions[MAX_COLLISIONS]; +size_t collisions_count = 0; +pthread_mutex_t collisions_mutex = PTHREAD_MUTEX_INITIALIZER; +void *while_rendering_0_func(void *vargp) +{ + while (!glfwWindowShouldClose(data_window)) + { + + assert((!pthread_mutex_lock(&data_data_mutex)) && "While Rendering 0"); + pthread_cond_wait(&data_data_cond, &data_data_mutex); + + size_t instance_count = 0; + struct list_head *ptr; + list_for_each(ptr, &data_model_instances) instance_count++; + { + struct + { + data_model_instance_t *id; + mat4 model; + float radius; + vec4 pos; + vec3 pos_high; + vec3 pos_low; + } _data[instance_count]; + + { + size_t i = 0; + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + if (!((instance_closure_t *)ptr->closure)->solid) + { + --instance_count; + continue; + } + _data[i].id = ptr; + glm_mat4_copy( + *(data_materials[data_models[ptr->model].material].get_model( + ptr->ubo)), + _data[i].model); + _data[i++].radius = data_models[ptr->model].radius; + } + } + + assert((!pthread_mutex_unlock(&data_data_mutex)) && "While Rendering 0"); + + for (size_t i = 0; i < instance_count; i++) + { + glm_mat4_mulv(_data[i].model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, + _data[i].pos); + for (size_t a = 0; a < 3; a++) + { + _data[i].pos_high[a] = _data[i].pos[a] + _data[i].radius; + _data[i].pos_low[a] = _data[i].pos[a] - _data[i].radius; + } + } + + assert((!pthread_mutex_lock(&collisions_mutex)) && "While Rendering 0"); + + collisions_count = 0; + + for (size_t x = 0; x < instance_count; x++) + { + if (x + 1 < instance_count) + { + for (size_t y = x + 1; y < instance_count; y++) + { + if (intersect(_data[x].pos_low, _data[x].pos_high, _data[y].pos_low, + _data[y].pos_high)) + { + if (glm_vec_distance(_data[x].pos, _data[y].pos) - + _data[x].radius - _data[y].radius < + 0) + { + assert((++collisions_count < MAX_COLLISIONS) && + "Overflow collisions"); + collisions[collisions_count - 1] = + (collision_t){_data[x].id, _data[y].id}; + } + } + } + } + } + } + assert((!pthread_mutex_unlock(&collisions_mutex)) && "While Rendering 0"); + } + return (NULL); +} + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + struct list_head **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = &this_map->list; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = &this_map->list; + } +} + +void (*data_setup_model_instance)(data_model_instance_t *inst); +uintptr_t data_uniform_ptr = 0; +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = &map->list; + data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, + uniform_map_t, list) + ->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp() +{ + glm_lookat(SUBO->viewPos, + (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], + SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, SUBO->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = list_entry(data_model_instances.next, data_model_instance_t, list); + setup_model_instance(inst); + ubo_0 = inst->ubo; + + assert( + !pthread_create(&while_rendering_0, NULL, while_rendering_0_func, NULL)); + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + static const shared_ubo_t empty_shared_ubo_s; + *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + SUBO->lightPos[0] = 0.0f; + SUBO->lightPos[1] = 250.0f; + SUBO->lightPos[2] = -250.0f; + SUBO->viewPos[0] = 0.0f; + SUBO->viewPos[1] = 0.0f; + SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(); + + previous_frame = glfwGetTime(); + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Init"); + assert((!pthread_cond_broadcast(&data_data_cond)) && "Init"); + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Init"); +} + +inline static void handle_input(double this_frame) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 rot0, rot1, trans0; + glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +inline static void process_collisions() +{ + for (size_t i = 0; i < collisions_count; i++) + { + data_model_instance_t *ids[2]; + vec3 pos[2], zrot[2]; + float zop[2], zadj[2]; + mat4 *model[2]; + ids[0] = collisions[i].x; + ids[1] = collisions[i].y; + for (size_t a = 0; a < 2; a++) + { + /* TODO: Skip no-longer available objects */ + model[a] = data_materials[data_models[ids[a]->model].material].get_model( + ids[a]->ubo); + _glm_decompose(*model[a], pos[a], NULL, zrot[a], &zop[a], &zadj[a]); + } + { + vec3 N /* Collision */, add0[2] /* overlapping points */; + glm_vec_sub(pos[0], pos[1], N); + for (size_t a = 0; a < 2; a++) + { + vec3 scale0; + float table[] = { + -data_models[ids[a]->model].radius, + data_models[ids[a]->model].radius, + }; + glm_vec_scale_as(N, table[a], scale0); + glm_vec_add(scale0, pos[a], add0[a]); + } + vec3 sub1 /* overlapping influence */; + glm_vec_sub(add0[0], add0[1], sub1); + { +#define MASS(x) ((instance_closure_t *)ids[x]->closure)->mass +#define SPEED(x) ((instance_closure_t *)ids[x]->closure)->speed + vec3 scale0, scale1, add0[2]; + float div0 = 1 / (MASS(0) + MASS(1)); + glm_vec_scale(zrot[0], SPEED(0) * (MASS(0) - MASS(1)), scale0); + glm_vec_scale(zrot[1], SPEED(1) * 2 * MASS(1), scale1); + glm_vec_add(scale0, scale1, add0[0]); + glm_vec_scale(zrot[1], SPEED(1) * (MASS(1) - MASS(0)), scale0); + glm_vec_scale(zrot[0], SPEED(0) * 2 * MASS(0), scale1); + glm_vec_scale(add0[0], div0, zrot[0]); + glm_vec_add(scale0, scale1, add0[1]); + glm_vec_scale(add0[1], div0, zrot[1]); + } + for (size_t a = 0; a < 2; a++) + { + vec3 scale1, add1, rot; + float table[] = { + -1.2f * MASS(0) / (MASS(0) + MASS(1)), + 1.2f * MASS(1) / (MASS(0) + MASS(1)), + }; +#undef MASS +#undef SPEED + glm_vec_scale(sub1, table[a], scale1); + glm_vec_add(scale1, pos[a], add1); + glm_vec_copy(add1, pos[a]); + + _glm_atan3(zrot[a], zop[a], zadj[a], rot); + + { + mat4 trans0, rot0, rot1, rot2; + glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot2); + glm_translate_make(trans0, pos[a]); + glm_mat4_mul(trans0, rot2, *model[a]); + } + } + } + } + collisions_count = 0; +} + +void data_update() +{ + double this_frame = glfwGetTime(); + + handle_input(this_frame); + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Update"); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; + + int err; + err = pthread_mutex_trylock(&collisions_mutex); + switch (err) + { + case 0: + if (collisions_count) + process_collisions(); + + assert((!pthread_cond_broadcast(&data_data_cond)) && "Update"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Update"); + + break; + case EBUSY: + break; + default: + assert((!err) && "pthread_mutex_trylock(&collisions_mutex): Update"); + } + + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Update"); +} + +void data_exit() +{ + assert((!pthread_mutex_lock(&collisions_mutex)) && "Exit"); + assert((!pthread_cond_broadcast(&data_data_cond)) && "Exit"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Exit"); + assert(!pthread_join(while_rendering_0, NULL)); +} diff --git a/0010tasks-during-render/vulkan.c b/0010tasks-during-render/vulkan.c new file mode 100644 index 0000000..18b50dc --- /dev/null +++ b/0010tasks-during-render/vulkan.c @@ -0,0 +1,1684 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, + UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); + data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[2] = set_layout_bindings[0]; + set_layout_bindings[2].binding = 2; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map, size_t material) +{ + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + uniform_descriptors[1] = uniform_descriptors[0]; + uniform_descriptors[1].offset = UNIFORM_SIZE; + uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; + + VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + + write_descriptor_sets[2] = write_descriptor_sets[0]; + write_descriptor_sets[2].dstBinding = 2; + write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageView = texture_image_views[material]; + image_info.sampler = texture_image_sampler; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(data_model_instance_t *inst) +{ + uniform_map_t *this_map; + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); + update_descriptor_set(this_map, data_models[inst->model].material); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_create_info.format = data_materials[i].texture_format; + image_create_info.extent.width = data_materials[i].texture_width; + image_create_info.extent.height = data_materials[i].texture_height; + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[i]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); + } +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + for (size_t i = 0; i < data_materials_count; i++) + { + allocate_texture_image(texture_images[i], gpu_memory_properties, + &texture_image_memorys[i]); + + void *data; + vkMapMemory(device, texture_image_memorys[i], 0, + data_materials[i].texture_size, 0, &data); + memcpy(data, data_materials[i].texture, data_materials[i].texture_size); + vkUnmapMemory(device, texture_image_memorys[i]); + } +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_view_create_info.image = texture_images[i]; + image_view_create_info.format = data_materials[i].texture_format; + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); + } +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_module_create_info.codeSize = *data_material_shaders[i].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[i].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); + } +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_stages_create_info[0].module = vert_modules[i]; + shader_stages_create_info[1].module = frag_modules[i]; + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[i]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); + } +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + size_t bound_shaders = SIZE_MAX; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + { + if (bound_shaders != + data_materials[data_models[inst->model].material].shader) + { + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + bound_shaders = data_materials[data_models[inst->model].material].shader; + } + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &list_entry(inst->uniform_map, uniform_map_t, list) + ->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + for (size_t i = 0; i < data_material_shaders_count; i++) + { + vkDestroyPipeline(device, graphics_pipelines[i], NULL); + graphics_pipelines[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[i], NULL); + frag_modules[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[i], NULL); + vert_modules[i] = VK_NULL_HANDLE; + } + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + for (size_t i = 0; i < data_materials_count; i++) + { + vkDestroyImageView(device, texture_image_views[i], NULL); + texture_image_views[i] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[i], NULL); + texture_image_memorys[i] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[i], NULL); + texture_images[i] = VK_NULL_HANDLE; + } + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = + VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + data_exit(); + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[data_materials_count]; + VkDeviceMemory texture_image_memorys[data_materials_count]; + VkImageView _texture_image_views[data_materials_count]; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[data_material_shaders_count]; + VkShaderModule frag_modules[data_material_shaders_count]; + VkPipeline graphics_pipelines[data_material_shaders_count]; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0011disappearing-instances.diff b/0011disappearing-instances.diff new file mode 100644 index 0000000..4fdcf68 --- /dev/null +++ b/0011disappearing-instances.diff @@ -0,0 +1,214 @@ +diff -bNur 0010tasks-during-render/data_bulk.c 0011disappearing-instances/data_bulk.c +--- 0010tasks-during-render/data_bulk.c 2019-03-02 20:06:22.829346100 -0600 ++++ 0011disappearing-instances/data_bulk.c 2019-03-02 20:06:22.833346287 -0600 +@@ -278,6 +278,10 @@ + + mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } + ++mat4 *get_bones_0(void *p) { return &((material_0_ubo_t *)p)->bones[0]; } ++ ++mat4 *get_bones_1(void *p) { return &((material_1_ubo_t *)p)->bones[0]; } ++ + #define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ +@@ -325,6 +329,7 @@ + 0, + sizeof(material_0_ubo_t), + get_model_0, ++ get_bones_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, +@@ -778,6 +783,7 @@ + 1, + sizeof(material_1_ubo_t), + get_model_1, ++ get_bones_1, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, +diff -bNur 0010tasks-during-render/data.h 0011disappearing-instances/data.h +--- 0010tasks-during-render/data.h 2019-03-02 19:55:02.569358313 -0600 ++++ 0011disappearing-instances/data.h 2019-03-02 19:55:02.573358415 -0600 +@@ -49,6 +49,7 @@ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); ++ void (*collision)(struct data_model_instance *, struct data_model_instance *); + void *closure; + struct list_head list; + void *ubo; +@@ -74,6 +75,7 @@ + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); ++ mat4 *(*get_bones)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; +diff -bNur 0010tasks-during-render/libdata.c 0011disappearing-instances/libdata.c +--- 0010tasks-during-render/libdata.c 2019-03-02 20:06:22.829346100 -0600 ++++ 0011disappearing-instances/libdata.c 2019-03-02 20:06:22.833346287 -0600 +@@ -9,6 +9,16 @@ + + inline static void player_shoot(); + ++struct ++{ ++ unsigned char forward; ++ unsigned char backward; ++ unsigned char turn_l; ++ unsigned char turn_r; ++ unsigned char climb_up; ++ unsigned char climb_down; ++} keys_count = {false, false, false, false, false, false}; ++ + void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) + { +@@ -71,6 +81,8 @@ + float mass; + float speed; + bool solid; ++ size_t hp; ++ float scale_left; + } instance_closure_t; + + void shoot_forward(data_model_instance_t *ptr, double t) +@@ -83,6 +95,37 @@ + glm_mat4_copy(rot0, *model); + } + ++void shrink_forward(data_model_instance_t *ptr, double t) ++{ ++ mat4 *bones = ++ data_materials[data_models[ptr->model].material].get_bones(ptr->ubo); ++ float *scale_left = &((instance_closure_t *)ptr->closure)->scale_left; ++ shoot_forward(ptr, t); ++ if (*scale_left == 0.0f) ++ *scale_left = 1.0f; ++ *scale_left -= t / 3.0f; ++ if (*scale_left <= 0.0f) ++ { ++ ptr->update = NULL; ++ *scale_left = 0.0f; ++ glm_scale1(bones[0], 0); ++ } ++ else ++ glm_scale1(bones[0], (*scale_left - t / 3.0f) / *scale_left); ++} ++ ++void reduce_hp_shrink(data_model_instance_t *a, data_model_instance_t *b) ++{ ++ assert(((instance_closure_t *)a->closure)->hp && ++ "Shouldn't have called collision()."); ++ if (--((instance_closure_t *)a->closure)->hp == 0) ++ { ++ ((instance_closure_t *)a->closure)->solid = false; ++ a->collision = NULL; ++ a->update = &shrink_forward; ++ } ++} ++ + inline static void setup_model_instance(data_model_instance_t *inst); + #define SUBO data_model_shared_ubo + struct shared_ubo *SUBO = NULL; +@@ -91,8 +134,10 @@ + { + static const instance_closure_t bullet_closure = { + 0.02f, +- 3.0f, ++ 1.0f, + true, ++ 3, ++ 0.0f, + }; + + data_model_instance_t *this_instance = NULL, +@@ -100,7 +145,8 @@ + "Bullet Object", + 1, + shoot_forward, +- &bullet_closure, ++ reduce_hp_shrink, ++ NULL, + {NULL, NULL}, + NULL, + VK_NULL_HANDLE, +@@ -109,6 +155,9 @@ + this_instance = malloc(sizeof(bullet_instance)); + assert(this_instance && "Out of memory."); + *this_instance = bullet_instance; ++ this_instance->closure = malloc(sizeof(bullet_closure)); ++ assert(this_instance->closure && "Out of memory."); ++ *((instance_closure_t *)this_instance->closure) = bullet_closure; + setup_model_instance(this_instance); + + { +@@ -144,10 +193,13 @@ + "Object", + 0, + NULL, ++ reduce_hp_shrink, + &(instance_closure_t){ + 1.0f, + 0.0f, + true, ++ 5, ++ 0.0f, + }, + {&(data_model_instances), &(data_model_instances)}, + NULL, +@@ -422,7 +474,7 @@ + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); +- if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) ++ if ((!keys_count.climb_up) ^ !keys_count.climb_down) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; +@@ -519,8 +571,13 @@ + } + if (new_model) + { +- mat4 rot0, rot1, trans0; +- glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); ++ mat4 scale0, trans0, rot0, rot1; ++#define SCALE ((instance_closure_t *)ptr->closure)->scale_left ++#define VALUE SCALE == 0.0f ? 1.0f : SCALE ++ glm_scale_make(scale0, (vec3){VALUE, VALUE, VALUE}); ++#undef VALUE ++#undef SCALE ++ glm_rotate_x(scale0, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); +@@ -540,6 +597,10 @@ + mat4 *model[2]; + ids[0] = collisions[i].x; + ids[1] = collisions[i].y; ++ if (ids[0]->collision) ++ ids[0]->collision(ids[0], ids[1]); ++ if (ids[1]->collision) ++ ids[1]->collision(ids[1], ids[0]); + for (size_t a = 0; a < 2; a++) + { + /* TODO: Skip no-longer available objects */ +@@ -592,8 +653,13 @@ + _glm_atan3(zrot[a], zop[a], zadj[a], rot); + + { +- mat4 trans0, rot0, rot1, rot2; +- glm_rotate_x(GLM_MAT4_IDENTITY, rot[0], rot0); ++ mat4 scale0, trans0, rot0, rot1, rot2; ++#define SCALE ((instance_closure_t *)ids[a]->closure)->scale_left ++#define VALUE SCALE == 0.0f ? 1.0f : SCALE ++ glm_scale_make(scale0, (vec3){VALUE, VALUE, VALUE}); ++#undef VALUE ++#undef SCALE ++ glm_rotate_x(scale0, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot2); + glm_translate_make(trans0, pos[a]); diff --git a/0011disappearing-instances/.gitignore b/0011disappearing-instances/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0011disappearing-instances/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0011disappearing-instances/0_frag.glsl b/0011disappearing-instances/0_frag.glsl new file mode 100644 index 0000000..b877549 --- /dev/null +++ b/0011disappearing-instances/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0011disappearing-instances/0_vert.glsl b/0011disappearing-instances/0_vert.glsl new file mode 100644 index 0000000..f8339a6 --- /dev/null +++ b/0011disappearing-instances/0_vert.glsl @@ -0,0 +1,54 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; +} ubo; + +layout (binding = 2) uniform SUBO +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} subo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = subo.lightPos - pos.xyz; + outViewVec = subo.viewPos - pos.xyz; +} diff --git a/0011disappearing-instances/Makefile b/0011disappearing-instances/Makefile new file mode 100644 index 0000000..47acdd4 --- /dev/null +++ b/0011disappearing-instances/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: -lpthread $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0011disappearing-instances/data.h b/0011disappearing-instances/data.h new file mode 100644 index 0000000..ebdfdb5 --- /dev/null +++ b/0011disappearing-instances/data.h @@ -0,0 +1,102 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); +void data_exit(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +extern struct shared_ubo *data_model_shared_ubo; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; + float radius; +} data_model_t; +extern data_model_t data_models[]; + +typedef struct data_model_instance +{ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void (*collision)(struct data_model_instance *, struct data_model_instance *); + void *closure; + struct list_head list; + void *ubo; + struct list_head *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; +extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; +extern const size_t data_material_shaders_count; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + mat4 *(*get_bones)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; +extern const size_t data_materials_count; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +#define SHARED_UNIFORM_SIZE (4096 * 32) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; + +#endif diff --git a/0011disappearing-instances/data_bulk.c b/0011disappearing-instances/data_bulk.c new file mode 100644 index 0000000..e820028 --- /dev/null +++ b/0011disappearing-instances/data_bulk.c @@ -0,0 +1,2907 @@ +#include "data_bulk.h" +#include +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + 0.5f, + }, + { + "Bullet", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, + 0.5f, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } + +mat4 *get_bones_0(void *p) { return &((material_0_ubo_t *)p)->bones[0]; } + +mat4 *get_bones_1(void *p) { return &((material_1_ubo_t *)p)->bones[0]; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + get_bones_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, + { + "Other Example", + 1, + sizeof(material_1_ubo_t), + get_model_1, + get_bones_1, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; +const size_t data_materials_count = + sizeof(data_materials) / sizeof(data_materials[0]); +const uint32_t material_shader_1_vert_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 183, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 983055, + 0, + 4, + 1852399981, + 0, + 21, + 30, + 103, + 105, + 109, + 123, + 144, + 166, + 169, + 176, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 393221, + 10, + 1701736290, + 1851880020, + 1919903347, + 109, + 196613, + 14, + 5194325, + 327686, + 14, + 0, + 1701080941, + 108, + 327686, + 14, + 1, + 1701736290, + 115, + 196613, + 16, + 7299701, + 327685, + 21, + 1866624617, + 1145660782, + 115, + 393221, + 30, + 1866624617, + 1700226414, + 1952999273, + 115, + 262149, + 103, + 1433695599, + 86, + 262149, + 105, + 1448439401, + 0, + 393221, + 107, + 1348430951, + 1700164197, + 2019914866, + 0, + 393222, + 107, + 0, + 1348430951, + 1953067887, + 7237481, + 196613, + 109, + 0, + 262149, + 112, + 1329747283, + 0, + 262150, + 112, + 0, + 28790, + 393222, + 112, + 1, + 1751607660, + 1936674932, + 0, + 327686, + 112, + 2, + 1633968496, + 0, + 327686, + 112, + 3, + 2003134838, + 7565136, + 327686, + 112, + 4, + 1650745712, + 0, + 262149, + 114, + 1868723571, + 0, + 262149, + 123, + 1867542121, + 115, + 196613, + 134, + 7565168, + 327685, + 144, + 1316255087, + 1634562671, + 108, + 327685, + 166, + 1867411049, + 1818324338, + 0, + 327685, + 169, + 1282700655, + 1952999273, + 6514006, + 327685, + 176, + 1450472815, + 1450665321, + 25445, + 262215, + 13, + 6, + 64, + 262216, + 14, + 0, + 5, + 327752, + 14, + 0, + 35, + 0, + 327752, + 14, + 0, + 7, + 16, + 262216, + 14, + 1, + 5, + 327752, + 14, + 1, + 35, + 64, + 327752, + 14, + 1, + 7, + 16, + 196679, + 14, + 2, + 262215, + 16, + 34, + 0, + 262215, + 16, + 33, + 0, + 262215, + 21, + 30, + 4, + 262215, + 30, + 30, + 3, + 262215, + 103, + 30, + 0, + 262215, + 105, + 30, + 2, + 327752, + 107, + 0, + 11, + 0, + 196679, + 107, + 2, + 262216, + 112, + 0, + 5, + 327752, + 112, + 0, + 35, + 0, + 327752, + 112, + 0, + 7, + 16, + 327752, + 112, + 1, + 35, + 64, + 327752, + 112, + 2, + 35, + 76, + 327752, + 112, + 3, + 35, + 80, + 327752, + 112, + 4, + 35, + 92, + 196679, + 112, + 2, + 262215, + 114, + 34, + 0, + 262215, + 114, + 33, + 2, + 262215, + 123, + 30, + 0, + 262215, + 144, + 30, + 1, + 262215, + 166, + 30, + 1, + 262215, + 169, + 30, + 3, + 262215, + 176, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262168, + 8, + 7, + 4, + 262176, + 9, + 7, + 8, + 262165, + 11, + 32, + 0, + 262187, + 11, + 12, + 64, + 262172, + 13, + 8, + 12, + 262174, + 14, + 8, + 13, + 262176, + 15, + 2, + 14, + 262203, + 15, + 16, + 2, + 262165, + 17, + 32, + 1, + 262187, + 17, + 18, + 1, + 262167, + 19, + 17, + 4, + 262176, + 20, + 1, + 19, + 262203, + 20, + 21, + 1, + 262187, + 11, + 22, + 0, + 262176, + 23, + 1, + 17, + 262176, + 26, + 2, + 8, + 262176, + 29, + 1, + 7, + 262203, + 29, + 30, + 1, + 262176, + 31, + 1, + 6, + 262187, + 11, + 35, + 1, + 262187, + 11, + 57, + 2, + 262187, + 11, + 79, + 3, + 262167, + 101, + 6, + 2, + 262176, + 102, + 3, + 101, + 262203, + 102, + 103, + 3, + 262176, + 104, + 1, + 101, + 262203, + 104, + 105, + 1, + 196638, + 107, + 7, + 262176, + 108, + 3, + 107, + 262203, + 108, + 109, + 3, + 262187, + 17, + 110, + 0, + 262167, + 111, + 6, + 3, + 458782, + 112, + 8, + 111, + 6, + 111, + 6, + 262176, + 113, + 2, + 112, + 262203, + 113, + 114, + 2, + 262176, + 122, + 1, + 111, + 262203, + 122, + 123, + 1, + 262187, + 6, + 125, + 1065353216, + 262176, + 131, + 3, + 7, + 262176, + 133, + 7, + 7, + 262176, + 143, + 3, + 111, + 262203, + 143, + 144, + 3, + 262168, + 151, + 111, + 3, + 262187, + 6, + 152, + 0, + 262203, + 122, + 166, + 1, + 262203, + 143, + 169, + 3, + 262176, + 170, + 2, + 111, + 262203, + 143, + 176, + 3, + 262187, + 17, + 177, + 3, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 9, + 10, + 7, + 262203, + 133, + 134, + 7, + 327745, + 23, + 24, + 21, + 22, + 262205, + 17, + 25, + 24, + 393281, + 26, + 27, + 16, + 18, + 25, + 262205, + 8, + 28, + 27, + 327745, + 31, + 32, + 30, + 22, + 262205, + 6, + 33, + 32, + 327823, + 8, + 34, + 28, + 33, + 196670, + 10, + 34, + 327745, + 23, + 36, + 21, + 35, + 262205, + 17, + 37, + 36, + 393281, + 26, + 38, + 16, + 18, + 37, + 262205, + 8, + 39, + 38, + 327745, + 31, + 40, + 30, + 35, + 262205, + 6, + 41, + 40, + 327823, + 8, + 42, + 39, + 41, + 262205, + 8, + 43, + 10, + 327761, + 7, + 44, + 43, + 0, + 327761, + 7, + 45, + 42, + 0, + 327809, + 7, + 46, + 44, + 45, + 327761, + 7, + 47, + 43, + 1, + 327761, + 7, + 48, + 42, + 1, + 327809, + 7, + 49, + 47, + 48, + 327761, + 7, + 50, + 43, + 2, + 327761, + 7, + 51, + 42, + 2, + 327809, + 7, + 52, + 50, + 51, + 327761, + 7, + 53, + 43, + 3, + 327761, + 7, + 54, + 42, + 3, + 327809, + 7, + 55, + 53, + 54, + 458832, + 8, + 56, + 46, + 49, + 52, + 55, + 196670, + 10, + 56, + 327745, + 23, + 58, + 21, + 57, + 262205, + 17, + 59, + 58, + 393281, + 26, + 60, + 16, + 18, + 59, + 262205, + 8, + 61, + 60, + 327745, + 31, + 62, + 30, + 57, + 262205, + 6, + 63, + 62, + 327823, + 8, + 64, + 61, + 63, + 262205, + 8, + 65, + 10, + 327761, + 7, + 66, + 65, + 0, + 327761, + 7, + 67, + 64, + 0, + 327809, + 7, + 68, + 66, + 67, + 327761, + 7, + 69, + 65, + 1, + 327761, + 7, + 70, + 64, + 1, + 327809, + 7, + 71, + 69, + 70, + 327761, + 7, + 72, + 65, + 2, + 327761, + 7, + 73, + 64, + 2, + 327809, + 7, + 74, + 72, + 73, + 327761, + 7, + 75, + 65, + 3, + 327761, + 7, + 76, + 64, + 3, + 327809, + 7, + 77, + 75, + 76, + 458832, + 8, + 78, + 68, + 71, + 74, + 77, + 196670, + 10, + 78, + 327745, + 23, + 80, + 21, + 79, + 262205, + 17, + 81, + 80, + 393281, + 26, + 82, + 16, + 18, + 81, + 262205, + 8, + 83, + 82, + 327745, + 31, + 84, + 30, + 79, + 262205, + 6, + 85, + 84, + 327823, + 8, + 86, + 83, + 85, + 262205, + 8, + 87, + 10, + 327761, + 7, + 88, + 87, + 0, + 327761, + 7, + 89, + 86, + 0, + 327809, + 7, + 90, + 88, + 89, + 327761, + 7, + 91, + 87, + 1, + 327761, + 7, + 92, + 86, + 1, + 327809, + 7, + 93, + 91, + 92, + 327761, + 7, + 94, + 87, + 2, + 327761, + 7, + 95, + 86, + 2, + 327809, + 7, + 96, + 94, + 95, + 327761, + 7, + 97, + 87, + 3, + 327761, + 7, + 98, + 86, + 3, + 327809, + 7, + 99, + 97, + 98, + 458832, + 8, + 100, + 90, + 93, + 96, + 99, + 196670, + 10, + 100, + 262205, + 101, + 106, + 105, + 196670, + 103, + 106, + 327745, + 26, + 115, + 114, + 110, + 262205, + 8, + 116, + 115, + 327745, + 26, + 117, + 16, + 110, + 262205, + 8, + 118, + 117, + 327826, + 8, + 119, + 116, + 118, + 262205, + 8, + 120, + 10, + 327826, + 8, + 121, + 119, + 120, + 262205, + 111, + 124, + 123, + 327761, + 6, + 126, + 124, + 0, + 327761, + 6, + 127, + 124, + 1, + 327761, + 6, + 128, + 124, + 2, + 458832, + 7, + 129, + 126, + 127, + 128, + 125, + 327825, + 7, + 130, + 121, + 129, + 327745, + 131, + 132, + 109, + 110, + 196670, + 132, + 130, + 327745, + 26, + 135, + 16, + 110, + 262205, + 8, + 136, + 135, + 262205, + 111, + 137, + 123, + 327761, + 6, + 138, + 137, + 0, + 327761, + 6, + 139, + 137, + 1, + 327761, + 6, + 140, + 137, + 2, + 458832, + 7, + 141, + 138, + 139, + 140, + 125, + 327825, + 7, + 142, + 136, + 141, + 196670, + 134, + 142, + 327745, + 26, + 145, + 16, + 110, + 262205, + 8, + 146, + 145, + 262205, + 8, + 147, + 10, + 327826, + 8, + 148, + 146, + 147, + 262228, + 8, + 149, + 148, + 393228, + 8, + 150, + 1, + 34, + 149, + 393297, + 6, + 153, + 150, + 0, + 0, + 393297, + 6, + 154, + 150, + 0, + 1, + 393297, + 6, + 155, + 150, + 0, + 2, + 393297, + 6, + 156, + 150, + 1, + 0, + 393297, + 6, + 157, + 150, + 1, + 1, + 393297, + 6, + 158, + 150, + 1, + 2, + 393297, + 6, + 159, + 150, + 2, + 0, + 393297, + 6, + 160, + 150, + 2, + 1, + 393297, + 6, + 161, + 150, + 2, + 2, + 393296, + 111, + 162, + 153, + 154, + 155, + 393296, + 111, + 163, + 156, + 157, + 158, + 393296, + 111, + 164, + 159, + 160, + 161, + 393296, + 151, + 165, + 162, + 163, + 164, + 262205, + 111, + 167, + 166, + 327825, + 111, + 168, + 165, + 167, + 196670, + 144, + 168, + 327745, + 170, + 171, + 114, + 18, + 262205, + 111, + 172, + 171, + 262205, + 7, + 173, + 134, + 524367, + 111, + 174, + 173, + 173, + 0, + 1, + 2, + 327811, + 111, + 175, + 172, + 174, + 196670, + 169, + 175, + 327745, + 170, + 178, + 114, + 177, + 262205, + 111, + 179, + 178, + 262205, + 7, + 180, + 134, + 524367, + 111, + 181, + 180, + 180, + 0, + 1, + 2, + 327811, + 111, + 182, + 179, + 181, + 196670, + 176, + 182, + 65789, + 65592, +}; + +const uint32_t material_shader_1_frag_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 71, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 655375, + 4, + 4, + 1852399981, + 0, + 17, + 24, + 53, + 69, + 70, + 196624, + 4, + 7, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 262149, + 9, + 1869377379, + 114, + 393221, + 13, + 1886216563, + 1131570540, + 1919904879, + 7364941, + 262149, + 17, + 1448439401, + 0, + 262149, + 21, + 1953720676, + 7500115, + 327685, + 24, + 1766616681, + 1450469479, + 25445, + 262149, + 29, + 1667585644, + 0, + 262149, + 34, + 1702130785, + 110, + 327685, + 44, + 1886351972, + 1684105331, + 30575, + 393221, + 53, + 1182037359, + 1130848626, + 1919904879, + 0, + 327685, + 69, + 1867411049, + 1818324338, + 0, + 327685, + 70, + 1767272041, + 1700165477, + 99, + 262215, + 13, + 34, + 0, + 262215, + 13, + 33, + 1, + 262215, + 17, + 30, + 0, + 262215, + 24, + 30, + 3, + 262215, + 53, + 30, + 0, + 262215, + 69, + 30, + 1, + 262215, + 70, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262176, + 8, + 7, + 7, + 589849, + 10, + 6, + 1, + 0, + 0, + 0, + 1, + 0, + 196635, + 11, + 10, + 262176, + 12, + 0, + 11, + 262203, + 12, + 13, + 0, + 262167, + 15, + 6, + 2, + 262176, + 16, + 1, + 15, + 262203, + 16, + 17, + 1, + 262176, + 20, + 7, + 6, + 262167, + 22, + 6, + 3, + 262176, + 23, + 1, + 22, + 262203, + 23, + 24, + 1, + 262176, + 28, + 7, + 22, + 262187, + 6, + 35, + 1065353216, + 262187, + 6, + 36, + 961656599, + 262187, + 6, + 41, + 0, + 262187, + 6, + 45, + 998445679, + 262176, + 52, + 3, + 7, + 262203, + 52, + 53, + 3, + 262203, + 23, + 69, + 1, + 262203, + 23, + 70, + 1, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 8, + 9, + 7, + 262203, + 20, + 21, + 7, + 262203, + 28, + 29, + 7, + 262203, + 20, + 34, + 7, + 262203, + 20, + 44, + 7, + 262205, + 11, + 14, + 13, + 262205, + 15, + 18, + 17, + 327767, + 7, + 19, + 14, + 18, + 196670, + 9, + 19, + 262205, + 22, + 25, + 24, + 262205, + 22, + 26, + 24, + 327828, + 6, + 27, + 25, + 26, + 196670, + 21, + 27, + 262205, + 22, + 30, + 24, + 262205, + 6, + 31, + 21, + 393228, + 6, + 32, + 1, + 32, + 31, + 327822, + 22, + 33, + 30, + 32, + 196670, + 29, + 33, + 262205, + 6, + 37, + 21, + 393228, + 6, + 38, + 1, + 31, + 37, + 327813, + 6, + 39, + 36, + 38, + 327811, + 6, + 40, + 35, + 39, + 524300, + 6, + 42, + 1, + 43, + 40, + 41, + 35, + 458764, + 6, + 43, + 1, + 40, + 42, + 41, + 196670, + 34, + 43, + 262205, + 6, + 46, + 21, + 393228, + 6, + 47, + 1, + 31, + 46, + 327813, + 6, + 48, + 45, + 47, + 327811, + 6, + 49, + 35, + 48, + 524300, + 6, + 50, + 1, + 43, + 49, + 41, + 35, + 458764, + 6, + 51, + 1, + 40, + 50, + 41, + 196670, + 44, + 51, + 262205, + 7, + 54, + 9, + 262205, + 6, + 55, + 44, + 327811, + 6, + 56, + 35, + 55, + 327822, + 7, + 57, + 54, + 56, + 327761, + 6, + 58, + 57, + 0, + 327761, + 6, + 59, + 57, + 1, + 327761, + 6, + 60, + 57, + 2, + 327761, + 6, + 61, + 57, + 3, + 458832, + 7, + 62, + 58, + 59, + 60, + 61, + 196670, + 53, + 62, + 262205, + 6, + 63, + 34, + 262205, + 7, + 64, + 53, + 524367, + 22, + 65, + 64, + 64, + 0, + 1, + 2, + 327822, + 22, + 66, + 65, + 63, + 262205, + 7, + 67, + 53, + 589903, + 7, + 68, + 67, + 66, + 4, + 5, + 6, + 3, + 196670, + 53, + 68, + 65789, + 65592, +}; +const size_t material_shader_1_vert_size = sizeof(material_shader_1_vert_spv); +const size_t material_shader_1_frag_size = sizeof(material_shader_1_frag_spv); diff --git a/0011disappearing-instances/data_bulk.h b/0011disappearing-instances/data_bulk.h new file mode 100644 index 0000000..ed7d5a4 --- /dev/null +++ b/0011disappearing-instances/data_bulk.h @@ -0,0 +1,17 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_0_ubo_t; + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_1_ubo_t; diff --git a/0011disappearing-instances/data_dynamic.c.in b/0011disappearing-instances/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0011disappearing-instances/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0011disappearing-instances/libdata.c b/0011disappearing-instances/libdata.c new file mode 100644 index 0000000..793a9c0 --- /dev/null +++ b/0011disappearing-instances/libdata.c @@ -0,0 +1,722 @@ +#include "data_bulk.h" +#include +#include +#include +#include +#include +#include +#include + +inline static void player_shoot(); + +struct +{ + unsigned char forward; + unsigned char backward; + unsigned char turn_l; + unsigned char turn_r; + unsigned char climb_up; + unsigned char climb_down; +} keys_count = {false, false, false, false, false, false}; + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + if (action == GLFW_PRESS) + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + case GLFW_KEY_X: + player_shoot(); + break; + } +} + +typedef struct shared_ubo +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} shared_ubo_t; + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const uint8_t material_shader_1_vert_spv[1]; +const size_t material_shader_1_vert_size; +const uint8_t material_shader_1_frag_spv[1]; +const size_t material_shader_1_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, + {{ + material_shader_1_vert_spv, + &material_shader_1_vert_size, + }, + { + material_shader_1_frag_spv, + &material_shader_1_frag_size, + }}, +}; +const size_t data_material_shaders_count = + sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + +typedef struct +{ + float mass; + float speed; + bool solid; + size_t hp; + float scale_left; +} instance_closure_t; + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, ((instance_closure_t *)ptr->closure)->speed * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +void shrink_forward(data_model_instance_t *ptr, double t) +{ + mat4 *bones = + data_materials[data_models[ptr->model].material].get_bones(ptr->ubo); + float *scale_left = &((instance_closure_t *)ptr->closure)->scale_left; + shoot_forward(ptr, t); + if (*scale_left == 0.0f) + *scale_left = 1.0f; + *scale_left -= t / 3.0f; + if (*scale_left <= 0.0f) + { + ptr->update = NULL; + *scale_left = 0.0f; + glm_scale1(bones[0], 0); + } + else + glm_scale1(bones[0], (*scale_left - t / 3.0f) / *scale_left); +} + +void reduce_hp_shrink(data_model_instance_t *a, data_model_instance_t *b) +{ + assert(((instance_closure_t *)a->closure)->hp && + "Shouldn't have called collision()."); + if (--((instance_closure_t *)a->closure)->hp == 0) + { + ((instance_closure_t *)a->closure)->solid = false; + a->collision = NULL; + a->update = &shrink_forward; + } +} + +inline static void setup_model_instance(data_model_instance_t *inst); +#define SUBO data_model_shared_ubo +struct shared_ubo *SUBO = NULL; +pthread_mutex_t data_data_mutex = PTHREAD_MUTEX_INITIALIZER; +inline static void player_shoot() +{ + static const instance_closure_t bullet_closure = { + 0.02f, + 1.0f, + true, + 3, + 0.0f, + }; + + data_model_instance_t *this_instance = NULL, + bullet_instance = { + "Bullet Object", + 1, + shoot_forward, + reduce_hp_shrink, + NULL, + {NULL, NULL}, + NULL, + VK_NULL_HANDLE, + }; + + this_instance = malloc(sizeof(bullet_instance)); + assert(this_instance && "Out of memory."); + *this_instance = bullet_instance; + this_instance->closure = malloc(sizeof(bullet_closure)); + assert(this_instance->closure && "Out of memory."); + *((instance_closure_t *)this_instance->closure) = bullet_closure; + setup_model_instance(this_instance); + + { + material_1_ubo_t *this_ubo = this_instance->ubo; + { + static const material_1_ubo_t empty_data_material_ubo_s; + *this_ubo = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, this_ubo->bones[0]); + + { + mat4 trans0; + glm_translate_to(GLM_MAT4_IDENTITY, SUBO->viewPos, trans0); + glm_rotate_y(trans0, center_dir, this_ubo->model); + glm_translate_z(this_ubo->model, 1.25f); + } + } + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Player Shoot"); + list_add_tail(&this_instance->list, &data_model_instances); + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Player Shoot"); +} + +typedef struct +{ + data_model_instance_t obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + reduce_hp_shrink, + &(instance_closure_t){ + 1.0f, + 0.0f, + true, + 5, + 0.0f, + }, + {&(data_model_instances), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +bool intersect(vec3 amin, vec3 amax, vec3 bmin, vec3 bmax) +{ + return (amin[0] <= bmax[0] && amax[0] >= bmin[0]) && + (amin[1] <= bmax[1] && amax[1] >= bmin[1]) && + (amin[2] <= bmax[2] && amax[2] >= bmin[2]); +} + +pthread_t while_rendering_0; +pthread_cond_t data_data_cond = PTHREAD_COND_INITIALIZER; +#define MAX_COLLISIONS (64 * 64) +typedef struct +{ + data_model_instance_t *x, *y; +} collision_t; +collision_t collisions[MAX_COLLISIONS]; +size_t collisions_count = 0; +pthread_mutex_t collisions_mutex = PTHREAD_MUTEX_INITIALIZER; +void *while_rendering_0_func(void *vargp) +{ + while (!glfwWindowShouldClose(data_window)) + { + + assert((!pthread_mutex_lock(&data_data_mutex)) && "While Rendering 0"); + pthread_cond_wait(&data_data_cond, &data_data_mutex); + + size_t instance_count = 0; + struct list_head *ptr; + list_for_each(ptr, &data_model_instances) instance_count++; + { + struct + { + data_model_instance_t *id; + mat4 model; + float radius; + vec4 pos; + vec3 pos_high; + vec3 pos_low; + } _data[instance_count]; + + { + size_t i = 0; + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + if (!((instance_closure_t *)ptr->closure)->solid) + { + --instance_count; + continue; + } + _data[i].id = ptr; + glm_mat4_copy( + *(data_materials[data_models[ptr->model].material].get_model( + ptr->ubo)), + _data[i].model); + _data[i++].radius = data_models[ptr->model].radius; + } + } + + assert((!pthread_mutex_unlock(&data_data_mutex)) && "While Rendering 0"); + + for (size_t i = 0; i < instance_count; i++) + { + glm_mat4_mulv(_data[i].model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, + _data[i].pos); + for (size_t a = 0; a < 3; a++) + { + _data[i].pos_high[a] = _data[i].pos[a] + _data[i].radius; + _data[i].pos_low[a] = _data[i].pos[a] - _data[i].radius; + } + } + + assert((!pthread_mutex_lock(&collisions_mutex)) && "While Rendering 0"); + + collisions_count = 0; + + for (size_t x = 0; x < instance_count; x++) + { + if (x + 1 < instance_count) + { + for (size_t y = x + 1; y < instance_count; y++) + { + if (intersect(_data[x].pos_low, _data[x].pos_high, _data[y].pos_low, + _data[y].pos_high)) + { + if (glm_vec_distance(_data[x].pos, _data[y].pos) - + _data[x].radius - _data[y].radius < + 0) + { + assert((++collisions_count < MAX_COLLISIONS) && + "Overflow collisions"); + collisions[collisions_count - 1] = + (collision_t){_data[x].id, _data[y].id}; + } + } + } + } + } + } + assert((!pthread_mutex_unlock(&collisions_mutex)) && "While Rendering 0"); + } + return (NULL); +} + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + struct list_head **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = &this_map->list; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = &this_map->list; + } +} + +void (*data_setup_model_instance)(data_model_instance_t *inst); +uintptr_t data_uniform_ptr = 0; +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = &map->list; + data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, + uniform_map_t, list) + ->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp() +{ + glm_lookat(SUBO->viewPos, + (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], + SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, SUBO->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = list_entry(data_model_instances.next, data_model_instance_t, list); + setup_model_instance(inst); + ubo_0 = inst->ubo; + + assert( + !pthread_create(&while_rendering_0, NULL, while_rendering_0_func, NULL)); + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + static const shared_ubo_t empty_shared_ubo_s; + *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + SUBO->lightPos[0] = 0.0f; + SUBO->lightPos[1] = 250.0f; + SUBO->lightPos[2] = -250.0f; + SUBO->viewPos[0] = 0.0f; + SUBO->viewPos[1] = 0.0f; + SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(); + + previous_frame = glfwGetTime(); + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Init"); + assert((!pthread_cond_broadcast(&data_data_cond)) && "Init"); + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Init"); +} + +inline static void handle_input(double this_frame) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if ((!keys_count.climb_up) ^ !keys_count.climb_down) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 scale0, trans0, rot0, rot1; +#define SCALE ((instance_closure_t *)ptr->closure)->scale_left +#define VALUE SCALE == 0.0f ? 1.0f : SCALE + glm_scale_make(scale0, (vec3){VALUE, VALUE, VALUE}); +#undef VALUE +#undef SCALE + glm_rotate_x(scale0, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +inline static void process_collisions() +{ + for (size_t i = 0; i < collisions_count; i++) + { + data_model_instance_t *ids[2]; + vec3 pos[2], zrot[2]; + float zop[2], zadj[2]; + mat4 *model[2]; + ids[0] = collisions[i].x; + ids[1] = collisions[i].y; + if (ids[0]->collision) + ids[0]->collision(ids[0], ids[1]); + if (ids[1]->collision) + ids[1]->collision(ids[1], ids[0]); + for (size_t a = 0; a < 2; a++) + { + /* TODO: Skip no-longer available objects */ + model[a] = data_materials[data_models[ids[a]->model].material].get_model( + ids[a]->ubo); + _glm_decompose(*model[a], pos[a], NULL, zrot[a], &zop[a], &zadj[a]); + } + { + vec3 N /* Collision */, add0[2] /* overlapping points */; + glm_vec_sub(pos[0], pos[1], N); + for (size_t a = 0; a < 2; a++) + { + vec3 scale0; + float table[] = { + -data_models[ids[a]->model].radius, + data_models[ids[a]->model].radius, + }; + glm_vec_scale_as(N, table[a], scale0); + glm_vec_add(scale0, pos[a], add0[a]); + } + vec3 sub1 /* overlapping influence */; + glm_vec_sub(add0[0], add0[1], sub1); + { +#define MASS(x) ((instance_closure_t *)ids[x]->closure)->mass +#define SPEED(x) ((instance_closure_t *)ids[x]->closure)->speed + vec3 scale0, scale1, add0[2]; + float div0 = 1 / (MASS(0) + MASS(1)); + glm_vec_scale(zrot[0], SPEED(0) * (MASS(0) - MASS(1)), scale0); + glm_vec_scale(zrot[1], SPEED(1) * 2 * MASS(1), scale1); + glm_vec_add(scale0, scale1, add0[0]); + glm_vec_scale(zrot[1], SPEED(1) * (MASS(1) - MASS(0)), scale0); + glm_vec_scale(zrot[0], SPEED(0) * 2 * MASS(0), scale1); + glm_vec_scale(add0[0], div0, zrot[0]); + glm_vec_add(scale0, scale1, add0[1]); + glm_vec_scale(add0[1], div0, zrot[1]); + } + for (size_t a = 0; a < 2; a++) + { + vec3 scale1, add1, rot; + float table[] = { + -1.2f * MASS(0) / (MASS(0) + MASS(1)), + 1.2f * MASS(1) / (MASS(0) + MASS(1)), + }; +#undef MASS +#undef SPEED + glm_vec_scale(sub1, table[a], scale1); + glm_vec_add(scale1, pos[a], add1); + glm_vec_copy(add1, pos[a]); + + _glm_atan3(zrot[a], zop[a], zadj[a], rot); + + { + mat4 scale0, trans0, rot0, rot1, rot2; +#define SCALE ((instance_closure_t *)ids[a]->closure)->scale_left +#define VALUE SCALE == 0.0f ? 1.0f : SCALE + glm_scale_make(scale0, (vec3){VALUE, VALUE, VALUE}); +#undef VALUE +#undef SCALE + glm_rotate_x(scale0, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot2); + glm_translate_make(trans0, pos[a]); + glm_mat4_mul(trans0, rot2, *model[a]); + } + } + } + } + collisions_count = 0; +} + +void data_update() +{ + double this_frame = glfwGetTime(); + + handle_input(this_frame); + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Update"); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; + + int err; + err = pthread_mutex_trylock(&collisions_mutex); + switch (err) + { + case 0: + if (collisions_count) + process_collisions(); + + assert((!pthread_cond_broadcast(&data_data_cond)) && "Update"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Update"); + + break; + case EBUSY: + break; + default: + assert((!err) && "pthread_mutex_trylock(&collisions_mutex): Update"); + } + + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Update"); +} + +void data_exit() +{ + assert((!pthread_mutex_lock(&collisions_mutex)) && "Exit"); + assert((!pthread_cond_broadcast(&data_data_cond)) && "Exit"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Exit"); + assert(!pthread_join(while_rendering_0, NULL)); +} diff --git a/0011disappearing-instances/vulkan.c b/0011disappearing-instances/vulkan.c new file mode 100644 index 0000000..18b50dc --- /dev/null +++ b/0011disappearing-instances/vulkan.c @@ -0,0 +1,1684 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, + UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); + data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[2] = set_layout_bindings[0]; + set_layout_bindings[2].binding = 2; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map, size_t material) +{ + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + uniform_descriptors[1] = uniform_descriptors[0]; + uniform_descriptors[1].offset = UNIFORM_SIZE; + uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; + + VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + + write_descriptor_sets[2] = write_descriptor_sets[0]; + write_descriptor_sets[2].dstBinding = 2; + write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageView = texture_image_views[material]; + image_info.sampler = texture_image_sampler; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(data_model_instance_t *inst) +{ + uniform_map_t *this_map; + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); + update_descriptor_set(this_map, data_models[inst->model].material); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_create_info.format = data_materials[i].texture_format; + image_create_info.extent.width = data_materials[i].texture_width; + image_create_info.extent.height = data_materials[i].texture_height; + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[i]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); + } +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + for (size_t i = 0; i < data_materials_count; i++) + { + allocate_texture_image(texture_images[i], gpu_memory_properties, + &texture_image_memorys[i]); + + void *data; + vkMapMemory(device, texture_image_memorys[i], 0, + data_materials[i].texture_size, 0, &data); + memcpy(data, data_materials[i].texture, data_materials[i].texture_size); + vkUnmapMemory(device, texture_image_memorys[i]); + } +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_view_create_info.image = texture_images[i]; + image_view_create_info.format = data_materials[i].texture_format; + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); + } +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_module_create_info.codeSize = *data_material_shaders[i].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[i].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); + } +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_stages_create_info[0].module = vert_modules[i]; + shader_stages_create_info[1].module = frag_modules[i]; + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[i]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); + } +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + size_t bound_shaders = SIZE_MAX; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + { + if (bound_shaders != + data_materials[data_models[inst->model].material].shader) + { + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + bound_shaders = data_materials[data_models[inst->model].material].shader; + } + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &list_entry(inst->uniform_map, uniform_map_t, list) + ->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + for (size_t i = 0; i < data_material_shaders_count; i++) + { + vkDestroyPipeline(device, graphics_pipelines[i], NULL); + graphics_pipelines[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[i], NULL); + frag_modules[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[i], NULL); + vert_modules[i] = VK_NULL_HANDLE; + } + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + for (size_t i = 0; i < data_materials_count; i++) + { + vkDestroyImageView(device, texture_image_views[i], NULL); + texture_image_views[i] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[i], NULL); + texture_image_memorys[i] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[i], NULL); + texture_images[i] = VK_NULL_HANDLE; + } + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = + VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + data_exit(); + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[data_materials_count]; + VkDeviceMemory texture_image_memorys[data_materials_count]; + VkImageView _texture_image_views[data_materials_count]; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[data_material_shaders_count]; + VkShaderModule frag_modules[data_material_shaders_count]; + VkPipeline graphics_pipelines[data_material_shaders_count]; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/0012raytrace.diff b/0012raytrace.diff new file mode 100644 index 0000000..ce4df51 --- /dev/null +++ b/0012raytrace.diff @@ -0,0 +1,9 @@ +diff -bNur 0011disappearing-instances/libdata.c 0012raytrace/libdata.c +--- 0011disappearing-instances/libdata.c 2019-03-02 20:06:22.833346287 -0600 ++++ 0012raytrace/libdata.c 2019-03-02 20:06:22.837346474 -0600 +@@ -719,4 +719,5 @@ + assert((!pthread_cond_broadcast(&data_data_cond)) && "Exit"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Exit"); + assert(!pthread_join(while_rendering_0, NULL)); ++ /* DELETE */ + } diff --git a/0012raytrace/.gitignore b/0012raytrace/.gitignore new file mode 100644 index 0000000..3ab96b1 --- /dev/null +++ b/0012raytrace/.gitignore @@ -0,0 +1,6 @@ +/data_dynamic.o +/data_dynamic.c +/*_frag.spv +/libdata.so +/*_vert.spv +/vulkan diff --git a/0012raytrace/0_frag.glsl b/0012raytrace/0_frag.glsl new file mode 100644 index 0000000..b877549 --- /dev/null +++ b/0012raytrace/0_frag.glsl @@ -0,0 +1,47 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColorMap; + +layout (location = 0) in vec2 inUV; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; + +layout (location = 0) out vec4 outFragColor; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + vec3 normal = normalize(inNormal); + vec3 surfaceToLight = normalize(inLightVec); + vec3 surfaceToCamera = normalize(inViewVec); + + //ambient + vec3 ambient = color.rgb / 150.0; + + //diffuse + float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight)); + vec3 diffuse = diffuseCoefficient * color.rgb / 15.0; + + //specular + float specularCoefficient = 0.0; + if(diffuseCoefficient > 0.0) + specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 8); + vec3 specular = specularCoefficient * vec3(255,255,255); + + //attenuation + float distanceToLight = length(inLightVec); + float attenuation = 1.0 / (1.0 + 0.2 * pow(distanceToLight, 2)); + + //linear color (color before gamma correction) + vec3 linearColor = ambient + attenuation*(diffuse + specular); + + //final color (after gamma correction) + vec3 gamma = vec3(1.0/2.2); + + outFragColor = vec4(pow(linearColor, gamma), color.a); +} diff --git a/0012raytrace/0_vert.glsl b/0012raytrace/0_vert.glsl new file mode 100644 index 0000000..f8339a6 --- /dev/null +++ b/0012raytrace/0_vert.glsl @@ -0,0 +1,54 @@ +#version 400 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inBoneWeights; +layout (location = 4) in ivec4 inBoneIDs; + +#define MAX_BONES 64 + +layout (binding = 0) uniform UBO +{ + mat4 model; + mat4 bones[MAX_BONES]; +} ubo; + +layout (binding = 2) uniform SUBO +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} subo; + +layout (location = 0) out vec2 outUV; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() { + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + + outUV = inUV; + + mat4 skinPos = ubo.model * boneTransform; + gl_Position = subo.vp * skinPos * vec4(inPos, 1.0); + + vec4 pos = skinPos * vec4(inPos, 1.0); + outNormal = inverse(transpose(mat3(skinPos))) * inNormal; + outLightVec = subo.lightPos - pos.xyz; + outViewVec = subo.viewPos - pos.xyz; +} diff --git a/0012raytrace/Makefile b/0012raytrace/Makefile new file mode 100644 index 0000000..47acdd4 --- /dev/null +++ b/0012raytrace/Makefile @@ -0,0 +1,26 @@ +# Makefile for vulkan + +# Our single executable +OBJS = vulkan + +all: $(OBJS) + +include ../misc-targets.mk + +DEPENDS = libdata.so +vulkan: -lpthread $(MYLDLIBS) $(DEPENDS) +LIBDEPENDS_DYNAMIC = 0_vert.spv 0_frag.spv +data_dynamic.o: $(LIBDEPENDS_DYNAMIC) data.h +LIBDEPENDS = data_bulk.o data_dynamic.o +libdata.so: libdata.c $(LIBDEPENDS) + $(LINK.c) -shared -fPIC $(OUTPUT_OPTION) $^ + +clean: + rm -f $(OBJS) $(DEPENDS) $(LIBDEPENDS) $(LIBDEPENDS_DYNAMIC) + + +# valgrind discovers bugs, google it. +test: clean all + valgrind ./vulkan + +.PHONY: all clean test diff --git a/0012raytrace/data.h b/0012raytrace/data.h new file mode 100644 index 0000000..ebdfdb5 --- /dev/null +++ b/0012raytrace/data.h @@ -0,0 +1,102 @@ +#ifndef HAND_DATA_H__ +#define HAND_DATA_H__ +#include "list.h" + +#define GLFW_INCLUDE_VULKAN +#include + +extern GLFWwindow *data_window; + +#ifdef NEWER_CGLM +#define GLM_DEPTH_ZERO_TO_ONE +#define GLM_FORCE_LEFT_HANDED +#endif +#include + +void data_init(VkExtent2D extent); +void data_update(); +void data_exit(); + +// Maximum number of bones per vertex +#define MAX_BONES_PER_VERTEX 4 + +extern uintptr_t data_uniform_ptr; + +extern const void *data_model_vertex; +extern const VkDeviceSize data_model_vertex_size; + +extern const VkVertexInputBindingDescription data_binding_description; +extern const VkVertexInputAttributeDescription data_attribute_descriptions[]; +extern const uint32_t data_attribute_descriptions_count; + +extern const struct data_model_index *data_model_index; +extern const VkDeviceSize data_model_index_size; + +extern struct shared_ubo *data_model_shared_ubo; + +typedef struct +{ + char *name; + uint32_t first; + uint32_t count; + size_t material; + float radius; +} data_model_t; +extern data_model_t data_models[]; + +typedef struct data_model_instance +{ + char *name; + size_t model; + void (*update)(struct data_model_instance *, double); + void (*collision)(struct data_model_instance *, struct data_model_instance *); + void *closure; + struct list_head list; + void *ubo; + struct list_head *uniform_map; +} data_model_instance_t; +extern struct list_head data_model_instances; +extern void (*data_setup_model_instance)(data_model_instance_t *inst); + +typedef struct +{ + struct + { + const void *spv; + const size_t *size; + } vert, frag; +} data_material_shader_t; +extern const data_material_shader_t data_material_shaders[]; +extern const size_t data_material_shaders_count; + +typedef struct +{ + char *name; + size_t shader; + VkDeviceSize ubo_vertex_shader_size; + mat4 *(*get_model)(void *); + mat4 *(*get_bones)(void *); + VkFormat texture_format; + uint32_t texture_width; + uint32_t texture_height; + void *texture; + VkDeviceSize texture_size; +} data_material_t; +extern const data_material_t data_materials[]; +extern const size_t data_materials_count; + +#define UNIFORM_ALIGN (sizeof(float) * 4) +#define FROM_UNIFORM_ALLOC(x) (x * UNIFORM_ALIGN) +#define TO_UNIFORM_ALLOC(x) ((x + UNIFORM_ALIGN - 1) / UNIFORM_ALIGN) +#define UNIFORM_SIZE (4096 * 4096) +#define SHARED_UNIFORM_SIZE (4096 * 32) +typedef struct +{ + VkDescriptorSet descriptor_set; + size_t offset; + size_t range; + size_t width; + struct list_head list; +} uniform_map_t; + +#endif diff --git a/0012raytrace/data_bulk.c b/0012raytrace/data_bulk.c new file mode 100644 index 0000000..e820028 --- /dev/null +++ b/0012raytrace/data_bulk.c @@ -0,0 +1,2907 @@ +#include "data_bulk.h" +#include +#include + +typedef struct +{ + vec3 position; + vec3 normal; + float uv[2]; + float boneWeights[MAX_BONES_PER_VERTEX]; + uint32_t boneIDs[MAX_BONES_PER_VERTEX]; +} vertex_t; + +/* Texture + ####0AA1######## + ####AAAA######## + ####AAAA######## + ####2AA3######## + 4BB56CC78DD9aEEb + BBBBCCCCDDDDEEEE + BBBBCCCCDDDDEEEE + cBBdeCCfgDDhEEEi + ####jFFk######## + ####FFFF######## + ####FFFF######## + ####lFFm######## + */ + +#define DMVPFR -0.5f +#define DMVPBA 0.5f +#define DMVPBO -0.5f +#define DMVPTO 0.5f +#define DMVPRI -0.5f +#define DMVPLE 0.5f + +#define DMVUXONE 0.0f +#define DMVUXTWO 0.25f +#define DMVUXTHR 0.5f +#define DMVUXFOR 0.75f +#define DMVUXFIV 1.0f +#define DMVUYONE 0.0f +#define DMVUYTWO 1.0f / 3.0f +#define DMVUYTHR 2.0f / 3.0f +#define DMVUYFOR 1.0f +const vertex_t model_vertex[] = { + {// 0 + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 1 + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYONE}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 2 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 3 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, DMVPTO * 2, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 4 + {DMVPLE, DMVPTO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 5 + {DMVPLE, DMVPTO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 6 + {DMVPLE, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 7 + {DMVPRI, DMVPTO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 8 + {DMVPRI, DMVPTO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// 9 + {DMVPRI, DMVPTO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// a + {DMVPRI, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// b + {DMVPLE, DMVPTO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTWO}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// c + {DMVPLE, DMVPBO, DMVPBA}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXONE, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// d + {DMVPLE, DMVPBO, DMVPFR}, + {DMVPLE * 2, 0.0f, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// e + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// f + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, 0.0f, DMVPFR * 2}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// g + {DMVPRI, DMVPBO, DMVPFR}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// h + {DMVPRI, DMVPBO, DMVPBA}, + {DMVPRI * 2, 0.0f, 0.0f}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// i + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFOR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// j + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, 0.0f, DMVPBA * 2}, + {DMVUXFIV, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPLE, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// k + {DMVPRI, DMVPBO, DMVPFR}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYTHR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// m + {DMVPLE, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTWO, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, + {// n + {DMVPRI, DMVPBO, DMVPBA}, + {0.0f, DMVPBO * 2, 0.0f}, + {DMVUXTHR, DMVUYFOR}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0, 0, 0, 0}}, +}; +const void *data_model_vertex = model_vertex; +const VkDeviceSize data_model_vertex_size = sizeof(model_vertex); +const VkVertexInputBindingDescription data_binding_description = { + .binding = 0, + .stride = sizeof(vertex_t), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}; +const VkVertexInputAttributeDescription data_attribute_descriptions[] = { + {.location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, position)}, + {.location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(vertex_t, normal)}, + {.location = 2, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(vertex_t, uv)}, + {.location = 3, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(vertex_t, boneWeights)}, + {.location = 4, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SINT, + .offset = offsetof(vertex_t, boneIDs)}}; +const uint32_t data_attribute_descriptions_count = + sizeof(data_attribute_descriptions) / + sizeof(data_attribute_descriptions[0]); + +const struct data_model_index +{ + struct + { + uint32_t first, second, third; + } cube[12], other_cube[12]; +} *data_model_index = &(struct data_model_index){ + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, + { + {2, 0, 1}, // A + {2, 1, 3}, + {12, 4, 5}, // B + {12, 5, 13}, + {14, 6, 7}, // C + {14, 7, 15}, + {16, 8, 9}, // D + {16, 9, 17}, + {18, 10, 11}, // E + {18, 11, 19}, + {22, 20, 21}, // F + {22, 21, 23}, + }, +}; +const VkDeviceSize data_model_index_size = sizeof(*data_model_index); + +data_model_t data_models[] = { + { + "Cube", + offsetof(struct data_model_index, cube) / sizeof(uint32_t), + sizeof(data_model_index->cube) / sizeof(uint32_t), + 0, + 0.5f, + }, + { + "Bullet", + offsetof(struct data_model_index, other_cube) / sizeof(uint32_t), + sizeof(data_model_index->other_cube) / sizeof(uint32_t), + 1, + 0.5f, + }, +}; + +mat4 *get_model_0(void *p) { return &((material_0_ubo_t *)p)->model; } + +mat4 *get_model_1(void *p) { return &((material_1_ubo_t *)p)->model; } + +mat4 *get_bones_0(void *p) { return &((material_0_ubo_t *)p)->bones[0]; } + +mat4 *get_bones_1(void *p) { return &((material_1_ubo_t *)p)->bones[0]; } + +#define DMTCLEAR \ + { \ + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, \ + {0, 0, 0, 0}, {0, 0, 0, 0}, \ + { \ + 0, 0, 0, 0 \ + } \ + } +#define DMTCONE 0xff +#define DMTCTWO 0xf0 +#define DMTCTHR 0xe0 +#define DMTCFOR 0xd0 +#define DMTCFIV 0xc0 +#define DMTCSIX 0xb0 +#define DMTCSEV 0xa0 +#define DMTCEIG 0x90 +#define DMTCNIN 0x80 +#define DMTCTEN 0x70 +#define DMTCELE 0x60 +#define DMTCTWE 0x50 +#define DMTCTHT 0x40 +#define DMTCFOT 0x30 +#define DMTCFIT 0x20 +#define DMTCSIT 0x10 +typedef struct +{ + struct + { + struct + { + struct + { + struct + { + uint8_t red, green, blue, alpha; + } one, two, three, four, five, six, seven, eight; + } one, two, three, four; + } one, two, three, four, five, six, seven, eight; + } one, two, three; +} texture_0_t; + +const data_material_t data_materials[] = { + { + "Example", + 0, + sizeof(material_0_ubo_t), + get_model_0, + get_bones_0, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, + { + "Other Example", + 1, + sizeof(material_1_ubo_t), + get_model_1, + get_bones_1, + VK_FORMAT_R8G8B8A8_UNORM, + 8 * 4, + 8 * 3, + (void *)&(texture_0_t){{{DMTCLEAR, + { + {DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}, + }, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}, + {{{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, +#if 1 + {0xff, 0xff, 0xff, 0xff}, +#else + {DMTCTWO, DMTCONE, 0, 0xff}, +#endif + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, +#if 1 + {{0xff, 0xff, 0xff, 0xff}, + {0xff, 0xff, 0xff, 0xff}, +#else + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, +#endif + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}, + {{DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}}, + {{DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}}}, + {{{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}, + {{DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}}, + {{DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}}}, + {{{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}, + {{DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}}, + {{DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}}}, + {{{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCONE, DMTCTWO, 0, 0xff}, + {DMTCONE, DMTCTHR, 0, 0xff}, + {DMTCONE, DMTCFOR, 0, 0xff}, + {DMTCONE, 0, DMTCFOR, 0xff}, + {DMTCONE, 0, DMTCTHR, 0xff}, + {DMTCONE, 0, DMTCTWO, 0xff}, + {DMTCONE, 0, DMTCONE, 0xff}}, + {{DMTCONE, DMTCONE, 0, 0xff}, + {DMTCTWO, DMTCONE, 0, 0xff}, + {DMTCTHR, DMTCONE, 0, 0xff}, + {DMTCFOR, DMTCONE, 0, 0xff}, + {0, DMTCONE, DMTCFOR, 0xff}, + {0, DMTCONE, DMTCTHR, 0xff}, + {0, DMTCONE, DMTCTWO, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}}}, + {{DMTCLEAR, + {{DMTCONE, 0, DMTCONE, 0xff}, + {DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}, + {0, DMTCONE, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTWO, 0, DMTCONE, 0xff}, + {DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}, + {0, DMTCTWO, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCTHR, 0, DMTCONE, 0xff}, + {DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}, + {0, DMTCTHR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFOR, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCFOR, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}, + {DMTCLEAR, + {{DMTCFIV, 0, DMTCONE, 0xff}, + {DMTCSIX, 0, DMTCONE, 0xff}, + {DMTCSEV, 0, DMTCONE, 0xff}, + {DMTCEIG, 0, DMTCONE, 0xff}, + {0, DMTCEIG, DMTCONE, 0xff}, + {0, DMTCSEV, DMTCONE, 0xff}, + {0, DMTCSIX, DMTCONE, 0xff}, + {0, DMTCFIV, DMTCONE, 0xff}}, + DMTCLEAR, + DMTCLEAR}}}, + sizeof(texture_0_t), + }, +}; +const size_t data_materials_count = + sizeof(data_materials) / sizeof(data_materials[0]); +const uint32_t material_shader_1_vert_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 183, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 983055, + 0, + 4, + 1852399981, + 0, + 21, + 30, + 103, + 105, + 109, + 123, + 144, + 166, + 169, + 176, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 393221, + 10, + 1701736290, + 1851880020, + 1919903347, + 109, + 196613, + 14, + 5194325, + 327686, + 14, + 0, + 1701080941, + 108, + 327686, + 14, + 1, + 1701736290, + 115, + 196613, + 16, + 7299701, + 327685, + 21, + 1866624617, + 1145660782, + 115, + 393221, + 30, + 1866624617, + 1700226414, + 1952999273, + 115, + 262149, + 103, + 1433695599, + 86, + 262149, + 105, + 1448439401, + 0, + 393221, + 107, + 1348430951, + 1700164197, + 2019914866, + 0, + 393222, + 107, + 0, + 1348430951, + 1953067887, + 7237481, + 196613, + 109, + 0, + 262149, + 112, + 1329747283, + 0, + 262150, + 112, + 0, + 28790, + 393222, + 112, + 1, + 1751607660, + 1936674932, + 0, + 327686, + 112, + 2, + 1633968496, + 0, + 327686, + 112, + 3, + 2003134838, + 7565136, + 327686, + 112, + 4, + 1650745712, + 0, + 262149, + 114, + 1868723571, + 0, + 262149, + 123, + 1867542121, + 115, + 196613, + 134, + 7565168, + 327685, + 144, + 1316255087, + 1634562671, + 108, + 327685, + 166, + 1867411049, + 1818324338, + 0, + 327685, + 169, + 1282700655, + 1952999273, + 6514006, + 327685, + 176, + 1450472815, + 1450665321, + 25445, + 262215, + 13, + 6, + 64, + 262216, + 14, + 0, + 5, + 327752, + 14, + 0, + 35, + 0, + 327752, + 14, + 0, + 7, + 16, + 262216, + 14, + 1, + 5, + 327752, + 14, + 1, + 35, + 64, + 327752, + 14, + 1, + 7, + 16, + 196679, + 14, + 2, + 262215, + 16, + 34, + 0, + 262215, + 16, + 33, + 0, + 262215, + 21, + 30, + 4, + 262215, + 30, + 30, + 3, + 262215, + 103, + 30, + 0, + 262215, + 105, + 30, + 2, + 327752, + 107, + 0, + 11, + 0, + 196679, + 107, + 2, + 262216, + 112, + 0, + 5, + 327752, + 112, + 0, + 35, + 0, + 327752, + 112, + 0, + 7, + 16, + 327752, + 112, + 1, + 35, + 64, + 327752, + 112, + 2, + 35, + 76, + 327752, + 112, + 3, + 35, + 80, + 327752, + 112, + 4, + 35, + 92, + 196679, + 112, + 2, + 262215, + 114, + 34, + 0, + 262215, + 114, + 33, + 2, + 262215, + 123, + 30, + 0, + 262215, + 144, + 30, + 1, + 262215, + 166, + 30, + 1, + 262215, + 169, + 30, + 3, + 262215, + 176, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262168, + 8, + 7, + 4, + 262176, + 9, + 7, + 8, + 262165, + 11, + 32, + 0, + 262187, + 11, + 12, + 64, + 262172, + 13, + 8, + 12, + 262174, + 14, + 8, + 13, + 262176, + 15, + 2, + 14, + 262203, + 15, + 16, + 2, + 262165, + 17, + 32, + 1, + 262187, + 17, + 18, + 1, + 262167, + 19, + 17, + 4, + 262176, + 20, + 1, + 19, + 262203, + 20, + 21, + 1, + 262187, + 11, + 22, + 0, + 262176, + 23, + 1, + 17, + 262176, + 26, + 2, + 8, + 262176, + 29, + 1, + 7, + 262203, + 29, + 30, + 1, + 262176, + 31, + 1, + 6, + 262187, + 11, + 35, + 1, + 262187, + 11, + 57, + 2, + 262187, + 11, + 79, + 3, + 262167, + 101, + 6, + 2, + 262176, + 102, + 3, + 101, + 262203, + 102, + 103, + 3, + 262176, + 104, + 1, + 101, + 262203, + 104, + 105, + 1, + 196638, + 107, + 7, + 262176, + 108, + 3, + 107, + 262203, + 108, + 109, + 3, + 262187, + 17, + 110, + 0, + 262167, + 111, + 6, + 3, + 458782, + 112, + 8, + 111, + 6, + 111, + 6, + 262176, + 113, + 2, + 112, + 262203, + 113, + 114, + 2, + 262176, + 122, + 1, + 111, + 262203, + 122, + 123, + 1, + 262187, + 6, + 125, + 1065353216, + 262176, + 131, + 3, + 7, + 262176, + 133, + 7, + 7, + 262176, + 143, + 3, + 111, + 262203, + 143, + 144, + 3, + 262168, + 151, + 111, + 3, + 262187, + 6, + 152, + 0, + 262203, + 122, + 166, + 1, + 262203, + 143, + 169, + 3, + 262176, + 170, + 2, + 111, + 262203, + 143, + 176, + 3, + 262187, + 17, + 177, + 3, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 9, + 10, + 7, + 262203, + 133, + 134, + 7, + 327745, + 23, + 24, + 21, + 22, + 262205, + 17, + 25, + 24, + 393281, + 26, + 27, + 16, + 18, + 25, + 262205, + 8, + 28, + 27, + 327745, + 31, + 32, + 30, + 22, + 262205, + 6, + 33, + 32, + 327823, + 8, + 34, + 28, + 33, + 196670, + 10, + 34, + 327745, + 23, + 36, + 21, + 35, + 262205, + 17, + 37, + 36, + 393281, + 26, + 38, + 16, + 18, + 37, + 262205, + 8, + 39, + 38, + 327745, + 31, + 40, + 30, + 35, + 262205, + 6, + 41, + 40, + 327823, + 8, + 42, + 39, + 41, + 262205, + 8, + 43, + 10, + 327761, + 7, + 44, + 43, + 0, + 327761, + 7, + 45, + 42, + 0, + 327809, + 7, + 46, + 44, + 45, + 327761, + 7, + 47, + 43, + 1, + 327761, + 7, + 48, + 42, + 1, + 327809, + 7, + 49, + 47, + 48, + 327761, + 7, + 50, + 43, + 2, + 327761, + 7, + 51, + 42, + 2, + 327809, + 7, + 52, + 50, + 51, + 327761, + 7, + 53, + 43, + 3, + 327761, + 7, + 54, + 42, + 3, + 327809, + 7, + 55, + 53, + 54, + 458832, + 8, + 56, + 46, + 49, + 52, + 55, + 196670, + 10, + 56, + 327745, + 23, + 58, + 21, + 57, + 262205, + 17, + 59, + 58, + 393281, + 26, + 60, + 16, + 18, + 59, + 262205, + 8, + 61, + 60, + 327745, + 31, + 62, + 30, + 57, + 262205, + 6, + 63, + 62, + 327823, + 8, + 64, + 61, + 63, + 262205, + 8, + 65, + 10, + 327761, + 7, + 66, + 65, + 0, + 327761, + 7, + 67, + 64, + 0, + 327809, + 7, + 68, + 66, + 67, + 327761, + 7, + 69, + 65, + 1, + 327761, + 7, + 70, + 64, + 1, + 327809, + 7, + 71, + 69, + 70, + 327761, + 7, + 72, + 65, + 2, + 327761, + 7, + 73, + 64, + 2, + 327809, + 7, + 74, + 72, + 73, + 327761, + 7, + 75, + 65, + 3, + 327761, + 7, + 76, + 64, + 3, + 327809, + 7, + 77, + 75, + 76, + 458832, + 8, + 78, + 68, + 71, + 74, + 77, + 196670, + 10, + 78, + 327745, + 23, + 80, + 21, + 79, + 262205, + 17, + 81, + 80, + 393281, + 26, + 82, + 16, + 18, + 81, + 262205, + 8, + 83, + 82, + 327745, + 31, + 84, + 30, + 79, + 262205, + 6, + 85, + 84, + 327823, + 8, + 86, + 83, + 85, + 262205, + 8, + 87, + 10, + 327761, + 7, + 88, + 87, + 0, + 327761, + 7, + 89, + 86, + 0, + 327809, + 7, + 90, + 88, + 89, + 327761, + 7, + 91, + 87, + 1, + 327761, + 7, + 92, + 86, + 1, + 327809, + 7, + 93, + 91, + 92, + 327761, + 7, + 94, + 87, + 2, + 327761, + 7, + 95, + 86, + 2, + 327809, + 7, + 96, + 94, + 95, + 327761, + 7, + 97, + 87, + 3, + 327761, + 7, + 98, + 86, + 3, + 327809, + 7, + 99, + 97, + 98, + 458832, + 8, + 100, + 90, + 93, + 96, + 99, + 196670, + 10, + 100, + 262205, + 101, + 106, + 105, + 196670, + 103, + 106, + 327745, + 26, + 115, + 114, + 110, + 262205, + 8, + 116, + 115, + 327745, + 26, + 117, + 16, + 110, + 262205, + 8, + 118, + 117, + 327826, + 8, + 119, + 116, + 118, + 262205, + 8, + 120, + 10, + 327826, + 8, + 121, + 119, + 120, + 262205, + 111, + 124, + 123, + 327761, + 6, + 126, + 124, + 0, + 327761, + 6, + 127, + 124, + 1, + 327761, + 6, + 128, + 124, + 2, + 458832, + 7, + 129, + 126, + 127, + 128, + 125, + 327825, + 7, + 130, + 121, + 129, + 327745, + 131, + 132, + 109, + 110, + 196670, + 132, + 130, + 327745, + 26, + 135, + 16, + 110, + 262205, + 8, + 136, + 135, + 262205, + 111, + 137, + 123, + 327761, + 6, + 138, + 137, + 0, + 327761, + 6, + 139, + 137, + 1, + 327761, + 6, + 140, + 137, + 2, + 458832, + 7, + 141, + 138, + 139, + 140, + 125, + 327825, + 7, + 142, + 136, + 141, + 196670, + 134, + 142, + 327745, + 26, + 145, + 16, + 110, + 262205, + 8, + 146, + 145, + 262205, + 8, + 147, + 10, + 327826, + 8, + 148, + 146, + 147, + 262228, + 8, + 149, + 148, + 393228, + 8, + 150, + 1, + 34, + 149, + 393297, + 6, + 153, + 150, + 0, + 0, + 393297, + 6, + 154, + 150, + 0, + 1, + 393297, + 6, + 155, + 150, + 0, + 2, + 393297, + 6, + 156, + 150, + 1, + 0, + 393297, + 6, + 157, + 150, + 1, + 1, + 393297, + 6, + 158, + 150, + 1, + 2, + 393297, + 6, + 159, + 150, + 2, + 0, + 393297, + 6, + 160, + 150, + 2, + 1, + 393297, + 6, + 161, + 150, + 2, + 2, + 393296, + 111, + 162, + 153, + 154, + 155, + 393296, + 111, + 163, + 156, + 157, + 158, + 393296, + 111, + 164, + 159, + 160, + 161, + 393296, + 151, + 165, + 162, + 163, + 164, + 262205, + 111, + 167, + 166, + 327825, + 111, + 168, + 165, + 167, + 196670, + 144, + 168, + 327745, + 170, + 171, + 114, + 18, + 262205, + 111, + 172, + 171, + 262205, + 7, + 173, + 134, + 524367, + 111, + 174, + 173, + 173, + 0, + 1, + 2, + 327811, + 111, + 175, + 172, + 174, + 196670, + 169, + 175, + 327745, + 170, + 178, + 114, + 177, + 262205, + 111, + 179, + 178, + 262205, + 7, + 180, + 134, + 524367, + 111, + 181, + 180, + 180, + 0, + 1, + 2, + 327811, + 111, + 182, + 179, + 181, + 196670, + 176, + 182, + 65789, + 65592, +}; + +const uint32_t material_shader_1_frag_spv[] = { + 0x07230203, + SPV_VERSION, + (SpvExecutionModeOriginLowerLeft << 16) + SpvSourceLanguageGLSL, + 71, + 0, + 131089, + 1, + 393227, + 1, + 1280527431, + 1685353262, + 808793134, + 0, + 196622, + 0, + 1, + 655375, + 4, + 4, + 1852399981, + 0, + 17, + 24, + 53, + 69, + 70, + 196624, + 4, + 7, + 196611, + 2, + 400, + 589828, + 1096764487, + 1935622738, + 1918988389, + 1600484449, + 1684105331, + 1868526181, + 1667590754, + 29556, + 589828, + 1096764487, + 1935622738, + 1768186216, + 1818191726, + 1969712737, + 1600481121, + 1882206772, + 7037793, + 262149, + 4, + 1852399981, + 0, + 262149, + 9, + 1869377379, + 114, + 393221, + 13, + 1886216563, + 1131570540, + 1919904879, + 7364941, + 262149, + 17, + 1448439401, + 0, + 262149, + 21, + 1953720676, + 7500115, + 327685, + 24, + 1766616681, + 1450469479, + 25445, + 262149, + 29, + 1667585644, + 0, + 262149, + 34, + 1702130785, + 110, + 327685, + 44, + 1886351972, + 1684105331, + 30575, + 393221, + 53, + 1182037359, + 1130848626, + 1919904879, + 0, + 327685, + 69, + 1867411049, + 1818324338, + 0, + 327685, + 70, + 1767272041, + 1700165477, + 99, + 262215, + 13, + 34, + 0, + 262215, + 13, + 33, + 1, + 262215, + 17, + 30, + 0, + 262215, + 24, + 30, + 3, + 262215, + 53, + 30, + 0, + 262215, + 69, + 30, + 1, + 262215, + 70, + 30, + 2, + 131091, + 2, + 196641, + 3, + 2, + 196630, + 6, + 32, + 262167, + 7, + 6, + 4, + 262176, + 8, + 7, + 7, + 589849, + 10, + 6, + 1, + 0, + 0, + 0, + 1, + 0, + 196635, + 11, + 10, + 262176, + 12, + 0, + 11, + 262203, + 12, + 13, + 0, + 262167, + 15, + 6, + 2, + 262176, + 16, + 1, + 15, + 262203, + 16, + 17, + 1, + 262176, + 20, + 7, + 6, + 262167, + 22, + 6, + 3, + 262176, + 23, + 1, + 22, + 262203, + 23, + 24, + 1, + 262176, + 28, + 7, + 22, + 262187, + 6, + 35, + 1065353216, + 262187, + 6, + 36, + 961656599, + 262187, + 6, + 41, + 0, + 262187, + 6, + 45, + 998445679, + 262176, + 52, + 3, + 7, + 262203, + 52, + 53, + 3, + 262203, + 23, + 69, + 1, + 262203, + 23, + 70, + 1, + 327734, + 2, + 4, + 0, + 3, + 131320, + 5, + 262203, + 8, + 9, + 7, + 262203, + 20, + 21, + 7, + 262203, + 28, + 29, + 7, + 262203, + 20, + 34, + 7, + 262203, + 20, + 44, + 7, + 262205, + 11, + 14, + 13, + 262205, + 15, + 18, + 17, + 327767, + 7, + 19, + 14, + 18, + 196670, + 9, + 19, + 262205, + 22, + 25, + 24, + 262205, + 22, + 26, + 24, + 327828, + 6, + 27, + 25, + 26, + 196670, + 21, + 27, + 262205, + 22, + 30, + 24, + 262205, + 6, + 31, + 21, + 393228, + 6, + 32, + 1, + 32, + 31, + 327822, + 22, + 33, + 30, + 32, + 196670, + 29, + 33, + 262205, + 6, + 37, + 21, + 393228, + 6, + 38, + 1, + 31, + 37, + 327813, + 6, + 39, + 36, + 38, + 327811, + 6, + 40, + 35, + 39, + 524300, + 6, + 42, + 1, + 43, + 40, + 41, + 35, + 458764, + 6, + 43, + 1, + 40, + 42, + 41, + 196670, + 34, + 43, + 262205, + 6, + 46, + 21, + 393228, + 6, + 47, + 1, + 31, + 46, + 327813, + 6, + 48, + 45, + 47, + 327811, + 6, + 49, + 35, + 48, + 524300, + 6, + 50, + 1, + 43, + 49, + 41, + 35, + 458764, + 6, + 51, + 1, + 40, + 50, + 41, + 196670, + 44, + 51, + 262205, + 7, + 54, + 9, + 262205, + 6, + 55, + 44, + 327811, + 6, + 56, + 35, + 55, + 327822, + 7, + 57, + 54, + 56, + 327761, + 6, + 58, + 57, + 0, + 327761, + 6, + 59, + 57, + 1, + 327761, + 6, + 60, + 57, + 2, + 327761, + 6, + 61, + 57, + 3, + 458832, + 7, + 62, + 58, + 59, + 60, + 61, + 196670, + 53, + 62, + 262205, + 6, + 63, + 34, + 262205, + 7, + 64, + 53, + 524367, + 22, + 65, + 64, + 64, + 0, + 1, + 2, + 327822, + 22, + 66, + 65, + 63, + 262205, + 7, + 67, + 53, + 589903, + 7, + 68, + 67, + 66, + 4, + 5, + 6, + 3, + 196670, + 53, + 68, + 65789, + 65592, +}; +const size_t material_shader_1_vert_size = sizeof(material_shader_1_vert_spv); +const size_t material_shader_1_frag_size = sizeof(material_shader_1_frag_spv); diff --git a/0012raytrace/data_bulk.h b/0012raytrace/data_bulk.h new file mode 100644 index 0000000..ed7d5a4 --- /dev/null +++ b/0012raytrace/data_bulk.h @@ -0,0 +1,17 @@ +#include "data.h" + +// Maximum number of bones per mesh +// Must not be higher than same const in skinning shader +#define MAX_BONES 64 + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_0_ubo_t; + +typedef struct +{ + mat4 model; + mat4 bones[MAX_BONES]; +} material_1_ubo_t; diff --git a/0012raytrace/data_dynamic.c.in b/0012raytrace/data_dynamic.c.in new file mode 100644 index 0000000..8f82a65 --- /dev/null +++ b/0012raytrace/data_dynamic.c.in @@ -0,0 +1,10 @@ +#include "data.h" + +const uint8_t material_shader_0_vert_spv[] = { +syscmd(`xxd -i < 0_vert.spv')dnl +}; +const size_t material_shader_0_vert_size = sizeof(material_shader_0_vert_spv); +const uint8_t material_shader_0_frag_spv[] = { +syscmd(`xxd -i < 0_frag.spv')dnl +}; +const size_t material_shader_0_frag_size = sizeof(material_shader_0_frag_spv); diff --git a/0012raytrace/libdata.c b/0012raytrace/libdata.c new file mode 100644 index 0000000..aec3b41 --- /dev/null +++ b/0012raytrace/libdata.c @@ -0,0 +1,723 @@ +#include "data_bulk.h" +#include +#include +#include +#include +#include +#include +#include + +inline static void player_shoot(); + +struct +{ + unsigned char forward; + unsigned char backward; + unsigned char turn_l; + unsigned char turn_r; + unsigned char climb_up; + unsigned char climb_down; +} keys_count = {false, false, false, false, false, false}; + +void key_callback(GLFWwindow *window, int key, int scancode, int action, + int mods) +{ + if (action == GLFW_PRESS) + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + case GLFW_KEY_X: + player_shoot(); + break; + } +} + +typedef struct shared_ubo +{ + mat4 vp; + vec3 lightPos; + float pada; + vec3 viewPos; + float padb; +} shared_ubo_t; + +float center_dir = 0; + +GLFWwindow *data_window = NULL; + +const uint8_t material_shader_0_vert_spv[1]; +const size_t material_shader_0_vert_size; +const uint8_t material_shader_0_frag_spv[1]; +const size_t material_shader_0_frag_size; +const uint8_t material_shader_1_vert_spv[1]; +const size_t material_shader_1_vert_size; +const uint8_t material_shader_1_frag_spv[1]; +const size_t material_shader_1_frag_size; +const data_material_shader_t data_material_shaders[] = { + {{ + material_shader_0_vert_spv, + &material_shader_0_vert_size, + }, + { + material_shader_0_frag_spv, + &material_shader_0_frag_size, + }}, + {{ + material_shader_1_vert_spv, + &material_shader_1_vert_size, + }, + { + material_shader_1_frag_spv, + &material_shader_1_frag_size, + }}, +}; +const size_t data_material_shaders_count = + sizeof(data_material_shaders) / sizeof(data_material_shaders[0]); + +typedef struct +{ + float mass; + float speed; + bool solid; + size_t hp; + float scale_left; +} instance_closure_t; + +void shoot_forward(data_model_instance_t *ptr, double t) +{ + mat4 rot0, + *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + glm_translate_z(*model, ((instance_closure_t *)ptr->closure)->speed * t); + glm_rotate_z(*model, t, rot0); + glm_mat4_copy(rot0, *model); +} + +void shrink_forward(data_model_instance_t *ptr, double t) +{ + mat4 *bones = + data_materials[data_models[ptr->model].material].get_bones(ptr->ubo); + float *scale_left = &((instance_closure_t *)ptr->closure)->scale_left; + shoot_forward(ptr, t); + if (*scale_left == 0.0f) + *scale_left = 1.0f; + *scale_left -= t / 3.0f; + if (*scale_left <= 0.0f) + { + ptr->update = NULL; + *scale_left = 0.0f; + glm_scale1(bones[0], 0); + } + else + glm_scale1(bones[0], (*scale_left - t / 3.0f) / *scale_left); +} + +void reduce_hp_shrink(data_model_instance_t *a, data_model_instance_t *b) +{ + assert(((instance_closure_t *)a->closure)->hp && + "Shouldn't have called collision()."); + if (--((instance_closure_t *)a->closure)->hp == 0) + { + ((instance_closure_t *)a->closure)->solid = false; + a->collision = NULL; + a->update = &shrink_forward; + } +} + +inline static void setup_model_instance(data_model_instance_t *inst); +#define SUBO data_model_shared_ubo +struct shared_ubo *SUBO = NULL; +pthread_mutex_t data_data_mutex = PTHREAD_MUTEX_INITIALIZER; +inline static void player_shoot() +{ + static const instance_closure_t bullet_closure = { + 0.02f, + 1.0f, + true, + 3, + 0.0f, + }; + + data_model_instance_t *this_instance = NULL, + bullet_instance = { + "Bullet Object", + 1, + shoot_forward, + reduce_hp_shrink, + NULL, + {NULL, NULL}, + NULL, + VK_NULL_HANDLE, + }; + + this_instance = malloc(sizeof(bullet_instance)); + assert(this_instance && "Out of memory."); + *this_instance = bullet_instance; + this_instance->closure = malloc(sizeof(bullet_closure)); + assert(this_instance->closure && "Out of memory."); + *((instance_closure_t *)this_instance->closure) = bullet_closure; + setup_model_instance(this_instance); + + { + material_1_ubo_t *this_ubo = this_instance->ubo; + { + static const material_1_ubo_t empty_data_material_ubo_s; + *this_ubo = empty_data_material_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, this_ubo->bones[0]); + + { + mat4 trans0; + glm_translate_to(GLM_MAT4_IDENTITY, SUBO->viewPos, trans0); + glm_rotate_y(trans0, center_dir, this_ubo->model); + glm_translate_z(this_ubo->model, 1.25f); + } + } + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Player Shoot"); + list_add_tail(&this_instance->list, &data_model_instances); + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Player Shoot"); +} + +typedef struct +{ + data_model_instance_t obj; +} model_instance_t; +model_instance_t model_instance; +struct list_head data_model_instances = {&(model_instance.obj.list), + &(model_instance.obj.list)}; +model_instance_t model_instance = { + { + "Object", + 0, + NULL, + reduce_hp_shrink, + &(instance_closure_t){ + 1.0f, + 0.0f, + true, + 5, + 0.0f, + }, + {&(data_model_instances), &(data_model_instances)}, + NULL, + VK_NULL_HANDLE, + }, +}; + +bool intersect(vec3 amin, vec3 amax, vec3 bmin, vec3 bmax) +{ + return (amin[0] <= bmax[0] && amax[0] >= bmin[0]) && + (amin[1] <= bmax[1] && amax[1] >= bmin[1]) && + (amin[2] <= bmax[2] && amax[2] >= bmin[2]); +} + +pthread_t while_rendering_0; +pthread_cond_t data_data_cond = PTHREAD_COND_INITIALIZER; +#define MAX_COLLISIONS (64 * 64) +typedef struct +{ + data_model_instance_t *x, *y; +} collision_t; +collision_t collisions[MAX_COLLISIONS]; +size_t collisions_count = 0; +pthread_mutex_t collisions_mutex = PTHREAD_MUTEX_INITIALIZER; +void *while_rendering_0_func(void *vargp) +{ + while (!glfwWindowShouldClose(data_window)) + { + + assert((!pthread_mutex_lock(&data_data_mutex)) && "While Rendering 0"); + pthread_cond_wait(&data_data_cond, &data_data_mutex); + + size_t instance_count = 0; + struct list_head *ptr; + list_for_each(ptr, &data_model_instances) instance_count++; + { + struct + { + data_model_instance_t *id; + mat4 model; + float radius; + vec4 pos; + vec3 pos_high; + vec3 pos_low; + } _data[instance_count]; + + { + size_t i = 0; + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + if (!((instance_closure_t *)ptr->closure)->solid) + { + --instance_count; + continue; + } + _data[i].id = ptr; + glm_mat4_copy( + *(data_materials[data_models[ptr->model].material].get_model( + ptr->ubo)), + _data[i].model); + _data[i++].radius = data_models[ptr->model].radius; + } + } + + assert((!pthread_mutex_unlock(&data_data_mutex)) && "While Rendering 0"); + + for (size_t i = 0; i < instance_count; i++) + { + glm_mat4_mulv(_data[i].model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, + _data[i].pos); + for (size_t a = 0; a < 3; a++) + { + _data[i].pos_high[a] = _data[i].pos[a] + _data[i].radius; + _data[i].pos_low[a] = _data[i].pos[a] - _data[i].radius; + } + } + + assert((!pthread_mutex_lock(&collisions_mutex)) && "While Rendering 0"); + + collisions_count = 0; + + for (size_t x = 0; x < instance_count; x++) + { + if (x + 1 < instance_count) + { + for (size_t y = x + 1; y < instance_count; y++) + { + if (intersect(_data[x].pos_low, _data[x].pos_high, _data[y].pos_low, + _data[y].pos_high)) + { + if (glm_vec_distance(_data[x].pos, _data[y].pos) - + _data[x].radius - _data[y].radius < + 0) + { + assert((++collisions_count < MAX_COLLISIONS) && + "Overflow collisions"); + collisions[collisions_count - 1] = + (collision_t){_data[x].id, _data[y].id}; + } + } + } + } + } + } + assert((!pthread_mutex_unlock(&collisions_mutex)) && "While Rendering 0"); + } + return (NULL); +} + +uniform_map_t starting_map; +struct list_head uniform_maps = {&(starting_map.list), &(starting_map.list)}; +uniform_map_t starting_map = { + VK_NULL_HANDLE, + 0, + 0, + TO_UNIFORM_ALLOC(UNIFORM_SIZE), + {&(uniform_maps), &(uniform_maps)}, +}; + +inline static void split_map(size_t size, uniform_map_t *map, + struct list_head **ptr) +{ + uniform_map_t *this_map; + this_map = malloc(sizeof(uniform_map_t)); + assert(this_map && "malloc(sizeof(uniform_map_t))"); + this_map->descriptor_set = VK_NULL_HANDLE; + if (map->range) + { + this_map->offset = map->offset + map->range; + this_map->range = size; + this_map->width = map->width - map->range; + map->width = map->range; + list_add(&this_map->list, map->list.next); + *ptr = &this_map->list; + } + else + { + this_map->offset = map->offset; + map->offset += this_map->width = this_map->range = size; + map->width -= size; + list_add(&this_map->list, &map->list); + *ptr = &this_map->list; + } +} + +void (*data_setup_model_instance)(data_model_instance_t *inst); +uintptr_t data_uniform_ptr = 0; +inline static void setup_model_instance(data_model_instance_t *inst) +{ + size_t size = TO_UNIFORM_ALLOC( + data_materials[data_models[inst->model].material].ubo_vertex_shader_size); + size_t contigious = 0; + size_t count = 0; + inst->uniform_map = NULL; + uniform_map_t *map; + list_for_each_entry(map, &uniform_maps, list) + { + if (map->range) + { + contigious = 0; + count = 0; + } + size_t free = map->width - map->range; + if (free) + { + contigious += free; + count++; + if ((!map->range) && (free >= size) && (size * 2 > free)) + { + map->range = size; + inst->uniform_map = &map->list; + data_setup_model_instance(inst); + break; + } + else if (size < free) + { + split_map(size, map, &inst->uniform_map); + data_setup_model_instance(inst); + break; + } + else if (size < free + contigious) + { + assert(!count && 0 && "TODO: Support for combining uniform maps."); + } + } + } + assert(inst->uniform_map && "Out of uniform space."); + inst->ubo = (void *)(FROM_UNIFORM_ALLOC(list_entry(inst->uniform_map, + uniform_map_t, list) + ->offset) + + data_uniform_ptr); +} + +mat4 projection; +mat4 view; +inline static void update_vp() +{ + glm_lookat(SUBO->viewPos, + (vec3){SUBO->viewPos[0] + sinf(center_dir), SUBO->viewPos[1], + SUBO->viewPos[2] + cosf(center_dir)}, + GLM_YUP, view); + glm_mat4_mul(projection, view, SUBO->vp); +} + +/* + * This code uses a float point frame counter. To make your code easier + * u may want to resolve this to an integer. One frame is the set of all + * player's turns. + */ +double previous_frame; + +void data_init(VkExtent2D extent) +{ + material_0_ubo_t *ubo_0; + data_model_instance_t *inst = list_entry(data_model_instances.next, data_model_instance_t, list); + setup_model_instance(inst); + ubo_0 = inst->ubo; + + assert( + !pthread_create(&while_rendering_0, NULL, while_rendering_0_func, NULL)); + + glfwSetKeyCallback(data_window, key_callback); + + { + static const material_0_ubo_t empty_data_material_ubo_s; + *ubo_0 = empty_data_material_ubo_s; + static const shared_ubo_t empty_shared_ubo_s; + *SUBO = empty_shared_ubo_s; + } + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->bones[0]); + SUBO->lightPos[0] = 0.0f; + SUBO->lightPos[1] = 250.0f; + SUBO->lightPos[2] = -250.0f; + SUBO->viewPos[0] = 0.0f; + SUBO->viewPos[1] = 0.0f; + SUBO->viewPos[2] = -3.0f; + + glm_mat4_copy(GLM_MAT4_IDENTITY, ubo_0->model); + +#ifdef NEWER_CGLM + glm_perspective_default((float)extent.width / (float)extent.height, + projection); +#else + mat4 oglproj; + glm_perspective_default((float)extent.width / (float)extent.height, oglproj); + /* This is for Vulkan, cglm is for OpenGL. */ + glm_mat4_mul((mat4){{1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}}, + oglproj, projection); +#endif + + update_vp(); + + previous_frame = glfwGetTime(); + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Init"); + assert((!pthread_cond_broadcast(&data_data_cond)) && "Init"); + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Init"); +} + +inline static void handle_input(double this_frame) +{ + float diagnal2 = 1; + bool need_lookat = false; + +#define GET_KEY(key) glfwGetKey(data_window, (key)) +#define GET_KEY2(a, b) (GET_KEY(a) || GET_KEY(b)) + if (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ^ GET_KEY2(GLFW_KEY_S, GLFW_KEY_DOWN)) + { + double dist = 1.5 * (GET_KEY2(GLFW_KEY_W, GLFW_KEY_UP) ? this_frame - previous_frame + : previous_frame - this_frame); + if ((!keys_count.climb_up) ^ !keys_count.climb_down) + diagnal2 = 0.70710678119f; + SUBO->viewPos[0] += sinf(center_dir) * dist * diagnal2; + SUBO->viewPos[2] += cosf(center_dir) * dist * diagnal2; + need_lookat = true; + } + + if (GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ^ GET_KEY2(GLFW_KEY_D, GLFW_KEY_RIGHT)) + { + center_dir += GET_KEY2(GLFW_KEY_A, GLFW_KEY_LEFT) ? this_frame - previous_frame + : previous_frame - this_frame; + need_lookat = true; + } + + if (GET_KEY(GLFW_KEY_R) ^ GET_KEY(GLFW_KEY_V)) + { + double dist = 1.5 * (GET_KEY(GLFW_KEY_R) ? this_frame - previous_frame + : previous_frame - this_frame); + SUBO->viewPos[1] += dist * diagnal2; + need_lookat = true; + } + + if (need_lookat) + update_vp(); +} + +void _glm_atan3(vec3 zvec, float zopposite, float zadjacent, vec3 rot) +{ + rot[0] = atan2f(zvec[1], zvec[2]); + rot[1] = atan2f(zvec[0], fabsf(zvec[2])); + rot[2] = atan2f(zopposite, zadjacent); +} + +void _glm_decompose(mat4 model, vec3 pos, vec3 rot, vec3 zvec, float *zopposite, + float *zadjacent) +{ + mat4 rot0, rot1; + vec4 mul1, mul2; + if (pos) + { + vec4 mul0; + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 0.0f, 1.0f}, mul0); + glm_vec_copy(mul0, pos); + } + glm_mat4_mulv(model, (vec4){0.0f, 0.0f, 1.0f, 0.0f}, mul1); + glm_rotate_y(model, -atan2f(mul1[0], fabsf(mul1[2])), rot0); + glm_rotate_x(rot0, -atan2f(mul1[1], mul1[2]), rot1); + glm_mat4_mulv(rot1, (vec4){0.0f, 1.0f, 0.0f, 0.0f}, mul2); + if (rot) + _glm_atan3(mul1, mul2[2], mul2[1], rot); + if (zvec) + glm_vec_copy(mul1, zvec); + if (zopposite && zadjacent) + { + *zopposite = mul2[2]; + *zadjacent = mul2[1]; + } +} + +inline static void take_turn(data_model_instance_t *ptr, double this_frame) +{ + if (ptr->update) + { + ptr->update(ptr, this_frame - previous_frame); + /* Check out of bounds and reflect. */ + { + vec3 pos, rot; + mat4 *model = + data_materials[data_models[ptr->model].material].get_model(ptr->ubo); + _glm_decompose(*model, pos, rot, NULL, NULL, NULL); + bool new_model = false; + for (size_t i = 0; i < 3; i++) + { +#define BOUND 7.0f + if (pos[i] < -BOUND || pos[i] > BOUND) + { + switch (i) + { + case 0: + rot[1] = -rot[1]; + break; + case 1: + rot[0] = -rot[0]; + break; + case 2: + rot[1] = CGLM_PI - rot[1]; + break; + default: + assert(0 && "Out of bounds."); + } + pos[i] += pos[i] < -BOUND ? (pos[i] + BOUND) * -2.0f + : (pos[i] - BOUND) * -2.0f; + new_model = true; + } + } + if (new_model) + { + mat4 scale0, trans0, rot0, rot1; +#define SCALE ((instance_closure_t *)ptr->closure)->scale_left +#define VALUE SCALE == 0.0f ? 1.0f : SCALE + glm_scale_make(scale0, (vec3){VALUE, VALUE, VALUE}); +#undef VALUE +#undef SCALE + glm_rotate_x(scale0, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot0); + glm_translate_make(trans0, pos); + glm_mat4_mul(trans0, rot0, *model); + } + } + } +} + +inline static void process_collisions() +{ + for (size_t i = 0; i < collisions_count; i++) + { + data_model_instance_t *ids[2]; + vec3 pos[2], zrot[2]; + float zop[2], zadj[2]; + mat4 *model[2]; + ids[0] = collisions[i].x; + ids[1] = collisions[i].y; + if (ids[0]->collision) + ids[0]->collision(ids[0], ids[1]); + if (ids[1]->collision) + ids[1]->collision(ids[1], ids[0]); + for (size_t a = 0; a < 2; a++) + { + /* TODO: Skip no-longer available objects */ + model[a] = data_materials[data_models[ids[a]->model].material].get_model( + ids[a]->ubo); + _glm_decompose(*model[a], pos[a], NULL, zrot[a], &zop[a], &zadj[a]); + } + { + vec3 N /* Collision */, add0[2] /* overlapping points */; + glm_vec_sub(pos[0], pos[1], N); + for (size_t a = 0; a < 2; a++) + { + vec3 scale0; + float table[] = { + -data_models[ids[a]->model].radius, + data_models[ids[a]->model].radius, + }; + glm_vec_scale_as(N, table[a], scale0); + glm_vec_add(scale0, pos[a], add0[a]); + } + vec3 sub1 /* overlapping influence */; + glm_vec_sub(add0[0], add0[1], sub1); + { +#define MASS(x) ((instance_closure_t *)ids[x]->closure)->mass +#define SPEED(x) ((instance_closure_t *)ids[x]->closure)->speed + vec3 scale0, scale1, add0[2]; + float div0 = 1 / (MASS(0) + MASS(1)); + glm_vec_scale(zrot[0], SPEED(0) * (MASS(0) - MASS(1)), scale0); + glm_vec_scale(zrot[1], SPEED(1) * 2 * MASS(1), scale1); + glm_vec_add(scale0, scale1, add0[0]); + glm_vec_scale(zrot[1], SPEED(1) * (MASS(1) - MASS(0)), scale0); + glm_vec_scale(zrot[0], SPEED(0) * 2 * MASS(0), scale1); + glm_vec_scale(add0[0], div0, zrot[0]); + glm_vec_add(scale0, scale1, add0[1]); + glm_vec_scale(add0[1], div0, zrot[1]); + } + for (size_t a = 0; a < 2; a++) + { + vec3 scale1, add1, rot; + float table[] = { + -1.2f * MASS(0) / (MASS(0) + MASS(1)), + 1.2f * MASS(1) / (MASS(0) + MASS(1)), + }; +#undef MASS +#undef SPEED + glm_vec_scale(sub1, table[a], scale1); + glm_vec_add(scale1, pos[a], add1); + glm_vec_copy(add1, pos[a]); + + _glm_atan3(zrot[a], zop[a], zadj[a], rot); + + { + mat4 scale0, trans0, rot0, rot1, rot2; +#define SCALE ((instance_closure_t *)ids[a]->closure)->scale_left +#define VALUE SCALE == 0.0f ? 1.0f : SCALE + glm_scale_make(scale0, (vec3){VALUE, VALUE, VALUE}); +#undef VALUE +#undef SCALE + glm_rotate_x(scale0, rot[0], rot0); + glm_rotate_y(rot0, rot[1], rot1); + glm_rotate_z(rot1, rot[2], rot2); + glm_translate_make(trans0, pos[a]); + glm_mat4_mul(trans0, rot2, *model[a]); + } + } + } + } + collisions_count = 0; +} + +void data_update() +{ + double this_frame = glfwGetTime(); + + handle_input(this_frame); + + assert((!pthread_mutex_lock(&data_data_mutex)) && "Update"); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + take_turn(ptr, this_frame); + + if (0) + { + material_0_ubo_t *ubo_0 = model_instance.obj.ubo; + mat4 model; + glm_mat4_copy(ubo_0->model, model); + glm_rotate_y(model, this_frame - previous_frame, ubo_0->model); + } + + previous_frame = this_frame; + + int err; + err = pthread_mutex_trylock(&collisions_mutex); + switch (err) + { + case 0: + if (collisions_count) + process_collisions(); + + assert((!pthread_cond_broadcast(&data_data_cond)) && "Update"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Update"); + + break; + case EBUSY: + break; + default: + assert((!err) && "pthread_mutex_trylock(&collisions_mutex): Update"); + } + + assert((!pthread_mutex_unlock(&data_data_mutex)) && "Update"); +} + +void data_exit() +{ + assert((!pthread_mutex_lock(&collisions_mutex)) && "Exit"); + assert((!pthread_cond_broadcast(&data_data_cond)) && "Exit"); + assert((!pthread_mutex_unlock(&collisions_mutex)) && "Exit"); + assert(!pthread_join(while_rendering_0, NULL)); + /* DELETE */ +} diff --git a/0012raytrace/vulkan.c b/0012raytrace/vulkan.c new file mode 100644 index 0000000..18b50dc --- /dev/null +++ b/0012raytrace/vulkan.c @@ -0,0 +1,1684 @@ +#include "data.h" +#include +#include + +VkExtent2D extent = {.width = 800, .height = 600}; + +/*********************************************** + * These are here if they need to be destroyed * + ***********************************************/ +VkInstance instance = VK_NULL_HANDLE; +VkSurfaceKHR surface = VK_NULL_HANDLE; +VkDevice device = VK_NULL_HANDLE; +VkSwapchainKHR swapchain = VK_NULL_HANDLE; +VkImage swapchain_images[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE}; +VkImageView swapchain_image_views[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkImage depth_stencil_image = VK_NULL_HANDLE; +VkDeviceMemory depth_stencil_image_memory = VK_NULL_HANDLE; +VkImageView depth_stencil_image_view = VK_NULL_HANDLE; +VkRenderPass render_pass = VK_NULL_HANDLE; +VkFramebuffer framebuffers[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, + VK_NULL_HANDLE}; +VkBuffer uniform_buffer = VK_NULL_HANDLE; +VkDeviceMemory uniform_buffer_memmory = VK_NULL_HANDLE; +VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; +VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; +VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; +VkSampler texture_image_sampler; +VkBuffer vertex_buffer = VK_NULL_HANDLE; +VkDeviceMemory vertex_buffer_memmory = VK_NULL_HANDLE; +VkBuffer index_buffer = VK_NULL_HANDLE; +VkDeviceMemory index_buffer_memmory = VK_NULL_HANDLE; +VkImageView *texture_image_views; +VkCommandPool command_pool = VK_NULL_HANDLE; +VkSemaphore wait_semaphore = VK_NULL_HANDLE; +VkFence queue_submit_fence = VK_NULL_HANDLE; +VkFence acquire_next_image_fence = VK_NULL_HANDLE; + +static void error_callback(int error, const char *description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +inline static void init_create_window() +{ + VkApplicationInfo application_info; + static const VkApplicationInfo EmptyVkApplicationInfo; + application_info = EmptyVkApplicationInfo; + application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + application_info.apiVersion = VK_API_VERSION_1_0; + application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1); + application_info.pApplicationName = "Cheako Vulkan Test 12"; + + glfwSetErrorCallback(error_callback); + assert(glfwInit()); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + data_window = glfwCreateWindow(extent.width, extent.height, + application_info.pApplicationName, NULL, NULL); + assert(glfwVulkanSupported()); + + VkInstanceCreateInfo instance_create_info; + static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo; + instance_create_info = EmptyVkInstanceCreateInfo; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &application_info; + + uint32_t glfwExtensionCount = 0; + const char **glfwExtensions; + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); + + instance_create_info.enabledExtensionCount = glfwExtensionCount; + instance_create_info.ppEnabledExtensionNames = glfwExtensions; + + VkResult err; + err = vkCreateInstance(&instance_create_info, NULL, &instance); + assert((err == VK_SUCCESS) && "vkCreateInstance: failed."); + + err = glfwCreateWindowSurface(instance, data_window, NULL, &surface); + assert(err == VK_SUCCESS && "glfwCreateWindowSurface: Failed."); +} + +inline static void +find_device_surface(VkPhysicalDevice *gpu, + VkPhysicalDeviceMemoryProperties *gpu_memory_properties) +{ + uint32_t gpu_count; + VkResult err; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); + assert((err == VK_SUCCESS) && gpu_count > 0 && + "vkEnumeratePhysicalDevices: Failed to count gpus."); + + { + VkPhysicalDevice gpus[gpu_count]; + err = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus); + assert((err == VK_SUCCESS) && + "vkEnumeratePhysicalDevices: Failed to discover gpus."); + /* for (size_t i = 0; i < gpu_count; i++) */ + { + /* TODO: This just selects first GPU. */ + *gpu = gpus[0]; + + VkSurfaceCapabilitiesKHR surface_capabilities; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*gpu, surface, + &surface_capabilities); + if (surface_capabilities.currentExtent.width < UINT32_MAX) + { + extent = surface_capabilities.currentExtent; + } + else + { + int width, height; + glfwGetWindowSize(data_window, &width, &height); + extent = (VkExtent2D){.width = width, .height = height}; + } + + vkGetPhysicalDeviceMemoryProperties(*gpu, gpu_memory_properties); + } + assert((*gpu != VK_NULL_HANDLE) && + "Vulkan ERROR: Usable device not found."); + } +} + +inline static void create_device_queu_family(VkPhysicalDevice gpu, + uint32_t *queue_family_index) +{ + uint32_t queue_count; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to count queue."); + VkQueueFamilyProperties queue_props[queue_count]; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + assert((queue_count > 0) && + "vkGetPhysicalDeviceQueueFamilyProperties: Failed to list queue."); + + *queue_family_index = UINT32_MAX; + for (size_t i = 0; i < queue_count; i++) + { + VkBool32 supports_present; + VkResult err; + err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, + &supports_present); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceSupportKHR: Failed."); + if (supports_present && (queue_props[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) + { + *queue_family_index = i; + break; + } + } + assert((*queue_family_index != UINT32_MAX) && + "Vulkan ERROR: Usable queue family not found."); + + static const float queue_priorities[1] = {1.0f}; + VkDeviceQueueCreateInfo device_queue_create_info; + static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo; + device_queue_create_info = EmptyVkDeviceQueueCreateInfo; + device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + device_queue_create_info.queueFamilyIndex = *queue_family_index; + device_queue_create_info.queueCount = 1; + device_queue_create_info.pQueuePriorities = queue_priorities; + + VkDeviceCreateInfo device_create_info; + static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo; + device_create_info = EmptyVkDeviceCreateInfo; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &device_queue_create_info; + device_create_info.enabledExtensionCount = 1; + const char *enable_extension_names[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + device_create_info.ppEnabledExtensionNames = enable_extension_names; + + VkResult err; + err = vkCreateDevice(gpu, &device_create_info, NULL, &device); + assert((err == VK_SUCCESS) && "vkCreateDevice: Failed."); +} + +inline static void discover_surface_format(VkPhysicalDevice gpu, + VkSurfaceFormatKHR *surface_format) +{ + VkResult err; + surface_format->format = VK_FORMAT_MAX_ENUM; + surface_format->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + uint32_t format_count; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, NULL); + assert((err == VK_SUCCESS) && (format_count > 0) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to count formats."); + VkSurfaceFormatKHR formats[format_count]; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &format_count, + formats); + assert((err == VK_SUCCESS) && + "vkGetPhysicalDeviceSurfaceFormatsKHR: Failed to list formats."); + + if (formats[0].format == VK_FORMAT_UNDEFINED) + { + surface_format->format = VK_FORMAT_B8G8R8A8_UNORM; + } + else + *surface_format = formats[0]; + assert((surface_format->format != VK_FORMAT_MAX_ENUM) && + "Vulkan ERROR: Usable surface format not found."); +} + +inline static void +fifo_or_mailbox_present_mode(VkPhysicalDevice gpu, + VkPresentModeKHR *present_mode, + uint32_t *swapchain_image_count) +{ + *present_mode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t mode_count; + VkResult err; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + NULL); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + { + VkPresentModeKHR modes[mode_count]; + err = vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &mode_count, + modes); + if ((err != VK_SUCCESS) && (mode_count > 0)) + return; + + for (size_t i = 0; i < mode_count; i++) + { + if (modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + { + *present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + *swapchain_image_count = 3; + return; + } + } + } +} + +inline static void create_swapchain(uint32_t swapchain_image_count, + VkSurfaceFormatKHR surface_format, + VkPresentModeKHR present_mode) +{ + VkSwapchainCreateInfoKHR swapchain_create_info; + static const VkSwapchainCreateInfoKHR EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info = EmptyVkSwapchainCreateInfoKHR; + swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchain_create_info.surface = surface; + swapchain_create_info.minImageCount = swapchain_image_count; + swapchain_create_info.imageFormat = surface_format.format; + swapchain_create_info.imageColorSpace = surface_format.colorSpace; + swapchain_create_info.imageExtent = extent; + swapchain_create_info.imageArrayLayers = 1; + swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = VK_NULL_HANDLE; + + VkResult err; + err = vkCreateSwapchainKHR(device, &swapchain_create_info, NULL, &swapchain); + assert((err == VK_SUCCESS) && "vkCreateSwapchainKHR: Failed."); +} + +inline static void +discover_swapchain_image_count(VkPresentModeKHR present_mode, + uint32_t *swapchain_image_count) +{ + uint32_t image_count = (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) ? 3 : 2; + VkResult err; + err = vkGetSwapchainImagesKHR(device, swapchain, swapchain_image_count, NULL); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to count swapchain images."); + assert((*swapchain_image_count == image_count) && + "vkGetSwapchainImagesKHR: Count swapchain images wrong."); + err = vkGetSwapchainImagesKHR(device, swapchain, &image_count, + swapchain_images); + assert((err == VK_SUCCESS) && + "vkGetSwapchainImagesKHR: Failed to get swapchain images."); + assert((image_count == *swapchain_image_count) && + "vkGetSwapchainImagesKHR: Get wrong count swapchain images."); +} + +inline static void +create_swapchain_image_views(VkSurfaceFormatKHR surface_format, + uint32_t swapchain_image_count) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = surface_format.format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + for (size_t i = 0; i < swapchain_image_count; i++) + { + image_view_create_info.image = swapchain_images[i]; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &swapchain_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed swapchain."); + } +} + +inline static void setup_swapchain(VkPhysicalDevice gpu, + VkSurfaceFormatKHR surface_format, + uint32_t *swapchain_image_count) +{ + VkPresentModeKHR present_mode; + fifo_or_mailbox_present_mode(gpu, &present_mode, swapchain_image_count); + create_swapchain(*swapchain_image_count, surface_format, present_mode); + discover_swapchain_image_count(present_mode, swapchain_image_count); + create_swapchain_image_views(surface_format, *swapchain_image_count); +} + +inline static void choose_depth_stencil_format(VkPhysicalDevice gpu, + VkFormat *depth_stencil_format) +{ + VkFormatProperties format_properties; + vkGetPhysicalDeviceFormatProperties(gpu, VK_FORMAT_D32_SFLOAT_S8_UINT, + &format_properties); + if ((format_properties.optimalTilingFeatures & + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + { + *depth_stencil_format = VK_FORMAT_D32_SFLOAT_S8_UINT; + return; + } + assert(0 && "vkGetPhysicalDeviceFormatProperties: Couldn't find usable depth " + "stencil format."); +} + +inline static void create_depth_stencil_image(VkFormat depth_stencil_format) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.format = depth_stencil_format; + image_create_info.extent.width = extent.width; + image_create_info.extent.height = extent.height; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &depth_stencil_image); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed depth stencil."); +} + +inline static void allocate_depth_stencil_memory( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, depth_stencil_image, + &image_memory_requirements); + + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate depth stencil memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + &depth_stencil_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed depth stencil."); + err = vkBindImageMemory(device, depth_stencil_image, + depth_stencil_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed depth stencil."); +} + +inline static void +create_depth_stencil_image_view(VkFormat depth_stencil_format) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.image = depth_stencil_image; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.format = depth_stencil_format; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &depth_stencil_image_view); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed depth stencil."); +} + +inline static void setup_depth_stencil_image( + VkPhysicalDevice gpu, VkFormat *depth_stencil_format, + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + choose_depth_stencil_format(gpu, depth_stencil_format); + create_depth_stencil_image(*depth_stencil_format); + allocate_depth_stencil_memory(gpu_memory_properties); + create_depth_stencil_image_view(*depth_stencil_format); +} + +inline static void create_render_pass(VkFormat depth_stencil_format, + VkSurfaceFormatKHR surface_format) +{ + VkAttachmentDescription attachments[2]; + static const VkAttachmentDescription EmptyVkAttachmentDescription; + attachments[0] = attachments[1] = EmptyVkAttachmentDescription; + attachments[0].format = depth_stencil_format; + attachments[1].format = surface_format.format; + attachments[0].samples = attachments[1].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[0].loadOp = attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachments[0].stencilLoadOp = attachments[1].stencilLoadOp = + VK_ATTACHMENT_LOAD_OP_CLEAR; + attachments[0].stencilStoreOp = attachments[1].stencilStoreOp = + VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[0].initialLayout = attachments[1].initialLayout = + VK_IMAGE_LAYOUT_UNDEFINED; + attachments[0].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference sub_passes_depth_stencil_attachment[1]; + static const VkAttachmentReference EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0] = EmptyVkAttachmentReference; + sub_passes_depth_stencil_attachment[0].attachment = 0; + sub_passes_depth_stencil_attachment[0].layout = + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + VkAttachmentReference sub_passes_color_attachments[1][1]; + sub_passes_color_attachments[0][0] = EmptyVkAttachmentReference; + sub_passes_color_attachments[0][0].attachment = 1; + sub_passes_color_attachments[0][0].layout = + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription sub_passes[1]; + static const VkSubpassDescription EmptyVkSubpassDescription; + sub_passes[0] = EmptyVkSubpassDescription; + sub_passes[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sub_passes[0].colorAttachmentCount = 1; + sub_passes[0].pColorAttachments = sub_passes_color_attachments[0]; + sub_passes[0].pDepthStencilAttachment = + &sub_passes_depth_stencil_attachment[0]; + + VkRenderPassCreateInfo render_pass_create_info; + static const VkRenderPassCreateInfo EmptyVkRenderPassCreateInfo; + render_pass_create_info = EmptyVkRenderPassCreateInfo; + render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + render_pass_create_info.attachmentCount = 2; + render_pass_create_info.pAttachments = attachments; + render_pass_create_info.subpassCount = 1; + render_pass_create_info.pSubpasses = sub_passes; + + VkResult err; + err = + vkCreateRenderPass(device, &render_pass_create_info, NULL, &render_pass); + assert((err == VK_SUCCESS) && "vkCreateRenderPass: Failed."); +} + +inline static void create_framebuffers(uint32_t swapchain_image_count) +{ + VkImageView attachments[] = {depth_stencil_image_view, VK_NULL_HANDLE}; + + VkFramebufferCreateInfo framebuffer_create_info; + static const VkFramebufferCreateInfo EmptyVkFramebufferCreateInfo; + framebuffer_create_info = EmptyVkFramebufferCreateInfo; + framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + framebuffer_create_info.renderPass = render_pass; + framebuffer_create_info.attachmentCount = 2; + framebuffer_create_info.pAttachments = attachments; + framebuffer_create_info.width = extent.width; + framebuffer_create_info.height = extent.height; + framebuffer_create_info.layers = 1; + + for (size_t i = 0; i < swapchain_image_count; i++) + { + attachments[1] = swapchain_image_views[i]; + + VkResult err; + err = vkCreateFramebuffer(device, &framebuffer_create_info, NULL, + &framebuffers[i]); + assert((err == VK_SUCCESS) && "vkCreateFramebuffer: Failed."); + } +} + +inline static void create_uniform_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = UNIFORM_SIZE + SHARED_UNIFORM_SIZE; + buffer_info_create.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &uniform_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed uniform buffer."); +} + +inline static void allocate_uniform_buffer( + VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, uniform_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for uniform."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &uniform_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed uniform buffer."); + + err = vkBindBufferMemory(device, uniform_buffer, uniform_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed uniform buffer."); +} + +inline static void +setup_uniform_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_uniform_buffer(); + allocate_uniform_buffer(gpu_memory_properties); + + VkResult err; + err = vkMapMemory(device, uniform_buffer_memmory, 0, + UNIFORM_SIZE + SHARED_UNIFORM_SIZE, 0, + (void **)&data_uniform_ptr); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed uniform buffer."); + data_model_shared_ubo = (struct shared_ubo *)(UNIFORM_SIZE + data_uniform_ptr); +} + +inline static void create_descriptor_set_layout() +{ + VkDescriptorSetLayoutBinding set_layout_bindings[3]; + static const VkDescriptorSetLayoutBinding EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layout_bindings[0].binding = 0; + set_layout_bindings[0].descriptorCount = 1; + + set_layout_bindings[2] = set_layout_bindings[0]; + set_layout_bindings[2].binding = 2; + + set_layout_bindings[1] = EmptyVkDescriptorSetLayoutBinding; + set_layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + set_layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layout_bindings[1].binding = 1; + set_layout_bindings[1].descriptorCount = 1; + + VkDescriptorSetLayoutCreateInfo set_layout_create_info; + static const VkDescriptorSetLayoutCreateInfo + EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info = EmptyVkDescriptorSetLayoutCreateInfo; + set_layout_create_info.sType = + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + set_layout_create_info.pBindings = set_layout_bindings; + set_layout_create_info.bindingCount = + sizeof(set_layout_bindings) / sizeof(set_layout_bindings[0]); + + VkResult err; + err = vkCreateDescriptorSetLayout(device, &set_layout_create_info, NULL, + &descriptor_set_layout); + assert((err == VK_SUCCESS) && "vkCreateDescriptorSetLayout: Failed."); +} + +inline static void create_descriptor_pool() +{ + VkDescriptorPoolSize pool_sizes[] = { + {VK_DESCRIPTOR_TYPE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000}, + {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000}, + {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000}}; + + VkDescriptorPoolCreateInfo pool_info; + static const VkDescriptorPoolCreateInfo EmptyVkDescriptorPoolCreateInfo; + pool_info = EmptyVkDescriptorPoolCreateInfo; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + pool_info.pPoolSizes = pool_sizes; + pool_info.maxSets = pool_sizes[0].descriptorCount * pool_info.poolSizeCount; + + VkResult err; + err = vkCreateDescriptorPool(device, &pool_info, NULL, &descriptor_pool); + assert((err == VK_SUCCESS) && "vkCreateDescriptorPool: Failed."); +} + +inline static void allocate_descriptor_set(VkDescriptorSet *descriptor_set) +{ + VkDescriptorSetAllocateInfo alloc_info; + static const VkDescriptorSetAllocateInfo EmptyVkDescriptorSetAllocateInfo; + alloc_info = EmptyVkDescriptorSetAllocateInfo; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.pSetLayouts = &descriptor_set_layout; + alloc_info.descriptorSetCount = 1; + + VkResult err; + err = vkAllocateDescriptorSets(device, &alloc_info, descriptor_set); + assert((err == VK_SUCCESS) && "vkAllocateDescriptorSets: Failed."); +} + +inline static void update_descriptor_set(uniform_map_t *map, size_t material) +{ + VkDescriptorBufferInfo uniform_descriptors[2]; + static const VkDescriptorBufferInfo EmptyVkDescriptorBufferInfo; + uniform_descriptors[0] = EmptyVkDescriptorBufferInfo; + uniform_descriptors[0].buffer = uniform_buffer; + uniform_descriptors[0].offset = FROM_UNIFORM_ALLOC(map->offset); + uniform_descriptors[0].range = FROM_UNIFORM_ALLOC(map->range); + + uniform_descriptors[1] = uniform_descriptors[0]; + uniform_descriptors[1].offset = UNIFORM_SIZE; + uniform_descriptors[1].range = SHARED_UNIFORM_SIZE; + + VkWriteDescriptorSet write_descriptor_sets[3]; + static const VkWriteDescriptorSet EmptyVkWriteDescriptorSet; + write_descriptor_sets[0] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[0].dstSet = map->descriptor_set; + write_descriptor_sets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write_descriptor_sets[0].dstBinding = 0; + write_descriptor_sets[0].pBufferInfo = &uniform_descriptors[0]; + write_descriptor_sets[0].descriptorCount = 1; + + write_descriptor_sets[2] = write_descriptor_sets[0]; + write_descriptor_sets[2].dstBinding = 2; + write_descriptor_sets[2].pBufferInfo = &uniform_descriptors[1]; + + VkDescriptorImageInfo image_info; + static const VkDescriptorImageInfo EmptyVkDescriptorImageInfo; + image_info = EmptyVkDescriptorImageInfo; + image_info.imageView = texture_image_views[material]; + image_info.sampler = texture_image_sampler; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + write_descriptor_sets[1] = EmptyVkWriteDescriptorSet; + write_descriptor_sets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_descriptor_sets[1].dstSet = map->descriptor_set; + write_descriptor_sets[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_descriptor_sets[1].dstBinding = 1; + write_descriptor_sets[1].pImageInfo = &image_info; + write_descriptor_sets[1].descriptorCount = 1; + + vkUpdateDescriptorSets( + device, sizeof(write_descriptor_sets) / sizeof(write_descriptor_sets[0]), + write_descriptor_sets, 0, NULL); +} + +void setup_model_instance(data_model_instance_t *inst) +{ + uniform_map_t *this_map; + this_map = list_entry(inst->uniform_map, uniform_map_t, list); + if (this_map->descriptor_set == VK_NULL_HANDLE) + allocate_descriptor_set(&this_map->descriptor_set); + update_descriptor_set(this_map, data_models[inst->model].material); +} + +inline static void create_pipeline_layout() +{ + VkPipelineLayoutCreateInfo pipeline_layout_create_info; + static const VkPipelineLayoutCreateInfo EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info = EmptyVkPipelineLayoutCreateInfo; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout; + + VkResult err; + err = vkCreatePipelineLayout(device, &pipeline_layout_create_info, NULL, + &pipeline_layout); + assert((err == VK_SUCCESS) && "vkCreatePipelineLayout: Failed."); +} + +inline static void create_texture_image_sampler() +{ + VkSamplerCreateInfo sampler_info; + static const VkSamplerCreateInfo EmptyVkSamplerCreateInfo; + sampler_info = EmptyVkSamplerCreateInfo; + sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.magFilter = VK_FILTER_LINEAR; + sampler_info.minFilter = VK_FILTER_LINEAR; + sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler_info.anisotropyEnable = VK_FALSE; + sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + sampler_info.unnormalizedCoordinates = VK_FALSE; + sampler_info.compareEnable = VK_FALSE; + sampler_info.compareOp = VK_COMPARE_OP_ALWAYS; + sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_info.mipLodBias = 0.0f; + sampler_info.minLod = 0.0f; + sampler_info.maxLod = 0.0f; + + VkResult err; + err = + vkCreateSampler(device, &sampler_info, NULL, &texture_image_sampler); + assert((err == VK_SUCCESS) && "vkCreateSampler: Failed."); +} + +inline static void setup_descriptor_set() +{ + create_descriptor_set_layout(); + create_descriptor_pool(); + create_pipeline_layout(); + create_texture_image_sampler(); +} + +inline static void create_vertex_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_vertex_size; + buffer_info_create.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &vertex_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed vertex buffer."); +} + +inline static void +allocate_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, vertex_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for vertex."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &vertex_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed vertex buffer."); + + err = vkBindBufferMemory(device, vertex_buffer, vertex_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed vertex buffer."); +} + +inline static void +setup_vertex_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_vertex_buffer(); + allocate_vertex_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, vertex_buffer_memmory, 0, data_model_vertex_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed vertex buffer."); + + memcpy(data, data_model_vertex, data_model_vertex_size); + + vkUnmapMemory(device, vertex_buffer_memmory); +} + +inline static void create_index_buffer() +{ + VkBufferCreateInfo buffer_info_create; + static const VkBufferCreateInfo EmptyVkBufferCreateInfo; + buffer_info_create = EmptyVkBufferCreateInfo; + buffer_info_create.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info_create.size = data_model_index_size; + buffer_info_create.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info_create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkResult err; + err = vkCreateBuffer(device, &buffer_info_create, NULL, &index_buffer); + assert((err == VK_SUCCESS) && "vkCreateBuffer: Failed index buffer."); +} + +inline static void +allocate_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + VkMemoryRequirements mememory_requirements; + vkGetBufferMemoryRequirements(device, index_buffer, &mememory_requirements); + + VkMemoryAllocateInfo allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + allocate_info = EmptyVkMemoryAllocateInfo; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = mememory_requirements.size; + + allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; ++i) + { + if ((mememory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + allocate_info.memoryTypeIndex = i; + break; + } + } + assert((allocate_info.memoryTypeIndex != UINT32_MAX) && + "Failed to find suitable memory type for index."); + + VkResult err; + err = vkAllocateMemory(device, &allocate_info, NULL, &index_buffer_memmory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed index buffer."); + + err = vkBindBufferMemory(device, index_buffer, index_buffer_memmory, 0); + assert((err == VK_SUCCESS) && "vkBindBufferMemory: Failed index buffer."); +} + +inline static void +setup_index_buffer(VkPhysicalDeviceMemoryProperties gpu_memory_properties) +{ + create_index_buffer(); + allocate_index_buffer(gpu_memory_properties); + + void *data; + VkResult err; + err = vkMapMemory(device, index_buffer_memmory, 0, data_model_index_size, 0, + &data); + assert((err == VK_SUCCESS) && "vkMapMemory: Failed index buffer."); + + memcpy(data, data_model_index, data_model_index_size); + + vkUnmapMemory(device, index_buffer_memmory); +} + +inline static void create_texture_images(VkImage *texture_images) +{ + VkImageCreateInfo image_create_info; + static const VkImageCreateInfo EmptyVkImageViewCreateInfo; + image_create_info = EmptyVkImageViewCreateInfo; + image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_create_info.imageType = VK_IMAGE_TYPE_2D; + image_create_info.extent.depth = 1; + image_create_info.mipLevels = 1; + image_create_info.arrayLayers = 1; + image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_create_info.tiling = VK_IMAGE_TILING_LINEAR; + image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_create_info.queueFamilyIndexCount = VK_QUEUE_FAMILY_IGNORED; + image_create_info.pQueueFamilyIndices = NULL; + image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_create_info.format = data_materials[i].texture_format; + image_create_info.extent.width = data_materials[i].texture_width; + image_create_info.extent.height = data_materials[i].texture_height; + VkResult err; + err = vkCreateImage(device, &image_create_info, NULL, &texture_images[i]); + assert((err == VK_SUCCESS) && "vkCreateImage: Failed texture."); + } +} + +inline static void +allocate_texture_image(VkImage texture_image, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memory) +{ + VkMemoryAllocateInfo memory_allocate_info; + static const VkMemoryAllocateInfo EmptyVkMemoryAllocateInfo; + memory_allocate_info = EmptyVkMemoryAllocateInfo; + memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + + VkMemoryRequirements image_memory_requirements; + vkGetImageMemoryRequirements(device, texture_image, + &image_memory_requirements); + memory_allocate_info.allocationSize = image_memory_requirements.size; + + memory_allocate_info.memoryTypeIndex = UINT32_MAX; + for (size_t i = 0; i < gpu_memory_properties.memoryTypeCount; i++) + { + if ((image_memory_requirements.memoryTypeBits & (1 << i)) && + ((gpu_memory_properties.memoryTypes[i].propertyFlags & + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) == + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))) + { + memory_allocate_info.memoryTypeIndex = i; + break; + } + } + assert((memory_allocate_info.memoryTypeIndex != UINT32_MAX) && + "Couldn't locate texture memory."); + + VkResult err; + err = vkAllocateMemory(device, &memory_allocate_info, NULL, + texture_image_memory); + assert((err == VK_SUCCESS) && "vkAllocateMemory: Failed texture."); + err = vkBindImageMemory(device, texture_image, *texture_image_memory, 0); + assert((err == VK_SUCCESS) && "vkBindImageMemory: Failed texture."); +} + +inline static void +setup_texture_images(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + create_texture_images(texture_images); + for (size_t i = 0; i < data_materials_count; i++) + { + allocate_texture_image(texture_images[i], gpu_memory_properties, + &texture_image_memorys[i]); + + void *data; + vkMapMemory(device, texture_image_memorys[i], 0, + data_materials[i].texture_size, 0, &data); + memcpy(data, data_materials[i].texture, data_materials[i].texture_size); + vkUnmapMemory(device, texture_image_memorys[i]); + } +} + +inline static void create_image_views(VkImage *texture_images) +{ + VkImageViewCreateInfo image_view_create_info; + static const VkImageViewCreateInfo EmptyVkImageViewCreateInfo; + image_view_create_info = EmptyVkImageViewCreateInfo; + image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + image_view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + image_view_create_info.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_COLOR_BIT; + image_view_create_info.subresourceRange.baseMipLevel = 0; + image_view_create_info.subresourceRange.levelCount = 1; + image_view_create_info.subresourceRange.baseArrayLayer = 0; + image_view_create_info.subresourceRange.layerCount = 1; + + for (size_t i = 0; i < data_materials_count; i++) + { + image_view_create_info.image = texture_images[i]; + image_view_create_info.format = data_materials[i].texture_format; + VkResult err; + err = vkCreateImageView(device, &image_view_create_info, NULL, + &texture_image_views[i]); + assert((err == VK_SUCCESS) && "vkCreateImageView: Failed texture."); + } +} + +inline static void +setup_textures(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys) +{ + setup_texture_images(texture_images, gpu_memory_properties, + texture_image_memorys); + create_image_views(texture_images); +} + +inline static void create_shaders(VkShaderModule *vert_modules, + VkShaderModule *frag_modules) +{ + VkShaderModuleCreateInfo shader_module_create_info; + static const VkShaderModuleCreateInfo EmptyVkShaderModuleCreateInfo; + shader_module_create_info = EmptyVkShaderModuleCreateInfo; + shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_module_create_info.codeSize = *data_material_shaders[i].vert.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].vert.spv; + VkResult err; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &vert_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed vert."); + + shader_module_create_info.codeSize = *data_material_shaders[i].frag.size; + shader_module_create_info.pCode = + (uint32_t *)data_material_shaders[i].frag.spv; + err = vkCreateShaderModule(device, &shader_module_create_info, NULL, + &frag_modules[i]); + assert((err == VK_SUCCESS) && "vkCreateShaderModule: Failed frag."); + } +} + +inline static void create_graphice_pipelines(VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + VkPipelineShaderStageCreateInfo shader_stages_create_info[2]; + static const VkPipelineShaderStageCreateInfo + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0] = shader_stages_create_info[1] = + EmptyVkPipelineShaderStageCreateInfo; + shader_stages_create_info[0].sType = shader_stages_create_info[1].sType = + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stages_create_info[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stages_create_info[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shader_stages_create_info[0].pName = shader_stages_create_info[1].pName = + "main"; + + VkPipelineVertexInputStateCreateInfo vertex_input_create_info; + static const VkPipelineVertexInputStateCreateInfo + EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info = EmptyVkPipelineVertexInputStateCreateInfo; + vertex_input_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_create_info.vertexBindingDescriptionCount = 1; + vertex_input_create_info.pVertexBindingDescriptions = + &data_binding_description; + vertex_input_create_info.vertexAttributeDescriptionCount = + data_attribute_descriptions_count; + vertex_input_create_info.pVertexAttributeDescriptions = + data_attribute_descriptions; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info; + static const VkPipelineInputAssemblyStateCreateInfo + EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info = EmptyVkPipelineInputAssemblyStateCreateInfo; + input_assembly_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport = (VkViewport){.x = 0.0f, + .y = 0.0f, + .width = extent.width, + .height = extent.height, + .minDepth = 0.0f, + .maxDepth = 1.0f}; + + VkRect2D scissor; + static const VkRect2D EmptyVkRect2D; + scissor = EmptyVkRect2D; + scissor = (VkRect2D){.offset = {0, 0}, .extent = extent}; + + VkPipelineViewportStateCreateInfo viewport_state_create_info; + static const VkPipelineViewportStateCreateInfo + EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info = EmptyVkPipelineViewportStateCreateInfo; + viewport_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_state_create_info.viewportCount = 1; + viewport_state_create_info.pViewports = &viewport; + viewport_state_create_info.scissorCount = 1; + viewport_state_create_info.pScissors = &scissor; + + VkPipelineRasterizationStateCreateInfo rasterization_create_info; + static const VkPipelineRasterizationStateCreateInfo + EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info = EmptyVkPipelineRasterizationStateCreateInfo; + rasterization_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterization_create_info.depthClampEnable = VK_FALSE; + rasterization_create_info.rasterizerDiscardEnable = VK_FALSE; + rasterization_create_info.polygonMode = VK_POLYGON_MODE_FILL; + rasterization_create_info.lineWidth = 1.0f; + rasterization_create_info.cullMode = VK_CULL_MODE_BACK_BIT; + rasterization_create_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterization_create_info.depthBiasEnable = VK_FALSE; + + VkPipelineMultisampleStateCreateInfo multisampling_create_info; + static const VkPipelineMultisampleStateCreateInfo + EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info = EmptyVkPipelineMultisampleStateCreateInfo; + multisampling_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling_create_info.sampleShadingEnable = VK_FALSE; + multisampling_create_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_stencil_create_info; + static const VkPipelineDepthStencilStateCreateInfo + EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info = EmptyVkPipelineDepthStencilStateCreateInfo; + depth_stencil_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil_create_info.depthTestEnable = VK_TRUE; + depth_stencil_create_info.depthWriteEnable = VK_TRUE; + depth_stencil_create_info.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil_create_info.depthBoundsTestEnable = VK_FALSE; + depth_stencil_create_info.minDepthBounds = 0.0f; + depth_stencil_create_info.maxDepthBounds = 1.0f; + depth_stencil_create_info.stencilTestEnable = VK_FALSE; + + VkPipelineColorBlendAttachmentState color_blend_attachment; + static const VkPipelineColorBlendAttachmentState + EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment = EmptyVkPipelineColorBlendAttachmentState; + color_blend_attachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + color_blend_attachment.blendEnable = VK_FALSE; + + VkPipelineColorBlendStateCreateInfo color_blending_create_info; + static const VkPipelineColorBlendStateCreateInfo + EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info = EmptyVkPipelineColorBlendStateCreateInfo; + color_blending_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blending_create_info.logicOpEnable = VK_FALSE; + color_blending_create_info.attachmentCount = 1; + color_blending_create_info.pAttachments = &color_blend_attachment; + + VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_LINE_WIDTH}; + + VkPipelineDynamicStateCreateInfo dynamic_state_create_info; + static const VkPipelineDynamicStateCreateInfo + EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info = EmptyVkPipelineDynamicStateCreateInfo; + dynamic_state_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_create_info.dynamicStateCount = 2; + dynamic_state_create_info.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo pipeline_create_info; + static const VkGraphicsPipelineCreateInfo EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info = EmptyVkGraphicsPipelineCreateInfo; + pipeline_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline_create_info.stageCount = 2; + pipeline_create_info.pStages = shader_stages_create_info; + pipeline_create_info.pVertexInputState = &vertex_input_create_info; + pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; + pipeline_create_info.pViewportState = &viewport_state_create_info; + pipeline_create_info.pRasterizationState = &rasterization_create_info; + pipeline_create_info.pMultisampleState = &multisampling_create_info; + pipeline_create_info.pDepthStencilState = &depth_stencil_create_info; + pipeline_create_info.pColorBlendState = &color_blending_create_info; + pipeline_create_info.pDynamicState = &dynamic_state_create_info; + pipeline_create_info.layout = pipeline_layout; + pipeline_create_info.renderPass = render_pass; + pipeline_create_info.subpass = 0; + + for (size_t i = 0; i < data_material_shaders_count; i++) + { + shader_stages_create_info[0].module = vert_modules[i]; + shader_stages_create_info[1].module = frag_modules[i]; + VkResult err; + err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, + &pipeline_create_info, NULL, + &graphics_pipelines[i]); + assert((err == VK_SUCCESS) && "vkCreateGraphicsPipelines: Failed."); + } +} + +inline static void setup_materials(VkImage *texture_images, + VkPhysicalDeviceMemoryProperties gpu_memory_properties, + VkDeviceMemory *texture_image_memorys, + VkShaderModule *vert_modules, + VkShaderModule *frag_modules, + VkPipeline *graphics_pipelines) +{ + setup_textures(texture_images, gpu_memory_properties, texture_image_memorys); + create_shaders(vert_modules, frag_modules); + create_graphice_pipelines(vert_modules, frag_modules, graphics_pipelines); +} + +inline static void create_command_pool(uint32_t queue_family_index) +{ + VkCommandPoolCreateInfo pool_create_info; + static const VkCommandPoolCreateInfo EmptyVkCommandPoolCreateInfo; + pool_create_info = EmptyVkCommandPoolCreateInfo; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.queueFamilyIndex = queue_family_index; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult err; + err = vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool); + assert((err == VK_SUCCESS) && "vkCreateCommandPool: Failed."); +} + +inline static void allocate_command_buffers(VkCommandBuffer *command_buffer) +{ + VkCommandBufferAllocateInfo command_buffer_allocate_info; + static const VkCommandBufferAllocateInfo EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info = EmptyVkCommandBufferAllocateInfo; + command_buffer_allocate_info.sType = + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + command_buffer_allocate_info.commandPool = command_pool; + command_buffer_allocate_info.commandBufferCount = 1; + command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + + VkResult err; + err = vkAllocateCommandBuffers(device, &command_buffer_allocate_info, + command_buffer); + assert((err == VK_SUCCESS) && "vkAllocateCommandBuffers: Failed."); +} + +inline static void create_presentation_semaphore() +{ + VkSemaphoreCreateInfo semaphore_create_info; + static const VkSemaphoreCreateInfo EmptyVkSemaphoreCreateInfo; + semaphore_create_info = EmptyVkSemaphoreCreateInfo; + semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + vkCreateSemaphore(device, &semaphore_create_info, NULL, &wait_semaphore); +} + +inline static void create_queue_submit_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, &queue_submit_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void create_acquire_next_image_fence() +{ + VkFenceCreateInfo fence_create_info; + static const VkFenceCreateInfo EmptyVkFenceCreateInfo; + fence_create_info = EmptyVkFenceCreateInfo; + fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + + VkResult err; + err = vkCreateFence(device, &fence_create_info, NULL, + &acquire_next_image_fence); + assert((err == VK_SUCCESS) && "vkCreateFence: Failed."); +} + +inline static void +get_next_swapchain_image(VkQueue queue, uint32_t *active_swapchain_image_id) +{ + VkResult err; + err = vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, 0, + acquire_next_image_fence, + active_swapchain_image_id); + assert((err == VK_SUCCESS) && "vkAcquireNextImageKHR: Failed."); + err = vkWaitForFences(device, 1, &acquire_next_image_fence, VK_FALSE, + UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed acquire next image."); + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from render loop."); +} + +inline static void begin_command_buffer(VkCommandBuffer command_buffer) +{ + VkCommandBufferBeginInfo command_buffer_begin_info; + static const VkCommandBufferBeginInfo EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info = EmptyVkCommandBufferBeginInfo; + command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + + VkResult err; + err = vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info); + assert((err == VK_SUCCESS) && "vkBeginCommandBuffer: Failed."); +} + +inline static void image_barriers(VkCommandBuffer command_buffer, VkImage *texture_images) +{ + VkImageMemoryBarrier barriers[1]; + static const VkImageMemoryBarrier EmptyVkImageMemoryBarrier; + barriers[0] = EmptyVkImageMemoryBarrier; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barriers[0].image = texture_images[0]; + barriers[0].subresourceRange = (VkImageSubresourceRange){VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + vkCmdPipelineBarrier( + command_buffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, + 0, VK_NULL_HANDLE, + 0, VK_NULL_HANDLE, + 1, barriers); +} + +inline static void begin_render_pass(VkCommandBuffer command_buffer, + uint32_t active_swapchain_image_id) +{ + VkRect2D render_area; + static const VkRect2D EmptyVkRect2D; + render_area = EmptyVkRect2D; + render_area.offset.x = 0; + render_area.offset.y = 0; + render_area.extent = extent; + + VkClearValue clear_values[2]; + static const VkClearValue EmptyVkClearValue; + clear_values[0] = clear_values[1] = EmptyVkClearValue; + clear_values[0].depthStencil.depth = 1.0f; + clear_values[0].depthStencil.stencil = 0; + clear_values[1].color.float32[0] = 1.0f; + clear_values[1].color.float32[1] = 0.0f; + clear_values[1].color.float32[2] = 0.0f; + clear_values[1].color.float32[3] = 0.0f; + + VkRenderPassBeginInfo render_pass_begin_info; + static const VkRenderPassBeginInfo EmptyVkRenderPassBeginInfo; + render_pass_begin_info = EmptyVkRenderPassBeginInfo; + render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + render_pass_begin_info.renderPass = render_pass; + render_pass_begin_info.framebuffer = framebuffers[active_swapchain_image_id]; + render_pass_begin_info.renderArea = render_area; + render_pass_begin_info.clearValueCount = 2; + render_pass_begin_info.pClearValues = clear_values; + + vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, + VK_SUBPASS_CONTENTS_INLINE); +} + +inline static void set_viewport(VkCommandBuffer command_buffer) +{ + VkViewport viewport; + static const VkViewport EmptyVkViewport; + viewport = EmptyVkViewport; + viewport.maxDepth = 1.0f; + viewport.minDepth = 0.0f; + viewport.width = extent.width; + viewport.height = extent.height; + viewport.x = 0; + viewport.y = 0; + + vkCmdSetViewport(command_buffer, 0, 1, &viewport); +} + +inline static void record_commands(VkCommandBuffer command_buffer, VkImage *texture_images, + uint32_t active_swapchain_image_id, + VkPipeline *graphics_pipelines) +{ + begin_command_buffer(command_buffer); + + static bool init = true; + if (init) + image_barriers(command_buffer, texture_images); + init = false; + + begin_render_pass(command_buffer, active_swapchain_image_id); + set_viewport(command_buffer); + + static const VkDeviceSize ZeroVkDeviceSize = 0; + vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, + &ZeroVkDeviceSize); + + vkCmdBindIndexBuffer(command_buffer, index_buffer, 0, VK_INDEX_TYPE_UINT32); + + size_t bound_shaders = SIZE_MAX; + data_model_instance_t *inst; + list_for_each_entry(inst, &data_model_instances, list) + { + if (bound_shaders != + data_materials[data_models[inst->model].material].shader) + { + vkCmdBindPipeline( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + graphics_pipelines[data_materials[data_models[inst->model].material] + .shader]); + bound_shaders = data_materials[data_models[inst->model].material].shader; + } + + vkCmdBindDescriptorSets( + command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &list_entry(inst->uniform_map, uniform_map_t, list) + ->descriptor_set, + 0, NULL); + + vkCmdDrawIndexed(command_buffer, data_models[inst->model].count, 1, + data_models[inst->model].first, 0, 0); + } + vkCmdEndRenderPass(command_buffer); + + VkResult err; + err = vkEndCommandBuffer(command_buffer); + assert((err == VK_SUCCESS) && "vkEndCommandBuffer: Failed."); +} + +inline static void submit_queue(VkQueue queue, VkCommandBuffer command_buffer) +{ + VkSubmitInfo submit_info; + static const VkSubmitInfo EmptyVkSubmitInfo; + submit_info = EmptyVkSubmitInfo; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; + submit_info.signalSemaphoreCount = 1; + submit_info.pSignalSemaphores = &wait_semaphore; + + VkResult err; + err = vkQueueSubmit(queue, 1, &submit_info, queue_submit_fence); + assert((err == VK_SUCCESS) && "vkQueueSubmit: Failed."); +} + +inline static void fences() +{ + VkResult err; + err = vkWaitForFences(device, 1, &queue_submit_fence, VK_FALSE, UINT64_MAX); + assert((err == VK_SUCCESS) && "vkWaitForFences: Failed queue submit."); + + err = vkResetFences( + device, 2, (VkFence[]){acquire_next_image_fence, queue_submit_fence}); + assert((err == VK_SUCCESS) && "vkResetFences: Failed."); +} + +inline static void present_image(VkQueue queue, + uint32_t *active_swapchain_image_id) +{ + VkResult present_results[1]; + VkPresentInfoKHR present_info; + static const VkPresentInfoKHR EmptyPresentInfoKHR; + present_info = EmptyPresentInfoKHR; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present_info.waitSemaphoreCount = 1; + present_info.pWaitSemaphores = &wait_semaphore; + present_info.swapchainCount = 1; + present_info.pSwapchains = &swapchain; + present_info.pImageIndices = active_swapchain_image_id; + present_info.pResults = present_results; + + VkResult err; + err = vkQueuePresentKHR(queue, &present_info); + assert((err == VK_SUCCESS) && "vkQueuePresentKHR: Failed."); + assert((present_results[0] == VK_SUCCESS) && + "vkQueuePresentKHR results: Failed."); +} + +inline static void blocking_render_loop(uint32_t queue_family_index, + VkImage *texture_images, + VkPipeline *graphics_pipelines) +{ + VkCommandBuffer command_buffer; + allocate_command_buffers(&command_buffer); + create_presentation_semaphore(); + create_queue_submit_fence(); + create_acquire_next_image_fence(); + + VkQueue queue; + vkGetDeviceQueue(device, queue_family_index, VK_NULL_HANDLE, &queue); + + while (!glfwWindowShouldClose(data_window)) + { + glfwPollEvents(); + + data_update(); + + uint32_t active_swapchain_image_id; + get_next_swapchain_image(queue, &active_swapchain_image_id); + + VkResult err; + err = vkResetCommandPool(device, command_pool, 0); + assert((err == VK_SUCCESS) && "vkResetCommandPool: Failed."); + record_commands(command_buffer, texture_images, + active_swapchain_image_id, + graphics_pipelines); + submit_queue(queue, command_buffer); + fences(); + present_image(queue, &active_swapchain_image_id); + + err = vkQueueWaitIdle(queue); + assert((err == VK_SUCCESS) && "vkQueueWaitIdle: Failed from bottom half."); + } + vkFreeCommandBuffers(device, command_pool, 1, &command_buffer); +} + +inline static void +clean_up(VkImage *texture_images, VkDeviceMemory *texture_image_memorys, + VkPipeline *graphics_pipelines, VkShaderModule *frag_modules, + VkShaderModule *vert_modules, uint32_t swapchain_image_count) +{ + vkDestroyFence(device, acquire_next_image_fence, NULL); + acquire_next_image_fence = VK_NULL_HANDLE; + vkDestroyFence(device, queue_submit_fence, NULL); + queue_submit_fence = VK_NULL_HANDLE; + vkDestroySemaphore(device, wait_semaphore, NULL); + wait_semaphore = VK_NULL_HANDLE; + vkDestroyCommandPool(device, command_pool, NULL); + command_pool = VK_NULL_HANDLE; + for (size_t i = 0; i < data_material_shaders_count; i++) + { + vkDestroyPipeline(device, graphics_pipelines[i], NULL); + graphics_pipelines[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, frag_modules[i], NULL); + frag_modules[i] = VK_NULL_HANDLE; + vkDestroyShaderModule(device, vert_modules[i], NULL); + vert_modules[i] = VK_NULL_HANDLE; + } + vkDestroySampler(device, texture_image_sampler, NULL); + texture_image_sampler = VK_NULL_HANDLE; + for (size_t i = 0; i < data_materials_count; i++) + { + vkDestroyImageView(device, texture_image_views[i], NULL); + texture_image_views[i] = VK_NULL_HANDLE; + vkFreeMemory(device, texture_image_memorys[i], NULL); + texture_image_memorys[i] = VK_NULL_HANDLE; + vkDestroyImage(device, texture_images[i], NULL); + texture_images[i] = VK_NULL_HANDLE; + } + vkFreeMemory(device, index_buffer_memmory, NULL); + index_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, index_buffer, NULL); + index_buffer = VK_NULL_HANDLE; + vkFreeMemory(device, vertex_buffer_memmory, NULL); + vertex_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, vertex_buffer, NULL); + vertex_buffer = VK_NULL_HANDLE; + vkDestroyPipelineLayout(device, pipeline_layout, NULL); + pipeline_layout = VK_NULL_HANDLE; + vkDestroyDescriptorPool(device, descriptor_pool, NULL); + descriptor_pool = VK_NULL_HANDLE; + vkDestroyDescriptorSetLayout(device, descriptor_set_layout, NULL); + descriptor_set_layout = VK_NULL_HANDLE; + vkUnmapMemory(device, uniform_buffer_memmory); + data_model_instance_t *ptr; + list_for_each_entry(ptr, &data_model_instances, list) + { + ptr->ubo = NULL; + list_entry(ptr->uniform_map, uniform_map_t, list)->descriptor_set = + VK_NULL_HANDLE; + } + vkFreeMemory(device, uniform_buffer_memmory, NULL); + uniform_buffer_memmory = VK_NULL_HANDLE; + vkDestroyBuffer(device, uniform_buffer, NULL); + uniform_buffer = VK_NULL_HANDLE; + for (size_t i = 0; i < swapchain_image_count; i++) + { + vkDestroyFramebuffer(device, framebuffers[i], NULL); + framebuffers[i] = VK_NULL_HANDLE; + vkDestroyImageView(device, swapchain_image_views[i], NULL); + swapchain_image_views[i] = VK_NULL_HANDLE; + } + vkDestroyRenderPass(device, render_pass, NULL); + render_pass = VK_NULL_HANDLE; + vkDestroyImageView(device, depth_stencil_image_view, NULL); + depth_stencil_image_view = VK_NULL_HANDLE; + vkFreeMemory(device, depth_stencil_image_memory, NULL); + depth_stencil_image_memory = VK_NULL_HANDLE; + vkDestroyImage(device, depth_stencil_image, NULL); + depth_stencil_image = VK_NULL_HANDLE; + vkDestroySwapchainKHR(device, swapchain, NULL); + swapchain = VK_NULL_HANDLE; + vkDestroyDevice(device, NULL); + device = VK_NULL_HANDLE; + vkDestroySurfaceKHR(instance, surface, NULL); + surface = VK_NULL_HANDLE; + vkDestroyInstance(instance, NULL); + instance = VK_NULL_HANDLE; + + data_exit(); + + glfwDestroyWindow(data_window); + + glfwTerminate(); +} + +int main(int argc, char *argv[]) +{ + init_create_window(); + VkPhysicalDevice gpu = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties gpu_memory_properties; + find_device_surface(&gpu, &gpu_memory_properties); + + uint32_t queue_family_index; + create_device_queu_family(gpu, &queue_family_index); + + VkSurfaceFormatKHR surface_format; + discover_surface_format(gpu, &surface_format); + uint32_t swapchain_image_count = 2; + setup_swapchain(gpu, surface_format, &swapchain_image_count); + + VkFormat depth_stencil_format; + setup_depth_stencil_image(gpu, &depth_stencil_format, gpu_memory_properties); + create_render_pass(depth_stencil_format, surface_format); + + create_framebuffers(swapchain_image_count); + + setup_uniform_buffer(gpu_memory_properties); + setup_descriptor_set(); + + setup_vertex_buffer(gpu_memory_properties); + setup_index_buffer(gpu_memory_properties); + + VkImage texture_images[data_materials_count]; + VkDeviceMemory texture_image_memorys[data_materials_count]; + VkImageView _texture_image_views[data_materials_count]; + texture_image_views = _texture_image_views; + VkShaderModule vert_modules[data_material_shaders_count]; + VkShaderModule frag_modules[data_material_shaders_count]; + VkPipeline graphics_pipelines[data_material_shaders_count]; + setup_materials(texture_images, gpu_memory_properties, texture_image_memorys, vert_modules, frag_modules, graphics_pipelines); + + data_setup_model_instance = setup_model_instance; + data_init(extent); + + create_command_pool(queue_family_index); + blocking_render_loop(queue_family_index, texture_images, graphics_pipelines); + + clean_up(texture_images, texture_image_memorys, graphics_pipelines, + frag_modules, vert_modules, swapchain_image_count); + exit(0); +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..23879f9 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +# Makefile for cheako-vulkan + +TOPTARGETS := all clean + +SUBDIRS := $(shell dirname $(sort $(wildcard 0*/.))) + +$(TOPTARGETS): lib $(SUBDIRS) +lib $(SUBDIRS): + $(MAKE) -C $@ $(filter $(TOPTARGETS),$(MAKECMDGOALS)) + +DISTDIFFS := $(addsuffix .diff,$(filter-out $(firstword $(SUBDIRS)),$(SUBDIRS))) +dist: + $(MAKE) clean + rm -f */*.orig */*.rej */data_dynamic.c */imgui.ini */default_js.h + rm -f 0*.diff + $(MAKE) $(DISTDIFFS) +$(DISTDIFFS): + diff -bNur $(shell echo $(basename $@) $(SUBDIRS) | tr \\n \ | awk -vRS=' ' '!f { f=$$0; next; }; $$0 == f { print l; exit; }; { l=$$0; }') $(basename $@) > $@; [ $$? -eq 1 ] + +clean: + +.PHONY: $(TOPTARGETS) lib $(SUBDIRS) diff --git a/archive/.gitignore b/archive/.gitignore new file mode 100644 index 0000000..d94351e --- /dev/null +++ b/archive/.gitignore @@ -0,0 +1 @@ +/cglm.min.h diff --git a/archive/cglm.min.js b/archive/cglm.min.js new file mode 100644 index 0000000..42829cb --- /dev/null +++ b/archive/cglm.min.js @@ -0,0 +1,273 @@ +var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(H,m,C){H!=Array.prototype&&H!=Object.prototype&&(H[m]=C.value)};$jscomp.getGlobal=function(H){return"undefined"!=typeof window&&window===H?H:"undefined"!=typeof global&&null!=global?global:H};$jscomp.global=$jscomp.getGlobal(this); +$jscomp.polyfill=function(H,m,C,z){if(m){C=$jscomp.global;H=H.split(".");for(z=0;z>>16&65535)*H+z*(C>>>16&65535)<<16>>>0)|0}},"es6","es3"); +$jscomp.polyfill("Math.clz32",function(H){return H?H:function(m){m=Number(m)>>>0;if(0===m)return 32;var C=0;0===(m&4294901760)&&(m<<=16,C+=16);0===(m&4278190080)&&(m<<=8,C+=8);0===(m&4026531840)&&(m<<=4,C+=4);0===(m&3221225472)&&(m<<=2,C+=2);0===(m&2147483648)&&C++;return C}},"es6","es3");$jscomp.polyfill("Math.trunc",function(H){return H?H:function(m){m=Number(m);if(isNaN(m)||Infinity===m||-Infinity===m||0===m)return m;var C=Math.floor(Math.abs(m));return 0>m?-C:C}},"es6","es3"); +module.exports=function(H){function m(e){this.storage=e||new Float32Array(z.buffer,yb("vec"),3)}function C(e){this.storage=e||new Float32Array(z.buffer,yb("mat4"),16)}var z=this.Module=function(e){function m(e,f){f||(f=16);return Math.ceil(e/f)*f}function C(e,f){e||tb("Assertion failed: "+f)}function H(e,f){if(0===f||!e)return"";for(var x=0,w,m=0;;){w=ra[e+m>>0];x|=w;if(0==w&&!f)break;m++;if(f&&m==f)break}f||(f=m);w="";if(128>x){for(;0w?x+=String.fromCharCode(w): +(w-=65536,x+=String.fromCharCode(55296|w>>10,56320|w&1023))}else x+=String.fromCharCode(w)}}return f}function z(){tb("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+ub+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or (4) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")} +function X(f){for(;0=a&&(a=65536+((a&1023)<<10)|e.charCodeAt(++b)&1023);if(127>=a){if(Q>=w)break;m[Q++]= +a}else{if(2047>=a){if(Q+1>=w)break;m[Q++]=192|a>>6}else{if(65535>=a){if(Q+2>=w)break;m[Q++]=224|a>>12}else{if(2097151>=a){if(Q+3>=w)break;m[Q++]=240|a>>18}else{if(67108863>=a){if(Q+4>=w)break;m[Q++]=248|a>>24}else{if(Q+5>=w)break;m[Q++]=252|a>>30;m[Q++]=128|a>>24&63}m[Q++]=128|a>>18&63}m[Q++]=128|a>>12&63}m[Q++]=128|a>>6&63}m[Q++]=128|a&63}}m[Q]=0}}return f}};var gh={string:f.stringToC,array:f.arrayToC},mc="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;"undefined"!==typeof TextDecoder&& +new TextDecoder("utf-16le");var Bb,ra,Cb,Z,Ob,ac,Hb,Da;var ib=T=Hb=T=V=Da=0;var vc=!1;V=e.TOTAL_STACK||5242880;var ub=e.TOTAL_MEMORY||16777216;ub>2]=V;vc=!0;var dh=!1, +eh="function"===typeof atob?atob:function(e){var f="",w=0;e=e.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(w++));var Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(w++));var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(w++));var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(w++));m=m<<2|Q>>4;Q=(Q& +15)<<4|b>>2;var C=(b&3)<<6|a;f+=String.fromCharCode(m);64!==b&&(f+=String.fromCharCode(Q));64!==a&&(f+=String.fromCharCode(C))}while(w>2]=f);return f},_abort:function(){e.abort()},_emscripten_memcpy_big:function(e,f,m){ra.set(ra.subarray(f,f+m),e);return e},_llvm_fabs_f32:wc,DYNAMICTOP_PTR:Da,tempDoublePtr:oa,ABORT:Ab,STACKTOP:Hb,STACK_MAX:T};f=function(e,f,m){function w(a){a|=0;var c=b[C>>2]|0;var g=c+a|0;if(0<(a|0)&(g|0)<(c|0)|0>(g|0))return La()|0,oa(12),-1;b[C>>2]=g;return(g|0)>(pa()|0)&&!(Y()|0)?(b[C>>2]=c,oa(12),-1):c|0}"use asm";var x=new e.Int8Array(m); +new e.Int16Array(m);var b=new e.Int32Array(m);new e.Uint8Array(m);new e.Uint16Array(m);new e.Uint32Array(m);var a=new e.Float32Array(m);new e.Float64Array(m);var C=f.DYNAMICTOP_PTR|0,F=f.tempDoublePtr|0,z=f.STACKTOP|0,H=0,R=0,D=e.Math.abs,B=e.Math.sqrt,N=e.Math.cos,K=e.Math.sin,V=e.Math.tan,Z=e.Math.acos,X=e.Math.asin,ra=e.Math.atan,T=e.Math.atan2,Y=f.enlargeMemory,pa=f.getTotalMemory,La=f.abortOnCannotGrowMemory,oa=f.___setErrNo,y=f._abort,ya=f._emscripten_memcpy_big;return{___errno_location:function(){return 504}, +_free:function(a){a|=0;var c=0,g=0,u=0,n=0,G=0,h=0,e=0,k=0,r=0,f=0,q=0,v=0,t=0,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+24>>2]|0;Qa=b[L+12>>2]|0;do if((Qa|0)==(L|0)){Xa=L+16|0;fb=Xa+4|0;if(lb=b[fb>>2]|0)r=lb,f=fb;else if(mb=b[Xa>>2]|0)r=mb,f=Xa;else{A=0;break}for(;;)if(nb=r+20|0,ob=b[nb>>2]|0,ob|0)r=ob,f=nb;else if(pb=r+16|0,La=b[pb>>2]|0)r=La,f=pb;else break;Ka>>>0>f>>>0?y():(b[f>>2]=0,A=r)}else Ra=b[L+8>>2]|0,Ka>>>0>Ra>>>0&&y(),eb=Ra+12|0,(b[eb>>2]|0)!=(L|0)&& +y(),Wa=Qa+8|0,(b[Wa>>2]|0)==(L|0)?(b[eb>>2]=Qa,b[Wa>>2]=Ra,A=Qa):y();while(0);if(Ma){Za=b[L+28>>2]|0;vb=312+(Za<<2)|0;if((b[vb>>2]|0)==(L|0)){if(b[vb>>2]=A,!A){b[3]&=~(1<>>0>Ma>>>0)y();else if(b[Ma+16+(((b[Ma+16>>2]|0)!=(L|0)&1)<<2)>>2]=A,!A){e=L;k=aa;ka=L;break a}qb=b[6]|0;qb>>>0>A>>>0&&y();b[A+24>>2]=Ma;$a=L+16|0;rb=b[$a>>2]|0;rb|0&&(qb>>>0>rb>>>0?y():(b[A+16>>2]=rb,b[rb+24>>2]=A));(na=b[$a+4>>2]|0)?(b[6]|0)>>>0>na>>>0?y():(b[A+20>>2]=na,b[na+24>>2]= +A,e=L,k=aa,ka=L):(e=L,k=aa,ka=L)}else e=L,k=aa,ka=L}}while(0);ka>>>0>=S>>>0&&y();m=S+4|0;w=b[m>>2]|0;w&1||y();if(w&2)b[m>>2]=w&-2,b[e+4>>2]=k|1,t=b[ka+k>>2]=k;else{if((b[8]|0)==(S|0)){jb=(b[5]|0)+k|0;b[5]=jb;b[8]=e;b[e+4>>2]=jb|1;if((e|0)!=(b[7]|0))return;b[7]=0;b[4]=0;return}if((b[7]|0)==(S|0)){x=(b[4]|0)+k|0;b[4]=x;b[7]=ka;b[e+4>>2]=x|1;b[ka+x>>2]=x;return}O=(w&-8)+k|0;F=w>>>3;a:do if(256>w>>>0)z=b[S+8>>2]|0,U=b[S+12>>2]|0,P=48+(F<<1<<2)|0,(z|0)!=(P|0)&&((b[6]|0)>>>0>z>>>0&&y(),(b[z+12>>2]|0)!= +(S|0)&&y()),(U|0)==(z|0)?b[2]&=~(1<>>0>U>>>0&&y(),D=U+8|0,(b[D>>2]|0)==(S|0)?J=D:y()),b[z+12>>2]=U,b[J>>2]=z);else{C=b[S+24>>2]|0;ba=b[S+12>>2]|0;do if((ba|0)==(S|0)){N=S+16|0;Q=N+4|0;if(Jb=b[Q>>2]|0)q=Jb,v=Q;else if(za=b[N>>2]|0)q=za,v=N;else{E=0;break}for(;;)if(Aa=q+20|0,Ed=b[Aa>>2]|0,Ed|0)q=Ed,v=Aa;else if(T=q+16|0,kb=b[T>>2]|0)q=kb,v=T;else break;(b[6]|0)>>>0>v>>>0?y():(b[v>>2]=0,E=q)}else K=b[S+8>>2]|0,(b[6]|0)>>>0>K>>>0&&y(),H=K+12|0,(b[H>>2]|0)!=(S|0)&&y(), +R=ba+8|0,(b[R>>2]|0)==(S|0)?(b[H>>2]=ba,b[R>>2]=K,E=ba):y();while(0);if(C|0){Z=b[S+28>>2]|0;Ba=312+(Z<<2)|0;if((b[Ba>>2]|0)==(S|0)){if(b[Ba>>2]=E,!E){b[3]&=~(1<>>0>C>>>0)y();else if(b[C+16+(((b[C+16>>2]|0)!=(S|0)&1)<<2)>>2]=E,!E)break a;V=b[6]|0;V>>>0>E>>>0&&y();b[E+24>>2]=C;Ca=S+16|0;ha=b[Ca>>2]|0;ha|0&&(V>>>0>ha>>>0?y():(b[E+16>>2]=ha,b[ha+24>>2]=E));Ia=b[Ca+4>>2]|0;Ia|0&&((b[6]|0)>>>0>Ia>>>0?y():(b[E+20>>2]=Ia,b[Ia+24>>2]=E))}}while(0);b[e+4>>2]=O|1;b[ka+O>>2]=O;if((e| +0)==(b[7]|0)){b[4]=O;return}t=O}Kb=t>>>3;if(256>t>>>0)Ja=48+(Kb<<1<<2)|0,ua=b[2]|0,Qb=1<>2]|0,(b[6]|0)>>>0>Ga>>>0?y():(h=Ga,M=Oa)):(b[2]=ua|Qb,h=Ja,M=Ja+8|0),b[M>>2]=e,b[h+12>>2]=e,b[e+8>>2]=h,b[e+12>>2]=Ja;else{(wa=t>>>8)?16777215>>0?G=31:(ia=(wa+1048320|0)>>>16&8,Rb=wa<>>16&4,X=Rb<>>16&2,ra=14-(Pa|ia|xa)+(X<>>15)|0,G=t>>>(ra+7|0)&1|ra<<1):G=0;Y=312+(G<<2)|0;b[e+28>>2]=G;b[e+20>>2]=0;b[e+16>>2]=0;ab=b[3]|0;Ta=1<>>1)|0);for(n=b[Y>>2]|0;;){if((b[n+4>>2]&-8|0)==(t|0)){Fb=124;break}Ua=n+16+(u>>>31<<2)|0;if(oa=b[Ua>>2]|0)u<<=1,n=oa;else{Fb=121;break}}121==(Fb|0)?(b[6]|0)>>>0>Ua>>>0?y():(b[Ua>>2]=e,b[e+24>>2]=n,b[e+12>>2]=e,b[e+8>>2]=e):124==(Fb|0)&&(Va=n+8|0,bb=b[Va>>2]|0,cb=b[6]|0,cb>>>0<=bb>>>0&cb>>>0<=n>>>0?(b[bb+12>>2]=e,b[Va>>2]=e,b[e+8>>2]=bb,b[e+12>>2]=n,b[e+24>>2]=0):y())}else b[3]=ab|Ta,b[Y>>2]=e,b[e+24>>2]=Y,b[e+12>>2]=e,b[e+8>>2]=e;va=(b[10]|0)+-1|0;b[10]=va;if(!va){for(g= +464;;)if(c=b[g>>2]|0)g=c+8|0;else break;b[10]=-1}}}},_glmc_aabb_center:function(c,d){c|=0;d|=0;var g=+a[c>>2]+ +a[c+12>>2];a[d>>2]=g;var b=+a[c+4>>2]+ +a[c+16>>2];var n=d+4|0;a[n>>2]=b;c=+a[c+8>>2]+ +a[c+20>>2];a[d>>2]=.5*g;a[n>>2]=.5*b;a[d+8>>2]=.5*c},_glmc_aabb_crop:function(c,d,g){c|=0;d|=0;g|=0;var b=+a[c>>2];var n=+a[d>>2];a[g>>2]=b>n?b:n;b=+a[c+4>>2];n=+a[d+4>>2];a[g+4>>2]=b>n?b:n;b=+a[c+8>>2];n=+a[d+8>>2];a[g+8>>2]=b>n?b:n;b=+a[c+12>>2];n=+a[d+12>>2];a[g+12>>2]=b>2];n=+a[d+ +16>>2];a[g+16>>2]=b>2];d=+a[d+20>>2];a[g+20>>2]=c>2];var e=+a[d>>2];u=u>e?u:e;a[b>>2]=u;var h=+a[c+4>>2];e=+a[d+4>>2];e=h>e?h:e;h=b+4|0;a[h>>2]=e;var l=+a[c+8>>2];var k=+a[d+8>>2];l=l>k?l:k;k=b+8|0;a[k>>2]=l;var r=+a[c+12>>2];var f=+a[d+12>>2];r=r>2]=r;var q=+a[c+16>>2];var v=+a[d+16>>2];q=q>2]=q;c=+a[c+20>>2];d=+a[d+20>>2];d=c>2]=d;var t=+a[g>> +2];a[b>>2]=t>2];a[h>>2]=b>2];a[k>>2]=b>2];a[f>>2]=b>r?b:r;b=+a[g+16>>2];a[v>>2]=b>q?b:q;g=+a[g+20>>2];a[c>>2]=g>d?g:d},_glmc_aabb_frustum:function(c,d){c|=0;d|=0;var g=+a[d>>2];var b=+a[d+4>>2];var n=+a[d+8>>2];if(g*+a[c+(12*(0>2]+b*+a[c+(12*(0>2]+n*+a[c+(12*(0>2]<-+a[d+12>>2])return 0;n=+a[d+16>>2];g=+a[d+20>>2];b=+a[d+24>>2];if(n*+a[c+(12*(0>2]+g*+a[c+(12*(0>2]+b*+a[c+(12*(0>2]<-+a[d+28>> +2])return 0;n=+a[d+32>>2];g=+a[d+36>>2];b=+a[d+40>>2];if(n*+a[c+(12*(0>2]+g*+a[c+(12*(0>2]+b*+a[c+(12*(0>2]<-+a[d+44>>2])return 0;n=+a[d+48>>2];g=+a[d+52>>2];b=+a[d+56>>2];if(n*+a[c+(12*(0>2]+g*+a[c+(12*(0>2]+b*+a[c+(12*(0>2]<-+a[d+60>>2])return 0;n=+a[d+64>>2];g=+a[d+68>>2];b=+a[d+72>>2];if(n*+a[c+(12*(0>2]+g*+a[c+(12*(0>2]+b*+a[c+(12*(0>2]<-+a[d+76>>2])return 0;n=+a[d+80>>2];g=+a[d+84>>2];b=+a[d+88>>2]; +return n*+a[c+(12*(0>2]+g*+a[c+(12*(0>2]+b*+a[c+(12*(0>2]<-+a[d+92>>2]?0:1},_glmc_aabb_invalidate:function(c){c|=0;a[c+8>>2]=3.4028234663852886E38;a[c+4>>2]=3.4028234663852886E38;a[c>>2]=3.4028234663852886E38;a[c+20>>2]=-3.4028234663852886E38;a[c+16>>2]=-3.4028234663852886E38;a[c+12>>2]=-3.4028234663852886E38},_glmc_aabb_isvalid:function(c){c|=0;var d=+a[c>>2];var g=+a[c+4>>2];var b=+a[c+8>>2];g=g>d?g:d;if(3.4028234663852886E38==(g>2];b=+a[c+ +16>>2];c=+a[c+20>>2];b=bc?c:b)|0},_glmc_aabb_merge:function(c,d,g){c|=0;d|=0;g|=0;var b=+a[c>>2];var n=+a[d>>2];a[g>>2]=b>2];n=+a[d+4>>2];a[g+4>>2]=b>2];n=+a[d+8>>2];a[g+8>>2]=b>2];n=+a[d+12>>2];a[g+12>>2]=b>n?b:n;b=+a[c+16>>2];n=+a[d+16>>2];a[g+16>>2]=b>n?b:n;c=+a[c+20>>2];d=+a[d+20>>2];a[g+20>>2]=c>d?c:d},_glmc_aabb_radius:function(c){c|=0;var d=+a[c+12>>2]-+a[c>>2];var g=+a[c+16>>2]-+a[c+4>>2];c=+a[c+20>>2]- ++a[c+8>>2];return+(.5*+B(+(d*d+g*g+c*c)))},_glmc_aabb_size:function(c){c|=0;var d=+a[c+12>>2]-+a[c>>2];var g=+a[c+16>>2]-+a[c+4>>2];c=+a[c+20>>2]-+a[c+8>>2];return+ +B(+(d*d+g*g+c*c))},_glmc_aabb_transform:function(c,d,g){c|=0;d|=0;g|=0;var b=+a[c>>2];var n=+a[d>>2];var e=b*n;var h=+a[d+4>>2];var l=b*h;var k=+a[d+8>>2];b*=k;var f=+a[c+12>>2];n*=f;h*=f;k*=f;var p=+a[c+4>>2];var q=+a[d+16>>2];f=p*q;var v=+a[d+20>>2];var t=p*v;var A=+a[d+24>>2];p*=A;var E=+a[c+16>>2];q*=E;v*=E;A*=E;var J=+a[c+8>>2]; +var I=+a[d+32>>2];E=J*I;var M=+a[d+36>>2];var S=J*M;var ca=+a[d+40>>2];J*=ca;var W=+a[c+20>>2];c=I*W;M*=W;ca*=W;I=+a[d+48>>2];W=+a[d+52>>2];d=+a[d+56>>2];a[g>>2]=I+((e>2]=W+((l>2]=d+((b>2]=I+((e>n?e:n)+(f>q?f:q)+(E>c?E:c));a[g+16>>2]=W+((l>h?l:h)+(t>v?t:v)+(S>M?S:M));a[g+20>>2]=d+((b>k?b:k)+(p>A?p:A)+(J>ca?J:ca))},_glmc_decompose:function(c,d,g,u){c|=0;d|=0;g|=0;u|=0;b[d>>2]=b[c+48>>2];b[d+ +4>>2]=b[c+52>>2];b[d+8>>2]=b[c+56>>2];b[d+12>>2]=b[c+60>>2];b[g>>2]=b[c>>2];var n=c+4|0;d=g+4|0;b[d>>2]=b[n>>2];var e=c+8|0;var h=g+8|0;b[h>>2]=b[e>>2];var l=g+12|0;b[l>>2]=b[c+12>>2];var k=c+16|0;var f=g+16|0;b[f>>2]=b[k>>2];var p=c+20|0;var q=g+20|0;b[q>>2]=b[p>>2];var v=c+24|0;var t=g+24|0;b[t>>2]=b[v>>2];var A=g+28|0;b[A>>2]=b[c+28>>2];var E=c+32|0;var J=g+32|0;b[J>>2]=b[E>>2];var I=c+36|0;var M=g+36|0;b[M>>2]=b[I>>2];var S=c+40|0;var ca=g+40|0;b[ca>>2]=b[S>>2];var W=g+44|0;b[W>>2]=b[c+44>>2]; +b[g+48>>2]=0;b[g+52>>2]=0;b[g+56>>2]=0;b[g+60>>2]=1065353216;var ka=+a[c>>2];var m=+a[n>>2];var w=+a[e>>2];ka=+B(+(ka*ka+m*m+w*w));a[u>>2]=ka;var jb=+a[k>>2];w=+a[p>>2];var x=+a[v>>2];m=u+4|0;a[m>>2]=+B(+(jb*jb+w*w+x*x));var y=+a[E>>2];x=+a[I>>2];jb=+a[S>>2];w=u+8|0;a[w>>2]=+B(+(y*y+x*x+jb*jb));y=1/ka;ka=y*+a[g>>2];a[g>>2]=ka;x=y*+a[d>>2];a[d>>2]=x;jb=y*+a[h>>2];a[h>>2]=jb;y*=+a[l>>2];a[l>>2]=y;var O=1/+a[m>>2];var z=+a[f>>2]*O;a[f>>2]=z;var F=O*+a[q>>2];a[q>>2]=F;var C=O*+a[t>>2];a[t>>2]=C;O*=+a[A>> +2];a[A>>2]=O;var P=1/+a[w>>2];var L=+a[J>>2]*P;a[J>>2]=L;var D=P*+a[M>>2];a[M>>2]=D;var K=P*+a[ca>>2];a[ca>>2]=K;P*=+a[W>>2];a[W>>2]=P;n=+a[n>>2];v=+a[v>>2];e=+a[e>>2];p=+a[p>>2];k=+a[k>>2];c=+a[c>>2];0>(n*v-e*p)*+a[E>>2]+(e*k-v*c)*+a[I>>2]+(p*c-n*k)*+a[S>>2]&&(a[g>>2]=-ka,a[d>>2]=-x,a[h>>2]=-jb,a[l>>2]=-y,a[f>>2]=-z,a[q>>2]=-F,a[t>>2]=-C,a[A>>2]=-O,a[J>>2]=-L,a[M>>2]=-D,a[ca>>2]=-K,a[W>>2]=-P,a[u>>2]=-+a[u>>2],a[m>>2]=-+a[m>>2],a[w>>2]=-+a[w>>2])},_glmc_decompose_rs:function(c,d,g){c|=0;d|=0;g|= +0;b[d>>2]=b[c>>2];var u=c+4|0;var n=d+4|0;b[n>>2]=b[u>>2];var e=c+8|0;var h=d+8|0;b[h>>2]=b[e>>2];var l=d+12|0;b[l>>2]=b[c+12>>2];var k=c+16|0;var f=d+16|0;b[f>>2]=b[k>>2];var p=c+20|0;var q=d+20|0;b[q>>2]=b[p>>2];var v=c+24|0;var t=d+24|0;b[t>>2]=b[v>>2];var A=d+28|0;b[A>>2]=b[c+28>>2];var E=c+32|0;var J=d+32|0;b[J>>2]=b[E>>2];var I=c+36|0;var M=d+36|0;b[M>>2]=b[I>>2];var S=c+40|0;var ca=d+40|0;b[ca>>2]=b[S>>2];var W=d+44|0;b[W>>2]=b[c+44>>2];b[d+48>>2]=0;b[d+52>>2]=0;b[d+56>>2]=0;b[d+60>>2]=1065353216; +var ka=+a[c>>2];var m=+a[u>>2];var w=+a[e>>2];ka=+B(+(ka*ka+m*m+w*w));a[g>>2]=ka;var x=+a[k>>2];w=+a[p>>2];var y=+a[v>>2];m=g+4|0;a[m>>2]=+B(+(x*x+w*w+y*y));var z=+a[E>>2];y=+a[I>>2];x=+a[S>>2];w=g+8|0;a[w>>2]=+B(+(z*z+y*y+x*x));z=1/ka;ka=z*+a[d>>2];a[d>>2]=ka;y=z*+a[n>>2];a[n>>2]=y;x=z*+a[h>>2];a[h>>2]=x;z*=+a[l>>2];a[l>>2]=z;var O=1/+a[m>>2];var F=+a[f>>2]*O;a[f>>2]=F;var C=O*+a[q>>2];a[q>>2]=C;var D=O*+a[t>>2];a[t>>2]=D;O*=+a[A>>2];a[A>>2]=O;var P=1/+a[w>>2];var L=+a[J>>2]*P;a[J>>2]=L;var K=P* ++a[M>>2];a[M>>2]=K;var H=P*+a[ca>>2];a[ca>>2]=H;P*=+a[W>>2];a[W>>2]=P;u=+a[u>>2];v=+a[v>>2];e=+a[e>>2];p=+a[p>>2];k=+a[k>>2];c=+a[c>>2];0>(u*v-e*p)*+a[E>>2]+(e*k-v*c)*+a[I>>2]+(p*c-u*k)*+a[S>>2]&&(a[d>>2]=-ka,a[n>>2]=-y,a[h>>2]=-x,a[l>>2]=-z,a[f>>2]=-F,a[q>>2]=-C,a[t>>2]=-D,a[A>>2]=-O,a[J>>2]=-L,a[M>>2]=-K,a[ca>>2]=-H,a[W>>2]=-P,a[g>>2]=-+a[g>>2],a[m>>2]=-+a[m>>2],a[w>>2]=-+a[w>>2])},_glmc_decompose_scalev:function(c,d){c|=0;d|=0;var g=+a[c>>2];var b=+a[c+4>>2];var n=+a[c+8>>2];a[d>>2]=+B(+(g*g+b* +b+n*n));g=+a[c+16>>2];b=+a[c+20>>2];n=+a[c+24>>2];a[d+4>>2]=+B(+(g*g+b*b+n*n));n=+a[c+32>>2];b=+a[c+36>>2];c=+a[c+40>>2];a[d+8>>2]=+B(+(n*n+b*b+c*c))},_glmc_euler:function(c,d){c|=0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g);var e=+K(+u);u=+N(+u);var h=+K(+n);var l=+N(+n);var k=c*l;var f=g*l;n=e*h;a[d>>2]=u*l;a[d+4>>2]=g*h+e*k;a[d+8>>2]=c*h-e*f;l=-u;a[d+16>>2]=h*l;a[d+20>>2]=f-c*n;a[d+24>>2]=k+g*n;a[d+32>>2]=e;a[d+36>>2]=c*l;a[d+40>>2]=g*u;a[d+12>>2]=0;a[d+28>>2]=0;c= +d+44|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_euler_angles:function(c,d){c|=0;d|=0;var g=+a[c>>2];var b=+a[c+16>>2];var n=+a[c+32>>2];var e=+a[c+4>>2];var h=+a[c+20>>2];var l=+a[c+36>>2];c=+a[c+40>>2];1>n?-1>2]=h;a[d+4>>2]=n;a[d+8>>2]=g},_glmc_euler_by_order:function(c,d,g){c|=0;d|=0;g|=0;var u=+a[c>>2];var n=+a[c+4>>2];var e=+a[c+8>>2];c=+K(+u);u= ++N(+u);var h=+K(+n);var l=+N(+n);n=+K(+e);var k=+N(+e);var f=l*k;e=l*n;var p=c*l;l*=u;var q=h*k;var v=u*k;k*=c;var t=u*n;var A=h*n;switch(d|0){case 24:a[g>>2]=f;a[g+4>>2]=c*h+u*e;a[g+8>>2]=p*n-u*h;a[g+16>>2]=-n;a[g+20>>2]=v;a[g+24>>2]=k;a[g+32>>2]=q;a[g+36>>2]=u*A-p;d=l+c*A;break;case 36:a[g>>2]=f;a[g+4>>2]=t+h*k;a[g+8>>2]=c*n-u*q;a[g+16>>2]=-e;a[g+20>>2]=v-c*A;a[g+24>>2]=k+u*A;a[g+32>>2]=h;a[g+36>>2]=-p;d=l;break;case 33:a[g>>2]=f+c*A;a[g+4>>2]=t;a[g+8>>2]=p*n-q;a[g+16>>2]=h*k-e;a[g+20>>2]=v;a[g+ +24>>2]=A+c*f;a[g+32>>2]=u*h;a[g+36>>2]=-c;d=l;break;case 9:a[g>>2]=f;a[g+4>>2]=n;a[g+8>>2]=-q;a[g+16>>2]=c*h-u*e;a[g+20>>2]=v;a[g+24>>2]=p+u*A;a[g+32>>2]=u*h+p*n;a[g+36>>2]=-k;d=l-c*A;break;case 18:a[g>>2]=f-c*A;a[g+4>>2]=e+h*k;a[g+8>>2]=-(u*h);a[g+16>>2]=-t;a[g+20>>2]=v;a[g+24>>2]=c;a[g+32>>2]=p*n+q;a[g+36>>2]=A-c*f;d=l;break;case 6:a[g>>2]=f;a[g+4>>2]=e;a[g+8>>2]=-h;a[g+16>>2]=h*k-t;a[g+20>>2]=v+c*A;a[g+24>>2]=p;a[g+32>>2]=c*n+u*q;a[g+36>>2]=u*A-k;d=l;break;default:a[(g+12|0)>>2]=0;a[(g+28|0)>> +2]=0;d=g+44|0;b[d>>2]=0;b[d+4>>2]=0;b[d+8>>2]=0;b[d+12>>2]=0;a[(g+60|0)>>2]=1;return}a[g+40>>2]=d;a[(g+12|0)>>2]=0;a[(g+28|0)>>2]=0;d=g+44|0;b[d>>2]=0;b[d+4>>2]=0;b[d+8>>2]=0;b[d+12>>2]=0;a[(g+60|0)>>2]=1},_glmc_euler_xyz:function(c,d){c|=0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g);var e=+K(+u);u=+N(+u);var h=+K(+n);var l=+N(+n);var k=c*l;var f=g*l;n=e*h;a[d>>2]=u*l;a[d+4>>2]=g*h+e*k;a[d+8>>2]=c*h-e*f;l=-u;a[d+16>>2]=h*l;a[d+20>>2]=f-c*n;a[d+24>>2]=k+g*n;a[d+32>>2]=e; +a[d+36>>2]=c*l;a[d+40>>2]=g*u;a[d+12>>2]=0;a[d+28>>2]=0;c=d+44|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_euler_xzy:function(c,d){c|=0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g);var e=+K(+u);u=+N(+u);var h=+K(+n);var l=+N(+n);var k=c*e;var f=c*u;n=g*e;var p=g*u;a[d>>2]=u*l;a[d+4>>2]=k+p*h;a[d+8>>2]=f*h-n;a[d+16>>2]=-h;a[d+20>>2]=g*l;a[d+24>>2]=c*l;a[d+32>>2]=e*l;a[d+36>>2]=n*h-f;a[d+40>>2]=p+k*h;a[d+12>>2]=0;a[d+28>>2]=0;c=d+44|0;b[c>>2]=0;b[c+ +4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_euler_yxz:function(c,d){c|=0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g);var e=+K(+u);u=+N(+u);var h=+K(+n);var l=+N(+n);var k=u*l;var f=e*h;n=e*l;var p=u*h;a[d>>2]=k+c*f;a[d+4>>2]=g*h;a[d+8>>2]=c*p-n;a[d+16>>2]=c*n-p;a[d+20>>2]=g*l;a[d+24>>2]=f+c*k;a[d+32>>2]=g*e;a[d+36>>2]=-c;a[d+40>>2]=g*u;a[d+12>>2]=0;a[d+28>>2]=0;c=d+44|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_euler_yzx:function(c,d){c|= +0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g);var e=+K(+u);var h=+N(+u);u=+K(+n);var l=+N(+n);var k=c*e;var f=g*h;n=c*h;var p=g*e;a[d>>2]=h*l;a[d+4>>2]=u;h=-l;a[d+8>>2]=e*h;a[d+16>>2]=k-f*u;a[d+20>>2]=g*l;a[d+24>>2]=n+p*u;a[d+32>>2]=p+n*u;a[d+36>>2]=c*h;a[d+40>>2]=f-k*u;a[d+12>>2]=0;a[d+28>>2]=0;c=d+44|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_euler_zxy:function(c,d){c|=0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g); +var e=+K(+u);u=+N(+u);var h=+K(+n);var l=+N(+n);var k=u*l;var f=c*e;n=u*h;a[d>>2]=k-f*h;a[d+4>>2]=n+f*l;f=-g;a[d+8>>2]=e*f;a[d+16>>2]=h*f;a[d+20>>2]=g*l;a[d+24>>2]=c;a[d+32>>2]=e*l+c*n;a[d+36>>2]=e*h-c*k;a[d+40>>2]=g*u;a[d+12>>2]=0;a[d+28>>2]=0;c=d+44|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_euler_zyx:function(c,d){c|=0;d|=0;var g=+a[c>>2];var u=+a[c+4>>2];var n=+a[c+8>>2];c=+K(+g);g=+N(+g);var e=+K(+u);u=+N(+u);var h=+K(+n);var l=+N(+n);var k=c*l;var f=g*l;n=e*h;a[d>> +2]=u*l;a[d+4>>2]=u*h;a[d+8>>2]=-e;a[d+16>>2]=e*k-g*h;a[d+20>>2]=f+c*n;a[d+24>>2]=c*u;a[d+32>>2]=c*h+e*f;a[d+36>>2]=g*n-k;a[d+40>>2]=g*u;a[d+12>>2]=0;a[d+28>>2]=0;c=d+44|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;a[d+60>>2]=1},_glmc_frustum:function(c,d,g,u,n,e,h){c=+c;d=+d;g=+g;u=+u;n=+n;e=+e;h|=0;var G=h+4|0;var k=G+60|0;do b[G>>2]=0,G=G+4|0;while((G|0)<(k|0));var f=1/(d-c);G=1/(u-g);k=-1/(e-n);var p=2*n;a[h>>2]=f*p;a[h+20>>2]=p*G;a[h+32>>2]=(c+d)*f;a[h+36>>2]=(g+u)*G;a[h+40>>2]=(n+e)*k;a[h+ +44>>2]=-1;a[h+56>>2]=p*e*k},_glmc_frustum_box:function(c,d,g){c|=0;d|=0;g|=0;var b,n,e,h;var l=+a[d>>2];var k=+a[d+16>>2];var f=+a[d+32>>2];var p=+a[d+48>>2];var q=+a[d+4>>2];var v=+a[d+20>>2];var t=+a[d+36>>2];var A=+a[d+52>>2];var E=+a[d+8>>2];var J=+a[d+24>>2];var I=+a[d+40>>2];var M=+a[d+56>>2];d=0;var S=n=b=3.4028234663852886E38;var ca=h=e=-3.4028234663852886E38;do{var W=+a[c+(d<<4)>>2];var m=+a[c+(d<<4)+4>>2];var w=+a[c+(d<<4)+8>>2];var x=+a[c+(d<<4)+12>>2];var B=l*W+k*m+f*w+p*x;var y=q*W+v* +m+t*w+A*x;W=E*W+J*m+I*w+M*x;b=bB?e:B;h=h>y?h:y;ca=ca>W?ca:W;d=d+1|0}while(8!=(d|0));a[g>>2]=b;a[g+4>>2]=n;a[g+8>>2]=S;a[g+12>>2]=e;a[g+16>>2]=h;a[g+20>>2]=ca},_glmc_frustum_center:function(c,d){c|=0;d|=0;var g=+a[c+4>>2]+ +a[c+20>>2]+ +a[c+36>>2]+ +a[c+52>>2]+ +a[c+68>>2]+ +a[c+84>>2]+ +a[c+100>>2]+ +a[c+116>>2];var b=+a[c+8>>2]+ +a[c+24>>2]+ +a[c+40>>2]+ +a[c+56>>2]+ +a[c+72>>2]+ +a[c+88>>2]+ +a[c+104>>2]+ +a[c+120>>2];var n=+a[c+12>>2]+ +a[c+28>>2]+ +a[c+44>>2]+ +a[c+ +60>>2]+ +a[c+76>>2]+ +a[c+92>>2]+ +a[c+108>>2]+ +a[c+124>>2];a[d>>2]=.125*(+a[c>>2]+ +a[c+16>>2]+ +a[c+32>>2]+ +a[c+48>>2]+ +a[c+64>>2]+ +a[c+80>>2]+ +a[c+96>>2]+ +a[c+112>>2]);a[d+4>>2]=.125*g;a[d+8>>2]=.125*b;a[d+12>>2]=.125*n},_glmc_frustum_corners:function(c,d){c|=0;d|=0;var g=+a[c>>2];var b=+a[c+16>>2];var n=-b-g;var e=+a[c+32>>2];var h=+a[c+48>>2];var l=+a[c+4>>2];var k=+a[c+20>>2];var f=-k-l;var p=+a[c+36>>2];var q=+a[c+52>>2];var v=+a[c+8>>2];var t=+a[c+24>>2];var A=-t-v;var E=+a[c+40>>2]; +var J=+a[c+56>>2];var I=+a[c+12>>2];var M=+a[c+28>>2];var S=-M-I;var ca=+a[c+44>>2];var W=+a[c+60>>2];var m=S-ca+W;var w=b-g;var x=k-l;var B=t-v;var y=M-I;var z=y-ca+W;c=g+b;var F=l+k;var C=v+t;var D=I+M;var U=D-ca+W;g-=b;l-=k;v-=t;t=I-M;I=t-ca+W;M=S+ca+W;S=y+ca+W;D=D+ca+W;ca=t+ca+W;W=1/m;a[d>>2]=(n-e+h)*W;a[d+4>>2]=(f-p+q)*W;a[d+8>>2]=(A-E+J)*W;a[d+12>>2]=m*W;m=1/z;a[d+16>>2]=(w-e+h)*m;a[d+20>>2]=(x-p+q)*m;a[d+24>>2]=(B-E+J)*m;a[d+28>>2]=z*m;z=1/U;a[d+32>>2]=(c-e+h)*z;a[d+36>>2]=(F-p+q)*z;a[d+40>> +2]=(C-E+J)*z;a[d+44>>2]=U*z;U=1/I;a[d+48>>2]=(g-e+h)*U;a[d+52>>2]=(l-p+q)*U;a[d+56>>2]=(v-E+J)*U;a[d+60>>2]=I*U;U=1/M;a[d+64>>2]=(n+e+h)*U;a[d+68>>2]=(f+p+q)*U;a[d+72>>2]=(A+E+J)*U;a[d+76>>2]=M*U;f=1/S;a[d+80>>2]=(w+e+h)*f;a[d+84>>2]=(x+p+q)*f;a[d+88>>2]=(B+E+J)*f;a[d+92>>2]=S*f;f=1/D;a[d+96>>2]=(c+e+h)*f;a[d+100>>2]=(F+p+q)*f;a[d+104>>2]=(C+E+J)*f;a[d+108>>2]=D*f;c=1/ca;a[d+112>>2]=(g+e+h)*c;a[d+116>>2]=(l+p+q)*c;a[d+120>>2]=(v+E+J)*c;a[d+124>>2]=ca*c},_glmc_frustum_corners_at:function(c,d,g,b){c|= +0;b|=0;var u=c+96|0;var e=c+32|0;var h=c+100|0;var l=c+104|0;var k=c+36|0;var f=c+40|0;var p=+a[e>>2]-+a[u>>2];var q=+a[k>>2]-+a[h>>2];var v=+a[f>>2]-+a[l>>2];d=+d/+g*+B(+(p*p+q*q+v*v));g=+a[c>>2];var t=+a[c+64>>2]-g;v=c+4|0;var A=+a[c+68>>2]-+a[v>>2];p=c+8|0;var E=+a[c+72>>2]-+a[p>>2];q=c+12|0;var J=+a[c+76>>2]-+a[q>>2];var I=+B(+(t*t+A*A+E*E+J*J));0==I?J=E=A=t=0:(I=d/I,t*=I,A*=I,E*=I,J*=I);a[b>>2]=g+t;a[b+4>>2]=A+ +a[v>>2];a[b+8>>2]=E+ +a[p>>2];a[b+12>>2]=J+ +a[q>>2];g=+a[c+16>>2];t=+a[c+80>>2]- +g;v=c+20|0;A=+a[c+84>>2]-+a[v>>2];p=c+24|0;E=+a[c+88>>2]-+a[p>>2];q=c+28|0;J=+a[c+92>>2]-+a[q>>2];I=+B(+(t*t+A*A+E*E+J*J));0==I?J=E=A=t=0:(I=d/I,t*=I,A*=I,E*=I,J*=I);a[b+16>>2]=g+t;a[b+20>>2]=A+ +a[v>>2];a[b+24>>2]=E+ +a[p>>2];a[b+28>>2]=J+ +a[q>>2];e=+a[e>>2];u=+a[u>>2]-e;g=+a[h>>2]-+a[k>>2];v=+a[l>>2]-+a[f>>2];l=c+44|0;h=+a[c+108>>2]-+a[l>>2];p=+B(+(u*u+g*g+v*v+h*h));0==p?h=v=g=u=0:(p=d/p,u*=p,g*=p,v*=p,h*=p);a[b+32>>2]=e+u;a[b+36>>2]=g+ +a[k>>2];a[b+40>>2]=v+ +a[f>>2];a[b+44>>2]=h+ +a[l>>2];u= ++a[c+48>>2];e=+a[c+112>>2]-u;g=c+52|0;l=+a[c+116>>2]-+a[g>>2];h=c+56|0;k=+a[c+120>>2]-+a[h>>2];f=c+60|0;c=+a[c+124>>2]-+a[f>>2];v=+B(+(e*e+l*l+k*k+c*c));0==v?(a[(b+48|0)>>2]=u+0,u=+a[g>>2],a[(b+52|0)>>2]=0+u,l=+a[h>>2],a[(b+56|0)>>2]=0+l,k=+a[f>>2],a[(b+60|0)>>2]=0+k):(d/=v,a[(b+48|0)>>2]=u+e*d,u=+a[g>>2],a[(b+52|0)>>2]=l*d+u,l=+a[h>>2],a[(b+56|0)>>2]=k*d+l,k=+a[f>>2],a[(b+60|0)>>2]=c*d+k)},_glmc_frustum_planes:function(c,d){c|=0;d|=0;var g=+a[c>>2];var b=+a[c+4>>2];var n=+a[c+16>>2];var e=+a[c+20>> +2];var h=+a[c+32>>2];var l=+a[c+36>>2];var k=+a[c+48>>2];var f=+a[c+52>>2];var p=+a[c+8>>2];var q=+a[c+12>>2];var v=+a[c+24>>2];var t=+a[c+28>>2];var A=+a[c+40>>2];var E=+a[c+44>>2];var J=+a[c+56>>2];c=+a[c+60>>2];var I=g+q;var M=n+t;var S=h+E;g=q-g;n=t-n;var ca=E-h;h=b+q;var m=e+t;var w=l+E;b=q-b;e=t-e;var x=E-l;l=p+q;var y=v+t;var z=A+E;p=q-p;v=t-v;A=E-A;E=1/+B(+(I*I+M*M+S*S));a[d>>2]=I*E;a[d+4>>2]=M*E;a[d+8>>2]=S*E;a[d+12>>2]=(k+c)*E;I=1/+B(+(g*g+n*n+ca*ca));a[d+16>>2]=g*I;a[d+20>>2]=n*I;a[d+24>> +2]=ca*I;a[d+28>>2]=(c-k)*I;k=1/+B(+(h*h+m*m+w*w));a[d+32>>2]=h*k;a[d+36>>2]=m*k;a[d+40>>2]=w*k;a[d+44>>2]=(f+c)*k;k=1/+B(+(b*b+e*e+x*x));a[d+48>>2]=b*k;a[d+52>>2]=e*k;a[d+56>>2]=x*k;a[d+60>>2]=(c-f)*k;f=1/+B(+(l*l+y*y+z*z));a[d+64>>2]=l*f;a[d+68>>2]=y*f;a[d+72>>2]=z*f;a[d+76>>2]=(J+c)*f;f=1/+B(+(p*p+v*v+A*A));a[d+80>>2]=p*f;a[d+84>>2]=v*f;a[d+88>>2]=A*f;a[d+92>>2]=(c-J)*f},_glmc_inv_tr:function(c){c|=0;var d=+a[c>>2];var g=c+16|0;var u=b[g>>2]|0;var n=c+32|0;var e=b[n>>2]|0;var h=c+4|0;var l=b[h>> +2]|0;var f=+a[c+20>>2];var r=c+36|0;var p=b[r>>2]|0;var q=c+8|0;var v=b[q>>2]|0;var t=c+24|0;var A=b[t>>2]|0;var E=+a[c+40>>2];b[h>>2]=u;b[q>>2]=e;b[g>>2]=l;b[t>>2]=p;b[n>>2]=v;b[r>>2]=A;r=c+48|0;t=+a[r>>2];q=c+52|0;g=+a[q>>2];l=d*t+g*(b[F>>2]=l,+a[F>>2]);c=c+56|0;d=+a[c>>2];v=l+d*(b[F>>2]=v,+a[F>>2]);A=t*(b[F>>2]=u,+a[F>>2])+f*g+d*(b[F>>2]=A,+a[F>>2]);p=-(t*(b[F>>2]=e,+a[F>>2])+g*(b[F>>2]=p,+a[F>>2])+E*d);a[r>>2]=-v;a[q>>2]=-A;a[c>>2]=p},_glmc_look:function(c,d,g,b){c|=0;d|=0;g|=0;b|=0;var u=+a[c>> +2];var e=c+4|0;var h=+a[e>>2];var l=c+8|0;var f=+a[l>>2];u=+a[d>>2]+u-u;h=+a[d+4>>2]+h-h;d=+a[d+8>>2]+f-f;var r=+B(+(u*u+h*h+d*d));f=0==r;r=1/r;u=f?0:u*r;h=f?0:h*r;d=f?0:d*r;r=+a[g+8>>2];var p=+a[g+4>>2];f=r*h-p*d;g=+a[g>>2];r=d*g-r*u;g=p*u-h*g;var q=+B(+(g*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function(c,d,g,b){c|=0;d|=0;g|=0;b|=0;var u=+a[d>>2]-+a[c>>2];var e=c+4|0;var h=+a[d+4>>2]-+a[e>>2];var f=c+8|0;d=+a[d+8>>2]- ++a[f>>2];var k=+B(+(u*u+h*h+d*d));var r=0==k;k=1/k;u=r?0:u*k;h=r?0:h*k;d=r?0:d*k;k=+a[g+8>>2];var p=+a[g+4>>2];r=k*h-p*d;g=+a[g>>2];k=d*g-k*u;g=p*u-h*g;var q=+B(+(g*g+(r*r+k*k)));p=0==q;q=1/q;g=p?0:q*g;k=p?0:q*k;r=p?0:r*q;p=d*k-h*g;q=u*g-d*r;var v=h*r-u*k;a[b>>2]=r;a[b+4>>2]=p;a[b+8>>2]=-u;a[b+16>>2]=k;a[b+20>>2]=q;a[b+24>>2]=-h;a[b+32>>2]=g;a[b+36>>2]=v;a[b+40>>2]=-d;a[b+48>>2]=-(r*+a[c>>2]+k*+a[e>>2]+g*+a[f>>2]);a[b+52>>2]=-(p*+a[c>>2]+q*+a[e>>2]+v*+a[f>>2]);a[b+56>>2]=u*+a[c>>2]+h*+a[e>>2]+d*+a[f>> +2];a[b+44>>2]=0;a[b+28>>2]=0;a[b+12>>2]=0;a[b+60>>2]=1},_glmc_mat3_copy:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+12>>2]=b[a+12>>2];b[d+16>>2]=b[a+16>>2];b[d+20>>2]=b[a+20>>2];b[d+24>>2]=b[a+24>>2];b[d+28>>2]=b[a+28>>2];b[d+32>>2]=b[a+32>>2];b[d+36>>2]=b[a+36>>2]},_glmc_mat3_det:function(c){c|=0;var d=+a[c+4>>2];var g=+a[c+8>>2];var b=+a[c+16>>2];var n=+a[c+20>>2];var e=+a[c+28>>2];var h=+a[c+32>>2];return+(+a[c+24>>2]*(d*n-g*b)+(+a[c>>2]*(b*h-n*e)-+a[c+12>> +2]*(d*h-g*e)))},_glmc_mat3_identity:function(a){a|=0;b[a>>2]=1065353216;b[a+4>>2]=0;b[a+8>>2]=0;b[a+12>>2]=0;b[a+16>>2]=1065353216;b[a+20>>2]=0;b[a+24>>2]=0;b[a+28>>2]=0;b[a+32>>2]=1065353216},_glmc_mat3_inv:function(c,d){c|=0;d|=0;var g=+a[c>>2];var b=+a[c+4>>2];var n=+a[c+8>>2];var e=+a[c+12>>2];var h=+a[c+16>>2];var f=+a[c+20>>2];var k=+a[c+24>>2];var r=+a[c+28>>2];c=+a[c+32>>2];var p=h*c-f*r;var q=-(e*c-f*k);var v=e*r-h*k;var t=1/(n*v+(g*p+b*q));a[d>>2]=p*t;a[d+4>>2]=-((b*c-n*r)*t);a[d+8>>2]= +(b*f-n*h)*t;a[d+12>>2]=t*q;a[d+16>>2]=(g*c-n*k)*t;a[d+20>>2]=-((g*f-n*e)*t);a[d+24>>2]=v*t;a[d+28>>2]=-((g*r-b*k)*t);a[d+32>>2]=(g*h-b*e)*t},_glmc_mat3_mul:function(c,d,g){c|=0;d|=0;g|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var h=+a[c+12>>2];var l=+a[c+16>>2];var k=+a[c+20>>2];var r=+a[c+24>>2];var p=+a[c+28>>2];c=+a[c+32>>2];var q=+a[d>>2];var v=+a[d+4>>2];var t=+a[d+8>>2];var A=+a[d+12>>2];var E=+a[d+16>>2];var J=+a[d+20>>2];var I=+a[d+24>>2];var M=+a[d+28>>2];d=+a[d+32>>2];a[g>>2]= +b*q+h*v+r*t;a[g+4>>2]=e*q+l*v+p*t;a[g+8>>2]=f*q+k*v+c*t;a[g+12>>2]=b*A+h*E+r*J;a[g+16>>2]=e*A+l*E+p*J;a[g+20>>2]=f*A+k*E+c*J;a[g+24>>2]=b*I+h*M+r*d;a[g+28>>2]=e*I+l*M+p*d;a[g+32>>2]=f*I+k*M+c*d},_glmc_mat3_mulv:function(c,d,b){c|=0;d|=0;b|=0;var g=d+4|0;var e=d+8|0;a[b>>2]=+a[c>>2]*+a[d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=c+20|0;a[b>>2]=+a[b>>2]*d;b=c+24|0;a[b>>2]=+a[b>>2]*d;b=c+28|0;a[b>>2]=+a[b>>2]*d;c=c+32|0;a[c>>2]=+a[c>>2]*d}, +_glmc_mat3_swap_col:function(a,d,g){a|=0;d|=0;g|=0;var c=a+(12*d|0)|0;var e=b[c>>2]|0;var f=a+(12*d|0)+4|0;var h=b[f>>2]|0;d=a+(12*d|0)+8|0;var l=b[d>>2]|0;var k=a+(12*g|0)|0;b[c>>2]=b[k>>2];c=a+(12*g|0)+4|0;b[f>>2]=b[c>>2];a=a+(12*g|0)+8|0;b[d>>2]=b[a>>2];b[k>>2]=e;b[c>>2]=h;b[a>>2]=l},_glmc_mat3_swap_row:function(a,d,g){a|=0;d|=0;g|=0;var c=a+(d<<2)|0;var e=b[c>>2]|0;var f=a+12+(d<<2)|0;var h=b[f>>2]|0;d=a+24+(d<<2)|0;var l=b[d>>2]|0;var k=a+(g<<2)|0;b[c>>2]=b[k>>2];c=a+12+(g<<2)|0;b[f>>2]=b[c>> +2];a=a+24+(g<<2)|0;b[d>>2]=b[a>>2];b[k>>2]=e;b[c>>2]=h;b[a>>2]=l},_glmc_mat3_transpose:function(a){a|=0;var c=a+12|0;var g=a+24|0;var u=b[g>>2]|0;var e=a+4|0;var f=b[e>>2]|0;var h=a+28|0;var l=b[h>>2]|0;var k=a+8|0;var r=b[k>>2]|0;a=a+20|0;var p=b[a>>2]|0;b[e>>2]=b[c>>2];b[k>>2]=u;b[c>>2]=f;b[a>>2]=l;b[g>>2]=r;b[h>>2]=p},_glmc_mat3_transpose_to:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+12>>2];b[d+8>>2]=b[a+24>>2];b[d+12>>2]=b[a+4>>2];b[d+16>>2]=b[a+16>>2];b[d+20>>2]=b[a+28>>2];b[d+24>> +2]=b[a+8>>2];b[d+28>>2]=b[a+20>>2];b[d+32>>2]=b[a+32>>2]},_glmc_mat4_copy:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+12>>2]=b[a+12>>2];b[d+16>>2]=b[a+16>>2];b[d+20>>2]=b[a+20>>2];b[d+24>>2]=b[a+24>>2];b[d+28>>2]=b[a+28>>2];b[d+32>>2]=b[a+32>>2];b[d+36>>2]=b[a+36>>2];b[d+40>>2]=b[a+40>>2];b[d+44>>2]=b[a+44>>2];b[d+48>>2]=b[a+48>>2];b[d+52>>2]=b[a+52>>2];b[d+56>>2]=b[a+56>>2];b[d+60>>2]=b[a+60>>2]},_glmc_mat4_det:function(c){c|=0;var d=+a[c+16>>2];var b=+a[c+ +20>>2];var u=+a[c+24>>2];var e=+a[c+28>>2];var f=+a[c+32>>2];var h=+a[c+36>>2];var l=+a[c+40>>2];var k=+a[c+44>>2];var r=+a[c+48>>2];var p=+a[c+52>>2];var q=+a[c+56>>2];var v=+a[c+60>>2];var t=l*v-k*q;var A=h*v-k*p;var E=h*q-l*p;k=f*v-k*r;l=f*q-l*r;f=f*p-h*r;return+(+a[c+8>>2]*(e*f+(d*A-b*k))+(+a[c>>2]*(e*E+(b*t-u*A))-+a[c+4>>2]*(e*l+(d*t-u*k)))-+a[c+12>>2]*(u*f+(d*E-b*l)))},_glmc_mat4_identity:function(a){a|=0;var c=a+4|0;b[a>>2]=1065353216;var g=a+24|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>> +2]=0;b[a+20>>2]=1065353216;c=a+44|0;b[g>>2]=0;b[g+4>>2]=0;b[g+8>>2]=0;b[g+12>>2]=0;b[a+40>>2]=1065353216;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;b[a+60>>2]=1065353216},_glmc_mat4_ins3:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+16>>2]=b[a+12>>2];b[d+20>>2]=b[a+16>>2];b[d+24>>2]=b[a+20>>2];b[d+32>>2]=b[a+24>>2];b[d+36>>2]=b[a+28>>2];b[d+40>>2]=b[a+32>>2]},_glmc_mat4_inv:function(c,d){c|=0;d|=0;var b=+a[c>>2];var u=+a[c+4>>2];var e=+a[c+8>>2];var f=+a[c+ +12>>2];var h=+a[c+16>>2];var l=+a[c+20>>2];var k=+a[c+24>>2];var r=+a[c+28>>2];var p=+a[c+32>>2];var q=+a[c+36>>2];var v=+a[c+40>>2];var t=+a[c+44>>2];var A=+a[c+48>>2];var E=+a[c+52>>2];var J=+a[c+56>>2];var I=+a[c+60>>2];var M=v*I-t*J;var S=q*I-t*E;var m=q*J-v*E;var w=p*I-t*A;var x=p*J-v*A;var y=p*E-q*A;a[d>>2]=r*m+(l*M-k*S);c=d+16|0;a[c>>2]=-(r*x+(h*M-k*w));var B=d+32|0;a[B>>2]=r*y+(h*S-l*w);var z=d+48|0;a[z>>2]=-(k*y+(h*m-l*x));var F=d+4|0;a[F>>2]=-(f*m+(u*M-e*S));var D=d+20|0;a[D>>2]=f*x+(b* +M-e*w);M=d+36|0;a[M>>2]=-(f*y+(b*S-u*w));S=d+52|0;a[S>>2]=e*y+(b*m-u*x);m=k*I-r*J;x=l*I-r*E;y=l*J-k*E;I=h*I-r*A;J=h*J-k*A;A=h*E-l*A;E=k*t-r*v;w=l*t-r*q;var C=l*v-k*q;r=h*t-r*p;k=h*v-k*p;h=h*q-l*p;l=+a[d>>2];p=+a[c>>2];q=+a[B>>2];v=+a[z>>2];t=1/(b*l+u*p+e*q+f*v);a[d>>2]=l*t;a[F>>2]=+a[F>>2]*t;a[d+8>>2]=(f*y+(u*m-e*x))*t;a[d+12>>2]=-((f*C+(u*E-e*w))*t);a[c>>2]=p*t;a[D>>2]=t*+a[D>>2];a[d+24>>2]=-((f*J+(b*m-e*I))*t);a[d+28>>2]=(f*k+(b*E-e*r))*t;a[B>>2]=q*t;a[M>>2]=t*+a[M>>2];a[d+40>>2]=(f*A+(b*x-u*I))* +t;a[d+44>>2]=-((f*h+(b*w-u*r))*t);a[z>>2]=v*t;a[S>>2]=t*+a[S>>2];a[d+56>>2]=-((e*A+(b*y-u*J))*t);a[d+60>>2]=(e*h+(b*C-u*k))*t},_glmc_mat4_inv_fast:function(c,d){c|=0;d|=0;var b=+a[c>>2];var u=+a[c+4>>2];var e=+a[c+8>>2];var f=+a[c+12>>2];var h=+a[c+16>>2];var l=+a[c+20>>2];var k=+a[c+24>>2];var r=+a[c+28>>2];var p=+a[c+32>>2];var q=+a[c+36>>2];var v=+a[c+40>>2];var t=+a[c+44>>2];var A=+a[c+48>>2];var E=+a[c+52>>2];var J=+a[c+56>>2];var I=+a[c+60>>2];var M=v*I-t*J;var m=q*I-t*E;var w=q*J-v*E;var W= +p*I-t*A;var x=p*J-v*A;var y=p*E-q*A;a[d>>2]=r*w+(l*M-k*m);c=d+16|0;a[c>>2]=-(r*x+(h*M-k*W));var B=d+32|0;a[B>>2]=r*y+(h*m-l*W);var z=d+48|0;a[z>>2]=-(k*y+(h*w-l*x));var F=d+4|0;a[F>>2]=-(f*w+(u*M-e*m));var D=d+20|0;a[D>>2]=f*x+(b*M-e*W);M=d+36|0;a[M>>2]=-(f*y+(b*m-u*W));m=d+52|0;a[m>>2]=e*y+(b*w-u*x);w=k*I-r*J;x=l*I-r*E;y=l*J-k*E;I=h*I-r*A;J=h*J-k*A;A=h*E-l*A;E=k*t-r*v;W=l*t-r*q;var C=l*v-k*q;r=h*t-r*p;k=h*v-k*p;h=h*q-l*p;l=+a[d>>2];p=+a[c>>2];q=+a[B>>2];v=+a[z>>2];t=1/(b*l+u*p+e*q+f*v);a[d>>2]=l* +t;a[F>>2]=+a[F>>2]*t;a[d+8>>2]=(f*y+(u*w-e*x))*t;a[d+12>>2]=-((f*C+(u*E-e*W))*t);a[c>>2]=p*t;a[D>>2]=t*+a[D>>2];a[d+24>>2]=-((f*J+(b*w-e*I))*t);a[d+28>>2]=(f*k+(b*E-e*r))*t;a[B>>2]=q*t;a[M>>2]=t*+a[M>>2];a[d+40>>2]=(f*A+(b*x-u*I))*t;a[d+44>>2]=-((f*h+(b*W-u*r))*t);a[z>>2]=v*t;a[m>>2]=t*+a[m>>2];a[d+56>>2]=-((e*A+(b*y-u*J))*t);a[d+60>>2]=(e*h+(b*C-u*k))*t},_glmc_mat4_inv_precise:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=+a[c+4>>2];var n=+a[c+8>>2];var f=+a[c+12>>2];var h=+a[c+16>>2];var l=+a[c+ +20>>2];var k=+a[c+24>>2];var r=+a[c+28>>2];var p=+a[c+32>>2];var q=+a[c+36>>2];var v=+a[c+40>>2];var t=+a[c+44>>2];var A=+a[c+48>>2];var E=+a[c+52>>2];var J=+a[c+56>>2];var I=+a[c+60>>2];var M=v*I-t*J;var m=q*I-t*E;var w=q*J-v*E;var x=p*I-t*A;var y=p*J-v*A;var B=p*E-q*A;a[d>>2]=r*w+(l*M-k*m);c=d+16|0;a[c>>2]=-(r*y+(h*M-k*x));var z=d+32|0;a[z>>2]=r*B+(h*m-l*x);var F=d+48|0;a[F>>2]=-(k*B+(h*w-l*y));var D=d+4|0;a[D>>2]=-(f*w+(e*M-n*m));var C=d+20|0;a[C>>2]=f*y+(b*M-n*x);M=d+36|0;a[M>>2]=-(f*B+(b*m-e* +x));m=d+52|0;a[m>>2]=n*B+(b*w-e*y);w=k*I-r*J;y=l*I-r*E;B=l*J-k*E;I=h*I-r*A;J=h*J-k*A;A=h*E-l*A;E=k*t-r*v;x=l*t-r*q;var O=l*v-k*q;r=h*t-r*p;k=h*v-k*p;h=h*q-l*p;l=+a[d>>2];p=+a[c>>2];q=+a[z>>2];v=+a[F>>2];t=1/(b*l+e*p+n*q+f*v);a[d>>2]=l*t;a[D>>2]=+a[D>>2]*t;a[d+8>>2]=(f*B+(e*w-n*y))*t;a[d+12>>2]=-((f*O+(e*E-n*x))*t);a[c>>2]=p*t;a[C>>2]=t*+a[C>>2];a[d+24>>2]=-((f*J+(b*w-n*I))*t);a[d+28>>2]=(f*k+(b*E-n*r))*t;a[z>>2]=q*t;a[M>>2]=t*+a[M>>2];a[d+40>>2]=(f*A+(b*y-e*I))*t;a[d+44>>2]=-((f*h+(b*x-e*r))*t);a[F>> +2]=v*t;a[m>>2]=t*+a[m>>2];a[d+56>>2]=-((n*A+(b*B-e*J))*t);a[d+60>>2]=(n*h+(b*O-e*k))*t},_glmc_mat4_mul:function(c,d,b){c|=0;d|=0;b|=0;var g=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var h=+a[c+12>>2];var l=+a[c+16>>2];var k=+a[c+20>>2];var r=+a[c+24>>2];var p=+a[c+28>>2];var q=+a[c+32>>2];var v=+a[c+36>>2];var t=+a[c+40>>2];var A=+a[c+44>>2];var E=+a[c+48>>2];var J=+a[c+52>>2];var I=+a[c+56>>2];c=+a[c+60>>2];var m=+a[d>>2];var w=+a[d+4>>2];var x=+a[d+8>>2];var y=+a[d+12>>2];var B=+a[d+16>>2];var z= ++a[d+20>>2];var F=+a[d+24>>2];var D=+a[d+28>>2];var C=+a[d+32>>2];var K=+a[d+36>>2];var O=+a[d+40>>2];var H=+a[d+44>>2];var R=+a[d+48>>2];var U=+a[d+52>>2];var P=+a[d+56>>2];d=+a[d+60>>2];a[b>>2]=g*m+l*w+q*x+E*y;a[b+4>>2]=e*m+k*w+v*x+J*y;a[b+8>>2]=f*m+r*w+t*x+I*y;a[b+12>>2]=h*m+p*w+A*x+c*y;a[b+16>>2]=g*B+l*z+q*F+E*D;a[b+20>>2]=e*B+k*z+v*F+J*D;a[b+24>>2]=f*B+r*z+t*F+I*D;a[b+28>>2]=h*B+p*z+A*F+c*D;a[b+32>>2]=g*C+l*K+q*O+E*H;a[b+36>>2]=e*C+k*K+v*O+J*H;a[b+40>>2]=f*C+r*K+t*O+I*H;a[b+44>>2]=h*C+p*K+A* +O+c*H;a[b+48>>2]=g*R+l*U+q*P+E*d;a[b+52>>2]=e*R+k*U+v*P+J*d;a[b+56>>2]=f*R+r*U+t*P+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2]*d;a[b+4>>2]=h;a[b+8>>2]=l;a[b+12>>2]=k},_glmc_mat4_mulv3:function(c,d,b,e){c|=0;d|=0;b=+b;e|=0;var g=+a[d>>2];var u=+a[d+4>>2];var h=+a[d+8>>2];d=g*+a[c+4>>2]+u*+a[c+20>>2]+h*+a[c+36>>2]+ +a[c+52>>2]*b;var f=g*+a[c+8>>2]+u*+a[c+24>>2]+h*+a[c+40>>2]+ +a[c+56>>2]*b;a[e>>2]=g*+a[c>>2]+u*+a[c+16>>2]+h* ++a[c+32>>2]+ +a[c+48>>2]*b;a[e+4>>2]=d;a[e+8>>2]=f},_glmc_mat4_pick3:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+12>>2]=b[a+16>>2];b[d+16>>2]=b[a+20>>2];b[d+20>>2]=b[a+24>>2];b[d+24>>2]=b[a+32>>2];b[d+28>>2]=b[a+36>>2];b[d+32>>2]=b[a+40>>2]},_glmc_mat4_pick3t:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+16>>2];b[d+8>>2]=b[a+32>>2];b[d+12>>2]=b[a+4>>2];b[d+16>>2]=b[a+20>>2];b[d+20>>2]=b[a+36>>2];b[d+24>>2]=b[a+8>>2];b[d+28>>2]=b[a+24>>2];b[d+32>>2]= +b[a+40>>2]},_glmc_mat4_quat:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=c+16|0;var n=+a[c+20>>2];var f=c+32|0;var h=+a[c+40>>2];var l=b+n+h;0<=l?(n=+B(+(l+1)),h=.5/n,a[d>>2]=h*(+a[c+24>>2]-+a[c+36>>2]),a[d+4>>2]=h*(+a[f>>2]-+a[c+8>>2]),a[d+8>>2]=h*(+a[c+4>>2]-+a[e>>2]),a[(d+12|0)>>2]=.5*n):(!(b>=n)|!(b>=h)?(l=1-b,n>=h?(n=+B(+(n+(l-h))),h=.5/n,a[d>>2]=h*(+a[c+4>>2]+ +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b>>2]*d;b=c+28|0;a[b>>2]=+a[b>>2]*d;b=c+32| +0;a[b>>2]=+a[b>>2]*d;b=c+36|0;a[b>>2]=+a[b>>2]*d;b=c+40|0;a[b>>2]=+a[b>>2]*d;b=c+44|0;a[b>>2]=+a[b>>2]*d;b=c+48|0;a[b>>2]=+a[b>>2]*d;b=c+52|0;a[b>>2]=+a[b>>2]*d;b=c+56|0;a[b>>2]=+a[b>>2]*d;c=c+60|0;a[c>>2]=+a[c>>2]*d},_glmc_mat4_swap_col:function(a,d,g){a|=0;d|=0;g|=0;var c=a+(d<<4)|0;var e=b[c>>2]|0;var f=a+(d<<4)+4|0;var h=b[f>>2]|0;var l=a+(d<<4)+8|0;var k=b[l>>2]|0;var r=a+(d<<4)+12|0;d=b[r>>2]|0;var p=a+(g<<4)|0;b[c>>2]=b[p>>2];c=a+(g<<4)+4|0;b[f>>2]=b[c>>2];f=a+(g<<4)+8|0;b[l>>2]=b[f>>2];a= +a+(g<<4)+12|0;b[r>>2]=b[a>>2];b[p>>2]=e;b[c>>2]=h;b[f>>2]=k;b[a>>2]=d},_glmc_mat4_swap_row:function(a,d,g){a|=0;d|=0;g|=0;var c=a+(d<<2)|0;var e=b[c>>2]|0;var f=a+16+(d<<2)|0;var h=b[f>>2]|0;var l=a+32+(d<<2)|0;var k=b[l>>2]|0;var r=a+48+(d<<2)|0;d=b[r>>2]|0;var p=a+(g<<2)|0;b[c>>2]=b[p>>2];c=a+16+(g<<2)|0;b[f>>2]=b[c>>2];f=a+32+(g<<2)|0;b[l>>2]=b[f>>2];a=a+48+(g<<2)|0;b[r>>2]=b[a>>2];b[p>>2]=e;b[c>>2]=h;b[f>>2]=k;b[a>>2]=d},_glmc_mat4_transpose:function(a){a|=0;var c=a+4|0;var g=b[c>>2]|0;var e= +b[a+20>>2]|0;var n=b[a+32>>2]|0;var f=b[a+36>>2]|0;var h=b[a+48>>2]|0;var l=b[a+52>>2]|0;var k=a+8|0;var r=b[k>>2]|0;var p=a+12|0;var q=b[p>>2]|0;var v=b[a+24>>2]|0;var t=b[a+28>>2]|0;var A=b[a+40>>2]|0;var E=b[a+44>>2]|0;var J=b[a+56>>2]|0;var m=b[a+60>>2]|0;b[c>>2]=b[a+16>>2];b[k>>2]=n;b[p>>2]=h;b[a+16>>2]=g;b[a+20>>2]=e;b[a+24>>2]=f;b[a+28>>2]=l;b[a+32>>2]=r;b[a+36>>2]=v;b[a+40>>2]=A;b[a+44>>2]=J;b[a+48>>2]=q;b[a+52>>2]=t;b[a+56>>2]=E;b[a+60>>2]=m},_glmc_mat4_transpose_to:function(a,d){a|=0;d|= +0;b[d>>2]=b[a>>2];b[d+16>>2]=b[a+4>>2];b[d+4>>2]=b[a+16>>2];b[d+20>>2]=b[a+20>>2];b[d+8>>2]=b[a+32>>2];b[d+24>>2]=b[a+36>>2];b[d+12>>2]=b[a+48>>2];b[d+28>>2]=b[a+52>>2];b[d+32>>2]=b[a+8>>2];b[d+48>>2]=b[a+12>>2];b[d+36>>2]=b[a+24>>2];b[d+52>>2]=b[a+28>>2];b[d+40>>2]=b[a+40>>2];b[d+56>>2]=b[a+44>>2];b[d+44>>2]=b[a+56>>2];b[d+60>>2]=b[a+60>>2]},_glmc_mat4_ucopy:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+12>>2]=b[a+12>>2];b[d+16>>2]=b[a+16>>2];b[d+20>>2]=b[a+ +20>>2];b[d+24>>2]=b[a+24>>2];b[d+28>>2]=b[a+28>>2];b[d+32>>2]=b[a+32>>2];b[d+36>>2]=b[a+36>>2];b[d+40>>2]=b[a+40>>2];b[d+44>>2]=b[a+44>>2];b[d+48>>2]=b[a+48>>2];b[d+52>>2]=b[a+52>>2];b[d+56>>2]=b[a+56>>2];b[d+60>>2]=b[a+60>>2]},_glmc_mul:function(c,d,b){c|=0;d|=0;b|=0;var g=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var h=+a[c+12>>2];var l=+a[c+16>>2];var k=+a[c+20>>2];var r=+a[c+24>>2];var p=+a[c+28>>2];var q=+a[c+32>>2];var v=+a[c+36>>2];var t=+a[c+40>>2];var A=+a[c+44>>2];var E=+a[c+48>>2];var m= ++a[c+52>>2];var I=+a[c+56>>2];c=+a[c+60>>2];var w=+a[d>>2];var x=+a[d+4>>2];var y=+a[d+8>>2];var B=+a[d+16>>2];var z=+a[d+20>>2];var F=+a[d+24>>2];var D=+a[d+32>>2];var C=+a[d+36>>2];var K=+a[d+40>>2];var H=+a[d+48>>2];var O=+a[d+52>>2];var R=+a[d+56>>2];d=+a[d+60>>2];a[b>>2]=g*w+l*x+q*y;a[b+4>>2]=e*w+k*x+v*y;a[b+8>>2]=f*w+r*x+t*y;a[b+12>>2]=h*w+p*x+A*y;a[b+16>>2]=g*B+l*z+q*F;a[b+20>>2]=e*B+k*z+v*F;a[b+24>>2]=f*B+r*z+t*F;a[b+28>>2]=h*B+p*z+A*F;a[b+32>>2]=g*D+l*C+q*K;a[b+36>>2]=e*D+k*C+v*K;a[b+40>> +2]=f*D+r*C+t*K;a[b+44>>2]=h*D+p*C+A*K;a[b+48>>2]=g*H+l*O+q*R+E*d;a[b+52>>2]=e*H+k*O+v*R+m*d;a[b+56>>2]=f*H+r*O+t*R+I*d;a[b+60>>2]=h*H+p*O+A*R+c*d},_glmc_mul_rot:function(c,d,g){c|=0;d|=0;g|=0;var e=+a[c>>2];var n=+a[c+4>>2];var f=+a[c+8>>2];var h=+a[c+12>>2];var l=+a[c+16>>2];var k=+a[c+20>>2];var r=+a[c+24>>2];var p=+a[c+28>>2];var q=+a[c+32>>2];var v=+a[c+36>>2];var t=+a[c+40>>2];var A=+a[c+44>>2];var E=b[c+48>>2]|0;var m=b[c+52>>2]|0;var I=b[c+56>>2]|0;c=b[c+60>>2]|0;var w=+a[d>>2];var x=+a[d+ +4>>2];var y=+a[d+8>>2];var B=+a[d+16>>2];var z=+a[d+20>>2];var F=+a[d+24>>2];var D=+a[d+32>>2];var C=+a[d+36>>2];d=+a[d+40>>2];a[g>>2]=e*w+l*x+q*y;a[g+4>>2]=n*w+k*x+v*y;a[g+8>>2]=f*w+r*x+t*y;a[g+12>>2]=h*w+p*x+A*y;a[g+16>>2]=e*B+l*z+q*F;a[g+20>>2]=n*B+k*z+v*F;a[g+24>>2]=f*B+r*z+t*F;a[g+28>>2]=h*B+p*z+A*F;a[g+32>>2]=e*D+l*C+q*d;a[g+36>>2]=n*D+k*C+v*d;a[g+40>>2]=f*D+r*C+t*d;a[g+44>>2]=h*D+p*C+A*d;b[g+48>>2]=E;b[g+52>>2]=m;b[g+56>>2]=I;b[g+60>>2]=c},_glmc_ortho:function(c,d,g,e,n,f,h){c=+c;d=+d;g=+g; +e=+e;n=+n;f=+f;h|=0;var u=h+4|0;var k=u+44|0;do b[u>>2]=0,u=u+4|0;while((u|0)<(k|0));var G=1/(d-c);u=1/(e-g);k=-1/(f-n);a[h>>2]=2*G;a[h+20>>2]=2*u;a[h+40>>2]=2*k;a[h+48>>2]=-((c+d)*G);a[h+52>>2]=-((g+e)*u);a[h+56>>2]=(n+f)*k;a[h+60>>2]=1},_glmc_ortho_aabb:function(c,d){c|=0;d|=0;var g=+a[c>>2];var e=+a[c+12>>2];var n=+a[c+4>>2];var f=+a[c+16>>2];var h=+a[c+20>>2];c=+a[c+8>>2];var l=d+4|0;var k=l+44|0;do b[l>>2]=0,l=l+4|0;while((l|0)<(k|0));l=1/(e-g);k=1/(f-n);var r=-1/(h-c);a[d>>2]=2*l;a[d+20>>2]= +2*k;a[d+40>>2]=2*r;a[d+48>>2]=-((g+e)*l);a[d+52>>2]=-((n+f)*k);a[d+56>>2]=(-c-h)*r;a[d+60>>2]=1},_glmc_ortho_aabb_p:function(c,d,g){c|=0;d=+d;g|=0;var e=+a[c>>2]-d;var n=+a[c+12>>2]+d;var f=+a[c+4>>2]-d;var h=+a[c+16>>2]+d;var l=+a[c+20>>2]+d;c=+a[c+8>>2]-d;d=g+4|0;var k=d+44|0;do b[d>>2]=0,d=d+4|0;while((d|0)<(k|0));d=1/(n-e);k=1/(h-f);var r=-1/(l-c);a[g>>2]=2*d;a[g+20>>2]=2*k;a[g+40>>2]=2*r;a[g+48>>2]=-((e+n)*d);a[g+52>>2]=-((f+h)*k);a[g+56>>2]=(-c-l)*r;a[g+60>>2]=1},_glmc_ortho_aabb_pz:function(c, +d,g){c|=0;d=+d;g|=0;var e=+a[c>>2];var n=+a[c+12>>2];var f=+a[c+4>>2];var h=+a[c+16>>2];var l=+a[c+20>>2]+d;c=+a[c+8>>2]-d;d=g+4|0;var k=d+44|0;do b[d>>2]=0,d=d+4|0;while((d|0)<(k|0));d=1/(n-e);k=1/(h-f);var r=-1/(l-c);a[g>>2]=2*d;a[g+20>>2]=2*k;a[g+40>>2]=2*r;a[g+48>>2]=-((e+n)*d);a[g+52>>2]=-((f+h)*k);a[g+56>>2]=(-c-l)*r;a[g+60>>2]=1},_glmc_ortho_default:function(c,d){c=+c;d|=0;if(1<=c){var g=d+4|0;var e=g+44|0;do b[g>>2]=0,g=g+4|0;while((g|0)<(e|0));e=1/(c+c);var n=-0;c=-((c-c)*e);g=1;e*=2}else{n= +-1/c;c=1/c;g=d+4|0;e=g+44|0;do b[g>>2]=0,g=g+4|0;while((g|0)<(e|0));g=1/(c-n);n=-((n+c)*g);c=-0;g*=2;e=1}a[d>>2]=e;a[d+20>>2]=g;a[d+40>>2]=-.009999999776482582;a[d+48>>2]=c;a[d+52>>2]=n;a[d+56>>2]=-0;a[d+60>>2]=1},_glmc_ortho_default_s:function(c,d,g){c=+c;d=+d;g|=0;var e=-d;if(1<=c){e*=c;var n=c*d;var f=-100-d;var h=d+100;c=g+4|0;var l=c+44|0;do b[c>>2]=0,c=c+4|0;while((c|0)<(l|0));var k=1/(n-e);l=1/(d+d);c=(e+n)*k;d=(d-d)*l;e=h-f;f+=h}else{e/=c;n=d/c;k=-100-d;f=d+100;c=g+4|0;l=c+44|0;do b[c>>2]= +0,c=c+4|0;while((c|0)<(l|0));h=1/(d+d);l=1/(n-e);c=(d-d)*h;d=(e+n)*l;e=f-k;f=k+f;k=h}e=-1/e;a[g>>2]=2*k;a[g+20>>2]=2*l;a[g+40>>2]=2*e;a[g+48>>2]=-c;a[g+52>>2]=-d;a[g+56>>2]=e*f;a[g+60>>2]=1},_glmc_persp_aspect:function(c){c|=0;return+(+a[c+20>>2]/+a[c>>2])},_glmc_persp_decomp:function(c,d,b,e,n,f,h){c|=0;var g=+a[c+32>>2];var u=+a[c+36>>2];var G=+a[c+40>>2];var p=+a[c+56>>2];var q=p/(G+-1);var v=q/+a[c+20>>2];c=q/+a[c>>2];a[(d|0)>>2]=q;a[(b|0)>>2]=p/(G+1);a[(n|0)>>2]=(u+-1)*v;a[(e|0)>>2]=(u+1)*v; +a[(f|0)>>2]=(g+-1)*c;a[(h|0)>>2]=(g+1)*c},_glmc_persp_decomp_far:function(c,d){c|=0;a[(d|0)>>2]=+a[c+56>>2]/(+a[c+40>>2]+1)},_glmc_persp_decomp_near:function(c,d){c|=0;a[(d|0)>>2]=+a[c+56>>2]/(+a[c+40>>2]+-1)},_glmc_persp_decomp_x:function(c,d,b){c|=0;var g=+a[c>>2];var e=+a[c+32>>2];c=+a[c+56>>2]/(+a[c+60>>2]+-1);a[(d|0)>>2]=(e+-1)*c/g;a[(b|0)>>2]=(e+1)*c/g},_glmc_persp_decomp_y:function(c,d,b){c|=0;var g=+a[c+36>>2];var e=+a[c+20>>2];c=+a[c+56>>2]/(+a[c+60>>2]+-1);a[(b|0)>>2]=(g+-1)*c/e;a[(d|0)>> +2]=(g+1)*c/e},_glmc_persp_decomp_z:function(c,d,b){c|=0;var g=+a[c+40>>2];c=+a[c+56>>2];a[(d|0)>>2]=c/(g+-1);a[(b|0)>>2]=c/(g+1)},_glmc_persp_decompv:function(c,d){c|=0;d|=0;var b=+a[c+32>>2];var e=+a[c+36>>2];var n=+a[c+40>>2];var f=+a[c+56>>2];var h=f/(n+-1);var l=h/+a[c+20>>2];c=h/+a[c>>2];a[d>>2]=h;a[d+4>>2]=f/(n+1);a[d+12>>2]=(e+-1)*l;a[d+8>>2]=(e+1)*l;a[d+16>>2]=(b+-1)*c;a[d+20>>2]=(b+1)*c},_glmc_persp_fovy:function(c){return+(2*+ra(+(1/+a[(c|0)+20>>2])))},_glmc_persp_sizes:function(c,d,b){c|= +0;b|=0;var g=2*+V(+(.5*+d));d=+a[c+20>>2]/+a[c>>2];var e=+a[c+40>>2];var f=+a[c+56>>2];c=f/(e+-1)*g;a[b+4>>2]=c;e=f/(e+1)*g;a[b+12>>2]=e;a[b>>2]=d*c;a[b+8>>2]=d*e},_glmc_perspective:function(c,d,g,e,n){d=+d;g=+g;e=+e;n|=0;var u=n+4|0;var f=u+60|0;do b[u>>2]=0,u=u+4|0;while((u|0)<(f|0));u=1/+V(+(.5*+c));c=1/(g-e);a[n>>2]=u/d;a[n+20>>2]=u;a[n+40>>2]=(g+e)*c;a[n+44>>2]=-1;a[n+56>>2]=2*g*e*c},_glmc_perspective_default:function(c,d){d|=0;var g=d+4|0;var e=g+60|0;do b[g>>2]=0,g=g+4|0;while((g|0)<(e|0)); +a[d>>2]=2.4142134189605713/+c;a[d+20>>2]=2.4142134189605713;a[d+40>>2]=-1.0002000331878662;a[d+44>>2]=-1;a[d+56>>2]=-.020002000033855438},_glmc_perspective_resize:function(c,d){d|=0;0!=+a[d>>2]&&(a[d>>2]=+a[d+20>>2]/+c)},_glmc_plane_normalize:function(c){c|=0;var d=+a[c>>2];var b=c+4|0;var e=+a[b>>2];var n=c+8|0;var f=+a[n>>2];var h=1/+B(+(d*d+e*e+f*f));a[c>>2]=d*h;a[b>>2]=e*h;a[n>>2]=f*h;c=c+12|0;a[c>>2]=h*+a[c>>2]},_glmc_project:function(c,d,b,e){c|=0;d|=0;b|=0;e|=0;var g=+a[c>>2];var u=+a[c+4>> +2];var f=+a[c+8>>2];c=1/(+a[d+60>>2]+(g*+a[d+12>>2]+u*+a[d+28>>2]+f*+a[d+44>>2]));var l=.5*((+a[d+52>>2]+(g*+a[d+4>>2]+u*+a[d+20>>2]+f*+a[d+36>>2]))*c+1);var k=.5*((+a[d+56>>2]+(g*+a[d+8>>2]+u*+a[d+24>>2]+f*+a[d+40>>2]))*c+1);a[e>>2]=+a[b>>2]+.5*+a[b+8>>2]*((+a[d+48>>2]+(g*+a[d>>2]+u*+a[d+16>>2]+f*+a[d+32>>2]))*c+1);a[e+4>>2]=+a[b+4>>2]+ +a[b+12>>2]*l;a[e+8>>2]=k},_glmc_quat:function(c,d,b,e,n){c|=0;b=+b;e=+e;n=+n;var g=.5*+d;d=+N(+g);var u=+K(+g);var f=+B(+(b*b+e*e+n*n));g=0==f;f=1/f;a[c>>2]=u*(g? +0:f*b);a[c+4>>2]=u*(g?0:f*e);a[c+8>>2]=u*(g?0:f*n);a[c+12>>2]=d},_glmc_quat_add:function(c,d,b){c|=0;d|=0;b|=0;a[b>>2]=+a[c>>2]+ +a[d>>2];a[b+4>>2]=+a[c+4>>2]+ +a[d+4>>2];a[b+8>>2]=+a[c+8>>2]+ +a[d+8>>2];a[b+12>>2]=+a[c+12>>2]+ +a[d+12>>2]},_glmc_quat_angle:function(c){c|=0;var d=+a[c>>2];var b=+a[c+4>>2];var e=+a[c+8>>2];b=+B(+(d*d+b*b+e*e));return+(2*+T(+b,+ +a[c+12>>2]))},_glmc_quat_axis:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=c+4|0;var n=+a[e>>2];c=c+8|0;var f=+a[c>>2];n=+B(+(b*b+n*n+f*f)); +0==n?(a[d>>2]=0,a[d+4>>2]=0,a[(d+8|0)>>2]=0):(n=1/n,a[d>>2]=b*n,a[d+4>>2]=n*+a[e>>2],e=n*+a[c>>2],a[(d+8|0)>>2]=e)},_glmc_quat_conjugate:function(c,d){c|=0;d|=0;a[d>>2]=-+a[c>>2];a[d+4>>2]=-+a[c+4>>2];a[d+8>>2]=-+a[c+8>>2];b[d+12>>2]=b[c+12>>2]},_glmc_quat_copy:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+12>>2]=b[a+12>>2]},_glmc_quat_dot:function(c,d){c|=0;d|=0;return+(+a[c>>2]*+a[d>>2]+ +a[c+4>>2]*+a[d+4>>2]+ +a[c+8>>2]*+a[d+8>>2]+ +a[c+12>>2]*+a[d+12>>2])}, +_glmc_quat_for:function(c,d,g,e){c|=0;d|=0;g|=0;e|=0;var u=+a[c>>2];var f=+a[c+4>>2];var h=+a[c+8>>2];var l=+a[d>>2];c=+a[d+4>>2];var k=+a[d+8>>2];d=u*l+f*c+h*k;9.999999974752427E-7>+D(+(d+1))?(d=b[g+4>>2]|0,f=b[g+8>>2]|0,b[e>>2]=b[g>>2],b[e+4>>2]=d,b[e+8>>2]=f,a[e+12>>2]=3.1415927410125732):9.999999974752427E-7>+D(+(d+-1))?(b[e>>2]=0,b[e+4>>2]=0,b[e+8>>2]=0,b[e+12>>2]=1065353216):(g=+Z(+d),d=h*c-f*k,h=u*k-h*l,f=f*l-u*c,u=+B(+(f*f+(d*d+h*h))),c=0==u,l=1/u,f=c?0:f*l,u=c?0:h*l,d=c?0:d*l,c=.5*g,g=+N(+c), +c=+K(+c),h=+B(+(f*f+(u*u+d*d))),l=0==h,h=1/h,a[e>>2]=c*(l?0:d*h),a[e+4>>2]=c*(l?0:u*h),a[e+8>>2]=c*(l?0:f*h),a[e+12>>2]=g)},_glmc_quat_forp:function(c,d,g,e,f){c|=0;d|=0;g|=0;e|=0;f|=0;var u=+a[g>>2];var n=+a[g+4>>2];var l=+a[g+8>>2];g=+a[d>>2]-+a[c>>2];var k=+a[d+4>>2]-+a[c+4>>2];d=+a[d+8>>2]-+a[c+8>>2];c=g*u+k*n+d*l;9.999999974752427E-7>+D(+(c+1))?(c=b[e+4>>2]|0,n=b[e+8>>2]|0,b[f>>2]=b[e>>2],b[f+4>>2]=c,b[f+8>>2]=n,a[f+12>>2]=3.1415927410125732):9.999999974752427E-7>+D(+(c+-1))?(b[f>>2]=0,b[f+4>> +2]=0,b[f+8>>2]=0,b[f+12>>2]=1065353216):(e=+Z(+c),c=d*n-k*l,l=g*l-d*u,n=k*u-g*n,u=+B(+(n*n+(c*c+l*l))),g=0==u,k=1/u,n=g?0:n*k,u=g?0:l*k,c=g?0:c*k,g=.5*e,e=+N(+g),g=+K(+g),l=+B(+(n*n+(u*u+c*c))),k=0==l,l=1/l,a[f>>2]=g*(k?0:c*l),a[f+4>>2]=g*(k?0:u*l),a[f+8>>2]=g*(k?0:n*l),a[f+12>>2]=e)},_glmc_quat_identity:function(a){a|=0;b[a>>2]=0;b[a+4>>2]=0;b[a+8>>2]=0;b[a+12>>2]=1065353216},_glmc_quat_imag:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2]},_glmc_quat_imaglen:function(c){c|= +0;var d=+a[c>>2];var b=+a[c+4>>2];c=+a[c+8>>2];return+ +B(+(d*d+b*b+c*c))},_glmc_quat_imagn:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=c+4|0;var f=+a[e>>2];c=c+8|0;var G=+a[c>>2];f=+B(+(b*b+f*f+G*G));0==f?(a[d>>2]=0,a[d+4>>2]=0,a[(d+8|0)>>2]=0):(f=1/f,a[d>>2]=b*f,a[d+4>>2]=f*+a[e>>2],e=f*+a[c>>2],a[(d+8|0)>>2]=e)},_glmc_quat_init:function(c,d,b,e,f){c|=0;a[c>>2]=+d;a[c+4>>2]=+b;a[c+8>>2]=+e;a[c+12>>2]=+f},_glmc_quat_inv:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var G= ++a[c+12>>2];c=1/(b*b+e*e+f*f+G*G);a[d>>2]=-(b*c);a[d+4>>2]=-(e*c);a[d+8>>2]=-(f*c);a[d+12>>2]=G*c},_glmc_quat_lerp:function(c,d,b,e){c|=0;d|=0;b=+b;e|=0;b=0b?b:1;var g=+a[c>>2];var f=c+4|0;var u=c+8|0;c=c+12|0;var l=b*(+a[d+4>>2]-+a[f>>2]);var k=b*(+a[d+8>>2]-+a[u>>2]);var r=b*(+a[d+12>>2]-+a[c>>2]);a[e>>2]=g+b*(+a[d>>2]-g);a[e+4>>2]=l+ +a[f>>2];a[e+8>>2]=k+ +a[u>>2];a[e+12>>2]=r+ +a[c>>2]},_glmc_quat_look:function(c,d,g){c|=0;d|=0;g|=0;var e=+a[d>>2];var f=+a[d+4>>2];var G=+a[d+8>>2]; +var h=+a[d+12>>2];d=+B(+(e*e+f*f+G*G+h*h));var l=0>2]=G;k=1-e*k;e=k-v;a[g+20>>2]=e;q=k-q;a[g+40>>2]=q;k=d+t;a[g+16>>2]=k;r=p+h;a[g+36>>2]=r;v=l+f;a[g+8>>2]=v;d-=t;a[g+4>>2]=d;h=p-h;a[g+24>>2]=h;p=l-f;a[g+32>>2]=p;a[g+12>>2]=0;a[g+28>>2]=0;f=g+44|0;b[f>>2]=0;b[f+4>>2]=0;b[f+8>>2]=0;b[f+12>>2]=0;a[g+60>>2]=1;f=+a[c>>2];l=+a[c+4>>2];c=+a[c+8>>2];a[g+48>>2]=-(G*f+k*l+p*c);a[g+52>>2]=-(d*f+e* +l+r*c);a[g+56>>2]=-(v*f+h*l+q*c)},_glmc_quat_mat3:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var G=+a[c+12>>2];c=+B(+(b*b+e*e+f*f+G*G));var h=0>2]=1-p-h;b=1-b*l;a[d+16>>2]=b-h;a[d+32>>2]=b-p;a[d+4>>2]=c+f;a[d+20>>2]=r+G;a[d+24>>2]=q+e;a[d+12>>2]=c-f;a[d+28>>2]=r-G;a[d+8>>2]=q-e},_glmc_quat_mat3t:function(c,d){c|=0;d|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var G= ++a[c+12>>2];c=+B(+(b*b+e*e+f*f+G*G));var h=0>2]=1-p-h;b=1-b*l;a[d+16>>2]=b-h;a[d+32>>2]=b-p;a[d+12>>2]=c+f;a[d+28>>2]=r+G;a[d+8>>2]=q+e;a[d+4>>2]=c-f;a[d+20>>2]=r-G;a[d+24>>2]=q-e},_glmc_quat_mat4:function(c,d){c|=0;d|=0;var g=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var G=+a[c+12>>2];c=+B(+(g*g+e*e+f*f+G*G));var h=0>2]=1-p-h;g=1-g*l;a[d+20>>2]=g-h;a[d+40>>2]=g-p;a[d+4>>2]=c+f;a[d+24>>2]=r+G;a[d+32>>2]=q+e;a[d+16>>2]=c-f;a[d+36>>2]=r-G;a[d+8>>2]=q-e;a[d+12>>2]=0;a[d+28>>2]=0;g=d+44|0;b[g>>2]=0;b[g+4>>2]=0;b[g+8>>2]=0;b[g+12>>2]=0;a[d+60>>2]=1},_glmc_quat_mat4t:function(c,d){c|=0;d|=0;var g=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];var G=+a[c+12>>2];c=+B(+(g*g+e*e+f*f+G*G));var h=0>2]=1-p-h;g=1-g*l;a[d+ +20>>2]=g-h;a[d+40>>2]=g-p;a[d+16>>2]=c+f;a[d+36>>2]=r+G;a[d+8>>2]=q+e;a[d+4>>2]=c-f;a[d+24>>2]=r-G;a[d+32>>2]=q-e;a[d+12>>2]=0;a[d+28>>2]=0;g=d+44|0;b[g>>2]=0;b[g+4>>2]=0;b[g+8>>2]=0;b[g+12>>2]=0;a[d+60>>2]=1},_glmc_quat_mul:function(c,d,b){c|=0;d|=0;b|=0;var g=c+12|0;var e=d+12|0;var f=c+4|0;var h=d+8|0;var l=c+8|0;var k=d+4|0;a[b>>2]=+a[g>>2]*+a[d>>2]+ +a[c>>2]*+a[e>>2]+ +a[f>>2]*+a[h>>2]-+a[l>>2]*+a[k>>2];a[b+4>>2]=+a[g>>2]*+a[k>>2]-+a[c>>2]*+a[h>>2]+ +a[f>>2]*+a[e>>2]+ +a[l>>2]*+a[d>>2];a[b+8>> +2]=+a[g>>2]*+a[h>>2]+ +a[c>>2]*+a[k>>2]-+a[f>>2]*+a[d>>2]+ +a[l>>2]*+a[e>>2];a[b+12>>2]=+a[g>>2]*+a[e>>2]-+a[c>>2]*+a[d>>2]-+a[f>>2]*+a[k>>2]-+a[l>>2]*+a[h>>2]},_glmc_quat_norm:function(c){c|=0;var d=+a[c>>2];var b=+a[c+4>>2];var e=+a[c+8>>2];c=+a[c+12>>2];return+ +B(+(d*d+b*b+e*e+c*c))},_glmc_quat_normalize:function(a){},_glmc_quat_normalize_to:function(c,d){c|=0;d|=0;var g=+a[c>>2];var e=c+4|0;var f=+a[e>>2];var G=c+8|0;var h=+a[G>>2];var l=c+12|0;var k=+a[l>>2];k=g*g+f*f+h*h+k*k;0>=k?(b[c>>2]= +0,b[e>>2]=0,b[G>>2]=0,b[l>>2]=1065353216):(c=1/+B(+k),a[d>>2]=g*c,a[d+4>>2]=c*+a[e>>2],a[d+8>>2]=c*+a[G>>2],a[d+12>>2]=c*+a[l>>2])},_glmc_quat_real:function(c){return+ +a[(c|0)+12>>2]},_glmc_quat_rotate:function(c,d,g){c|=0;d|=0;g|=0;var e=+a[d>>2];var f=+a[d+4>>2];var G=+a[d+8>>2];d=+a[d+12>>2];var h=+B(+(e*e+f*f+G*G+d*d));var l=0> +2];l=+a[c+4>>2];t=+a[c+8>>2];var A=+a[c+12>>2];var E=+a[c+16>>2];var m=+a[c+20>>2];var w=+a[c+24>>2];var x=+a[c+28>>2];var y=+a[c+32>>2];var z=+a[c+36>>2];var F=+a[c+40>>2];var D=+a[c+44>>2];var C=b[c+48>>2]|0;var K=b[c+52>>2]|0;var H=b[c+56>>2]|0;c=b[c+60>>2]|0;a[g>>2]=E*h+v*G+q*y;a[g+4>>2]=l*G+h*m+q*z;a[g+8>>2]=t*G+h*w+q*F;a[g+12>>2]=A*G+h*x+q*D;a[g+16>>2]=v*k+E*e+r*y;a[g+20>>2]=l*k+m*e+r*z;a[g+24>>2]=t*k+e*w+r*F;a[g+28>>2]=A*k+e*x+r*D;a[g+32>>2]=v*f+E*p+d*y;a[g+36>>2]=l*f+p*m+d*z;a[g+40>>2]=t* +f+p*w+d*F;a[g+44>>2]=A*f+p*x+d*D;b[g+48>>2]=C;b[g+52>>2]=K;b[g+56>>2]=H;b[g+60>>2]=c},_glmc_quat_rotate_at:function(c,d,b){c|=0;d|=0;b|=0;var g=+a[b>>2];var e=+a[b+4>>2];var f=+a[b+8>>2];b=-g;var h=-e;var l=-f;var k=c+4|0;var r=+a[k>>2];var p=c+8|0;var q=+a[p>>2];var v=c+12|0;var t=+a[v>>2];var A=c+16|0;var E=+a[A>>2];var m=c+20|0;var w=+a[m>>2];var x=c+24|0;var y=+a[x>>2];var z=c+28|0;var F=+a[z>>2];var D=c+32|0;var C=+a[D>>2];var K=c+36|0;var H=+a[K>>2];var R=c+40|0;var N=+a[R>>2];var O=c+44|0; +var Q=+a[O>>2];var T=c+48|0;var U=c+52|0;var P=c+56|0;var L=c+60|0;var Sa=e*w+(g*r+ +a[U>>2]);var Z=e*y+(g*q+ +a[P>>2]);var ba=e*F+(g*t+ +a[L>>2]);e=f*C+(e*E+(g*+a[c>>2]+ +a[T>>2]));a[T>>2]=e;g=f*H+Sa;a[U>>2]=g;Z=f*N+Z;a[P>>2]=Z;f=f*Q+ba;a[L>>2]=f;ba=+a[d>>2];var aa=+a[d+4>>2];Sa=+a[d+8>>2];d=+a[d+12>>2];var ja=+B(+(ba*ba+aa*aa+Sa*Sa+d*d));var qa=0>2];V=C*za+(E*Aa+Y*aa);a[c>>2]=V;c=H*za+(w*Aa+r*aa);a[k>>2]=c;k=N*za+(y*Aa+q*aa);a[p>>2]=k;p=Q*za+(F*Aa+t*aa);a[v>>2]=p;v=C*ma+(Y*ea+E*Sa);a[A>>2]=v;A=H*ma+(r*ea+w*Sa);a[m>>2]=A;m=N*ma+(q*ea+y*Sa);a[x>>2]=m;x=Q*ma+(t*ea+F*Sa);a[z>>2]=x;E=Y*d+E*ja+C*ba;a[D>>2]=E;w=r*d+w*ja+H*ba;a[K>>2]=w;q=q*d+y*ja+N*ba;a[R>>2]=q;t=t*d+F*ja+Q*ba;a[O>>2]=t;a[T>>2]=E*l+(v*h+(e+V*b));a[U>>2]=w*l+(A*h+(g+c*b));a[P>>2]=q*l+(m*h+(Z+k*b));a[L>>2]=t*l+(x* +h+(f+p*b))},_glmc_quat_rotate_atm:function(c,d,g){c|=0;d|=0;g|=0;var e=-+a[g>>2];var f=g+4|0;var G=-+a[f>>2];var h=g+8|0;var l=-+a[h>>2];var k=c+4|0;b[c>>2]=1065353216;var r=c+24|0;b[k>>2]=0;b[k+4>>2]=0;b[k+8>>2]=0;b[k+12>>2]=0;b[c+20>>2]=1065353216;var p=c+44|0;b[r>>2]=0;b[r+4>>2]=0;b[r+8>>2]=0;b[r+12>>2]=0;b[c+40>>2]=1065353216;b[p>>2]=0;b[p+4>>2]=0;b[p+8>>2]=0;b[p+12>>2]=0;b[c+60>>2]=1065353216;r=c+48|0;g=b[g>>2]|0;b[r>>2]=g;p=b[f>>2]|0;f=c+52|0;b[f>>2]=p;var q=b[h>>2]|0;h=c+56|0;b[h>>2]=q;var v= ++a[d>>2];var t=+a[d+4>>2];var A=+a[d+8>>2];d=+a[d+12>>2];var E=+B(+(v*v+t*t+A*A+d*d));var m=0>2]=E;t*=0;y=D+(C+t);a[k>>2]=y;t=K+t;k=m+t;a[c+8>>2]=k;t=D+t;a[c+12>>2]=t;C=0*A;m=0*w;D=m+(x+C);a[c+16>>2]=D;x*=0;A=m+(x+A);a[c+20>>2]=A;x+=C;w+=x;a[c+24>>2]=w;x=m+x;a[c+28>>2]=x;K=0*z;C=0*v;m=d+K+C;a[c+32>>2]=m;var H= +0*d;d=z+H+C;a[c+36>>2]=d;z=H+K;v+=z;a[c+40>>2]=v;z+=C;a[c+44>>2]=z;g=E*e+(b[F>>2]=g,+a[F>>2]);p=y*e+(b[F>>2]=p,+a[F>>2]);q=w*G+(k*e+(b[F>>2]=q,+a[F>>2]));a[r>>2]=m*l+(D*G+g);a[f>>2]=d*l+(A*G+p);a[h>>2]=v*l+q;a[c+60>>2]=z*l+(x*G+(t*e+1))},_glmc_quat_rotatev:function(c,d,g){c|=0;d|=0;g|=0;var e=+a[c>>2];var f=c+4|0;var G=+a[f>>2];var h=c+8|0;var l=+a[h>>2];var k=c+12|0;var r=+a[k>>2];var p=e*e+G*G+l*l+r*r;0>=p?(b[c>>2]=0,b[f>>2]=0,b[h>>2]=0,b[k>>2]=1065353216,k=G=e=r=0):(c=1/+B(+p),r*=c,e*=c,G*=c,k= +l*c);c=+a[d>>2];l=+a[d+4>>2];d=+a[d+8>>2];p=2*(e*c+G*l+k*d);f=r*r-(e*e+G*G+k*k);r*=2;a[g>>2]=r*(G*d-k*l)+(c*f+e*p);a[g+4>>2]=r*(k*c-e*d)+(f*l+G*p);a[g+8>>2]=r*(e*l-G*c)+(f*d+k*p)},_glmc_quat_slerp:function(c,d,b,e){c|=0;d|=0;b=+b;e|=0;var g=+a[c>>2];var f=+a[d>>2];var u=c+4|0;var l=+a[u>>2];var k=+a[d+4>>2];var r=c+8|0;var p=+a[r>>2];var q=+a[d+8>>2];var v=c+12|0;var t=+a[v>>2];d=+a[d+12>>2];c=g*f+l*k+p*q+t*d;if(1<=+D(+c))a[e>>2]=g,a[e+4>>2]=l,a[e+8>>2]=p,a[(e+12|0)>>2]=t;else{if(0>c){var A=-c;c= +-g;var m=-l;var w=-p;var x=-t}else A=c,c=g,m=l,w=p,x=t;var y=+B(+(1-A*A));.0010000000474974513>+D(+y)?(b=0b?b:1,a[e>>2]=g+b*(f-g),a[e+4>>2]=b*(k-l)+ +a[u>>2],a[e+8>>2]=b*(q-p)+ +a[r>>2],k=b*(d-t)+ +a[v>>2],a[(e+12|0)>>2]=k):(p=+Z(+A),r=+K(+((1-b)*p)),b=+K(+(p*b)),p=1/y,a[e>>2]=p*(c*r+f*b),a[e+4>>2]=p*(m*r+k*b),a[e+8>>2]=p*(w*r+q*b),a[(e+12|0)>>2]=p*(x*r+d*b))}},_glmc_quat_sub:function(c,d,b){c|=0;d|=0;b|=0;a[b>>2]=+a[c>>2]-+a[d>>2];a[b+4>>2]=+a[c+4>>2]-+a[d+4>>2];a[b+8>>2]=+a[c+8>>2]-+a[d+ +8>>2];a[b+12>>2]=+a[c+12>>2]-+a[d+12>>2]},_glmc_quatv:function(c,d,b){c|=0;b|=0;var g=+a[b>>2];var e=+a[b+4>>2];b=+a[b+8>>2];var f=.5*+d;d=+N(+f);var h=+K(+f);var l=+B(+(g*g+e*e+b*b));f=0==l;l=1/l;a[c>>2]=h*(f?0:g*l);a[c+4>>2]=h*(f?0:e*l);a[c+8>>2]=h*(f?0:b*l);a[c+12>>2]=d},_glmc_rotate:function(c,d,b){c|=0;d=+d;b|=0;var g=+a[b>>2];var e=+a[b+4>>2];b=+a[b+8>>2];var f=+N(+d);var h=+B(+(g*g+e*e+b*b));var l=0==h;var k=1/h;g=l?0:g*k;h=l?0:e*k;var r=l?0:b*k;e=1-f;k=e*g;var p=e*h;var q=e*r;d=+K(+d);var v= +d*g;var t=d*h;b=d*r;d=f+g*k;e=g*p-b;g=t+g*q;b+=h*k;l=f+h*p;h=h*q-v;k=r*k-t;p=v+r*p;f+=r*q;r=+a[c>>2];q=c+4|0;v=+a[q>>2];t=c+8|0;var A=+a[t>>2];var m=c+12|0;var w=+a[m>>2];var x=c+16|0;var y=+a[x>>2];var z=c+20|0;var D=+a[z>>2];var C=c+24|0;var F=+a[C>>2];var H=c+28|0;var R=+a[H>>2];var Q=c+32|0;var ea=+a[Q>>2];var Y=c+36|0;var O=+a[Y>>2];var V=c+40|0;var Z=+a[V>>2];var U=c+44|0;var P=+a[U>>2];a[c>>2]=r*d+y*b+k*ea;a[q>>2]=v*d+b*D+k*O;a[t>>2]=A*d+b*F+k*Z;a[m>>2]=w*d+b*R+k*P;a[x>>2]=r*e+y*l+p*ea;a[z>> +2]=v*e+l*D+p*O;a[C>>2]=A*e+l*F+p*Z;a[H>>2]=w*e+l*R+p*P;a[Q>>2]=r*g+y*h+f*ea;a[Y>>2]=v*g+h*D+f*O;a[V>>2]=A*g+h*F+f*Z;a[U>>2]=w*g+h*R+f*P},_glmc_rotate_at:function(c,b,g,e){c|=0;b|=0;g=+g;e|=0;var d=+a[b>>2];var f=+a[b+4>>2];var h=+a[b+8>>2];b=-d;var u=-f;var k=-h;var r=c+4|0;var p=c+8|0;var q=c+12|0;var v=+a[q>>2];var t=c+16|0;var A=+a[t>>2];var m=c+20|0;var w=+a[m>>2];var x=c+24|0;var y=+a[x>>2];var z=c+28|0;var D=+a[z>>2];var C=c+32|0;var F=+a[C>>2];var H=c+36|0;var R=+a[H>>2];var Q=c+40|0;var ea= ++a[Q>>2];var Y=c+44|0;var O=+a[Y>>2];var Z=c+48|0;var V=c+52|0;var U=c+56|0;var P=c+60|0;var L=f*w+(d*+a[r>>2]+ +a[V>>2]);var T=f*y+(d*+a[p>>2]+ +a[U>>2]);var X=f*D+(d*v+ +a[P>>2]);a[Z>>2]=h*F+(f*A+(d*+a[c>>2]+ +a[Z>>2]));a[V>>2]=h*R+L;a[U>>2]=h*ea+T;a[P>>2]=h*O+X;h=+a[e>>2];f=+a[e+4>>2];L=+a[e+8>>2];d=+N(+g);e=+B(+(h*h+f*f+L*L));T=0==e;X=1/e;h=T?0:h*X;e=T?0:f*X;X=T?0:L*X;f=1-d;var ba=f*h;var aa=f*e;var ja=f*X;g=+K(+g);var qa=g*h;var ma=g*e;T=g*X;L=d+h*ba;f=h*aa-T;g=ma+h*ja;T+=e*ba;h=d+e*aa;e=e*ja- +qa;ma=X*ba-ma;ba=qa+X*aa;X=d+X*ja;qa=+a[c>>2];ja=+a[r>>2];aa=+a[p>>2];d=F*ma+(qa*L+A*T);a[c>>2]=d;c=R*ma+(ja*L+w*T);a[r>>2]=c;r=ea*ma+(aa*L+y*T);a[p>>2]=r;p=O*ma+(v*L+D*T);a[q>>2]=p;q=F*ba+(qa*f+A*h);a[t>>2]=q;t=R*ba+(ja*f+w*h);a[m>>2]=t;m=ea*ba+(aa*f+y*h);a[x>>2]=m;x=O*ba+(v*f+D*h);a[z>>2]=x;A=F*X+(qa*g+A*e);a[C>>2]=A;w=R*X+(ja*g+w*e);a[H>>2]=w;y=ea*X+(aa*g+y*e);a[Q>>2]=y;v=O*X+(v*g+D*e);a[Y>>2]=v;Y=t*u+(c*b+ +a[V>>2]);D=m*u+(r*b+ +a[U>>2]);Q=x*u+(p*b+ +a[P>>2]);a[Z>>2]=A*k+(q*u+(d*b+ +a[Z>>2])); +a[V>>2]=w*k+Y;a[U>>2]=y*k+D;a[P>>2]=v*k+Q},_glmc_rotate_atm:function(c,d,g,e){c|=0;d|=0;g=+g;e|=0;var f=-+a[d>>2];var u=d+4|0;var h=-+a[u>>2];var l=d+8|0;var k=-+a[l>>2];var r=c+4|0;b[c>>2]=1065353216;var p=c+24|0;b[r>>2]=0;b[r+4>>2]=0;b[r+8>>2]=0;b[r+12>>2]=0;b[c+20>>2]=1065353216;var q=c+44|0;b[p>>2]=0;b[p+4>>2]=0;b[p+8>>2]=0;b[p+12>>2]=0;b[c+40>>2]=1065353216;b[q>>2]=0;b[q+4>>2]=0;b[q+8>>2]=0;b[q+12>>2]=0;b[c+60>>2]=1065353216;p=c+48|0;b[p>>2]=b[d>>2];d=c+52|0;b[d>>2]=b[u>>2];u=c+56|0;b[u>>2]= +b[l>>2];var v=+a[e>>2];l=+a[e+4>>2];q=+a[e+8>>2];e=+N(+g);var t=+B(+(v*v+l*l+q*q));var A=0==t;var m=1/t;t=A?0:v*m;l=A?0:l*m;A=A?0:q*m;q=1-e;var w=q*t;var x=q*l;var y=q*A;g=+K(+g);var z=g*t;var D=g*l;m=g*A;q=e+t*w;v=t*x-m;g=D+t*y;m+=l*w;t=e+l*x;l=l*y-z;D=A*w-D;w=z+A*x;A=e+A*y;y=0*m;x=0*D;e=x+(q+y);a[c>>2]=e;z=0*q;q=x+(m+z);a[r>>2]=q;m=z+y;r=D+m;a[c+8>>2]=r;x+=m;a[c+12>>2]=x;D=0*t;y=0*w;m=y+(v+D);a[c+16>>2]=m;z=0*v;v=y+(t+z);a[c+20>>2]=v;D=z+D;t=w+D;a[c+24>>2]=t;y+=D;a[c+28>>2]=y;z=0*l;D=0*A;w=D+(g+ +z);a[c+32>>2]=w;var C=0*g;g=D+(l+C);a[c+36>>2]=g;z=C+z;l=A+z;a[c+40>>2]=l;A=D+z;a[c+44>>2]=A;c=c+60|0;q=v*h+(q*f+ +a[d>>2]);r=t*h+(r*f+ +a[u>>2]);v=y*h+(x*f+ +a[c>>2]);a[p>>2]=w*k+(m*h+(e*f+ +a[p>>2]));a[d>>2]=g*k+q;a[u>>2]=l*k+r;a[c>>2]=A*k+v},_glmc_rotate_make:function(c,d,g){c|=0;d=+d;g|=0;var e=+a[g>>2];var f=+a[g+4>>2];var G=+a[g+8>>2];g=+N(+d);var h=+B(+(e*e+f*f+G*G));var l=0==h;h=1/h;e=l?0:e*h;f=l?0:f*h;G=l?0:G*h;var k=1-g;l=k*e;h=k*f;k*=G;var r=+K(+d);d=r*e;var p=r*f;r*=G;a[c>>2]=g+e*l;a[c+ +16>>2]=e*h-r;a[c+32>>2]=p+e*k;a[c+4>>2]=r+f*l;a[c+20>>2]=g+f*h;a[c+36>>2]=f*k-d;a[c+8>>2]=G*l-p;a[c+24>>2]=d+G*h;a[c+40>>2]=g+G*k;g=c+44|0;a[c+28>>2]=0;a[c+12>>2]=0;b[g>>2]=0;b[g+4>>2]=0;b[g+8>>2]=0;b[g+12>>2]=0;a[c+60>>2]=1},_glmc_rotate_x:function(c,d,g){c|=0;d=+d;g|=0;var e=+N(+d);var f=+K(+d);var G=-f;var h=+a[c>>2];var l=+a[c+4>>2];var k=+a[c+8>>2];var r=+a[c+12>>2];d=+a[c+16>>2];var p=+a[c+20>>2];var q=+a[c+24>>2];var v=+a[c+28>>2];var t=+a[c+32>>2];var m=+a[c+36>>2];var w=+a[c+40>>2];var x= ++a[c+44>>2];var y=b[c+48>>2]|0;var z=b[c+52>>2]|0;var D=b[c+56>>2]|0;c=b[c+60>>2]|0;a[g>>2]=h+0*d+0*t;a[g+4>>2]=l+0*p+0*m;a[g+8>>2]=k+0*q+0*w;a[g+12>>2]=r+0*v+0*x;h*=0;a[g+16>>2]=h+e*d+f*t;l*=0;a[g+20>>2]=l+e*p+f*m;k*=0;a[g+24>>2]=k+e*q+f*w;r*=0;a[g+28>>2]=r+e*v+f*x;a[g+32>>2]=h+d*G+e*t;a[g+36>>2]=l+p*G+e*m;a[g+40>>2]=k+q*G+e*w;a[g+44>>2]=r+v*G+e*x;b[g+48>>2]=y;b[g+52>>2]=z;b[g+56>>2]=D;b[g+60>>2]=c},_glmc_rotate_y:function(c,d,g){c|=0;d=+d;g|=0;var e=+N(+d);var f=+K(+d);var m=-f;var h=+a[c>>2];var l= ++a[c+4>>2];d=+a[c+8>>2];var k=+a[c+12>>2];var r=+a[c+16>>2];var p=+a[c+20>>2];var q=+a[c+24>>2];var v=+a[c+28>>2];var t=+a[c+32>>2];var A=+a[c+36>>2];var w=+a[c+40>>2];var x=+a[c+44>>2];var y=b[c+48>>2]|0;var z=b[c+52>>2]|0;var D=b[c+56>>2]|0;c=b[c+60>>2]|0;var B=0*r;a[g>>2]=e*h+B+t*m;var C=0*p;a[g+4>>2]=e*l+C+A*m;var F=0*q;a[g+8>>2]=e*d+F+w*m;var H=0*v;a[g+12>>2]=e*k+H+x*m;a[g+16>>2]=0*h+r+0*t;a[g+20>>2]=0*l+p+0*A;a[g+24>>2]=0*d+q+0*w;a[g+28>>2]=0*k+v+0*x;a[g+32>>2]=f*h+B+e*t;a[g+36>>2]=f*l+C+e* +A;a[g+40>>2]=f*d+F+e*w;a[g+44>>2]=f*k+H+e*x;b[g+48>>2]=y;b[g+52>>2]=z;b[g+56>>2]=D;b[g+60>>2]=c},_glmc_rotate_z:function(c,d,g){c|=0;d=+d;g|=0;var e=+N(+d);var f=+K(+d);var m=-f;var h=+a[c>>2];var l=+a[c+4>>2];d=+a[c+8>>2];var k=+a[c+12>>2];var r=+a[c+16>>2];var p=+a[c+20>>2];var q=+a[c+24>>2];var v=+a[c+28>>2];var t=+a[c+32>>2];var w=+a[c+36>>2];var x=+a[c+40>>2];var y=+a[c+44>>2];var z=b[c+48>>2]|0;var D=b[c+52>>2]|0;var B=b[c+56>>2]|0;c=b[c+60>>2]|0;var C=0*t;a[g>>2]=e*h+f*r+C;var F=0*w;a[g+4>> +2]=e*l+f*p+F;var H=0*x;a[g+8>>2]=e*d+f*q+H;var R=0*y;a[g+12>>2]=e*k+f*v+R;a[g+16>>2]=h*m+e*r+C;a[g+20>>2]=l*m+e*p+F;a[g+24>>2]=d*m+e*q+H;a[g+28>>2]=k*m+e*v+R;a[g+32>>2]=0*h+0*r+t;a[g+36>>2]=0*l+0*p+w;a[g+40>>2]=0*d+0*q+x;a[g+44>>2]=0*k+0*v+y;b[g+48>>2]=z;b[g+52>>2]=D;b[g+56>>2]=B;b[g+60>>2]=c},_glmc_scale:function(c,b){c|=0;b|=0;var d=+a[b>>2];a[c>>2]=d*+a[c>>2];var e=c+4|0;a[e>>2]=d*+a[e>>2];e=c+8|0;a[e>>2]=d*+a[e>>2];e=c+12|0;a[e>>2]=d*+a[e>>2];e=c+16|0;d=+a[b+4>>2];a[e>>2]=d*+a[e>>2];e=c+20|0; +a[e>>2]=d*+a[e>>2];e=c+24|0;a[e>>2]=d*+a[e>>2];e=c+28|0;a[e>>2]=d*+a[e>>2];d=c+32|0;b=+a[b+8>>2];a[d>>2]=b*+a[d>>2];d=c+36|0;a[d>>2]=b*+a[d>>2];d=c+40|0;a[d>>2]=b*+a[d>>2];c=c+44|0;a[c>>2]=b*+a[c>>2]},_glmc_scale_make:function(a,d){a|=0;d|=0;var c=a+4|0;b[a>>2]=1065353216;var e=a+24|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;b[a+20>>2]=1065353216;c=a+44|0;b[e>>2]=0;b[e+4>>2]=0;b[e+8>>2]=0;b[e+12>>2]=0;b[a+40>>2]=1065353216;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;b[a+60>>2]=1065353216; +b[a>>2]=b[d>>2];b[a+20>>2]=b[d+4>>2];b[a+40>>2]=b[d+8>>2]},_glmc_scale_to:function(c,d,g){c|=0;d|=0;g|=0;var e=+a[d>>2];a[g>>2]=e*+a[c>>2];a[g+4>>2]=e*+a[c+4>>2];a[g+8>>2]=e*+a[c+8>>2];a[g+12>>2]=e*+a[c+12>>2];e=+a[d+4>>2];a[g+16>>2]=e*+a[c+16>>2];a[g+20>>2]=e*+a[c+20>>2];a[g+24>>2]=e*+a[c+24>>2];a[g+28>>2]=e*+a[c+28>>2];d=+a[d+8>>2];a[g+32>>2]=d*+a[c+32>>2];a[g+36>>2]=d*+a[c+36>>2];a[g+40>>2]=d*+a[c+40>>2];a[g+44>>2]=d*+a[c+44>>2];b[g+48>>2]=b[c+48>>2];b[g+52>>2]=b[c+52>>2];b[g+56>>2]=b[c+56>>2]; +b[g+60>>2]=b[c+60>>2]},_glmc_scale_uni:function(c,b){c|=0;b=+b;a[c>>2]=+a[c>>2]*b;var d=c+4|0;a[d>>2]=+a[d>>2]*b;d=c+8|0;a[d>>2]=+a[d>>2]*b;d=c+12|0;a[d>>2]=+a[d>>2]*b;d=c+16|0;a[d>>2]=+a[d>>2]*b;d=c+20|0;a[d>>2]=+a[d>>2]*b;d=c+24|0;a[d>>2]=+a[d>>2]*b;d=c+28|0;a[d>>2]=+a[d>>2]*b;d=c+32|0;a[d>>2]=+a[d>>2]*b;d=c+36|0;a[d>>2]=+a[d>>2]*b;d=c+40|0;a[d>>2]=+a[d>>2]*b;c=c+44|0;a[c>>2]=+a[c>>2]*b},_glmc_translate:function(c,b){c|=0;b|=0;var d=+a[b>>2];var e=+a[b+4>>2];b=+a[b+8>>2];var f=b*+a[c+36>>2];var m= +b*+a[c+40>>2];var h=b*+a[c+44>>2];var l=c+48|0;var k=c+52|0;var r=c+56|0;var p=c+60|0;var q=e*+a[c+20>>2]+(d*+a[c+4>>2]+ +a[k>>2]);var v=e*+a[c+24>>2]+(d*+a[c+8>>2]+ +a[r>>2]);var t=e*+a[c+28>>2]+(d*+a[c+12>>2]+ +a[p>>2]);a[l>>2]=b*+a[c+32>>2]+(e*+a[c+16>>2]+(d*+a[c>>2]+ +a[l>>2]));a[k>>2]=f+q;a[r>>2]=m+v;a[p>>2]=h+t},_glmc_translate_make:function(a,d){a|=0;d|=0;var c=a+4|0;b[a>>2]=1065353216;var e=a+24|0;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;b[a+20>>2]=1065353216;c=a+44|0;b[e>>2]=0;b[e+ +4>>2]=0;b[e+8>>2]=0;b[e+12>>2]=0;b[a+40>>2]=1065353216;b[c>>2]=0;b[c+4>>2]=0;b[c+8>>2]=0;b[c+12>>2]=0;b[a+60>>2]=1065353216;b[a+48>>2]=b[d>>2];b[a+52>>2]=b[d+4>>2];b[a+56>>2]=b[d+8>>2]},_glmc_translate_to:function(c,d,g){c|=0;d|=0;g|=0;var e=b[c>>2]|0;b[g>>2]=e;var f=b[c+4>>2]|0;b[g+4>>2]=f;var m=b[c+8>>2]|0;b[g+8>>2]=m;var h=b[c+12>>2]|0;b[g+12>>2]=h;var l=b[c+16>>2]|0;b[g+16>>2]=l;var k=b[c+20>>2]|0;b[g+20>>2]=k;var r=b[c+24>>2]|0;b[g+24>>2]=r;var p=b[c+28>>2]|0;b[g+28>>2]=p;var q=b[c+32>>2]|0; +b[g+32>>2]=q;var v=b[c+36>>2]|0;b[g+36>>2]=v;var t=b[c+40>>2]|0;b[g+40>>2]=t;var w=b[c+44>>2]|0;b[g+44>>2]=w;var x=b[c+48>>2]|0;b[g+48>>2]=x;var y=b[c+52>>2]|0;b[g+52>>2]=y;var z=b[c+56>>2]|0;b[g+56>>2]=z;c=b[c+60>>2]|0;b[g+60>>2]=c;var D=+a[d>>2];var B=+a[d+4>>2];d=+a[d+8>>2];e=D*(b[F>>2]=e,+a[F>>2]);f=D*(b[F>>2]=f,+a[F>>2]);m=D*(b[F>>2]=m,+a[F>>2]);h=D*(b[F>>2]=h,+a[F>>2]);l=B*(b[F>>2]=l,+a[F>>2]);k=B*(b[F>>2]=k,+a[F>>2]);r=B*(b[F>>2]=r,+a[F>>2]);p=B*(b[F>>2]=p,+a[F>>2]);q=d*(b[F>>2]=q,+a[F>>2]); +v=d*(b[F>>2]=v,+a[F>>2]);t=d*(b[F>>2]=t,+a[F>>2]);w=d*(b[F>>2]=w,+a[F>>2]);x=e+(b[F>>2]=x,+a[F>>2]);y=f+(b[F>>2]=y,+a[F>>2]);z=m+(b[F>>2]=z,+a[F>>2]);c=p+(h+(b[F>>2]=c,+a[F>>2]));a[g+48>>2]=q+(l+x);a[g+52>>2]=v+(k+y);a[g+56>>2]=t+(r+z);a[g+60>>2]=w+c},_glmc_translate_x:function(c,b){c|=0;b=+b;var d=+a[c+4>>2]*b;var e=+a[c+8>>2]*b;var f=+a[c+12>>2]*b;var m=c+48|0;a[m>>2]=+a[c>>2]*b+ +a[m>>2];b=c+52|0;a[b>>2]=d+ +a[b>>2];d=c+56|0;a[d>>2]=e+ +a[d>>2];c=c+60|0;a[c>>2]=f+ +a[c>>2]},_glmc_translate_y:function(c, +b){c|=0;b=+b;var d=+a[c+20>>2]*b;var e=+a[c+24>>2]*b;var f=+a[c+28>>2]*b;var m=c+48|0;a[m>>2]=+a[c+16>>2]*b+ +a[m>>2];b=c+52|0;a[b>>2]=d+ +a[b>>2];d=c+56|0;a[d>>2]=e+ +a[d>>2];c=c+60|0;a[c>>2]=f+ +a[c>>2]},_glmc_translate_z:function(c,b){c|=0;b=+b;var d=+a[c+36>>2]*b;var e=+a[c+40>>2]*b;var f=+a[c+44>>2]*b;var m=c+48|0;a[m>>2]=+a[c+32>>2]*b+ +a[m>>2];b=c+52|0;a[b>>2]=d+ +a[b>>2];d=c+56|0;a[d>>2]=e+ +a[d>>2];c=c+60|0;a[c>>2]=f+ +a[c>>2]},_glmc_uniscaled:function(c){c|=0;var b=+a[c>>2];var g=+a[c+4>> +2];var e=+a[c+8>>2];g=+B(+(b*b+g*g+e*e));var f=+a[c+16>>2];e=+a[c+20>>2];b=+a[c+24>>2];f=+B(+(f*f+e*e+b*b));b=+a[c+32>>2];e=+a[c+36>>2];c=+a[c+40>>2];return(g==f?g==+B(+(b*b+e*e+c*c)):0)|0},_glmc_unproject:function(c,b,e,f){c|=0;b|=0;e|=0;f|=0;var d=+a[b>>2];var g=+a[b+4>>2];var h=+a[b+8>>2];var u=+a[b+12>>2];var k=+a[b+16>>2];var r=+a[b+20>>2];var p=+a[b+24>>2];var q=+a[b+28>>2];var m=+a[b+32>>2];var t=+a[b+36>>2];var w=+a[b+40>>2];var x=+a[b+44>>2];var y=+a[b+48>>2];var z=+a[b+52>>2];var D=+a[b+ +56>>2];var B=+a[b+60>>2];var C=w*B-x*D;var F=t*B-x*z;var H=t*D-w*z;var K=m*B-x*y;var R=m*D-w*y;var Q=m*z-t*y;var N=q*H+(r*C-p*F);var ea=-(q*R+(k*C-p*K));var O=q*Q+(k*F-r*K);var T=-(p*Q+(k*H-r*R));var Y=p*B-q*D;b=r*B-q*z;var U=r*D-p*z;B=k*B-q*y;D=k*D-p*y;y=k*z-r*y;z=p*x-q*w;var P=r*x-q*t;var L=r*w-p*t;q=k*x-q*m;p=k*w-p*m;m=k*t-r*m;k=1/(u*T+(h*O+(d*N+g*ea)));r=2*(+a[c>>2]-+a[e>>2])/+a[e+8>>2]+-1;e=2*(+a[c+4>>2]-+a[e+4>>2])/+a[e+12>>2]+-1;c=2*+a[c+8>>2]+-1;z=1/((h*m+(d*L-g*p))*k+(e*(u*p+(d*z-h*q))*k- +r*(u*L+(g*z-h*P))*k-c*(u*m+(d*P-g*q))*k));a[f>>2]=(k*T+(c*O*k+(r*N*k+e*k*ea)))*z;a[f+4>>2]=((h*Q+(d*H-g*R))*k+(e*(u*R+(d*C-h*K))*k-r*(u*H+(g*C-h*F))*k-c*(u*Q+(d*F-g*K))*k))*z;a[f+8>>2]=(c*(u*y+(d*b-g*B))*k+(r*(u*U+(g*Y-h*b))*k-e*(u*D+(d*Y-h*B))*k)-(h*y+(d*U-g*D))*k)*z},_glmc_unprojecti:function(c,b,e,f){c|=0;b|=0;e|=0;f|=0;var d=2*(+a[c>>2]-+a[e>>2])/+a[e+8>>2]+-1;e=2*(+a[c+4>>2]-+a[e+4>>2])/+a[e+12>>2]+-1;c=2*+a[c+8>>2]+-1;var g=1/(+a[b+60>>2]+(d*+a[b+12>>2]+e*+a[b+28>>2]+c*+a[b+44>>2]));var h=(+a[b+ +52>>2]+(d*+a[b+4>>2]+e*+a[b+20>>2]+c*+a[b+36>>2]))*g;var u=(+a[b+56>>2]+(d*+a[b+8>>2]+e*+a[b+24>>2]+c*+a[b+40>>2]))*g;a[f>>2]=(+a[b+48>>2]+(c*+a[b+32>>2]+(+a[b>>2]*d+ +a[b+16>>2]*e)))*g;a[f+4>>2]=h;a[f+8>>2]=u},_glmc_vec3:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2]},_glmc_vec4:function(c,d,e){c|=0;e|=0;b[e>>2]=b[c>>2];b[e+4>>2]=b[c+4>>2];b[e+8>>2]=b[c+8>>2];a[e+12>>2]=+d},_glmc_vec4_add:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[c>>2]+ +a[b>>2];a[e+4>>2]=+a[c+4>> +2]+ +a[b+4>>2];a[e+8>>2]=+a[c+8>>2]+ +a[b+8>>2];a[e+12>>2]=+a[c+12>>2]+ +a[b+12>>2]},_glmc_vec4_addadd:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[e>>2]+(+a[c>>2]+ +a[b>>2]);var d=e+4|0;a[d>>2]=+a[d>>2]+(+a[c+4>>2]+ +a[b+4>>2]);d=e+8|0;a[d>>2]=+a[d>>2]+(+a[c+8>>2]+ +a[b+8>>2]);e=e+12|0;a[e>>2]=+a[e>>2]+(+a[c+12>>2]+ +a[b+12>>2])},_glmc_vec4_adds:function(c,b,e){c|=0;b=+b;e|=0;a[e>>2]=+a[c>>2]+b;a[e+4>>2]=+a[c+4>>2]+b;a[e+8>>2]=+a[c+8>>2]+b;a[e+12>>2]=+a[c+12>>2]+b},_glmc_vec4_broadcast:function(c,b){c= ++c;b|=0;a[b+12>>2]=c;a[b+8>>2]=c;a[b+4>>2]=c;a[b>>2]=c},_glmc_vec4_clamp:function(c,b,e){c|=0;b=+b;e=+e;var d=+a[c>>2];d=d>b?d:b;a[c>>2]=d>2];g=g>b?g:b;a[d>>2]=g>2];g=g>b?g:b;a[d>>2]=g>2];b=d>b?d:b;a[c>>2]=b>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2];b[d+12>>2]=b[a+12>>2]},_glmc_vec4_copy3:function(a,d){a|=0;d|=0;b[d>>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2]}, +_glmc_vec4_distance:function(c,b){c|=0;b|=0;var d=+a[b>>2]-+a[c>>2];var e=+a[b+4>>2]-+a[c+4>>2];var f=+a[b+8>>2]-+a[c+8>>2];c=+a[b+12>>2]-+a[c+12>>2];return+ +B(+(d*d+e*e+f*f+c*c))},_glmc_vec4_div:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[c>>2]/+a[b>>2];a[e+4>>2]=+a[c+4>>2]/+a[b+4>>2];a[e+8>>2]=+a[c+8>>2]/+a[b+8>>2];a[e+12>>2]=+a[c+12>>2]/+a[b+12>>2]},_glmc_vec4_divs:function(c,b,e){c|=0;e|=0;b=1/+b;a[e>>2]=b*+a[c>>2];a[e+4>>2]=b*+a[c+4>>2];a[e+8>>2]=b*+a[c+8>>2];a[e+12>>2]=b*+a[c+12>>2]},_glmc_vec4_dot:function(c, +b){c|=0;b|=0;return+(+a[c>>2]*+a[b>>2]+ +a[c+4>>2]*+a[b+4>>2]+ +a[c+8>>2]*+a[b+8>>2]+ +a[c+12>>2]*+a[b+12>>2])},_glmc_vec4_eq:function(c,b){c|=0;var d=+a[c>>2];return(d==+b?d==+a[c+4>>2]?d==+a[c+8>>2]?d==+a[c+12>>2]:0:0:0)|0},_glmc_vec4_eq_all:function(c){c|=0;var b=+a[c>>2];return b!=+a[c+4>>2]||b!=+a[c+8>>2]?0:b==+a[c+12>>2]|0},_glmc_vec4_eq_eps:function(c,b){c|=0;b=+b;return 1.1920928955078125E-7>=+D(+(+a[c>>2]-b))&&1.1920928955078125E-7>=+D(+(+a[c+4>>2]-b))&&1.1920928955078125E-7>=+D(+(+a[c+8>> +2]-b))?1.1920928955078125E-7>=+D(+(+a[c+12>>2]-b))|0:0},_glmc_vec4_eqv:function(c,b){c|=0;b|=0;return+a[c>>2]!=+a[b>>2]||+a[c+4>>2]!=+a[b+4>>2]||+a[c+8>>2]!=+a[b+8>>2]?0:+a[c+12>>2]==+a[b+12>>2]|0},_glmc_vec4_eqv_eps:function(c,b){c|=0;b|=0;return 1.1920928955078125E-7>=+D(+(+a[c>>2]-+a[b>>2]))&&1.1920928955078125E-7>=+D(+(+a[c+4>>2]-+a[b+4>>2]))&&1.1920928955078125E-7>=+D(+(+a[c+8>>2]-+a[b+8>>2]))?1.1920928955078125E-7>=+D(+(+a[c+12>>2]-+a[b+12>>2]))|0:0},_glmc_vec4_flipsign:function(c){c|=0;a[c>> +2]=-+a[c>>2];var b=c+4|0;a[b>>2]=-+a[b>>2];b=c+8|0;a[b>>2]=-+a[b>>2];c=c+12|0;a[c>>2]=-+a[c>>2]},_glmc_vec4_flipsign_to:function(c,b){c|=0;b|=0;a[b>>2]=-+a[c>>2];a[b+4>>2]=-+a[c+4>>2];a[b+8>>2]=-+a[c+8>>2];a[b+12>>2]=-+a[c+12>>2]},_glmc_vec4_inv:function(c){c|=0;a[c>>2]=-+a[c>>2];var b=c+4|0;a[b>>2]=-+a[b>>2];b=c+8|0;a[b>>2]=-+a[b>>2];c=c+12|0;a[c>>2]=-+a[c>>2]},_glmc_vec4_inv_to:function(c,d){c|=0;d|=0;var e=b[c>>2]|0;b[d>>2]=e;var f=b[c+4>>2]|0;var n=d+4|0;b[n>>2]=f;var m=b[c+8>>2]|0;var h=d+8| +0;b[h>>2]=m;c=+a[c+12>>2];a[d>>2]=-(b[F>>2]=e,+a[F>>2]);a[n>>2]=-(b[F>>2]=f,+a[F>>2]);a[h>>2]=-(b[F>>2]=m,+a[F>>2]);a[d+12>>2]=-c},_glmc_vec4_isinf:function(a){a|=0;return 2139095040==(b[a>>2]&2147483647|0)||2139095040==(b[a+4>>2]&2147483647|0)||2139095040==(b[a+8>>2]&2147483647|0)?1:2139095040==(b[a+12>>2]&2147483647|0)|0},_glmc_vec4_isnan:function(a){a|=0;return 2139095040<(b[a>>2]&2147483647)>>>0||2139095040<(b[a+4>>2]&2147483647)>>>0||2139095040<(b[a+8>>2]&2147483647)>>>0?1:2139095040<(b[a+12>> +2]&2147483647)>>>0|0},_glmc_vec4_isvalid:function(a){a|=0;var c=b[a>>2]&2147483647;if(2139095040>>0)return 0;var e=b[a+4>>2]&2147483647;if(2139095040>>0)return 0;var f=b[a+8>>2]&2147483647;if(2139095040>>0)return 0;a=b[a+12>>2]&2147483647;return 2139095040!=(a|0)&((2139095040==(f|0)|2139095040==(e|0)|2139095040==(c|0)|2139095040>>0)^1)|0},_glmc_vec4_lerp:function(c,b,e,f){c|=0;b|=0;e=+e;f|=0;e=0e?e:1;var d=+a[c>>2];var g=c+4|0;var h=c+8|0;c=c+12|0;var u=e*(+a[b+4>>2]-+a[g>> +2]);var k=e*(+a[b+8>>2]-+a[h>>2]);var r=e*(+a[b+12>>2]-+a[c>>2]);a[f>>2]=d+e*(+a[b>>2]-d);a[f+4>>2]=u+ +a[g>>2];a[f+8>>2]=k+ +a[h>>2];a[f+12>>2]=r+ +a[c>>2]},_glmc_vec4_max:function(c){c|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];e=e>b?e:b;f=e>2];return+(c>f?c:f)},_glmc_vec4_maxv:function(c,b,e){c|=0;b|=0;e|=0;var d=+a[c>>2];var g=+a[b>>2];a[e>>2]=d>2];g=+a[b+4>>2];a[e+4>>2]=d>2];g=+a[b+8>>2];a[e+8>>2]=d>2];b=+a[b+12>>2];a[e+ +12>>2]=c>2];var e=+a[c+4>>2];var f=+a[c+8>>2];e=ef?f:e;c=+a[c+12>>2];return+(c>2];var g=+a[b>>2];a[e>>2]=d>g?d:g;d=+a[c+4>>2];g=+a[b+4>>2];a[e+4>>2]=d>g?d:g;d=+a[c+8>>2];g=+a[b+8>>2];a[e+8>>2]=d>g?d:g;c=+a[c+12>>2];b=+a[b+12>>2];a[e+12>>2]=c>b?c:b},_glmc_vec4_mul:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[c>>2]*+a[b>>2];a[e+4>>2]=+a[c+4>>2]*+a[b+4>>2];a[e+8>>2]=+a[c+8>>2]* ++a[b+8>>2];a[e+12>>2]=+a[c+12>>2]*+a[b+12>>2]},_glmc_vec4_muladd:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[e>>2]+ +a[c>>2]*+a[b>>2];var d=e+4|0;a[d>>2]=+a[d>>2]+ +a[c+4>>2]*+a[b+4>>2];d=e+8|0;a[d>>2]=+a[d>>2]+ +a[c+8>>2]*+a[b+8>>2];e=e+12|0;a[e>>2]=+a[e>>2]+ +a[c+12>>2]*+a[b+12>>2]},_glmc_vec4_muladds:function(c,b,e){c|=0;b=+b;e|=0;a[e>>2]=+a[e>>2]+ +a[c>>2]*b;var d=e+4|0;a[d>>2]=+a[d>>2]+ +a[c+4>>2]*b;d=e+8|0;a[d>>2]=+a[d>>2]+ +a[c+8>>2]*b;e=e+12|0;a[e>>2]=+a[e>>2]+ +a[c+12>>2]*b},_glmc_vec4_mulv:function(c, +b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[c>>2]*+a[b>>2];a[e+4>>2]=+a[c+4>>2]*+a[b+4>>2];a[e+8>>2]=+a[c+8>>2]*+a[b+8>>2];a[e+12>>2]=+a[c+12>>2]*+a[b+12>>2]},_glmc_vec4_norm:function(c){c|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];c=+a[c+12>>2];return+ +B(+(b*b+e*e+f*f+c*c))},_glmc_vec4_norm2:function(c){c|=0;var b=+a[c>>2];var e=+a[c+4>>2];var f=+a[c+8>>2];c=+a[c+12>>2];return+(b*b+e*e+f*f+c*c)},_glmc_vec4_normalize:function(c){c|=0;var d=+a[c>>2];var e=c+4|0;var f=+a[e>>2];var n=c+8|0;var m=+a[n>> +2];var h=c+12|0;var l=+a[h>>2];var k=+B(+(d*d+f*f+m*m+l*l));0==k?(b[c>>2]=0,b[c+4>>2]=0,b[c+8>>2]=0,b[c+12>>2]=0):(k=1/k,a[c>>2]=d*k,a[e>>2]=f*k,a[n>>2]=m*k,a[h>>2]=l*k)},_glmc_vec4_normalize_to:function(c,d){c|=0;d|=0;var e=+a[c>>2];var f=c+4|0;var n=+a[f>>2];var m=c+8|0;var h=+a[m>>2];c=c+12|0;var l=+a[c>>2];n=+B(+(e*e+n*n+h*h+l*l));0==n?(b[d>>2]=0,b[d+4>>2]=0,b[d+8>>2]=0,b[d+12>>2]=0):(n=1/n,a[d>>2]=e*n,a[d+4>>2]=n*+a[f>>2],a[d+8>>2]=n*+a[m>>2],a[d+12>>2]=n*+a[c>>2])},_glmc_vec4_one:function(c){c|= +0;a[c>>2]=1;a[c+4>>2]=1;a[c+8>>2]=1;a[c+12>>2]=1},_glmc_vec4_scale:function(c,b,e){c|=0;b=+b;e|=0;a[e>>2]=+a[c>>2]*b;a[e+4>>2]=+a[c+4>>2]*b;a[e+8>>2]=+a[c+8>>2]*b;a[e+12>>2]=+a[c+12>>2]*b},_glmc_vec4_scale_as:function(c,d,e){c|=0;d=+d;e|=0;var g=+a[c>>2];var f=c+4|0;var m=+a[f>>2];var h=c+8|0;var l=+a[h>>2];c=c+12|0;var k=+a[c>>2];l=+B(+(g*g+m*m+l*l+k*k));0==l?(b[e>>2]=0,b[e+4>>2]=0,b[e+8>>2]=0,b[e+12>>2]=0):(d/=l,a[e>>2]=g*d,a[e+4>>2]=d*+a[f>>2],a[e+8>>2]=d*+a[h>>2],a[e+12>>2]=d*+a[c>>2])},_glmc_vec4_sign:function(c, +b){c|=0;b|=0;var d=+a[c>>2];a[b>>2]=+((0d&1)|0);d=+a[c+4>>2];a[b+4>>2]=+((0d&1)|0);d=+a[c+8>>2];a[b+8>>2]=+((0d&1)|0);c=+a[c+12>>2];a[b+12>>2]=+((0c&1)|0)},_glmc_vec4_sqrt:function(c,b){c|=0;b|=0;a[b>>2]=+B(+ +a[c>>2]);a[b+4>>2]=+B(+ +a[c+4>>2]);a[b+8>>2]=+B(+ +a[c+8>>2]);a[b+12>>2]=+B(+ +a[c+12>>2])},_glmc_vec4_sub:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[c>>2]-+a[b>>2];a[e+4>>2]=+a[c+4>>2]-+a[b+4>>2];a[e+8>>2]=+a[c+8>>2]-+a[b+8>>2];a[e+12>>2]=+a[c+12>>2]-+a[b+ +12>>2]},_glmc_vec4_subadd:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[e>>2]+(+a[c>>2]-+a[b>>2]);var d=e+4|0;a[d>>2]=+a[d>>2]+(+a[c+4>>2]-+a[b+4>>2]);d=e+8|0;a[d>>2]=+a[d>>2]+(+a[c+8>>2]-+a[b+8>>2]);e=e+12|0;a[e>>2]=+a[e>>2]+(+a[c+12>>2]-+a[b+12>>2])},_glmc_vec4_subs:function(c,b,e){c|=0;b=+b;e|=0;a[e>>2]=+a[c>>2]-b;a[e+4>>2]=+a[c+4>>2]-b;a[e+8>>2]=+a[c+8>>2]-b;a[e+12>>2]=+a[c+12>>2]-b},_glmc_vec4_zero:function(a){a|=0;b[a>>2]=0;b[a+4>>2]=0;b[a+8>>2]=0;b[a+12>>2]=0},_glmc_vec_add:function(c,b,e){c|= +0;b|=0;e|=0;a[e>>2]=+a[c>>2]+ +a[b>>2];a[e+4>>2]=+a[c+4>>2]+ +a[b+4>>2];a[e+8>>2]=+a[c+8>>2]+ +a[b+8>>2]},_glmc_vec_addadd:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[e>>2]+(+a[c>>2]+ +a[b>>2]);var d=e+4|0;a[d>>2]=+a[d>>2]+(+a[c+4>>2]+ +a[b+4>>2]);e=e+8|0;a[e>>2]=+a[e>>2]+(+a[c+8>>2]+ +a[b+8>>2])},_glmc_vec_adds:function(c,b,e){c|=0;b=+b;e|=0;a[e>>2]=+a[c>>2]+b;a[e+4>>2]=+a[c+4>>2]+b;a[e+8>>2]=+a[c+8>>2]+b},_glmc_vec_angle:function(c,b){c|=0;b|=0;var d=+a[c>>2];var e=+a[c+4>>2];c=+a[c+8>>2];var f=+a[b>> +2];var m=+a[b+4>>2];b=+a[b+8>>2];return+ +Z(+((d*f+e*m+c*b)*(1/(+B(+(d*d+e*e+c*c))*+B(+(f*f+m*m+b*b))))))},_glmc_vec_broadcast:function(c,b){c=+c;b|=0;a[b+8>>2]=c;a[b+4>>2]=c;a[b>>2]=c},_glmc_vec_center:function(c,b,e){c|=0;b|=0;e|=0;var d=+a[c>>2]+ +a[b>>2];a[e>>2]=d;var g=+a[c+4>>2]+ +a[b+4>>2];var f=e+4|0;a[f>>2]=g;c=+a[c+8>>2]+ +a[b+8>>2];a[e>>2]=.5*d;a[f>>2]=.5*g;a[e+8>>2]=.5*c},_glmc_vec_clamp:function(c,b,e){c|=0;b=+b;e=+e;var d=+a[c>>2];d=d>b?d:b;a[c>>2]=d>2];g=g> +b?g:b;a[d>>2]=g>2];b=d>b?d:b;a[c>>2]=b>2]=b[a>>2];b[d+4>>2]=b[a+4>>2];b[d+8>>2]=b[a+8>>2]},_glmc_vec_cross:function(c,b,e){c|=0;b|=0;e|=0;var d=c+4|0;var g=b+8|0;var f=c+8|0;var h=b+4|0;a[e>>2]=+a[d>>2]*+a[g>>2]-+a[f>>2]*+a[h>>2];a[e+4>>2]=+a[f>>2]*+a[b>>2]-+a[c>>2]*+a[g>>2];a[e+8>>2]=+a[c>>2]*+a[h>>2]-+a[d>>2]*+a[b>>2]},_glmc_vec_distance:function(c,b){c|=0;b|=0;var d=+a[b>>2]-+a[c>>2];var e=+a[b+4>>2]-+a[c+4>>2];c=+a[b+8>> +2]-+a[c+8>>2];return+ +B(+(d*d+e*e+c*c))},_glmc_vec_div:function(c,b,e){c|=0;b|=0;e|=0;a[e>>2]=+a[c>>2]/+a[b>>2];a[e+4>>2]=+a[c+4>>2]/+a[b+4>>2];a[e+8>>2]=+a[c+8>>2]/+a[b+8>>2]},_glmc_vec_divs:function(c,b,e){c|=0;b=+b;e|=0;a[e>>2]=+a[c>>2]/b;a[e+4>>2]=+a[c+4>>2]/b;a[e+8>>2]=+a[c+8>>2]/b},_glmc_vec_dot:function(c,b){c|=0;b|=0;return+(+a[c>>2]*+a[b>>2]+ +a[c+4>>2]*+a[b+4>>2]+ +a[c+8>>2]*+a[b+8>>2])},_glmc_vec_eq:function(c,b){c|=0;var d=+a[c>>2];return d!=+b||d!=+a[c+4>>2]?0:d==+a[c+8>>2]|0},_glmc_vec_eq_all:function(c){c|= +0;var b=+a[c>>2];return b!=+a[c+4>>2]?0:b==+a[c+8>>2]|0},_glmc_vec_eq_eps:function(c,b){c|=0;b=+b;return 1.1920928955078125E-7>=+D(+(+a[c>>2]-b))&&1.1920928955078125E-7>=+D(+(+a[c+4>>2]-b))?1.1920928955078125E-7>=+D(+(+a[c+8>>2]-b))|0:0},_glmc_vec_eqv:function(c,b){c|=0;b|=0;return+a[c>>2]!=+a[b>>2]||+a[c+4>>2]!=+a[b+4>>2]?0:+a[c+8>>2]==+a[b+8>>2]|0},_glmc_vec_eqv_eps:function(b,d){b|=0;d|=0;return 1.1920928955078125E-7>=+D(+(+a[b>>2]-+a[d>>2]))&&1.1920928955078125E-7>=+D(+(+a[b+4>>2]-+a[d+4>>2]))? +1.1920928955078125E-7>=+D(+(+a[b+8>>2]-+a[d+8>>2]))|0:0},_glmc_vec_flipsign:function(b){b|=0;a[b>>2]=-+a[b>>2];var c=b+4|0;a[c>>2]=-+a[c>>2];b=b+8|0;a[b>>2]=-+a[b>>2]},_glmc_vec_flipsign_to:function(b,d){b|=0;d|=0;a[d>>2]=-+a[b>>2];a[d+4>>2]=-+a[b+4>>2];a[d+8>>2]=-+a[b+8>>2]},_glmc_vec_inv:function(b){b|=0;a[b>>2]=-+a[b>>2];var c=b+4|0;a[c>>2]=-+a[c>>2];b=b+8|0;a[b>>2]=-+a[b>>2]},_glmc_vec_inv_to:function(b,d){b|=0;d|=0;a[d>>2]=-+a[b>>2];a[d+4>>2]=-+a[b+4>>2];a[d+8>>2]=-+a[b+8>>2]},_glmc_vec_isinf:function(a){a|= +0;return 2139095040==(b[a>>2]&2147483647|0)||2139095040==(b[a+4>>2]&2147483647|0)?1:2139095040==(b[a+8>>2]&2147483647|0)|0},_glmc_vec_isnan:function(a){a|=0;return 2139095040<(b[a>>2]&2147483647)>>>0||2139095040<(b[a+4>>2]&2147483647)>>>0?1:2139095040<(b[a+8>>2]&2147483647)>>>0|0},_glmc_vec_isvalid:function(a){a|=0;var c=b[a>>2]&2147483647;if(2139095040>>0)return 0;var e=b[a+4>>2]&2147483647;if(2139095040>>0)return 0;a=b[a+8>>2]&2147483647;return 2139095040!=(a|0)&((2139095040==(e|0)|2139095040== +(c|0)|2139095040>>0)^1)|0},_glmc_vec_lerp:function(b,d,e,f){b|=0;d|=0;e=+e;f|=0;e=0e?e:1;var c=+a[b>>2];var g=b+4|0;b=b+8|0;var h=e*(+a[d+4>>2]-+a[g>>2]);var l=e*(+a[d+8>>2]-+a[b>>2]);a[f>>2]=c+e*(+a[d>>2]-c);a[f+4>>2]=h+ +a[g>>2];a[f+8>>2]=l+ +a[b>>2]},_glmc_vec_max:function(b){b|=0;var c=+a[b>>2];var e=+a[b+4>>2];b=+a[b+8>>2];e=e>c?e:c;return+(e>2];var g=+a[d>>2];a[e>>2]=c>2];g=+a[d+4>>2];a[e+4>>2]=c< +g?c:g;b=+a[b+8>>2];d=+a[d+8>>2];a[e+8>>2]=b>2];var e=+a[b+4>>2];b=+a[b+8>>2];e=eb?b:e)},_glmc_vec_minv:function(b,d,e){b|=0;d|=0;e|=0;var c=+a[b>>2];var g=+a[d>>2];a[e>>2]=c>g?c:g;c=+a[b+4>>2];g=+a[d+4>>2];a[e+4>>2]=c>g?c:g;b=+a[b+8>>2];d=+a[d+8>>2];a[e+8>>2]=b>d?b:d},_glmc_vec_mul:function(b,d,e){b|=0;d|=0;e|=0;a[e>>2]=+a[b>>2]*+a[d>>2];a[e+4>>2]=+a[b+4>>2]*+a[d+4>>2];a[e+8>>2]=+a[b+8>>2]*+a[d+8>>2]},_glmc_vec_muladd:function(b,d, +e){b|=0;d|=0;e|=0;a[e>>2]=+a[e>>2]+ +a[b>>2]*+a[d>>2];var c=e+4|0;a[c>>2]=+a[c>>2]+ +a[b+4>>2]*+a[d+4>>2];e=e+8|0;a[e>>2]=+a[e>>2]+ +a[b+8>>2]*+a[d+8>>2]},_glmc_vec_muladds:function(b,d,e){b|=0;d=+d;e|=0;a[e>>2]=+a[e>>2]+ +a[b>>2]*d;var c=e+4|0;a[c>>2]=+a[c>>2]+ +a[b+4>>2]*d;e=e+8|0;a[e>>2]=+a[e>>2]+ +a[b+8>>2]*d},_glmc_vec_mulv:function(b,d,e){b|=0;d|=0;e|=0;a[e>>2]=+a[b>>2]*+a[d>>2];a[e+4>>2]=+a[b+4>>2]*+a[d+4>>2];a[e+8>>2]=+a[b+8>>2]*+a[d+8>>2]},_glmc_vec_norm:function(b){b|=0;var c=+a[b>>2];var e= ++a[b+4>>2];b=+a[b+8>>2];return+ +B(+(c*c+e*e+b*b))},_glmc_vec_norm2:function(b){b|=0;var c=+a[b>>2];var e=+a[b+4>>2];b=+a[b+8>>2];return+(c*c+e*e+b*b)},_glmc_vec_normalize:function(b){b|=0;var c=+a[b>>2];var e=b+4|0;var f=+a[e>>2];var n=b+8|0;var m=+a[n>>2];var h=+B(+(c*c+f*f+m*m));0==h?(a[n>>2]=0,a[e>>2]=0,a[b>>2]=0):(h=1/h,a[b>>2]=c*h,a[e>>2]=f*h,a[n>>2]=m*h)},_glmc_vec_normalize_to:function(b,d){b|=0;d|=0;var c=+a[b>>2];var e=b+4|0;var f=+a[e>>2];b=b+8|0;var m=+a[b>>2];f=+B(+(c*c+f*f+m*m));0== +f?(a[d>>2]=0,a[d+4>>2]=0,a[(d+8|0)>>2]=0):(f=1/f,a[d>>2]=c*f,a[d+4>>2]=f*+a[e>>2],e=f*+a[b>>2],a[(d+8|0)>>2]=e)},_glmc_vec_one:function(b){b|=0;a[b>>2]=1;a[b+4>>2]=1;a[b+8>>2]=1},_glmc_vec_ortho:function(b,d){b|=0;d|=0;var c=b+4|0;var e=b+8|0;a[d>>2]=+a[c>>2]-+a[e>>2];a[d+4>>2]=+a[e>>2]-+a[b>>2];a[d+8>>2]=+a[b>>2]-+a[c>>2]},_glmc_vec_proj:function(b,d,e){b|=0;d|=0;e|=0;var c=+a[d>>2];var f=d+4|0;var g=+a[f>>2];d=d+8|0;var h=+a[d>>2];b=(+a[b>>2]*c+ +a[b+4>>2]*g+ +a[b+8>>2]*h)/(c*c+g*g+h*h);a[e>>2]= +c*b;a[e+4>>2]=+a[f>>2]*b;a[e+8>>2]=b*+a[d>>2]},_glmc_vec_rotate:function(b,d,e){b|=0;d=+d;e|=0;var c=+a[e>>2];var f=+a[e+4>>2];var g=+a[e+8>>2];e=+N(+d);d=+K(+d);var h=+B(+(c*c+f*f+g*g));var l=0==h;h=1/h;f=l?0:f*h;c=l?0:c*h;g=l?0:g*h;l=+a[b>>2];h=b+4|0;var k=+a[h>>2];var m=b+8|0;var p=+a[m>>2];var q=(1-e)*(g*p+(l*c+k*f));a[b>>2]=e*l+d*(f*p-k*g)+c*q;a[h>>2]=e*k+d*(l*g-c*p)+f*q;a[m>>2]=e*p+d*(k*c-l*f)+g*q},_glmc_vec_rotate_m3:function(b,d,e){b|=0;d|=0;e|=0;var c=+a[b>>2];var f=+a[b+4>>2];var g=+a[b+ +8>>2];var h=+a[b+12>>2];var l=+a[b+16>>2];var k=+a[b+20>>2];var m=+a[b+24>>2];var p=+a[b+28>>2];b=+a[b+32>>2];var q=+B(+(c*c+f*f+g*g));var v=0==q;q=1/q;var t=+B(+(h*h+l*l+k*k));var w=0==t;t=1/t;var x=+B(+(m*m+p*p+b*b));var y=0==x;x=1/x;var z=+a[d>>2];var D=+a[d+4>>2];d=+a[d+8>>2];a[e>>2]=(v?0:c*q)*z+(w?0:h*t)*D+(y?0:m*x)*d;a[e+4>>2]=(v?0:f*q)*z+(w?0:l*t)*D+(y?0:p*x)*d;a[e+8>>2]=(v?0:g*q)*z+(w?0:k*t)*D+(y?0:b*x)*d},_glmc_vec_rotate_m4:function(b,d,e){b|=0;d|=0;e|=0;var c=+a[b>>2];var f=+a[b+4>>2]; +var g=+a[b+8>>2];var h=+a[b+12>>2];var l=+B(+(c*c+f*f+g*g+h*h));h=0==l;l=1/l;var k=+a[b+16>>2];var m=+a[b+20>>2];var p=+a[b+24>>2];var q=+a[b+28>>2];var v=+B(+(k*k+m*m+p*p+q*q));q=0==v;v=1/v;var t=+a[b+32>>2];var w=+a[b+36>>2];var x=+a[b+40>>2];b=+a[b+44>>2];var y=+B(+(t*t+w*w+x*x+b*b));b=0==y;y=1/y;var z=+a[d>>2];var D=+a[d+4>>2];d=+a[d+8>>2];a[e>>2]=(h?0:c*l)*z+(q?0:k*v)*D+(b?0:t*y)*d;a[e+4>>2]=(h?0:f*l)*z+(q?0:m*v)*D+(b?0:w*y)*d;a[e+8>>2]=(h?0:g*l)*z+(q?0:p*v)*D+(b?0:x*y)*d},_glmc_vec_scale:function(b, +d,e){b|=0;d=+d;e|=0;a[e>>2]=+a[b>>2]*d;a[e+4>>2]=+a[b+4>>2]*d;a[e+8>>2]=+a[b+8>>2]*d},_glmc_vec_scale_as:function(b,d,e){b|=0;d=+d;e|=0;var c=+a[b>>2];var f=b+4|0;var g=+a[f>>2];b=b+8|0;var h=+a[b>>2];g=+B(+(c*c+g*g+h*h));0==g?(a[e>>2]=0,a[e+4>>2]=0,a[(e+8|0)>>2]=0):(d/=g,a[e>>2]=c*d,a[e+4>>2]=d*+a[f>>2],f=d*+a[b>>2],a[(e+8|0)>>2]=f)},_glmc_vec_sign:function(b,d){b|=0;d|=0;var c=+a[b>>2];a[d>>2]=+((0c&1)|0);c=+a[b+4>>2];a[d+4>>2]=+((0c&1)|0);b=+a[b+8>>2];a[d+8>>2]=+((0b& +1)|0)},_glmc_vec_sqrt:function(b,d){b|=0;d|=0;a[d>>2]=+B(+ +a[b>>2]);a[d+4>>2]=+B(+ +a[b+4>>2]);a[d+8>>2]=+B(+ +a[b+8>>2])},_glmc_vec_sub:function(b,d,e){b|=0;d|=0;e|=0;a[e>>2]=+a[b>>2]-+a[d>>2];a[e+4>>2]=+a[b+4>>2]-+a[d+4>>2];a[e+8>>2]=+a[b+8>>2]-+a[d+8>>2]},_glmc_vec_subadd:function(b,d,e){b|=0;d|=0;e|=0;a[e>>2]=+a[e>>2]+(+a[b>>2]-+a[d>>2]);var c=e+4|0;a[c>>2]=+a[c>>2]+(+a[b+4>>2]-+a[d+4>>2]);e=e+8|0;a[e>>2]=+a[e>>2]+(+a[b+8>>2]-+a[d+8>>2])},_glmc_vec_subs:function(b,d,e){b|=0;d=+d;e|=0;a[e>>2]= ++a[b>>2]-d;a[e+4>>2]=+a[b+4>>2]-d;a[e+8>>2]=+a[b+8>>2]-d},_glmc_vec_zero:function(b){b|=0;a[b>>2]=0;a[b+4>>2]=0;a[b+8>>2]=0},_malloc:function(a){a|=0;var c=0,e=0,f=0,n=0,m=0,h=0,l=0,k=0,r=0,p=0,q=0,v=0,t=0,x=0,D=0,B=0,C=0,F=0,H=0,K=0,R=0,Q=0,N=0,ea=0,T=0,Y=0,Z=0,O=0,X=0,V=0,U=0,P=0,L=0,ra=0,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>>>de;fe=ee>>>5&8;ge=ee>>>fe;he=ge>>>2&4;ie=ge>>>he;je=ie>>>1&2;ke=ie>>>je;le=ke>>>1&1;Ia=0;Oa=b[312+((fe|de|he|je|le)+(ke>>>le)<<2)>>2]|0}else Ia=Na,Oa=Gb;Oa?(Kb=Ia,Fa=ib,Ga=Oa,da=85):(ha=Ia,ua=ib)}if(85==(da|0))for(;;)if(da=0,ne=(b[Ga+4>>2]&-8)-gb|0,f=(oc=ne>>>0>>0)?ne:Fa,Qb=oc?Ga:Kb,Ga=b[Ga+16+((0==(b[Ga+16>>2]|0)& +1)<<2)>>2]|0)Kb=Qb,Fa=f,da=85;else{ha=Qb;ua=f;break}if(ha&&ua>>>0<((b[4]|0)-gb|0)>>>0){dd=b[6]|0;dd>>>0>ha>>>0&&y();ta=ha+gb|0;ta>>>0<=ha>>>0&&y();cc=b[ha+24>>2]|0;Gc=b[ha+12>>2]|0;do if((Gc|0)==(ha|0)){qe=ha+20|0;if(pc=b[qe>>2]|0)za=pc,Aa=qe;else if(re=ha+16|0,qc=b[re>>2]|0)za=qc,Aa=re;else{Ca=0;break}for(;;)if(se=za+20|0,te=b[se>>2]|0,te|0)za=te,Aa=se;else if(ue=za+16|0,rc=b[ue>>2]|0)za=rc,Aa=ue;else break;dd>>>0>Aa>>>0?y():(b[Aa>>2]=0,Ca=za)}else ed=b[ha+8>>2]|0,dd>>>0>ed>>>0&&y(),oe=ed+12|0,(b[oe>> +2]|0)!=(ha|0)&&y(),pe=Gc+8|0,(b[pe>>2]|0)==(ha|0)?(b[oe>>2]=Gc,b[pe>>2]=ed,Ca=Gc):y();while(0);a:do if(cc){ve=b[ha+28>>2]|0;we=312+(ve<<2)|0;if((ha|0)==(b[we>>2]|0)){if(b[we>>2]=Ca,!Ca){sc=Sb&~(1<>>0>cc>>>0)y();else if(b[cc+16+(((b[cc+16>>2]|0)!=(ha|0)&1)<<2)>>2]=Ca,!Ca){Tb=Sb;break a}xe=b[6]|0;xe>>>0>Ca>>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24>>2]=0):y())}else b[3]=Tb|Qe,b[gd>>2]=ta,b[ta+24>>2]=gd,b[ta+12>>2]=ta,b[ta+8>>2]=ta;m=ha+8|0;z=hb;return m|0}}x=gb}while(0);ec=b[4]|0;if(ec>>>0>=x>>>0)return Jc=ec-x|0,Ub=b[7]|0,15>>0?(Ve=Ub+x|0,b[7]=Ve,b[4]=Jc,b[Ve+4>>2]=Jc|1,b[Ub+ec>>2]=Jc,b[Ub+4>>2]=x|3):(b[4]=0,b[7]=0,b[Ub+4>>2]=ec|3,Xe=Ub+ec+4|0,b[Xe>>2]|=1),m=Ub+8|0,z=hb,m|0;jd=b[5]|0;if(jd>>>0>x>>>0)return Ye=jd-x|0,b[5]=Ye,kd=b[8]|0,Ze=kd+x|0,b[8]=Ze,b[Ze+4>>2]=Ye|1,b[kd+4>>2]=x|3, +m=kd+8|0,z=hb,m|0;b[120]|0?ld=b[122]|0:(b[122]=4096,b[121]=4096,b[123]=-1,b[124]=-1,b[125]=0,b[113]=0,b[120]=Bb&-16^1431655768,ld=4096);uc=x+48|0;af=x+47|0;bf=ld+af|0;cf=0-ld|0;fc=bf&cf;if(fc>>>0<=x>>>0)return m=0,z=hb,m|0;df=b[112]|0;if(df|0&&(ef=b[110]|0,ff=ef+fc|0,ff>>>0<=ef>>>0|ff>>>0>df>>>0))return m=0,z=hb,m|0;a:do{if(b[113]&4)Ja=0;else{md=b[8]|0;b:do if(md){for(h=456;;){hf=b[h>>2]|0;if(hf>>>0<=md>>>0&&(jf=h+4|0,(hf+(b[jf>>2]|0)|0)>>>0>md>>>0))break;if(vc=b[h+8>>2]|0)h=vc;else{da=163;break b}}gc= +bf-jd&cf;if(2147483647>gc>>>0)if(Lc=w(gc|0)|0,(Lc|0)==((b[h>>2]|0)+(b[jf>>2]|0)|0))if(-1==(Lc|0))na=gc;else{wa=gc;ia=Lc;da=180;break a}else Da=Lc,kb=gc,da=171;else na=0}else da=163;while(0);if(163==(da|0))if(Kc=w(0)|0,-1==(Kc|0))na=0;else if(nd=Kc,kf=b[121]|0,lf=kf+-1|0,n=(0==(lf&nd|0)?0:(lf+nd&0-kf)-nd|0)+fc|0,nf=b[110]|0,of=n+nf|0,n>>>0>x>>>0&2147483647>n>>>0)if(pf=b[112]|0,pf|0&&of>>>0<=nf>>>0|of>>>0>pf>>>0)na=0;else if(qf=w(n|0)|0,(qf|0)==(Kc|0)){wa=n;ia=Kc;da=180;break a}else Da=qf,kb=n,da=171; +else na=0;do if(171==(da|0)){wc=0-kb|0;if(!(uc>>>0>kb>>>0&2147483647>kb>>>0&-1!=(Da|0)))if(-1==(Da|0)){na=0;break}else{wa=kb;ia=Da;da=180;break a}sf=b[122]|0;od=af-kb+sf&0-sf;if(2147483647<=od>>>0){wa=kb;ia=Da;da=180;break a}if(-1==(w(od|0)|0))w(wc|0)|0,na=0;else{wa=od+kb|0;ia=Da;da=180;break a}}while(0);b[113]|=4;Ja=na}da=178}while(0);178==(da|0)&&2147483647>fc>>>0&&(hc=w(fc|0)|0,pd=w(0)|0,uf=pd-hc|0,vf=uf>>>0>(x+40|0)>>>0,-1==(hc|0)|vf^1|hc>>>0>>0&-1!=(hc|0)&-1!=(pd|0)^1||(wa=vf?uf:Ja,ia=hc, +da=180));if(180==(da|0)){qd=(b[110]|0)+wa|0;b[110]=qd;qd>>>0>(b[111]|0)>>>0&&(b[111]=qd);if(fa=b[8]|0){for(K=456;;){Df=b[K>>2]|0;Ef=K+4|0;Ff=b[Ef>>2]|0;if((ia|0)==(Df+Ff|0)){da=188;break}if($c=b[K+8>>2]|0)K=$c;else break}if(188==(da|0)&&!(b[K+12>>2]&8)&&ia>>>0>fa>>>0&Df>>>0<=fa>>>0)b[Ef>>2]=Ff+wa,Gf=(b[5]|0)+wa|0,Hf=fa+8|0,If=0==(Hf&7|0)?0:0-Hf&7,Jf=fa+If|0,Kf=Gf-If|0,b[8]=Jf,b[5]=Kf,b[Jf+4>>2]=Kf|1,b[fa+Gf+4>>2]=40,b[9]=b[124];else{Lf=b[6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<>2]|0,(b[6]|0)>>>0>Qg>>>0?y():(F=Qg,Rb=Pg)):(b[2]=Ng|Og,F=Zc,Rb=Zc+8|0),b[Rb>>2]= +fa,b[F+12>>2]=fa,b[fa+8>>2]=F,b[fa+12>>2]=Zc;else if((Rg=xb>>>8)?16777215>>0?H=31:(Sg=(Rg+1048320|0)>>>16&8,Tg=Rg<>>16&4,Vg=Tg<>>16&2,Db=14-(Ug|Sg|Wg)+(Vg<>>15)|0,H=xb>>>(Db+7|0)&1|Db<<1):H=0,Ta=312+(H<<2)|0,b[fa+28>>2]=H,b[fa+20>>2]=0,b[Fg>>2]=0,Ua=b[3]|0,Ka=1<>>1)|0);for(C=b[Ta>>2]|0;;){if((b[C+4>>2]&-8|0)==(xb|0)){da=289;break}Va=C+16+(B>>>31<<2)|0;if(bb=b[Va>>2]|0)B<<=1,C=bb;else{da=286;break}}286==(da|0)?(b[6]| +0)>>>0>Va>>>0?y():(b[Va>>2]=fa,b[fa+24>>2]=C,b[fa+12>>2]=fa,b[fa+8>>2]=fa):289==(da|0)&&(cb=C+8|0,va=b[cb>>2]|0,db=b[6]|0,db>>>0<=va>>>0&db>>>0<=C>>>0?(b[va+12>>2]=fa,b[cb>>2]=fa,b[fa+8>>2]=va,b[fa+12>>2]=C,b[fa+24>>2]=0):y())}else b[3]=Ua|Ka,b[Ta>>2]=fa,b[fa+24>>2]=Ta,b[fa+12>>2]=fa,b[fa+8>>2]=fa}}else wf=b[6]|0,0==(wf|0)|ia>>>0>>0&&(b[6]=ia),b[114]=ia,b[115]=wa,b[117]=0,b[11]=b[120],b[10]=-1,b[15]=48,b[14]=48,b[17]=56,b[16]=56,b[19]=64,b[18]=64,b[21]=72,b[20]=72,b[23]=80,b[22]=80,b[25]=88,b[24]= +88,b[27]=96,b[26]=96,b[29]=104,b[28]=104,b[31]=112,b[30]=112,b[33]=120,b[32]=120,b[35]=128,b[34]=128,b[37]=136,b[36]=136,b[39]=144,b[38]=144,b[41]=152,b[40]=152,b[43]=160,b[42]=160,b[45]=168,b[44]=168,b[47]=176,b[46]=176,b[49]=184,b[48]=184,b[51]=192,b[50]=192,b[53]=200,b[52]=200,b[55]=208,b[54]=208,b[57]=216,b[56]=216,b[59]=224,b[58]=224,b[61]=232,b[60]=232,b[63]=240,b[62]=240,b[65]=248,b[64]=248,b[67]=256,b[66]=256,b[69]=264,b[68]=264,b[71]=272,b[70]=272,b[73]=280,b[72]=280,b[75]=288,b[74]=288, +b[77]=296,b[76]=296,yf=wa+-40|0,zf=ia+8|0,Af=0==(zf&7|0)?0:0-zf&7,Bf=ia+Af|0,Cf=yf-Af|0,b[8]=Bf,b[5]=Cf,b[Bf+4>>2]=Cf|1,b[ia+yf+4>>2]=40,b[9]=b[124];Ma=b[5]|0;if(Ma>>>0>x>>>0)return Qa=Ma-x|0,b[5]=Qa,Ra=b[8]|0,eb=Ra+x|0,b[8]=eb,b[eb+4>>2]=Qa|1,b[Ra+4>>2]=x|3,m=Ra+8|0,z=hb,m|0}b[126]=12;m=0;z=hb;return m|0},_memcpy:function(a,d,e){a|=0;d|=0;e|=0;var c;if(8192<=(e|0))return ya(a|0,d|0,e|0)|0;var f=a|0;var g=a+e|0;if((a&3)==(d&3)){for(;a&3;){if(!e)return f|0;x[a>>0]=x[d>>0]|0;a=a+1|0;d=d+1|0;e=e-1|0}e= +g&-4|0;for(c=e-64|0;(a|0)<=(c|0);)b[a>>2]=b[d>>2],b[a+4>>2]=b[d+4>>2],b[a+8>>2]=b[d+8>>2],b[a+12>>2]=b[d+12>>2],b[a+16>>2]=b[d+16>>2],b[a+20>>2]=b[d+20>>2],b[a+24>>2]=b[d+24>>2],b[a+28>>2]=b[d+28>>2],b[a+32>>2]=b[d+32>>2],b[a+36>>2]=b[d+36>>2],b[a+40>>2]=b[d+40>>2],b[a+44>>2]=b[d+44>>2],b[a+48>>2]=b[d+48>>2],b[a+52>>2]=b[d+52>>2],b[a+56>>2]=b[d+56>>2],b[a+60>>2]=b[d+60>>2],a=a+64|0,d=d+64|0;for(;(a|0)<(e|0);)b[a>>2]=b[d>>2],a=a+4|0,d=d+4|0}else for(e=g-4|0;(a|0)<(e|0);)x[a>>0]=x[d>>0]|0,x[a+1>>0]= +x[d+1>>0]|0,x[a+2>>0]=x[d+2>>0]|0,x[a+3>>0]=x[d+3>>0]|0,a=a+4|0,d=d+4|0;for(;(a|0)<(g|0);)x[a>>0]=x[d>>0]|0,a=a+1|0,d=d+1|0;return f|0},_memset:function(a,d,e){a|=0;e|=0;var c;var f=a+e|0;d=(d|0)&255;if(67<=(e|0)){for(;a&3;)x[a>>0]=d,a=a+1|0;var g=f&-4|0;var h=g-64|0;for(c=d|d<<8|d<<16|d<<24;(a|0)<=(h|0);)b[a>>2]=c,b[a+4>>2]=c,b[a+8>>2]=c,b[a+12>>2]=c,b[a+16>>2]=c,b[a+20>>2]=c,b[a+24>>2]=c,b[a+28>>2]=c,b[a+32>>2]=c,b[a+36>>2]=c,b[a+40>>2]=c,b[a+44>>2]=c,b[a+48>>2]=c,b[a+52>>2]=c,b[a+56>>2]=c,b[a+ +60>>2]=c,a=a+64|0;for(;(a|0)<(g|0);)b[a>>2]=c,a=a+4|0}for(;(a|0)<(f|0);)x[a>>0]=d,a=a+1|0;return f-e|0},_sbrk:w,establishStackSpace:function(a,b){z=a|0},getTempRet0:function(){return R|0},runPostSets:function(){},setTempRet0:function(a){R=a|0},setThrew:function(a,b){H||(H=a|0)},stackAlloc:function(a){var b=z;z=z+(a|0)|0;z=z+15&-16;return b|0},stackRestore:function(a){z=a|0},stackSave:function(){return z|0}}}(e.asmGlobalArg,e.asmLibraryArg,f);e.___errno_location=f.___errno_location;e._free=f._free; +e._glmc_aabb_center=f._glmc_aabb_center;e._glmc_aabb_crop=f._glmc_aabb_crop;e._glmc_aabb_crop_until=f._glmc_aabb_crop_until;e._glmc_aabb_frustum=f._glmc_aabb_frustum;e._glmc_aabb_invalidate=f._glmc_aabb_invalidate;e._glmc_aabb_isvalid=f._glmc_aabb_isvalid;e._glmc_aabb_merge=f._glmc_aabb_merge;e._glmc_aabb_radius=f._glmc_aabb_radius;e._glmc_aabb_size=f._glmc_aabb_size;e._glmc_aabb_transform=f._glmc_aabb_transform;e._glmc_decompose=f._glmc_decompose;e._glmc_decompose_rs=f._glmc_decompose_rs;e._glmc_decompose_scalev= +f._glmc_decompose_scalev;e._glmc_euler=f._glmc_euler;e._glmc_euler_angles=f._glmc_euler_angles;e._glmc_euler_by_order=f._glmc_euler_by_order;e._glmc_euler_xyz=f._glmc_euler_xyz;e._glmc_euler_xzy=f._glmc_euler_xzy;e._glmc_euler_yxz=f._glmc_euler_yxz;e._glmc_euler_yzx=f._glmc_euler_yzx;e._glmc_euler_zxy=f._glmc_euler_zxy;e._glmc_euler_zyx=f._glmc_euler_zyx;e._glmc_frustum=f._glmc_frustum;e._glmc_frustum_box=f._glmc_frustum_box;e._glmc_frustum_center=f._glmc_frustum_center;e._glmc_frustum_corners=f._glmc_frustum_corners; +e._glmc_frustum_corners_at=f._glmc_frustum_corners_at;e._glmc_frustum_planes=f._glmc_frustum_planes;e._glmc_inv_tr=f._glmc_inv_tr;e._glmc_look=f._glmc_look;e._glmc_look_anyup=f._glmc_look_anyup;e._glmc_lookat=f._glmc_lookat;e._glmc_mat3_copy=f._glmc_mat3_copy;e._glmc_mat3_det=f._glmc_mat3_det;e._glmc_mat3_identity=f._glmc_mat3_identity;e._glmc_mat3_inv=f._glmc_mat3_inv;e._glmc_mat3_mul=f._glmc_mat3_mul;e._glmc_mat3_mulv=f._glmc_mat3_mulv;e._glmc_mat3_quat=f._glmc_mat3_quat;e._glmc_mat3_scale=f._glmc_mat3_scale; +e._glmc_mat3_swap_col=f._glmc_mat3_swap_col;e._glmc_mat3_swap_row=f._glmc_mat3_swap_row;e._glmc_mat3_transpose=f._glmc_mat3_transpose;e._glmc_mat3_transpose_to=f._glmc_mat3_transpose_to;e._glmc_mat4_copy=f._glmc_mat4_copy;e._glmc_mat4_det=f._glmc_mat4_det;e._glmc_mat4_identity=f._glmc_mat4_identity;e._glmc_mat4_ins3=f._glmc_mat4_ins3;e._glmc_mat4_inv=f._glmc_mat4_inv;e._glmc_mat4_inv_fast=f._glmc_mat4_inv_fast;e._glmc_mat4_inv_precise=f._glmc_mat4_inv_precise;e._glmc_mat4_mul=f._glmc_mat4_mul;e._glmc_mat4_mulN= +f._glmc_mat4_mulN;e._glmc_mat4_mulv=f._glmc_mat4_mulv;e._glmc_mat4_mulv3=f._glmc_mat4_mulv3;e._glmc_mat4_pick3=f._glmc_mat4_pick3;e._glmc_mat4_pick3t=f._glmc_mat4_pick3t;e._glmc_mat4_quat=f._glmc_mat4_quat;e._glmc_mat4_scale=f._glmc_mat4_scale;e._glmc_mat4_scale_p=f._glmc_mat4_scale_p;e._glmc_mat4_swap_col=f._glmc_mat4_swap_col;e._glmc_mat4_swap_row=f._glmc_mat4_swap_row;e._glmc_mat4_transpose=f._glmc_mat4_transpose;e._glmc_mat4_transpose_to=f._glmc_mat4_transpose_to;e._glmc_mat4_ucopy=f._glmc_mat4_ucopy; +e._glmc_mul=f._glmc_mul;e._glmc_mul_rot=f._glmc_mul_rot;e._glmc_ortho=f._glmc_ortho;e._glmc_ortho_aabb=f._glmc_ortho_aabb;e._glmc_ortho_aabb_p=f._glmc_ortho_aabb_p;e._glmc_ortho_aabb_pz=f._glmc_ortho_aabb_pz;e._glmc_ortho_default=f._glmc_ortho_default;e._glmc_ortho_default_s=f._glmc_ortho_default_s;e._glmc_persp_aspect=f._glmc_persp_aspect;e._glmc_persp_decomp=f._glmc_persp_decomp;e._glmc_persp_decomp_far=f._glmc_persp_decomp_far;e._glmc_persp_decomp_near=f._glmc_persp_decomp_near;e._glmc_persp_decomp_x= +f._glmc_persp_decomp_x;e._glmc_persp_decomp_y=f._glmc_persp_decomp_y;e._glmc_persp_decomp_z=f._glmc_persp_decomp_z;e._glmc_persp_decompv=f._glmc_persp_decompv;e._glmc_persp_fovy=f._glmc_persp_fovy;e._glmc_persp_sizes=f._glmc_persp_sizes;e._glmc_perspective=f._glmc_perspective;e._glmc_perspective_default=f._glmc_perspective_default;e._glmc_perspective_resize=f._glmc_perspective_resize;e._glmc_plane_normalize=f._glmc_plane_normalize;e._glmc_project=f._glmc_project;e._glmc_quat=f._glmc_quat;e._glmc_quat_add= +f._glmc_quat_add;e._glmc_quat_angle=f._glmc_quat_angle;e._glmc_quat_axis=f._glmc_quat_axis;e._glmc_quat_conjugate=f._glmc_quat_conjugate;e._glmc_quat_copy=f._glmc_quat_copy;e._glmc_quat_dot=f._glmc_quat_dot;e._glmc_quat_for=f._glmc_quat_for;e._glmc_quat_forp=f._glmc_quat_forp;e._glmc_quat_identity=f._glmc_quat_identity;e._glmc_quat_imag=f._glmc_quat_imag;e._glmc_quat_imaglen=f._glmc_quat_imaglen;e._glmc_quat_imagn=f._glmc_quat_imagn;e._glmc_quat_init=f._glmc_quat_init;e._glmc_quat_inv=f._glmc_quat_inv; +e._glmc_quat_lerp=f._glmc_quat_lerp;e._glmc_quat_look=f._glmc_quat_look;e._glmc_quat_mat3=f._glmc_quat_mat3;e._glmc_quat_mat3t=f._glmc_quat_mat3t;e._glmc_quat_mat4=f._glmc_quat_mat4;e._glmc_quat_mat4t=f._glmc_quat_mat4t;e._glmc_quat_mul=f._glmc_quat_mul;e._glmc_quat_norm=f._glmc_quat_norm;e._glmc_quat_normalize=f._glmc_quat_normalize;e._glmc_quat_normalize_to=f._glmc_quat_normalize_to;e._glmc_quat_real=f._glmc_quat_real;e._glmc_quat_rotate=f._glmc_quat_rotate;e._glmc_quat_rotate_at=f._glmc_quat_rotate_at; +e._glmc_quat_rotate_atm=f._glmc_quat_rotate_atm;e._glmc_quat_rotatev=f._glmc_quat_rotatev;e._glmc_quat_slerp=f._glmc_quat_slerp;e._glmc_quat_sub=f._glmc_quat_sub;e._glmc_quatv=f._glmc_quatv;e._glmc_rotate=f._glmc_rotate;e._glmc_rotate_at=f._glmc_rotate_at;e._glmc_rotate_atm=f._glmc_rotate_atm;e._glmc_rotate_make=f._glmc_rotate_make;e._glmc_rotate_x=f._glmc_rotate_x;e._glmc_rotate_y=f._glmc_rotate_y;e._glmc_rotate_z=f._glmc_rotate_z;e._glmc_scale=f._glmc_scale;e._glmc_scale_make=f._glmc_scale_make; +e._glmc_scale_to=f._glmc_scale_to;e._glmc_scale_uni=f._glmc_scale_uni;e._glmc_translate=f._glmc_translate;e._glmc_translate_make=f._glmc_translate_make;e._glmc_translate_to=f._glmc_translate_to;e._glmc_translate_x=f._glmc_translate_x;e._glmc_translate_y=f._glmc_translate_y;e._glmc_translate_z=f._glmc_translate_z;e._glmc_uniscaled=f._glmc_uniscaled;e._glmc_unproject=f._glmc_unproject;e._glmc_unprojecti=f._glmc_unprojecti;e._glmc_vec3=f._glmc_vec3;e._glmc_vec4=f._glmc_vec4;e._glmc_vec4_add=f._glmc_vec4_add; +e._glmc_vec4_addadd=f._glmc_vec4_addadd;e._glmc_vec4_adds=f._glmc_vec4_adds;e._glmc_vec4_broadcast=f._glmc_vec4_broadcast;e._glmc_vec4_clamp=f._glmc_vec4_clamp;e._glmc_vec4_copy=f._glmc_vec4_copy;e._glmc_vec4_copy3=f._glmc_vec4_copy3;e._glmc_vec4_distance=f._glmc_vec4_distance;e._glmc_vec4_div=f._glmc_vec4_div;e._glmc_vec4_divs=f._glmc_vec4_divs;e._glmc_vec4_dot=f._glmc_vec4_dot;e._glmc_vec4_eq=f._glmc_vec4_eq;e._glmc_vec4_eq_all=f._glmc_vec4_eq_all;e._glmc_vec4_eq_eps=f._glmc_vec4_eq_eps;e._glmc_vec4_eqv= +f._glmc_vec4_eqv;e._glmc_vec4_eqv_eps=f._glmc_vec4_eqv_eps;e._glmc_vec4_flipsign=f._glmc_vec4_flipsign;e._glmc_vec4_flipsign_to=f._glmc_vec4_flipsign_to;e._glmc_vec4_inv=f._glmc_vec4_inv;e._glmc_vec4_inv_to=f._glmc_vec4_inv_to;e._glmc_vec4_isinf=f._glmc_vec4_isinf;e._glmc_vec4_isnan=f._glmc_vec4_isnan;e._glmc_vec4_isvalid=f._glmc_vec4_isvalid;e._glmc_vec4_lerp=f._glmc_vec4_lerp;e._glmc_vec4_max=f._glmc_vec4_max;e._glmc_vec4_maxv=f._glmc_vec4_maxv;e._glmc_vec4_min=f._glmc_vec4_min;e._glmc_vec4_minv= +f._glmc_vec4_minv;e._glmc_vec4_mul=f._glmc_vec4_mul;e._glmc_vec4_muladd=f._glmc_vec4_muladd;e._glmc_vec4_muladds=f._glmc_vec4_muladds;e._glmc_vec4_mulv=f._glmc_vec4_mulv;e._glmc_vec4_norm=f._glmc_vec4_norm;e._glmc_vec4_norm2=f._glmc_vec4_norm2;e._glmc_vec4_normalize=f._glmc_vec4_normalize;e._glmc_vec4_normalize_to=f._glmc_vec4_normalize_to;e._glmc_vec4_one=f._glmc_vec4_one;e._glmc_vec4_scale=f._glmc_vec4_scale;e._glmc_vec4_scale_as=f._glmc_vec4_scale_as;e._glmc_vec4_sign=f._glmc_vec4_sign;e._glmc_vec4_sqrt= +f._glmc_vec4_sqrt;e._glmc_vec4_sub=f._glmc_vec4_sub;e._glmc_vec4_subadd=f._glmc_vec4_subadd;e._glmc_vec4_subs=f._glmc_vec4_subs;e._glmc_vec4_zero=f._glmc_vec4_zero;e._glmc_vec_add=f._glmc_vec_add;e._glmc_vec_addadd=f._glmc_vec_addadd;e._glmc_vec_adds=f._glmc_vec_adds;e._glmc_vec_angle=f._glmc_vec_angle;e._glmc_vec_broadcast=f._glmc_vec_broadcast;e._glmc_vec_center=f._glmc_vec_center;e._glmc_vec_clamp=f._glmc_vec_clamp;e._glmc_vec_copy=f._glmc_vec_copy;e._glmc_vec_cross=f._glmc_vec_cross;e._glmc_vec_distance= +f._glmc_vec_distance;e._glmc_vec_div=f._glmc_vec_div;e._glmc_vec_divs=f._glmc_vec_divs;e._glmc_vec_dot=f._glmc_vec_dot;e._glmc_vec_eq=f._glmc_vec_eq;e._glmc_vec_eq_all=f._glmc_vec_eq_all;e._glmc_vec_eq_eps=f._glmc_vec_eq_eps;e._glmc_vec_eqv=f._glmc_vec_eqv;e._glmc_vec_eqv_eps=f._glmc_vec_eqv_eps;e._glmc_vec_flipsign=f._glmc_vec_flipsign;e._glmc_vec_flipsign_to=f._glmc_vec_flipsign_to;e._glmc_vec_inv=f._glmc_vec_inv;e._glmc_vec_inv_to=f._glmc_vec_inv_to;e._glmc_vec_isinf=f._glmc_vec_isinf;e._glmc_vec_isnan= +f._glmc_vec_isnan;e._glmc_vec_isvalid=f._glmc_vec_isvalid;e._glmc_vec_lerp=f._glmc_vec_lerp;e._glmc_vec_max=f._glmc_vec_max;e._glmc_vec_maxv=f._glmc_vec_maxv;e._glmc_vec_min=f._glmc_vec_min;e._glmc_vec_minv=f._glmc_vec_minv;e._glmc_vec_mul=f._glmc_vec_mul;e._glmc_vec_muladd=f._glmc_vec_muladd;e._glmc_vec_muladds=f._glmc_vec_muladds;e._glmc_vec_mulv=f._glmc_vec_mulv;e._glmc_vec_norm=f._glmc_vec_norm;e._glmc_vec_norm2=f._glmc_vec_norm2;e._glmc_vec_normalize=f._glmc_vec_normalize;e._glmc_vec_normalize_to= +f._glmc_vec_normalize_to;e._glmc_vec_one=f._glmc_vec_one;e._glmc_vec_ortho=f._glmc_vec_ortho;e._glmc_vec_proj=f._glmc_vec_proj;e._glmc_vec_rotate=f._glmc_vec_rotate;e._glmc_vec_rotate_m3=f._glmc_vec_rotate_m3;e._glmc_vec_rotate_m4=f._glmc_vec_rotate_m4;e._glmc_vec_scale=f._glmc_vec_scale;e._glmc_vec_scale_as=f._glmc_vec_scale_as;e._glmc_vec_sign=f._glmc_vec_sign;e._glmc_vec_sqrt=f._glmc_vec_sqrt;e._glmc_vec_sub=f._glmc_vec_sub;e._glmc_vec_subadd=f._glmc_vec_subadd;e._glmc_vec_subs=f._glmc_vec_subs; +e._glmc_vec_zero=f._glmc_vec_zero;e._malloc=f._malloc;e._memcpy=f._memcpy;e._memset=f._memset;e._sbrk=f._sbrk;e.establishStackSpace=f.establishStackSpace;e.getTempRet0=f.getTempRet0;e.runPostSets=f.runPostSets;e.setTempRet0=f.setTempRet0;e.setThrew=f.setThrew;var uc=e.stackAlloc=f.stackAlloc,tc=e.stackRestore=f.stackRestore,sc=e.stackSave=f.stackSave;e.asm=f;if(pa)if(yb(pa)||("function"===typeof e.locateFile?pa=e.locateFile(pa):e.memoryInitializerPrefixURL&&(pa=e.memoryInitializerPrefixURL+pa)),na|| +Y)Y=e.readBinary(pa),ra.set(Y,8);else{var $c=function(){e.readAsync(pa,Zb,function(){throw"could not load memory initializer "+pa;})};Na++;e.monitorRunDependencies&&e.monitorRunDependencies(Na);var Zb=function(f){f.byteLength&&(f=new Uint8Array(f));ra.set(f,8);e.memoryInitializerRequest&&delete e.memoryInitializerRequest.response;Na--;e.monitorRunDependencies&&e.monitorRunDependencies(Na);0==Na&&(null!==Pb&&(clearInterval(Pb),Pb=null),Ib&&(f=Ib,Ib=null,f()))};(Y=ya(pa))?Zb(Y.buffer):e.memoryInitializerRequest? +(Y=function(){var f=e.memoryInitializerRequest,m=f.response;if(200!==f.status&&0!==f.status)if(m=ya(e.memoryInitializerRequestURL))m=m.buffer;else{console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+f.status+", retrying "+pa);$c();return}Zb(m)},e.memoryInitializerRequest.response?setTimeout(Y,0):e.memoryInitializerRequest.addEventListener("load",Y)):$c()}zb.prototype=Error();zb.prototype.constructor=zb;Ib=function x(){e.calledRun||Mb();e.calledRun||(Ib=x)}; +e.run=Mb;e.exit=function(f,m){if(!m||!e.noExitRuntime||0!==f){if(!e.noExitRuntime&&(Ab=!0,Hb=void 0,X(hh),e.onExit))e.onExit(f);na&&process.exit(f);e.quit(f,new zb(f))}};e.abort=tb;if(e.preInit)for("function"==typeof e.preInit&&(e.preInit=[e.preInit]);0>2];e=f+e+15&-16;Z[Da>>2]=e;return e>=ub?(z(),Z[Da>>2]=f,0):f};e.getNativeTypeSize=function(e){switch(e){case "i1":case "i8":return 1;case "i16":return 2; +case "i32":return 4;case "i64":return 8;case "float":return 4;case "double":return 8;default:return"*"===e[e.length-1]?4:"i"===e[0]?(e=parseInt(e.substr(1)),C(0===e%8),e/8):0}};e.ccall=function(f,m,z,R,b){b=e["_"+f];C(b,"Cannot call unknown function "+f+", make sure it is exported");var a=[];f=0;if(R)for(var x=0;x>0]=f;break;case "i8":Bb[e>>0]=f;break;case "i16":Cb[e>>1]=f;break;case "i32":Z[e>>2]=f;break;case "i64":tempI64=[f>>>0,(tempDouble=f,1<=+wc(tempDouble)?0>>0:~~+ih((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)];Z[e>>2]=tempI64[0];Z[e+4>>2]=tempI64[1];break;case "float":Ob[e>>2]=f;break;case "double":ac[e>>3]=f;break;default:tb("invalid type for setValue: "+m)}};e.getValue= +function(e,f,m){f=f||"i8";"*"===f.charAt(f.length-1)&&(f="i32");switch(f){case "i1":return Bb[e>>0];case "i8":return Bb[e>>0];case "i16":return Cb[e>>1];case "i32":return Z[e>>2];case "i64":return Z[e>>2];case "float":return Ob[e>>2];case "double":return ac[e>>3];default:tb("invalid type for getValue: "+f)}return null};return e}(H instanceof Buffer?{buffer:H}:void 0),X=function(e){var m=z.getNativeTypeSize(e)|0;if(m)return m;m=z.getNativeTypeSize("float")|0;switch(e){case "vec2":return 2*m;case "vec":case "vec3":return 3* +m;case "vec4":return 4*m;case "mat3":return 9*m;case "mat4":return 16*m}assert(0)},yb=function(e){return z.ccall("malloc","number",["number"],[X(e)])};m.prototype.free=function(){z.ccall("free","void",["number"],[this.storage.byteOffset]);delete this.storage};this.vec=this.vec3=function(){if(1>arguments.length||!(arguments[0]instanceof Float32Array)){var e=new m;e.set(arguments)}else e=new m(arguments[0]);return e};m.prototype.set=function(){if(1>arguments.length)for(var e=0;3>e;e++)this.storage[e]= +0;else if(arguments[0]instanceof m||arguments[0]instanceof vec4)for(e=0;3>e;e++)this.storage[e]=arguments[0].storage[e];else if(arguments[0]instanceof vec2){for(e=0;2>e;e++)this.storage[e]=arguments[0].storage[e];this[2]=0}else switch(arguments.length){case 1:this.storage[0]=this.storage[1]=this.storage[2]=arguments[0];break;case 2:for(e=0;2>e;e++)this.storage[e]=arguments[e];this[2]=0;break;case 3:case 4:for(e=0;3>e;e++)this.storage[e]=arguments[e];break;default:for(e=0;3>e;e++)this.storage[e]=0}}; +m.prototype.dot=function(e){assert(e instanceof m);return z.ccall("cglm_vec_dot","number",["number","number"],[this.storage.byteOffset,e.storage.byteOffset])};m.prototype.cross=function(e,C){assert(e instanceof m);C instanceof m||(C=new m);z.ccall("cglm_vec_cross","void",["number","number","number"],[this.storage.byteOffset,e.storage.byteOffset,C.storage.byteOffset]);this.free();return C};m.prototype.norm=function(){return z.ccall("cglm_vec_norm","number",["number"],[this.storage.byteOffset])};m.prototype.norm2= +function(){return z.ccall("cglm_vec_norm2","number",["number"],[this.storage.byteOffset])};m.prototype.normalize=function(){z.ccall("cglm_vec_normalize","void",["number"],[this.storage.byteOffset]);return this};C.prototype.free=function(){z.ccall("free","void",["number"],[this.storage.byteOffset]);delete this.storage};this.mat4=function(){if(1>arguments.length||!(arguments[0]instanceof Float32Array)){var e=new C;e.set(arguments)}else e=new C(arguments[0]);return e};C.prototype.set=function(){if(1> +arguments.length)for(var e=0;16>e;e++)this.storage[e]=0;else if(arguments[0]instanceof _vec)this.storage[0]=arguments[0].storage[0],this.storage[1]=this.storage[2]=this.storage[3]=0,this.storage[5]=arguments[0].storage[1],this.storage[4]=this.storage[6]=this.storage[7]=0,this.storage[10]=arguments[0].storage[2],this.storage[8]=this.storage[9]=this.storage[11]=0,this.storage[12]=this.storage[13]=this.storage[14]=this.storage[15]=0;else if(arguments[0]instanceof _vec4)this.storage[0]=arguments[0].storage[0], +this.storage[1]=this.storage[2]=this.storage[3]=0,this.storage[5]=arguments[0].storage[1],this.storage[4]=this.storage[6]=this.storage[7]=0,this.storage[10]=arguments[0].storage[2],this.storage[8]=this.storage[9]=this.storage[11]=0,this.storage[15]=arguments[0].storage[3],this.storage[12]=this.storage[13]=this.storage[14]=0;else if(arguments[0]instanceof _mat3){for(e=0;3>e;e++)this.storage[e]=arguments[0].storage[e];this.storage[3]=0;for(e=3;6>e;e++)this.storage[e+1]=arguments[0].storage[e];this.storage[7]= +0;for(e=6;9>e;e++)this.storage[e+2]=arguments[0].storage[e];this.storage[11]=0;this.storage[15]=1;this.storage[12]=this.storage[13]=this.storage[14]=0}else if(arguments[0]instanceof _mat4)for(e=0;16>e;e++)this.storage[e]=arguments[0].storage[e];else switch(arguments.length){case 0:this.storage[0]=1;this.storage[1]=this.storage[2]=this.storage[3]=0;this.storage[5]=1;this.storage[4]=this.storage[6]=this.storage[7]=0;this.storage[10]=1;this.storage[8]=this.storage[9]=this.storage[11]=0;this.storage[15]= +1;this.storage[12]=this.storage[13]=this.storage[14]=0;break;case 1:this.storage[0]=this.storage[5]=this.storage[10]=arguments[0];this.storage[1]=this.storage[2]=this.storage[3]=0;this.storage[4]=this.storage[6]=this.storage[7]=0;this.storage[8]=this.storage[9]=this.storage[11]=0;this.storage[15]=1;this.storage[12]=this.storage[13]=this.storage[14]=0;break;case 3:this.storage[0]=arguments[0];this.storage[1]=this.storage[2]=this.storage[3]=0;this.storage[5]=arguments[1];this.storage[4]=this.storage[6]= +this.storage[7]=0;this.storage[10]=arguments[2];this.storage[8]=this.storage[9]=this.storage[11]=0;this.storage[15]=1;this.storage[12]=this.storage[13]=this.storage[14]=0;break;case 4:this.storage[0]=arguments[0];this.storage[1]=this.storage[2]=this.storage[3]=0;this.storage[5]=arguments[1];this.storage[4]=this.storage[6]=this.storage[7]=0;this.storage[10]=arguments[2];this.storage[8]=this.storage[9]=this.storage[11]=0;this.storage[15]=arguments[3];this.storage[12]=this.storage[13]=this.storage[14]= +0;break;case 16:for(e=0;16>e;e++)this.storage[e]=arguments[e];break;default:assert(0)}};C.prototype.translate_z=function(e){z.ccall("cglm_translate_z","void",["number","number"],[this.storage.byteOffsed,e]);return this};C.prototype.rotate_z=function(e,H){H instanceof C||(H=new m);z.ccall("cglm_rotate_z","void",["number","number","number"],[this.storage.byteOffset,e,H.storage.byteOffset]);this.free();return H};this.epsilon=function(){return 5};this.pi=Math.PI;this.root_two=Math.sqrt(2);this.add=function(e, +m){return e+m};this.sub=function(e,m){return e-m};this.mul=function(e,m){return e*m};this.vec_dot=function(e,C){assert(e instanceof m);assert(C instanceof m);return z.ccall("cglm_vec_dot","number",["number","number"],[e.storage.byteOffset,C.storage.byteOffset])};this.vec_cross=function(e,C,H){assert(e instanceof m);assert(C instanceof m);H instanceof m||(H=new m);z.ccall("cglm_vec_cross","void",["number","number","number"],[e.storage.byteOffset,C.storage.byteOffset,H.storage.byteOffset]);return H}; +this.vec_norm=function(e){assert(e instanceof m);return z.ccall("cglm_vec_norm","number",["number"],[e.storage.byteOffset])};this.vec_norm2=function(e){assert(e instanceof m);return z.ccall("cglm_vec_norm2","number",["number"],[e.storage.byteOffset])};this.vec_normalize=function(e){assert(e instanceof m);z.ccall("cglm_vec_normalize","void",["number"],[e.storage.byteOffset]);return e};this.translate_z=function(e,m){assert(e instanceof C);z.ccall("cglm_translate_z","void",["number","number"],[e.storage.byteOffsed, +m]);return e};this.rotate_z=function(e,H,X){assert(e instanceof C);X instanceof C||(X=new m);z.ccall("cglm_rotate_z","void",["number","number","number"],[e.storage.byteOffset,H,X.storage.byteOffset]);this.free();return X}}; diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h new file mode 100644 index 0000000..aa5d560 --- /dev/null +++ b/include/cglm/affine-mat.h @@ -0,0 +1,100 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest); + CGLM_INLINE void glm_inv_tr(mat4 mat); + */ + +#ifndef cglm_affine_mat_h +#define cglm_affine_mat_h + +#include "common.h" +#include "mat4.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/affine.h" +#endif + +#ifdef CGLM_AVX_FP +# include "simd/avx/affine.h" +#endif + +#include + +CGLM_INLINE +void +glm_mul(mat4 m1, mat4 m2, mat4 dest) { +#ifdef __AVX__ + glm_mul_avx(m1, m2, dest); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + glm_mul_sse2(m1, m2, dest); +#else + float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], a03 = m1[0][3], + a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], a13 = m1[1][3], + a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2], a23 = m1[2][3], + a30 = m1[3][0], a31 = m1[3][1], a32 = m1[3][2], a33 = m1[3][3], + + b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2], + b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2], + b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2], + b30 = m2[3][0], b31 = m2[3][1], b32 = m2[3][2], b33 = m2[3][3]; + + dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02; + dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02; + dest[0][2] = a02 * b00 + a12 * b01 + a22 * b02; + dest[0][3] = a03 * b00 + a13 * b01 + a23 * b02; + + dest[1][0] = a00 * b10 + a10 * b11 + a20 * b12; + dest[1][1] = a01 * b10 + a11 * b11 + a21 * b12; + dest[1][2] = a02 * b10 + a12 * b11 + a22 * b12; + dest[1][3] = a03 * b10 + a13 * b11 + a23 * b12; + + dest[2][0] = a00 * b20 + a10 * b21 + a20 * b22; + dest[2][1] = a01 * b20 + a11 * b21 + a21 * b22; + dest[2][2] = a02 * b20 + a12 * b21 + a22 * b22; + dest[2][3] = a03 * b20 + a13 * b21 + a23 * b22; + + dest[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; + dest[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; + dest[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; + dest[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; +#endif +} + +/*! + * @brief inverse orthonormal rotation + translation matrix (ridig-body) + * + * @code + * X = | R T | X' = | R' -R'T | + * | 0 1 | | 0 1 | + * @endcode + * + * @param[in,out] mat matrix + */ +CGLM_INLINE +void +glm_inv_tr(mat4 mat) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_inv_tr_sse2(mat); +#else + CGLM_ALIGN(16) mat3 r; + CGLM_ALIGN(16) vec3 t; + + /* rotate */ + glm_mat4_pick3t(mat, r); + glm_mat4_ins3(r, mat); + + /* translate */ + glm_mat3_mulv(r, mat[3], t); + glm_vec_flipsign(t); + glm_vec_copy(t, mat[3]); +#endif +} + +#endif /* cglm_affine_mat_h */ diff --git a/include/cglm/affine.h b/include/cglm/affine.h new file mode 100644 index 0000000..6cb1f74 --- /dev/null +++ b/include/cglm/affine.h @@ -0,0 +1,409 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_translate_to(mat4 m, vec3 v, mat4 dest); + CGLM_INLINE void glm_translate(mat4 m, vec3 v); + CGLM_INLINE void glm_translate_x(mat4 m, float to); + CGLM_INLINE void glm_translate_y(mat4 m, float to); + CGLM_INLINE void glm_translate_z(mat4 m, float to); + CGLM_INLINE void glm_translate_make(mat4 m, vec3 v); + CGLM_INLINE void glm_scale_to(mat4 m, vec3 v, mat4 dest); + CGLM_INLINE void glm_scale_make(mat4 m, vec3 v); + CGLM_INLINE void glm_scale(mat4 m, vec3 v); + CGLM_INLINE void glm_scale1(mat4 m, float s); + CGLM_INLINE void glm_rotate_x(mat4 m, float rad, mat4 dest); + CGLM_INLINE void glm_rotate_y(mat4 m, float rad, mat4 dest); + CGLM_INLINE void glm_rotate_z(mat4 m, float rad, mat4 dest); + CGLM_INLINE void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc); + CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis); + CGLM_INLINE void glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc); + CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis); + CGLM_INLINE void glm_decompose_scalev(mat4 m, vec3 s); + CGLM_INLINE bool glm_uniscaled(mat4 m); + CGLM_INLINE void glm_decompose_rs(mat4 m, mat4 r, vec3 s); + CGLM_INLINE void glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s); + */ + +#ifndef cglm_affine_h +#define cglm_affine_h + +#include "common.h" +#include "vec4.h" +#include "affine-mat.h" +#include "util.h" + +CGLM_INLINE +void +glm_translate_to(mat4 m, vec3 v, mat4 dest) { + mat4 t = GLM_MAT4_IDENTITY_INIT; + +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(t[0]), + _mm_set1_ps(v[0])), + _mm_mul_ps(_mm_load_ps(t[1]), + _mm_set1_ps(v[1]))), + _mm_add_ps(_mm_mul_ps(_mm_load_ps(t[2]), + _mm_set1_ps(v[2])), + _mm_load_ps(t[3])))) + ; + + _mm_store_ps(dest[0], _mm_load_ps(m[0])); + _mm_store_ps(dest[1], _mm_load_ps(m[1])); + _mm_store_ps(dest[2], _mm_load_ps(m[2])); +#else + vec4 v1, v2, v3; + + glm_vec4_scale(t[0], v[0], v1); + glm_vec4_scale(t[1], v[1], v2); + glm_vec4_scale(t[2], v[2], v3); + + glm_vec4_add(v1, t[3], t[3]); + glm_vec4_add(v2, t[3], t[3]); + glm_vec4_add(v3, t[3], t[3]); + + glm__memcpy(float, dest, t, sizeof(mat4)); +#endif +} + +CGLM_INLINE +void +glm_translate(mat4 m, vec3 v) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(m[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]), + _mm_set1_ps(v[0])), + _mm_mul_ps(_mm_load_ps(m[1]), + _mm_set1_ps(v[1]))), + _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]), + _mm_set1_ps(v[2])), + _mm_load_ps(m[3])))) + ; +#else + vec4 v1, v2, v3; + + glm_vec4_scale(m[0], v[0], v1); + glm_vec4_scale(m[1], v[1], v2); + glm_vec4_scale(m[2], v[2], v3); + + glm_vec4_add(v1, m[3], m[3]); + glm_vec4_add(v2, m[3], m[3]); + glm_vec4_add(v3, m[3], m[3]); +#endif +} + +CGLM_INLINE +void +glm_translate_x(mat4 m, float to) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(m[3], + _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]), + _mm_set1_ps(to)), + _mm_load_ps(m[3]))) + ; +#else + vec4 v1; + glm_vec4_scale(m[0], to, v1); + glm_vec4_add(v1, m[3], m[3]); +#endif +} + +CGLM_INLINE +void +glm_translate_y(mat4 m, float to) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(m[3], + _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[1]), + _mm_set1_ps(to)), + _mm_load_ps(m[3]))) + ; +#else + vec4 v1; + glm_vec4_scale(m[1], to, v1); + glm_vec4_add(v1, m[3], m[3]); +#endif +} + +CGLM_INLINE +void +glm_translate_z(mat4 m, float to) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(m[3], + _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]), + _mm_set1_ps(to)), + _mm_load_ps(m[3]))) + ; +#else + vec4 v1; + glm_vec4_scale(m[2], to, v1); + glm_vec4_add(v1, m[3], m[3]); +#endif +} + +CGLM_INLINE +void +glm_translate_make(mat4 m, vec3 v) { + mat4 t = GLM_MAT4_IDENTITY_INIT; + glm_translate_to(t, v, m); +} + +/* scale */ + +CGLM_INLINE +void +glm_scale_to(mat4 m, vec3 v, mat4 dest) { + glm_vec4_scale(m[0], v[0], dest[0]); + glm_vec4_scale(m[1], v[1], dest[1]); + glm_vec4_scale(m[2], v[2], dest[2]); + + glm_vec4_copy(m[3], dest[3]); +} + +CGLM_INLINE +void +glm_scale_make(mat4 m, vec3 v) { + mat4 t = GLM_MAT4_IDENTITY_INIT; + glm_scale_to(t, v, m); +} + +CGLM_INLINE +void +glm_scale(mat4 m, vec3 v) { + glm_scale_to(m, v, m); +} + +CGLM_INLINE +void +glm_scale1(mat4 m, float s) { + vec3 v = { s, s, s }; + glm_scale_to(m, v, m); +} + +CGLM_INLINE +void +glm_rotate_x(mat4 m, float rad, mat4 dest) { + float cosVal; + float sinVal; + mat4 t = GLM_MAT4_IDENTITY_INIT; + + cosVal = cosf(rad); + sinVal = sinf(rad); + + t[1][1] = cosVal; + t[1][2] = sinVal; + t[2][1] = -sinVal; + t[2][2] = cosVal; + + glm_mat4_mul(m, t, dest); +} + +CGLM_INLINE +void +glm_rotate_y(mat4 m, float rad, mat4 dest) { + float cosVal; + float sinVal; + mat4 t = GLM_MAT4_IDENTITY_INIT; + + cosVal = cosf(rad); + sinVal = sinf(rad); + + t[0][0] = cosVal; + t[0][2] = -sinVal; + t[2][0] = sinVal; + t[2][2] = cosVal; + + glm_mat4_mul(m, t, dest); +} + +CGLM_INLINE +void +glm_rotate_z(mat4 m, float rad, mat4 dest) { + float cosVal; + float sinVal; + mat4 t = GLM_MAT4_IDENTITY_INIT; + + cosVal = cosf(rad); + sinVal = sinf(rad); + + t[0][0] = cosVal; + t[0][1] = sinVal; + t[1][0] = -sinVal; + t[1][1] = cosVal; + + glm_mat4_mul(m, t, dest); +} + +CGLM_INLINE +void +glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) { + /* https://www.opengl.org/sdk/docs/man2/xhtml/glRotate.xml */ + + vec3 v, vs; + float c; + + c = cosf(angle); + + glm_vec_scale(axis_ndc, 1.0f - c, v); + glm_vec_scale(axis_ndc, sinf(angle), vs); + + glm_vec_scale(axis_ndc, v[0], m[0]); + glm_vec_scale(axis_ndc, v[1], m[1]); + glm_vec_scale(axis_ndc, v[2], m[2]); + + m[0][0] += c; + m[0][1] += vs[2]; + m[0][2] -= vs[1]; + + m[1][0] -= vs[2]; + m[1][1] += c; + m[1][2] += vs[0]; + + m[2][0] += vs[1]; + m[2][1] -= vs[0]; + m[2][2] += c; + + m[0][3] = m[1][3] = m[2][3] = m[3][0] = m[3][1] = m[3][2] = 0.0f; + m[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_rotate_make(mat4 m, float angle, vec3 axis) { + vec3 axis_ndc; + + glm_vec_normalize_to(axis, axis_ndc); + glm_rotate_ndc_make(m, angle, axis_ndc); +} + +CGLM_INLINE +void +glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) { + mat4 rot, tmp; + + glm_rotate_ndc_make(rot, angle, axis_ndc); + + glm_vec4_scale(m[0], rot[0][0], tmp[1]); + glm_vec4_scale(m[1], rot[0][1], tmp[0]); + glm_vec4_add(tmp[1], tmp[0], tmp[1]); + glm_vec4_scale(m[2], rot[0][2], tmp[0]); + glm_vec4_add(tmp[1], tmp[0], tmp[1]); + + glm_vec4_scale(m[0], rot[1][0], tmp[2]); + glm_vec4_scale(m[1], rot[1][1], tmp[0]); + glm_vec4_add(tmp[2], tmp[0], tmp[2]); + glm_vec4_scale(m[2], rot[1][2], tmp[0]); + glm_vec4_add(tmp[2], tmp[0], tmp[2]); + + glm_vec4_scale(m[0], rot[2][0], tmp[3]); + glm_vec4_scale(m[1], rot[2][1], tmp[0]); + glm_vec4_add(tmp[3], tmp[0], tmp[3]); + glm_vec4_scale(m[2], rot[2][2], tmp[0]); + glm_vec4_add(tmp[3], tmp[0], tmp[3]); + + glm_vec4_copy(tmp[1], m[0]); + glm_vec4_copy(tmp[2], m[1]); + glm_vec4_copy(tmp[3], m[2]); +} + +CGLM_INLINE +void +glm_rotate(mat4 m, float angle, vec3 axis) { + vec3 axis_ndc; + + glm_vec_normalize_to(axis, axis_ndc); + glm_rotate_ndc(m, angle, axis_ndc); +} + +/*! + * @brief decompose scale vector + * + * @param[in] m affine transform + * @param[out] s scale vector (Sx, Sy, Sz) + */ +CGLM_INLINE +void +glm_decompose_scalev(mat4 m, vec3 s) { + s[0] = glm_vec_norm(m[0]); + s[1] = glm_vec_norm(m[1]); + s[2] = glm_vec_norm(m[2]); +} + +/*! + * @brief returns true if matrix is uniform scaled. This is helpful for + * creating normal matrix. + * + * @param[in] m m + * + * @return boolean + */ +CGLM_INLINE +bool +glm_uniscaled(mat4 m) { + vec3 s; + glm_decompose_scalev(m, s); + + return glm_vec_eq_all(s); +} + +/*! + * @brief decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz] + * DON'T pass projected matrix here + * + * @param[in] m affine transform + * @param[out] r rotation matrix + * @param[out] s scale matrix + */ +CGLM_INLINE +void +glm_decompose_rs(mat4 m, mat4 r, vec3 s) { + vec4 t = {0.0f, 0.0f, 0.0f, 1.0f}; + vec3 v; + + glm_vec4_copy(m[0], r[0]); + glm_vec4_copy(m[1], r[1]); + glm_vec4_copy(m[2], r[2]); + glm_vec4_copy(t, r[3]); + + s[0] = glm_vec_norm(m[0]); + s[1] = glm_vec_norm(m[1]); + s[2] = glm_vec_norm(m[2]); + + glm_vec4_scale(r[0], 1.0f/s[0], r[0]); + glm_vec4_scale(r[1], 1.0f/s[1], r[1]); + glm_vec4_scale(r[2], 1.0f/s[2], r[2]); + + /* Note from Apple Open Source (asume that the matrix is orthonormal): + check for a coordinate system flip. If the determinant + is -1, then negate the matrix and the scaling factors. */ + glm_vec_cross(m[0], m[1], v); + if (glm_vec_dot(v, m[2]) < 0.0f) { + glm_vec4_flipsign(r[0]); + glm_vec4_flipsign(r[1]); + glm_vec4_flipsign(r[2]); + glm_vec_flipsign(s); + } +} + +/*! + * @brief decompose affine transform, TODO: extract shear factors. + * DON'T pass projected matrix here + * + * @param[in] m affine transfrom + * @param[out] t translation vector + * @param[out] r rotation matrix (mat4) + * @param[out] s scaling vector [X, Y, Z] + */ +CGLM_INLINE +void +glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { + glm_vec4_copy(m[3], t); + glm_decompose_rs(m, r, s); +} + +#endif /* cglm_affine_h */ diff --git a/include/cglm/cam.h b/include/cglm/cam.h new file mode 100644 index 0000000..a78ba4b --- /dev/null +++ b/include/cglm/cam.h @@ -0,0 +1,425 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_frustum(float left, + float right, + float bottom, + float top, + float nearVal, + float farVal, + mat4 dest); + CGLM_INLINE void glm_ortho(float left, + float right, + float bottom, + float top, + float nearVal, + float farVal, + mat4 dest); + CGLM_INLINE void glm_ortho_default(float aspect, mat4 dest); + CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest); + CGLM_INLINE void glm_perspective(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest); + CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj); + CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest); + CGLM_INLINE void glm_persp_decomp(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right); + CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6]); + CGLM_INLINE void glm_persp_decomp_x(mat4 proj, + float * __restrict left, + float * __restrict right); + CGLM_INLINE void glm_persp_decomp_y(mat4 proj, + float * __restrict top, + float * __restrict bottom); + CGLM_INLINE void glm_persp_decomp_z(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal); + CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float * __restrict farVal); + CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *__restrict nearVal); + */ + +#ifndef cglm_vcam_h +#define cglm_vcam_h + +#include "common.h" + +/*! + * @brief set up perspective peprojection matrix + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum(float left, + float right, + float bottom, + float top, + float nearVal, + float farVal, + mat4 dest) { + float rl, tb, fn, nv; + + glm__memzero(float, dest, sizeof(mat4)); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farVal - nearVal); + nv = 2.0f * nearVal; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] = (farVal + nearVal) * fn; + dest[2][3] =-1.0f; + dest[3][2] = farVal * nv * fn; +} + +/*! + * @brief set up orthographic projection matrix + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho(float left, + float right, + float bottom, + float top, + float nearVal, + float farVal, + mat4 dest) { + float rl, tb, fn; + + glm__memzero(float, dest, sizeof(mat4)); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farVal - nearVal); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] = 2.0f * fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = (farVal + nearVal) * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up unit orthographic projection matrix + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default(float aspect, + mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho(-1.0f * aspect, + 1.0f * aspect, + -1.0f, + 1.0f, + -100.0f, + 100.0f, + dest); + return; + } + + glm_ortho(-1.0f, + 1.0f, + -1.0f / aspect, + 1.0f / aspect, + -100.0f, + 100.0f, + dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s(float aspect, + float size, + mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +/*! + * @brief set up perspective projection matrix + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + float f, fn; + + glm__memzero(float, dest, sizeof(mat4)); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearVal - farVal); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] = (nearVal + farVal) * fn; + dest[2][3] =-1.0f; + dest[3][2] = 2.0f * nearVal * farVal * fn; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default(float aspect, + mat4 dest) { + glm_perspective((float)CGLM_PI_4, + aspect, + 0.01f, + 100.0f, + dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this very make easy to resize proj matrix when window, viewport + * reized + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize(float aspect, + mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief set up view matrix + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat(vec3 eye, + vec3 center, + vec3 up, + mat4 dest) { + vec3 f, u, s; + + glm_vec_sub(center, eye, f); + glm_vec_normalize(f); + + glm_vec_cross(f, up, s); + glm_vec_normalize(s); + + glm_vec_cross(s, f, u); + + dest[0][0] = s[0]; + dest[0][1] = u[0]; + dest[0][2] =-f[0]; + dest[1][0] = s[1]; + dest[1][1] = u[1]; + dest[1][2] =-f[1]; + dest[2][0] = s[2]; + dest[2][1] = u[2]; + dest[2][2] =-f[2]; + dest[3][0] =-glm_vec_dot(s, eye); + dest[3][1] =-glm_vec_dot(u, eye); + dest[3][2] = glm_vec_dot(f, eye); + dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; + dest[3][3] = 1.0f; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearVal near + * @param[out] farVal far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) { + *nearVal = proj[3][2] / (proj[2][2] - 1); + *farVal = proj[3][2] / (proj[2][2] + 1); + *bottom = *nearVal * (proj[2][1] - 1) / proj[1][1]; + *top = *nearVal * (proj[2][1] + 1) / proj[1][1]; + *left = *nearVal * (proj[2][0] - 1) / proj[0][0]; + *right = *nearVal * (proj[2][0] + 1) / proj[0][0]; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv(mat4 proj, float dest[6]) { + glm_persp_decomp(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_x(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearVal; + + nearVal = proj[3][2] / (proj[3][3] - 1); + *left = nearVal * (proj[2][0] - 1) / proj[0][0]; + *right = nearVal * (proj[2][0] + 1) / proj[0][0]; +} + +/*! + * @brief decomposes top and bottom values of perspective projection. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearVal; + + nearVal = proj[3][2] / (proj[3][3] - 1); + *bottom = nearVal * (proj[2][1] - 1) / proj[1][1]; + *top = nearVal * (proj[2][1] + 1) / proj[1][1]; +} + +/*! + * @brief decomposes near and far values of perspective projection. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearVal near + * @param[out] farVal far + */ +CGLM_INLINE +void +glm_persp_decomp_z(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal) { + *nearVal = proj[3][2] / (proj[2][2] - 1); + *farVal = proj[3][2] / (proj[2][2] + 1); +} + +/*! + * @brief decomposes far value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] farVal far + */ +CGLM_INLINE +void +glm_persp_decomp_far(mat4 proj, float * __restrict farVal) { + *farVal = proj[3][2] / (proj[2][2] + 1); +} + +/*! + * @brief decomposes near value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearVal near + */ +CGLM_INLINE +void +glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) { + *nearVal = proj[3][2] / (proj[2][2] - 1); +} +#endif /* cglm_vcam_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h new file mode 100644 index 0000000..1dabb70 --- /dev/null +++ b/include/cglm/cglm.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_h +#define cglm_h + +#include "common.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" +#include "mat3.h" +#include "affine.h" +#include "cam.h" +#include "quat.h" +#include "euler.h" +#include "util.h" +#include "io.h" + +#endif /* cglm_h */ diff --git a/include/cglm/common.h b/include/cglm/common.h new file mode 100644 index 0000000..f68908b --- /dev/null +++ b/include/cglm/common.h @@ -0,0 +1,59 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_common_h +#define cglm_common_h + +#define _USE_MATH_DEFINES /* for windows */ + +#include +#include + +#if defined(_WIN32) +# ifdef CGLM_DLL +# define CGLM_EXPORT __declspec(dllexport) +# else +# define CGLM_EXPORT __declspec(dllimport) +# endif +# define CGLM_INLINE __forceinline +#else +# define CGLM_EXPORT __attribute__((visibility("default"))) +# define CGLM_INLINE static inline __attribute((always_inline)) +#endif + +#define glm__memcpy(type, dest, src, size) \ + do { \ + type *srci; \ + type *srci_end; \ + type *desti; \ + \ + srci = (type *)src; \ + srci_end = (type *)((char *)srci + size); \ + desti = (type *)dest; \ + \ + while (srci != srci_end) \ + *desti++ = *srci++; \ + } while (0) + +#define glm__memset(type, dest, size, val) \ + do { \ + type *desti; \ + type *desti_end; \ + \ + desti = (type *)dest; \ + desti_end = (type *)((char *)desti + size); \ + \ + while (desti != desti_end) \ + *desti++ = val; \ + } while (0) + +#define glm__memzero(type, dest, size) glm__memset(type, dest, size, 0) + +#include "types.h" +#include "simd/intrin.h" + +#endif /* cglm_common_h */ diff --git a/include/cglm/euler.h b/include/cglm/euler.h new file mode 100644 index 0000000..bf62bb7 --- /dev/null +++ b/include/cglm/euler.h @@ -0,0 +1,378 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Types: + enum glm_euler_sq + + Functions: + CGLM_INLINE glm_euler_sq glm_euler_order(int newOrder[3]); + CGLM_INLINE void glm_euler_angles(mat4 m, vec3 dest); + CGLM_INLINE void glm_euler(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_zyx(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_zxy(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_xzy(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_yzx(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_yxz(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_by_order(vec3 angles, + glm_euler_sq axis, + mat4 dest); + */ + +#ifndef cglm_euler_h +#define cglm_euler_h + +#include "common.h" + +/*! + * if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]... + * vector then you can convert it to this enum by doing this: + * @code + * glm_euler_sq order; + * order = orderVec[0] | orderVec[1] << 2 | orderVec[2] << 4; + * @endcode + * you may need to explicit cast if required + */ +typedef enum glm_euler_sq { + GLM_EULER_XYZ = 0 << 0 | 1 << 2 | 2 << 4, + GLM_EULER_XZY = 0 << 0 | 2 << 2 | 1 << 4, + GLM_EULER_YZX = 1 << 0 | 2 << 2 | 0 << 4, + GLM_EULER_YXZ = 1 << 0 | 0 << 2 | 2 << 4, + GLM_EULER_ZXY = 2 << 0 | 0 << 2 | 1 << 4, + GLM_EULER_ZYX = 2 << 0 | 1 << 2 | 0 << 4 +} glm_euler_sq; + +CGLM_INLINE +glm_euler_sq +glm_euler_order(int newOrder[3]) { + return (glm_euler_sq)(newOrder[0] | newOrder[1] << 2 | newOrder[2] << 4); +} + +/*! + * @brief euler angles (in radian) using xyz sequence + * + * @param[in] m affine transform + * @param[out] dest angles vector [x, y, z] + */ +CGLM_INLINE +void +glm_euler_angles(mat4 m, vec3 dest) { + if (m[0][2] < 1.0f) { + if (m[0][2] > -1.0f) { + vec3 a[2]; + float cy1, cy2; + int path; + + a[0][1] = asinf(-m[0][2]); + a[1][1] = CGLM_PI - a[0][1]; + + cy1 = cosf(a[0][1]); + cy2 = cosf(a[1][1]); + + a[0][0] = atan2f(m[1][2] / cy1, m[2][2] / cy1); + a[1][0] = atan2f(m[1][2] / cy2, m[2][2] / cy2); + + a[0][2] = atan2f(m[0][1] / cy1, m[0][0] / cy1); + a[1][2] = atan2f(m[0][1] / cy2, m[0][0] / cy2); + + path = (fabsf(a[0][0]) + fabsf(a[0][1]) + fabsf(a[0][2])) >= + (fabsf(a[1][0]) + fabsf(a[1][1]) + fabsf(a[1][2])); + + glm_vec_copy(a[path], dest); + } else { + dest[0] = atan2f(m[1][0], m[2][0]); + dest[1] = CGLM_PI_2; + dest[2] = 0.0f; + } + } else { + dest[0] = atan2f(-m[1][0], -m[2][0]); + dest[1] =-CGLM_PI_2; + dest[2] = 0.0f; + } +} + +/*! + * @brief build rotation matrix from euler angles(ExEyEz/RzRyRx) + * + * @param[in] angles angles as vector [Ex, Ey, Ez] + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler(vec3 angles, mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + dest[0][0] = cy * cz; + dest[0][1] = cy * sz; + dest[0][2] =-sy; + dest[1][0] = cz * sx * sy - cx * sz; + dest[1][1] = cx * cz + sx * sy * sz; + dest[1][2] = cy * sx; + dest[2][0] = cx * cz * sy + sx * sz; + dest[2][1] =-cz * sx + cx * sy * sz; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +/*! + * @brief build rotation matrix from euler angles (EzEyEx/RxRyRz) + */ +CGLM_INLINE +void +glm_euler_zyx(vec3 angles, + mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + dest[0][0] = cy * cz; + dest[0][1] = cz * sx * sy + cx * sz; + dest[0][2] =-cx * cz * sy + sx * sz; + dest[1][0] =-cy * sz; + dest[1][1] = cx * cz - sx * sy * sz; + dest[1][2] = cz * sx + cx * sy * sz; + dest[2][0] = sy; + dest[2][1] =-cy * sx; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_euler_zxy(vec3 angles, + mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + dest[0][0] = cy * cz + sx * sy * sz; + dest[0][1] = cx * sz; + dest[0][2] =-cz * sy + cy * sx * sz; + dest[1][0] = cz * sx * sy - cy * sz; + dest[1][1] = cx * cz; + dest[1][2] = cy * cz * sx + sy * sz; + dest[2][0] = cx * sy; + dest[2][1] =-sx; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_euler_xzy(vec3 angles, + mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + dest[0][0] = cy * cz; + dest[0][1] = sz; + dest[0][2] =-cz * sy; + dest[1][0] = sx * sy - cx * cy * sz; + dest[1][1] = cx * cz; + dest[1][2] = cy * sx + cx * sy * sz; + dest[2][0] = cx * sy + cy * sx * sz; + dest[2][1] =-cz * sx; + dest[2][2] = cx * cy - sx * sy * sz; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_euler_yzx(vec3 angles, + mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + dest[0][0] = cy * cz; + dest[0][1] = sx * sy + cx * cy * sz; + dest[0][2] =-cx * sy + cy * sx * sz; + dest[1][0] =-sz; + dest[1][1] = cx * cz; + dest[1][2] = cz * sx; + dest[2][0] = cz * sy; + dest[2][1] =-cy * sx + cx * sy * sz; + dest[2][2] = cx * cy + sx * sy * sz; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_euler_yxz(vec3 angles, + mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + dest[0][0] = cy * cz - sx * sy * sz; + dest[0][1] = cz * sx * sy + cy * sz; + dest[0][2] =-cx * sy; + dest[1][0] =-cx * sz; + dest[1][1] = cx * cz; + dest[1][2] = sx; + dest[2][0] = cz * sy + cy * sx * sz; + dest[2][1] =-cy * cz * sx + sy * sz; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + float cycz, cysz, cysx, cxcy, + czsy, cxcz, czsx, cxsz, + sysz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + cycz = cy * cz; cysz = cy * sz; + cysx = cy * sx; cxcy = cx * cy; + czsy = cz * sy; cxcz = cx * cz; + czsx = cz * sx; cxsz = cx * sz; + sysz = sy * sz; + + switch (axis) { + case GLM_EULER_XYZ: + dest[0][0] = cycz; + dest[0][1] = cysz; + dest[0][2] =-sy; + dest[1][0] = czsx * sy - cxsz; + dest[1][1] = cxcz + sx * sysz; + dest[1][2] = cysx; + dest[2][0] = cx * czsy + sx * sz; + dest[2][1] =-czsx + cx * sysz; + dest[2][2] = cxcy; + break; + case GLM_EULER_XZY: + dest[0][0] = cycz; + dest[0][1] = sz; + dest[0][2] =-czsy; + dest[1][0] = sx * sy - cx * cysz; + dest[1][1] = cxcz; + dest[1][2] = cysx + cx * sysz; + dest[2][0] = cx * sy + cysx * sz; + dest[2][1] =-czsx; + dest[2][2] = cxcy - sx * sysz; + break; + case GLM_EULER_ZXY: + dest[0][0] = cycz + sx * sysz; + dest[0][1] = cxsz; + dest[0][2] =-czsy + cysx * sz; + dest[1][0] = czsx * sy - cysz; + dest[1][1] = cxcz; + dest[1][2] = cycz * sx + sysz; + dest[2][0] = cx * sy; + dest[2][1] =-sx; + dest[2][2] = cxcy; + break; + case GLM_EULER_ZYX: + dest[0][0] = cycz; + dest[0][1] = czsx * sy + cxsz; + dest[0][2] =-cx * czsy + sx * sz; + dest[1][0] =-cysz; + dest[1][1] = cxcz - sx * sysz; + dest[1][2] = czsx + cx * sysz; + dest[2][0] = sy; + dest[2][1] =-cysx; + dest[2][2] = cxcy; + break; + case GLM_EULER_YXZ: + dest[0][0] = cycz - sx * sysz; + dest[0][1] = czsx * sy + cysz; + dest[0][2] =-cx * sy; + dest[1][0] =-cxsz; + dest[1][1] = cxcz; + dest[1][2] = sx; + dest[2][0] = czsy + cysx * sz; + dest[2][1] =-cycz * sx + sysz; + dest[2][2] = cxcy; + break; + case GLM_EULER_YZX: + dest[0][0] = cycz; + dest[0][1] = sx * sy + cx * cysz; + dest[0][2] =-cx * sy + cysx * sz; + dest[1][0] =-sz; + dest[1][1] = cxcz; + dest[1][2] = czsx; + dest[2][0] = czsy; + dest[2][1] =-cysx + cx * sysz; + dest[2][2] = cxcy + sx * sysz; + break; + } + + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +#endif /* cglm_euler_h */ diff --git a/include/cglm/io.h b/include/cglm/io.h new file mode 100644 index 0000000..2ee8ee8 --- /dev/null +++ b/include/cglm/io.h @@ -0,0 +1,174 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_mat4_print(mat4 matrix, FILE *ostream); + CGLM_INLINE void glm_mat3_print(mat3 matrix, FILE *ostream); + CGLM_INLINE void glm_vec4_print(vec4 vec, FILE *ostream); + CGLM_INLINE void glm_vec3_print(vec3 vec, FILE *ostream); + CGLM_INLINE void glm_ivec3_print(ivec3 vec, FILE *ostream); + CGLM_INLINE void glm_versor_print(versor vec, FILE *ostream); + */ + +#ifndef cglm_io_h +#define cglm_io_h + +#include "common.h" + +#include +#include + +CGLM_INLINE +void +glm_mat4_print(mat4 matrix, + FILE * __restrict ostream) { + int i; + int j; + +#define m 4 +#define n 4 + + fprintf(ostream, "Matrix (float%dx%d):\n", m, n); + + for (i = 0; i < m; i++) { + fprintf(ostream, "\t|"); + for (j = 0; j < n; j++) { + fprintf(ostream, "%0.4f", matrix[j][i]);; + + if (j != n - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n"); + } + + fprintf(ostream, "\n"); + +#undef m +#undef n +} + +CGLM_INLINE +void +glm_mat3_print(mat3 matrix, + FILE * __restrict ostream) { + int i; + int j; + +#define m 3 +#define n 3 + + fprintf(ostream, "Matrix (float%dx%d):\n", m, n); + + for (i = 0; i < m; i++) { + fprintf(ostream, "\t|"); + for (j = 0; j < n; j++) { + fprintf(ostream, "%0.4f", matrix[j][i]);; + + if (j != n - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n"); + } + + fprintf(ostream, "\n"); + +#undef m +#undef n +} + +CGLM_INLINE +void +glm_vec4_print(vec4 vec, + FILE * __restrict ostream) { + int i; + +#define m 4 + + fprintf(ostream, "Vector (float%d):\n\t|", m); + + for (i = 0; i < m; i++) { + fprintf(ostream, "%0.4f", vec[i]); + + if (i != m - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_vec3_print(vec3 vec, + FILE * __restrict ostream) { + int i; + +#define m 3 + + fprintf(ostream, "Vector (float%d):\n\t|", m); + + for (i = 0; i < m; i++) { + fprintf(ostream, "%0.4f", vec[i]); + + if (i != m - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_ivec3_print(ivec3 vec, + FILE * __restrict ostream) { + int i; + +#define m 3 + + fprintf(ostream, "Vector (int%d):\n\t|", m); + + for (i = 0; i < m; i++) { + fprintf(ostream, "%d", vec[i]); + + if (i != m - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_versor_print(versor vec, + FILE * __restrict ostream) { + int i; + +#define m 4 + + fprintf(ostream, "Versor (float%d):\n\t|", m); + + for (i = 0; i < m; i++) { + fprintf(ostream, "%0.4f", vec[i]); + + if (i != m - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n\n"); + +#undef m +} + +#endif /* cglm_io_h */ diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h new file mode 100644 index 0000000..9b454ce --- /dev/null +++ b/include/cglm/mat3.h @@ -0,0 +1,291 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_MAT3_IDENTITY_INIT + GLM_MAT3_ZERO_INIT + GLM_MAT3_IDENTITY + GLM_MAT3_ZERO + glm_mat3_dup(mat, dest) + + Functions: + CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest); + CGLM_INLINE void glm_mat3_identity(mat3 mat); + CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest); + CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); + CGLM_INLINE void glm_mat3_transpose(mat3 m); + CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_mat3_scale(mat3 m, float s); + CGLM_INLINE float glm_mat3_det(mat3 mat); + CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest); + CGLM_INLINE void glm_mat3_swap_col(mat3 mat, int col1, int col2); + CGLM_INLINE void glm_mat3_swap_row(mat3 mat, int row1, int row2); + */ + +#ifndef cglm_mat3_h +#define cglm_mat3_h + +#include "common.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/mat3.h" +#endif + +#define GLM_MAT3_IDENTITY_INIT {{1.0f, 0.0f, 0.0f}, \ + {0.0f, 1.0f, 0.0f}, \ + {0.0f, 0.0f, 1.0f}} +#define GLM_MAT3_ZERO_INIT {{0.0f, 0.0f, 0.0f}, \ + {0.0f, 0.0f, 0.0f}, \ + {0.0f, 0.0f, 0.0f}} + + +/* for C only */ +#define GLM_MAT3_IDENTITY (mat3)GLM_MAT3_IDENTITY_INIT +#define GLM_MAT3_ZERO (mat3)GLM_MAT3_ZERO_INIT + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glm_mat3_dup(mat, dest) glm_mat3_copy(mat, dest) + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat3_copy(mat3 mat, mat3 dest) { + glm__memcpy(float, dest, mat, sizeof(mat3)); +} + +/*! + * @brief make given matrix identity. It is identical with below, + * but it is more easy to do that with this func especially for members + * e.g. glm_mat3_identity(aStruct->aMatrix); + * + * @code + * glm_mat3_copy(GLM_MAT3_IDENTITY, mat); // C only + * + * // or + * mat3 mat = GLM_MAT3_IDENTITY_INIT; + * @endcode + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat3_identity(mat3 mat) { + mat3 t = GLM_MAT3_IDENTITY_INIT; + glm_mat3_copy(t, mat); +} + +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * mat3 m = GLM_MAT3_IDENTITY_INIT; + * glm_mat3_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat3_mul_sse2(m1, m2, dest); +#else + float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], + a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], + a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2], + + b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2], + b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2], + b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2]; + + dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02; + dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02; + dest[0][2] = a02 * b00 + a12 * b01 + a22 * b02; + dest[1][0] = a00 * b10 + a10 * b11 + a20 * b12; + dest[1][1] = a01 * b10 + a11 * b11 + a21 * b12; + dest[1][2] = a02 * b10 + a12 * b11 + a22 * b12; + dest[2][0] = a00 * b20 + a10 * b21 + a20 * b22; + dest[2][1] = a01 * b20 + a11 * b21 + a21 * b22; + dest[2][2] = a02 * b20 + a12 * b21 + a22 * b22; +#endif +} + +/*! + * @brief transpose mat3 and store in dest + * + * source matrix will not be transposed unless dest is m + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +void +glm_mat3_transpose_to(mat3 m, mat3 dest) { + dest[0][0] = m[0][0]; + dest[0][1] = m[1][0]; + dest[0][2] = m[2][0]; + dest[1][0] = m[0][1]; + dest[1][1] = m[1][1]; + dest[1][2] = m[2][1]; + dest[2][0] = m[0][2]; + dest[2][1] = m[1][2]; + dest[2][2] = m[2][2]; +} + +/*! + * @brief tranpose mat3 and store result in same matrix + * + * @param[in, out] m source and dest + */ +CGLM_INLINE +void +glm_mat3_transpose(mat3 m) { + mat3 tmp; + + tmp[0][1] = m[1][0]; + tmp[0][2] = m[2][0]; + tmp[1][0] = m[0][1]; + tmp[1][2] = m[2][1]; + tmp[2][0] = m[0][2]; + tmp[2][1] = m[1][2]; + + m[0][1] = tmp[0][1]; + m[0][2] = tmp[0][2]; + m[1][0] = tmp[1][0]; + m[1][2] = tmp[1][2]; + m[2][0] = tmp[2][0]; + m[2][1] = tmp[2][1]; +} + +/*! + * @brief multiply mat3 with vec3 (column vector) and store in dest vector + * + * @param[in] m mat3 (left) + * @param[in] v vec3 (right, column vector) + * @param[out] dest vec3 (result, column vector) + */ +CGLM_INLINE +void +glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { + dest[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2]; + dest[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2]; + dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat3_scale(mat3 m, float s) { + m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; + m[1][0] *= s; m[1][1] *= s; m[1][2] *= s; + m[2][0] *= s; m[2][1] *= s; m[2][2] *= s; +} + +/*! + * @brief mat3 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glm_mat3_det(mat3 mat) { + float a = mat[0][0], b = mat[0][1], c = mat[0][2], + d = mat[1][0], e = mat[1][1], f = mat[1][2], + g = mat[2][0], h = mat[2][1], i = mat[2][2]; + + return a * (e * i - h * f) - d * (b * i - c * h) + g * (b * f - c * e); +} + +/*! + * @brief inverse mat3 and store in dest + * + * @param[in] mat matrix + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +glm_mat3_inv(mat3 mat, mat3 dest) { + float det; + float a = mat[0][0], b = mat[0][1], c = mat[0][2], + d = mat[1][0], e = mat[1][1], f = mat[1][2], + g = mat[2][0], h = mat[2][1], i = mat[2][2]; + + dest[0][0] = e * i - f * h; + dest[0][1] = -(b * i - h * c); + dest[0][2] = b * f - e * c; + dest[1][0] = -(d * i - g * f); + dest[1][1] = a * i - c * g; + dest[1][2] = -(a * f - d * c); + dest[2][0] = d * h - g * e; + dest[2][1] = -(a * h - g * b); + dest[2][2] = a * e - b * d; + + det = 1.0f / (a * dest[0][0] + b * dest[1][0] + c * dest[2][0]); + + glm_mat3_scale(dest, det); +} + +/*! + * @brief swap two matrix columns + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat3_swap_col(mat3 mat, int col1, int col2) { + vec3 tmp; + glm_vec_copy(mat[col1], tmp); + glm_vec_copy(mat[col2], mat[col1]); + glm_vec_copy(tmp, mat[col2]); +} + +/*! + * @brief swap two matrix rows + * + * @param[in,out] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + */ +CGLM_INLINE +void +glm_mat3_swap_row(mat3 mat, int row1, int row2) { + vec3 tmp; + tmp[0] = mat[0][row1]; + tmp[1] = mat[1][row1]; + tmp[2] = mat[2][row1]; + + mat[0][row1] = mat[0][row2]; + mat[1][row1] = mat[1][row2]; + mat[2][row1] = mat[2][row2]; + + mat[0][row2] = tmp[0]; + mat[1][row2] = tmp[1]; + mat[2][row2] = tmp[2]; +} + +#endif /* cglm_mat3_h */ diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h new file mode 100644 index 0000000..4da3fc7 --- /dev/null +++ b/include/cglm/mat4.h @@ -0,0 +1,572 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * Most of functions in this header are optimized manually with SIMD + * if available. You dont need to call/incude SIMD headers manually + */ + +/* + Macros: + GLM_MAT4_IDENTITY_INIT + GLM_MAT4_ZERO_INIT + GLM_MAT4_IDENTITY + GLM_MAT4_ZERO + glm_mat4_udup(mat, dest) + glm_mat4_dup(mat, dest) + + Functions: + CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest); + CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest); + CGLM_INLINE void glm_mat4_identity(mat4 mat); + CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest); + CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest); + CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest); + CGLM_INLINE void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); + CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest); + CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); + CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest); + CGLM_INLINE void glm_mat4_transpose(mat4 m); + CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s); + CGLM_INLINE void glm_mat4_scale(mat4 m, float s); + CGLM_INLINE float glm_mat4_det(mat4 mat); + CGLM_INLINE void glm_mat4_inv(mat4 mat, mat4 dest); + CGLM_INLINE void glm_mat4_inv_fast(mat4 mat, mat4 dest); + CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2); + CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2); + */ + +#ifndef cglm_mat_h +#define cglm_mat_h + +#include "common.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/mat4.h" +#endif + +#ifdef CGLM_AVX_FP +# include "simd/avx/mat4.h" +#endif + +#ifdef CGLM_NEON_FP +# include "simd/neon/mat4.h" +#endif + +#include + +#define GLM_MAT4_IDENTITY_INIT {{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}} + +#define GLM_MAT4_ZERO_INIT {{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}} + +/* for C only */ +#define GLM_MAT4_IDENTITY (mat4)GLM_MAT4_IDENTITY_INIT +#define GLM_MAT4_ZERO (mat4)GLM_MAT4_ZERO_INIT + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glm_mat4_udup(mat, dest) glm_mat4_ucopy(mat, dest) +#define glm_mat4_dup(mat, dest) glm_mat4_copy(mat, dest) + +/* DEPRECATED! default is precise now. */ +#define glm_mat4_inv_precise(mat, dest) glm_mat4_inv(mat, dest) + +/*! + * @brief copy all members of [mat] to [dest] + * + * matrix may not be aligned, u stands for unaligned, this may be useful when + * copying a matrix from external source e.g. asset importer... + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4_ucopy(mat4 mat, mat4 dest) { + glm__memcpy(float, dest, mat, sizeof(mat4)); +} + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4_copy(mat4 mat, mat4 dest) { +#ifdef __AVX__ + _mm256_store_ps(dest[0], _mm256_load_ps(mat[0])); + _mm256_store_ps(dest[2], _mm256_load_ps(mat[2])); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest[0], _mm_load_ps(mat[0])); + _mm_store_ps(dest[1], _mm_load_ps(mat[1])); + _mm_store_ps(dest[2], _mm_load_ps(mat[2])); + _mm_store_ps(dest[3], _mm_load_ps(mat[3])); +#else + glm_mat4_ucopy(mat, dest); +#endif +} + +/*! + * @brief make given matrix identity. It is identical with below, + * but it is more easy to do that with this func especially for members + * e.g. glm_mat4_identity(aStruct->aMatrix); + * + * @code + * glm_mat4_copy(GLM_MAT4_IDENTITY, mat); // C only + * + * // or + * mat4 mat = GLM_MAT4_IDENTITY_INIT; + * @endcode + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat4_identity(mat4 mat) { + mat4 t = GLM_MAT4_IDENTITY_INIT; + glm_mat4_copy(t, mat); +} + +/*! + * @brief copy upper-left of mat4 to mat3 + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4_pick3(mat4 mat, mat3 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + dest[0][2] = mat[0][2]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + dest[1][2] = mat[1][2]; + + dest[2][0] = mat[2][0]; + dest[2][1] = mat[2][1]; + dest[2][2] = mat[2][2]; +} + +/*! + * @brief copy upper-left of mat4 to mat3 (transposed) + * + * the postfix t stands for transpose + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4_pick3t(mat4 mat, mat3 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[1][0]; + dest[0][2] = mat[2][0]; + + dest[1][0] = mat[0][1]; + dest[1][1] = mat[1][1]; + dest[1][2] = mat[2][1]; + + dest[2][0] = mat[0][2]; + dest[2][1] = mat[1][2]; + dest[2][2] = mat[2][2]; +} + +/*! + * @brief copy mat3 to mat4's upper-left + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4_ins3(mat3 mat, mat4 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + dest[0][2] = mat[0][2]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + dest[1][2] = mat[1][2]; + + dest[2][0] = mat[2][0]; + dest[2][1] = mat[2][1]; + dest[2][2] = mat[2][2]; +} + +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * mat4 m = GLM_MAT4_IDENTITY_INIT; + * glm_mat4_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { +#ifdef __AVX__ + glm_mat4_mul_avx(m1, m2, dest); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_mul_sse2(m1, m2, dest); +#elif defined( __ARM_NEON_FP ) + glm_mat4_mul_neon(m1, m2, dest); +#else + float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], a03 = m1[0][3], + a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], a13 = m1[1][3], + a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2], a23 = m1[2][3], + a30 = m1[3][0], a31 = m1[3][1], a32 = m1[3][2], a33 = m1[3][3], + + b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2], b03 = m2[0][3], + b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2], b13 = m2[1][3], + b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2], b23 = m2[2][3], + b30 = m2[3][0], b31 = m2[3][1], b32 = m2[3][2], b33 = m2[3][3]; + + dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; + dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; + dest[0][2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; + dest[0][3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; + dest[1][0] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; + dest[1][1] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; + dest[1][2] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; + dest[1][3] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; + dest[2][0] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; + dest[2][1] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; + dest[2][2] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; + dest[2][3] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; + dest[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; + dest[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; + dest[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; + dest[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; +#endif +} + +/*! + * @brief mupliply N mat4 matrices and store result in dest + * + * this function lets you multiply multiple (more than two or more...) matrices + *

multiplication will be done in loop, this may reduce instructions + * size but if len is too small then compiler may unroll whole loop, + * usage: + * @code + * mat m1, m2, m3, m4, res; + * + * glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res); + * @endcode + * + * @warning matrices parameter is pointer array not mat4 array! + * + * @param[in] matrices mat4 * array + * @param[in] len matrices count + * @param[out] dest result + */ +CGLM_INLINE +void +glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest) { + int i; + + assert(len > 1 && "there must be least 2 matrices to go!"); + + glm_mat4_mul(*matrices[0], + *matrices[1], + dest); + + for (i = 2; i < len; i++) + glm_mat4_mul(dest, + *matrices[i], + dest); +} + +/*! + * @brief multiply mat4 with vec4 (column vector) and store in dest vector + * + * @param[in] m mat4 (left) + * @param[in] v vec4 (right, column vector) + * @param[out] dest vec4 (result, column vector) + */ +CGLM_INLINE +void +glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_mulv_sse2(m, v, dest); +#else + vec4 res; + res[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0] * v[3]; + res[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1] * v[3]; + res[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2] * v[3]; + res[3] = m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3] * v[3]; + glm_vec4_copy(res, dest); +#endif +} + +/*! + * @brief multiply vector with mat4's mat3 part(rotation) + * + * @param[in] m mat4(affine transform) + * @param[in] v vec3 + * @param[out] dest vec3 + */ +CGLM_INLINE +void +glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest) { + vec3 res; + res[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2]; + res[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2]; + res[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; + glm_vec_copy(res, dest); +} + +/*! + * @brief transpose mat4 and store in dest + * + * source matrix will not be transposed unless dest is m + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +void +glm_mat4_transpose_to(mat4 m, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_transp_sse2(m, dest); +#else + dest[0][0] = m[0][0]; dest[1][0] = m[0][1]; + dest[0][1] = m[1][0]; dest[1][1] = m[1][1]; + dest[0][2] = m[2][0]; dest[1][2] = m[2][1]; + dest[0][3] = m[3][0]; dest[1][3] = m[3][1]; + dest[2][0] = m[0][2]; dest[3][0] = m[0][3]; + dest[2][1] = m[1][2]; dest[3][1] = m[1][3]; + dest[2][2] = m[2][2]; dest[3][2] = m[2][3]; + dest[2][3] = m[3][2]; dest[3][3] = m[3][3]; +#endif +} + +/*! + * @brief tranpose mat4 and store result in same matrix + * + * @param[in, out] m source and dest + */ +CGLM_INLINE +void +glm_mat4_transpose(mat4 m) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_transp_sse2(m, m); +#else + mat4 d; + + glm_mat4_transpose_to(m, d); + + glm__memcpy(float, m, d, sizeof(mat4)); +#endif +} + +/*! + * @brief scale (multiply with scalar) matrix without simd optimization + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat4_scale_p(mat4 m, float s) { + m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; m[0][3] *= s; + m[1][0] *= s; m[1][1] *= s; m[1][2] *= s; m[1][3] *= s; + m[2][0] *= s; m[2][1] *= s; m[2][2] *= s; m[2][3] *= s; + m[3][0] *= s; m[3][1] *= s; m[3][2] *= s; m[3][3] *= s; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat4_scale(mat4 m, float s) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_scale_sse2(m, s); +#else + glm_mat4_scale_p(m, s); +#endif +} + +/*! + * @brief mat4 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glm_mat4_det(mat4 mat) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + return glm_mat4_det_sse2(mat); +#else + /* [square] det(A) = det(At) */ + float t[6]; + float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[0][3], + e = mat[1][0], f = mat[1][1], g = mat[1][2], h = mat[1][3], + i = mat[2][0], j = mat[2][1], k = mat[2][2], l = mat[2][3], + m = mat[3][0], n = mat[3][1], o = mat[3][2], p = mat[3][3]; + + t[0] = k * p - o * l; + t[1] = j * p - n * l; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + t[5] = i * n - m * j; + + return a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]); +#endif +} + +/*! + * @brief inverse mat4 and store in dest + * + * @param[in] mat matrix + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +glm_mat4_inv(mat4 mat, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_inv_sse2(mat, dest); +#else + float t[6]; + float det; + float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[0][3], + e = mat[1][0], f = mat[1][1], g = mat[1][2], h = mat[1][3], + i = mat[2][0], j = mat[2][1], k = mat[2][2], l = mat[2][3], + m = mat[3][0], n = mat[3][1], o = mat[3][2], p = mat[3][3]; + + t[0] = k * p - o * l; t[1] = j * p - n * l; t[2] = j * o - n * k; + t[3] = i * p - m * l; t[4] = i * o - m * k; t[5] = i * n - m * j; + + dest[0][0] = f * t[0] - g * t[1] + h * t[2]; + dest[1][0] =-(e * t[0] - g * t[3] + h * t[4]); + dest[2][0] = e * t[1] - f * t[3] + h * t[5]; + dest[3][0] =-(e * t[2] - f * t[4] + g * t[5]); + + dest[0][1] =-(b * t[0] - c * t[1] + d * t[2]); + dest[1][1] = a * t[0] - c * t[3] + d * t[4]; + dest[2][1] =-(a * t[1] - b * t[3] + d * t[5]); + dest[3][1] = a * t[2] - b * t[4] + c * t[5]; + + t[0] = g * p - o * h; t[1] = f * p - n * h; t[2] = f * o - n * g; + t[3] = e * p - m * h; t[4] = e * o - m * g; t[5] = e * n - m * f; + + dest[0][2] = b * t[0] - c * t[1] + d * t[2]; + dest[1][2] =-(a * t[0] - c * t[3] + d * t[4]); + dest[2][2] = a * t[1] - b * t[3] + d * t[5]; + dest[3][2] =-(a * t[2] - b * t[4] + c * t[5]); + + t[0] = g * l - k * h; t[1] = f * l - j * h; t[2] = f * k - j * g; + t[3] = e * l - i * h; t[4] = e * k - i * g; t[5] = e * j - i * f; + + dest[0][3] =-(b * t[0] - c * t[1] + d * t[2]); + dest[1][3] = a * t[0] - c * t[3] + d * t[4]; + dest[2][3] =-(a * t[1] - b * t[3] + d * t[5]); + dest[3][3] = a * t[2] - b * t[4] + c * t[5]; + + det = 1.0f / (a * dest[0][0] + b * dest[1][0] + + c * dest[2][0] + d * dest[3][0]); + + glm_mat4_scale_p(dest, det); +#endif +} + +/*! + * @brief inverse mat4 and store in dest + * + * this func uses reciprocal approximation without extra corrections + * e.g Newton-Raphson. this should work faster than normal, + * to get more precise use glm_mat4_inv version. + * + * NOTE: You will lose precision, glm_mat4_inv is more accurate + * + * @param[in] mat matrix + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +glm_mat4_inv_fast(mat4 mat, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_inv_fast_sse2(mat, dest); +#else + glm_mat4_inv(mat, dest); +#endif +} + +/*! + * @brief swap two matrix columns + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat4_swap_col(mat4 mat, int col1, int col2) { + vec4 tmp; + glm_vec4_copy(mat[col1], tmp); + glm_vec4_copy(mat[col2], mat[col1]); + glm_vec4_copy(tmp, mat[col2]); +} + +/*! + * @brief swap two matrix rows + * + * @param[in,out] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + */ +CGLM_INLINE +void +glm_mat4_swap_row(mat4 mat, int row1, int row2) { + vec4 tmp; + tmp[0] = mat[0][row1]; + tmp[1] = mat[1][row1]; + tmp[2] = mat[2][row1]; + tmp[3] = mat[3][row1]; + + mat[0][row1] = mat[0][row2]; + mat[1][row1] = mat[1][row2]; + mat[2][row1] = mat[2][row2]; + mat[3][row1] = mat[3][row2]; + + mat[0][row2] = tmp[0]; + mat[1][row2] = tmp[1]; + mat[2][row2] = tmp[2]; + mat[3][row2] = tmp[3]; +} + +#else +#endif /* cglm_mat_h */ diff --git a/include/cglm/quat.h b/include/cglm/quat.h new file mode 100644 index 0000000..2df2d70 --- /dev/null +++ b/include/cglm/quat.h @@ -0,0 +1,212 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_QUAT_IDENTITY_INIT + GLM_QUAT_IDENTITY + + Functions: + CGLM_INLINE void glm_quat_identity(versor q); + CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z); + CGLM_INLINE void glm_quatv(versor q, float angle, vec3 v); + CGLM_INLINE float glm_quat_norm(versor q); + CGLM_INLINE void glm_quat_normalize(versor q); + CGLM_INLINE float glm_quat_dot(versor q, versor r); + CGLM_INLINE void glm_quat_mulv(versor q1, versor q2, versor dest); + CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest); + CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest); + */ + +#ifndef cglm_quat_h +#define cglm_quat_h + +#include "common.h" +#include "vec4.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/quat.h" +#endif + +#define GLM_QUAT_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f} +#define GLM_QUAT_IDENTITY (versor){1.0f, 0.0f, 0.0f, 0.0f} + +CGLM_INLINE +void +glm_quat_identity(versor q) { + versor v = GLM_QUAT_IDENTITY_INIT; + glm_vec4_copy(v, q); +} + +CGLM_INLINE +void +glm_quat(versor q, + float angle, + float x, + float y, + float z) { + float a, c, s; + + a = angle * 0.5f; + c = cosf(a); + s = sinf(a); + + q[0] = c; + q[1] = s * x; + q[2] = s * y; + q[3] = s * z; +} + +CGLM_INLINE +void +glm_quatv(versor q, + float angle, + vec3 v) { + float a, c, s; + + a = angle * 0.5f; + c = cosf(a); + s = sinf(a); + + q[0] = c; + q[1] = s * v[0]; + q[2] = s * v[1]; + q[3] = s * v[2]; +} + +CGLM_INLINE +float +glm_quat_norm(versor q) { + return glm_vec4_norm(q); +} + +CGLM_INLINE +void +glm_quat_normalize(versor q) { + float sum; + + sum = q[0] * q[0] + q[1] * q[1] + + q[2] * q[2] + q[3] * q[3]; + + if (fabs(1.0f - sum) < 0.0001f) + return; + + glm_vec4_scale(q, 1.0f / sqrtf(sum), q); +} + +CGLM_INLINE +float +glm_quat_dot(versor q, versor r) { + return glm_vec4_dot(q, r); +} + +CGLM_INLINE +void +glm_quat_mulv(versor q1, versor q2, versor dest) { + dest[0] = q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2] - q2[3] * q1[3]; + dest[1] = q2[0] * q1[1] + q2[1] * q1[0] - q2[2] * q1[3] + q2[3] * q1[2]; + dest[2] = q2[0] * q1[2] + q2[1] * q1[3] + q2[2] * q1[0] - q2[3] * q1[1]; + dest[3] = q2[0] * q1[3] - q2[1] * q1[2] + q2[2] * q1[1] + q2[3] * q1[0]; + + glm_quat_normalize(dest); +} + +CGLM_INLINE +void +glm_quat_mat4(versor q, mat4 dest) { + float w, x, y, z; + float xx, yy, zz; + float xy, yz, xz; + float wx, wy, wz; + + w = q[0]; + x = q[1]; + y = q[2]; + z = q[3]; + + xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x; + yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y; + zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z; + + dest[0][0] = 1.0f - yy - zz; + dest[1][1] = 1.0f - xx - zz; + dest[2][2] = 1.0f - xx - yy; + + dest[0][1] = xy + wz; + dest[1][2] = yz + wx; + dest[2][0] = xz + wy; + + dest[1][0] = xy - wz; + dest[2][1] = yz - wx; + dest[0][2] = xz - wy; + + dest[1][3] = 0.0f; + dest[0][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +CGLM_INLINE +void +glm_quat_slerp(versor q, + versor r, + float t, + versor dest) { + /* https://en.wikipedia.org/wiki/Slerp */ +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_quat_slerp_sse2(q, r, t, dest); +#else + float cosTheta, sinTheta, angle, a, b, c; + + cosTheta = glm_quat_dot(q, r); + if (cosTheta < 0.0f) { + q[0] *= -1.0f; + q[1] *= -1.0f; + q[2] *= -1.0f; + q[3] *= -1.0f; + + cosTheta = -cosTheta; + } + + if (fabs(cosTheta) >= 1.0f) { + dest[0] = q[0]; + dest[1] = q[1]; + dest[2] = q[2]; + dest[3] = q[3]; + return; + } + + sinTheta = sqrt(1.0f - cosTheta * cosTheta); + + c = 1.0f - t; + + /* LERP */ + /* TODO: FLT_EPSILON vs 0.001? */ + if (sinTheta < 0.001f) { + dest[0] = c * q[0] + t * r[0]; + dest[1] = c * q[1] + t * r[1]; + dest[2] = c * q[2] + t * r[2]; + dest[3] = c * q[3] + t * r[3]; + return; + } + + /* SLERP */ + angle = acosf(cosTheta); + a = sinf(c * angle); + b = sinf(t * angle); + + dest[0] = (q[0] * a + r[0] * b) / sinTheta; + dest[1] = (q[1] * a + r[1] * b) / sinTheta; + dest[2] = (q[2] * a + r[2] * b) / sinTheta; + dest[3] = (q[3] * a + r[3] * b) / sinTheta; +#endif +} + +#endif /* cglm_quat_h */ diff --git a/include/cglm/simd/avx/affine.h b/include/cglm/simd/avx/affine.h new file mode 100644 index 0000000..1b0dcea --- /dev/null +++ b/include/cglm/simd/avx/affine.h @@ -0,0 +1,63 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_affine_mat_avx_h +#define cglm_affine_mat_avx_h +#ifdef __AVX__ + +#include "../../common.h" +#include "../intrin.h" + +#include + +CGLM_INLINE +void +glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; + + y0 = _mm256_load_ps(m2[0]); /* h g f e d c b a */ + y1 = _mm256_load_ps(m2[2]); /* p o n m l k j i */ + + y2 = _mm256_load_ps(m1[0]); /* h g f e d c b a */ + y3 = _mm256_load_ps(m1[2]); /* p o n m l k j i */ + + y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ + y5 = _mm256_permute2f128_ps(y3, y3, 0b00000000); /* l k j i l k j i */ + + /* f f f f a a a a */ + /* g g g g c c c c */ + /* e e e e b b b b */ + y7 = _mm256_permute_ps(y0, 0b10101010); + y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); + + _mm256_store_ps(dest[0], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y4, y8)), + _mm256_mul_ps(y5, y7))); + + + /* n n n n i i i i */ + /* p p p p k k k k */ + /* m m m m j j j j */ + /* o o o o l l l l */ + y6 = _mm256_permutevar_ps(y1, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y7 = _mm256_permutevar_ps(y1, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); + y8 = _mm256_permutevar_ps(y1, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); + y9 = _mm256_permutevar_ps(y1, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); + + _mm256_store_ps(dest[2], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); +} + +#endif +#endif /* cglm_affine_mat_avx_h */ diff --git a/include/cglm/simd/avx/mat4.h b/include/cglm/simd/avx/mat4.h new file mode 100644 index 0000000..e2ef9da --- /dev/null +++ b/include/cglm/simd/avx/mat4.h @@ -0,0 +1,65 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat_simd_avx_h +#define cglm_mat_simd_avx_h +#ifdef __AVX__ + +#include "../../common.h" +#include "../intrin.h" + +#include + +CGLM_INLINE +void +glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; + + y0 = _mm256_load_ps(m2[0]); /* h g f e d c b a */ + y1 = _mm256_load_ps(m2[2]); /* p o n m l k j i */ + + y2 = _mm256_load_ps(m1[0]); /* h g f e d c b a */ + y3 = _mm256_load_ps(m1[2]); /* p o n m l k j i */ + + y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ + y5 = _mm256_permute2f128_ps(y3, y3, 0b00000011); /* l k j i p o n m */ + + /* f f f f a a a a */ + /* h h h h c c c c */ + /* e e e e b b b b */ + /* g g g g d d d d */ + y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y7 = _mm256_permutevar_ps(y0, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); + y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); + y9 = _mm256_permutevar_ps(y0, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); + + _mm256_store_ps(dest[0], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); + + /* n n n n i i i i */ + /* p p p p k k k k */ + /* m m m m j j j j */ + /* o o o o l l l l */ + y6 = _mm256_permutevar_ps(y1, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y7 = _mm256_permutevar_ps(y1, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); + y8 = _mm256_permutevar_ps(y1, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); + y9 = _mm256_permutevar_ps(y1, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); + + _mm256_store_ps(dest[2], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); +} + +#endif +#endif /* cglm_mat_simd_avx_h */ diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h new file mode 100644 index 0000000..c0f2e53 --- /dev/null +++ b/include/cglm/simd/intrin.h @@ -0,0 +1,52 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_intrin_h +#define cglm_intrin_h + +#if defined( _WIN32 ) +# if (defined(_M_AMD64) || defined(_M_X64)) || _M_IX86_FP == 2 +# define __SSE2__ +# elif _M_IX86_FP == 1 +# define __SSE__ +# endif +#endif + +#if defined( __SSE__ ) || defined( __SSE2__ ) +# include +# include + +/* float */ +# define _mm_shuffle1_ps(a, z, y, x, w) \ + _mm_shuffle_ps(a, a, _MM_SHUFFLE(z, y, x, w)) + +# define _mm_shuffle1_ps1(a, x) \ + _mm_shuffle_ps(a, a, _MM_SHUFFLE(x, x, x, x)) + +# define _mm_shuffle2_ps(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ + _mm_shuffle1_ps(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ + z1, y1, x1, w1) +#endif + +/* x86, x64 */ +#if defined( __SSE__ ) || defined( __SSE2__ ) +# define CGLM_SSE_FP 1 +#endif + +#ifdef __AVX__ +# define CGLM_AVX_FP 1 +#endif + +/* ARM Neon */ +#if defined(__ARM_NEON) && defined(__ARM_NEON_FP) +# include +# define CGLM_NEON_FP 1 +#else +# undef CGLM_NEON_FP +#endif + +#endif /* cglm_intrin_h */ diff --git a/include/cglm/simd/neon/mat4.h b/include/cglm/simd/neon/mat4.h new file mode 100644 index 0000000..0623dc0 --- /dev/null +++ b/include/cglm/simd/neon/mat4.h @@ -0,0 +1,57 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat4_neon_h +#define cglm_mat4_neon_h +#if defined(__ARM_NEON_FP) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mat4_mul_neon(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + float32x4_t l0, l1, l2, l3, r, d0, d1, d2, d3; + + l0 = vld1q_f32(m2[0]); + l1 = vld1q_f32(m2[1]); + l2 = vld1q_f32(m2[2]); + l3 = vld1q_f32(m2[3]); + + r = vld1q_f32(m1[0]); + d0 = vmulq_lane_f32(r, vget_low_f32(l0), 0); + d1 = vmulq_lane_f32(r, vget_low_f32(l1), 0); + d2 = vmulq_lane_f32(r, vget_low_f32(l2), 0); + d3 = vmulq_lane_f32(r, vget_low_f32(l3), 0); + + r = vld1q_f32(m1[1]); + d0 = vmlaq_lane_f32(d0, r, vget_low_f32(l0), 1); + d1 = vmlaq_lane_f32(d1, r, vget_low_f32(l1), 1); + d2 = vmlaq_lane_f32(d2, r, vget_low_f32(l2), 1); + d3 = vmlaq_lane_f32(d3, r, vget_low_f32(l3), 1); + + r = vld1q_f32(m1[2]); + d0 = vmlaq_lane_f32(d0, r, vget_high_f32(l0), 0); + d1 = vmlaq_lane_f32(d1, r, vget_high_f32(l1), 0); + d2 = vmlaq_lane_f32(d2, r, vget_high_f32(l2), 0); + d3 = vmlaq_lane_f32(d3, r, vget_high_f32(l3), 0); + + r = vld1q_f32(m1[3]); + d0 = vmlaq_lane_f32(d0, r, vget_high_f32(l0), 1); + d1 = vmlaq_lane_f32(d1, r, vget_high_f32(l1), 1); + d2 = vmlaq_lane_f32(d2, r, vget_high_f32(l2), 1); + d3 = vmlaq_lane_f32(d3, r, vget_high_f32(l3), 1); + + vst1q_f32(dest[0], d0); + vst1q_f32(dest[1], d1); + vst1q_f32(dest[2], d2); + vst1q_f32(dest[3], d3); +} + +#endif +#endif /* cglm_mat4_neon_h */ diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h new file mode 100644 index 0000000..3ec8f5f --- /dev/null +++ b/include/cglm/simd/sse2/affine.h @@ -0,0 +1,79 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_affine_mat_sse2_h +#define cglm_affine_mat_sse2_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + __m128 l0, l1, l2, l3, r; + + l0 = _mm_load_ps(m1[0]); + l1 = _mm_load_ps(m1[1]); + l2 = _mm_load_ps(m1[2]); + l3 = _mm_load_ps(m1[3]); + + r = _mm_load_ps(m2[0]); + _mm_store_ps(dest[0], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + + r = _mm_load_ps(m2[1]); + _mm_store_ps(dest[1], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + + r = _mm_load_ps(m2[2]); + _mm_store_ps(dest[2], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + + r = _mm_load_ps(m2[3]); + _mm_store_ps(dest[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); +} + +CGLM_INLINE +void +glm_inv_tr_sse2(mat4 mat) { + __m128 r0, r1, r2, r3, x0, x1; + + r0 = _mm_load_ps(mat[0]); + r1 = _mm_load_ps(mat[1]); + r2 = _mm_load_ps(mat[2]); + r3 = _mm_load_ps(mat[3]); + x1 = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f); + + _MM_TRANSPOSE4_PS(r0, r1, r2, x1); + + x0 = _mm_add_ps(_mm_mul_ps(r0, _mm_shuffle1_ps(r3, 0, 0, 0, 0)), + _mm_mul_ps(r1, _mm_shuffle1_ps(r3, 1, 1, 1, 1))); + x0 = _mm_add_ps(x0, _mm_mul_ps(r2, _mm_shuffle1_ps(r3, 2, 2, 2, 2))); + x0 = _mm_xor_ps(x0, _mm_set1_ps(-0.f)); + + x0 = _mm_add_ps(x0, x1); + + _mm_store_ps(mat[0], r0); + _mm_store_ps(mat[1], r1); + _mm_store_ps(mat[2], r2); + _mm_store_ps(mat[3], x0); +} + +#endif +#endif /* cglm_affine_mat_sse2_h */ diff --git a/include/cglm/simd/sse2/mat3.h b/include/cglm/simd/sse2/mat3.h new file mode 100644 index 0000000..a0dcc02 --- /dev/null +++ b/include/cglm/simd/sse2/mat3.h @@ -0,0 +1,61 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat3_sse_h +#define cglm_mat3_sse_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mat3_mul_sse2(mat3 m1, mat3 m2, mat3 dest) { + __m128 l0, l1, l2; + __m128 r0, r1, r2; + __m128 x0, x1, x2; + + l0 = _mm_loadu_ps(m1[0]); + l1 = _mm_loadu_ps(&m1[1][1]); + l2 = _mm_set1_ps(m1[2][2]); + + r0 = _mm_loadu_ps(m2[0]); + r1 = _mm_loadu_ps(&m2[1][1]); + r2 = _mm_set1_ps(m2[2][2]); + + x1 = _mm_shuffle2_ps(l0, l1, 1, 0, 3, 3, 0, 3, 2, 0); + x2 = _mm_shuffle2_ps(l1, l2, 0, 0, 3, 2, 0, 2, 1, 0); + + x0 = _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps(l0, 0, 2, 1, 0), + _mm_shuffle1_ps(r0, 3, 0, 0, 0)), + _mm_mul_ps(x1, + _mm_shuffle2_ps(r0, r1, 0, 0, 1, 1, 2, 0, 0, 0))); + + x0 = _mm_add_ps(x0, + _mm_mul_ps(x2, + _mm_shuffle2_ps(r0, r1, 1, 1, 2, 2, 2, 0, 0, 0))); + + _mm_storeu_ps(dest[0], x0); + + x0 = _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps(l0, 1, 0, 2, 1), + _mm_shuffle_ps(r0, r1, _MM_SHUFFLE(2, 2, 3, 3))), + _mm_mul_ps(_mm_shuffle1_ps(x1, 1, 0, 2, 1), + _mm_shuffle1_ps(r1, 3, 3, 0, 0))); + + x0 = _mm_add_ps(x0, + _mm_mul_ps(_mm_shuffle1_ps(x2, 1, 0, 2, 1), + _mm_shuffle_ps(r1, r2, _MM_SHUFFLE(0, 0, 1, 1)))); + + _mm_storeu_ps(&dest[1][1], x0); + + dest[2][2] = m1[0][2] * m2[2][0] + + m1[1][2] * m2[2][1] + + m1[2][2] * m2[2][2]; +} + +#endif +#endif /* cglm_mat3_sse_h */ diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h new file mode 100644 index 0000000..77874a8 --- /dev/null +++ b/include/cglm/simd/sse2/mat4.h @@ -0,0 +1,409 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat_sse_h +#define cglm_mat_sse_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +#define glm_mat4_inv_precise_sse2(mat, dest) glm_mat4_inv_sse2(mat, dest) + +CGLM_INLINE +void +glm_mat4_scale_sse2(mat4 m, float s){ + __m128 x0; + x0 = _mm_set1_ps(s); + + _mm_store_ps(m[0], _mm_mul_ps(_mm_load_ps(m[0]), x0)); + _mm_store_ps(m[1], _mm_mul_ps(_mm_load_ps(m[1]), x0)); + _mm_store_ps(m[2], _mm_mul_ps(_mm_load_ps(m[2]), x0)); + _mm_store_ps(m[3], _mm_mul_ps(_mm_load_ps(m[3]), x0)); +} + +CGLM_INLINE +void +glm_mat4_transp_sse2(mat4 m, mat4 dest){ + __m128 r0, r1, r2, r3; + + r0 = _mm_load_ps(m[0]); + r1 = _mm_load_ps(m[1]); + r2 = _mm_load_ps(m[2]); + r3 = _mm_load_ps(m[3]); + + _MM_TRANSPOSE4_PS(r0, r1, r2, r3); + + _mm_store_ps(dest[0], r0); + _mm_store_ps(dest[1], r1); + _mm_store_ps(dest[2], r2); + _mm_store_ps(dest[3], r3); +} + +CGLM_INLINE +void +glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + __m128 l0, l1, l2, l3, r; + + l0 = _mm_load_ps(m1[0]); + l1 = _mm_load_ps(m1[1]); + l2 = _mm_load_ps(m1[2]); + l3 = _mm_load_ps(m1[3]); + + r = _mm_load_ps(m2[0]); + _mm_store_ps(dest[0], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + r = _mm_load_ps(m2[1]); + _mm_store_ps(dest[1], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + r = _mm_load_ps(m2[2]); + _mm_store_ps(dest[2], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + + r = _mm_load_ps(m2[3]); + _mm_store_ps(dest[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); +} + +CGLM_INLINE +void +glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { + __m128 x0, x1, x2; + + x0 = _mm_load_ps(v); + x1 = _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]), + _mm_shuffle1_ps1(x0, 0)), + _mm_mul_ps(_mm_load_ps(m[1]), + _mm_shuffle1_ps1(x0, 1))); + + x2 = _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]), + _mm_shuffle1_ps1(x0, 2)), + _mm_mul_ps(_mm_load_ps(m[3]), + _mm_shuffle1_ps1(x0, 3))); + + _mm_store_ps(dest, _mm_add_ps(x1, x2)); +} + +CGLM_INLINE +float +glm_mat4_det_sse2(mat4 mat) { + __m128 r0, r1, r2, r3, x0, x1, x2; + + /* 127 <- 0, [square] det(A) = det(At) */ + r0 = _mm_load_ps(mat[0]); /* d c b a */ + r1 = _mm_load_ps(mat[1]); /* h g f e */ + r2 = _mm_load_ps(mat[2]); /* l k j i */ + r3 = _mm_load_ps(mat[3]); /* p o n m */ + + /* + t[1] = j * p - n * l; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + */ + x0 = _mm_sub_ps(_mm_mul_ps(_mm_shuffle1_ps(r2, 0, 0, 1, 1), + _mm_shuffle1_ps(r3, 2, 3, 2, 3)), + _mm_mul_ps(_mm_shuffle1_ps(r3, 0, 0, 1, 1), + _mm_shuffle1_ps(r2, 2, 3, 2, 3))); + /* + t[0] = k * p - o * l; + t[0] = k * p - o * l; + t[5] = i * n - m * j; + t[5] = i * n - m * j; + */ + x1 = _mm_sub_ps(_mm_mul_ps(_mm_shuffle1_ps(r2, 0, 0, 2, 2), + _mm_shuffle1_ps(r3, 1, 1, 3, 3)), + _mm_mul_ps(_mm_shuffle1_ps(r3, 0, 0, 2, 2), + _mm_shuffle1_ps(r2, 1, 1, 3, 3))); + + /* + a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]) + */ + x2 = _mm_sub_ps(_mm_mul_ps(_mm_shuffle1_ps(r1, 0, 0, 0, 1), + _mm_shuffle_ps(x1, x0, _MM_SHUFFLE(1, 0, 0, 0))), + _mm_mul_ps(_mm_shuffle1_ps(r1, 1, 1, 2, 2), + _mm_shuffle1_ps(x0, 3, 2, 2, 0))); + + x2 = _mm_add_ps(x2, + _mm_mul_ps(_mm_shuffle1_ps(r1, 2, 3, 3, 3), + _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 2, 3, 1)))); + x2 = _mm_xor_ps(x2, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + + x0 = _mm_mul_ps(r0, x2); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 3, 3, 1)); + + return _mm_cvtss_f32(x0); +} + +CGLM_INLINE +void +glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { + __m128 r0, r1, r2, r3, + v0, v1, v2, v3, + t0, t1, t2, t3, t4, t5, + x0, x1, x2, x3, x4, x5, x6, x7; + + /* 127 <- 0 */ + r0 = _mm_load_ps(mat[0]); /* d c b a */ + r1 = _mm_load_ps(mat[1]); /* h g f e */ + r2 = _mm_load_ps(mat[2]); /* l k j i */ + r3 = _mm_load_ps(mat[3]); /* p o n m */ + + x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ + x1 = _mm_shuffle1_ps(x0, 1, 3, 3, 3); /* l p p p */ + x2 = _mm_shuffle1_ps(x0, 0, 2, 2, 2); /* k o o o */ + x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ + x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ + + /* t1[0] = k * p - o * l; + t1[0] = k * p - o * l; + t2[0] = g * p - o * h; + t3[0] = g * l - k * h; */ + t0 = _mm_sub_ps(_mm_mul_ps(x3, x1), _mm_mul_ps(x2, x0)); + + x4 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(2, 1, 2, 1)); /* o n k j */ + x4 = _mm_shuffle1_ps(x4, 0, 2, 2, 2); /* j n n n */ + x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ + + /* t1[1] = j * p - n * l; + t1[1] = j * p - n * l; + t2[1] = f * p - n * h; + t3[1] = f * l - j * h; */ + t1 = _mm_sub_ps(_mm_mul_ps(x5, x1), _mm_mul_ps(x4, x0)); + + /* t1[2] = j * o - n * k + t1[2] = j * o - n * k; + t2[2] = f * o - n * g; + t3[2] = f * k - j * g; */ + t2 = _mm_sub_ps(_mm_mul_ps(x5, x2), _mm_mul_ps(x4, x3)); + + x6 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(0, 0, 0, 0)); /* e e i i */ + x7 = _mm_shuffle2_ps(r3, r2, 0, 0, 0, 0, 2, 0, 0, 0); /* i m m m */ + + /* t1[3] = i * p - m * l; + t1[3] = i * p - m * l; + t2[3] = e * p - m * h; + t3[3] = e * l - i * h; */ + t3 = _mm_sub_ps(_mm_mul_ps(x6, x1), _mm_mul_ps(x7, x0)); + + /* t1[4] = i * o - m * k; + t1[4] = i * o - m * k; + t2[4] = e * o - m * g; + t3[4] = e * k - i * g; */ + t4 = _mm_sub_ps(_mm_mul_ps(x6, x2), _mm_mul_ps(x7, x3)); + + /* t1[5] = i * n - m * j; + t1[5] = i * n - m * j; + t2[5] = e * n - m * f; + t3[5] = e * j - i * f; */ + t5 = _mm_sub_ps(_mm_mul_ps(x6, x4), _mm_mul_ps(x7, x5)); + + x0 = _mm_shuffle2_ps(r1, r0, 0, 0, 0, 0, 2, 2, 2, 0); /* a a a e */ + x1 = _mm_shuffle2_ps(r1, r0, 1, 1, 1, 1, 2, 2, 2, 0); /* b b b f */ + x2 = _mm_shuffle2_ps(r1, r0, 2, 2, 2, 2, 2, 2, 2, 0); /* c c c g */ + x3 = _mm_shuffle2_ps(r1, r0, 3, 3, 3, 3, 2, 2, 2, 0); /* d d d h */ + + /* + dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; + dest[0][1] =-(b * t1[0] - c * t1[1] + d * t1[2]); + dest[0][2] = b * t2[0] - c * t2[1] + d * t2[2]; + dest[0][3] =-(b * t3[0] - c * t3[1] + d * t3[2]); */ + v0 = _mm_add_ps(_mm_mul_ps(x3, t2), + _mm_sub_ps(_mm_mul_ps(x1, t0), + _mm_mul_ps(x2, t1))); + v0 = _mm_xor_ps(v0, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + + /* + dest[1][0] =-(e * t1[0] - g * t1[3] + h * t1[4]); + dest[1][1] = a * t1[0] - c * t1[3] + d * t1[4]; + dest[1][2] =-(a * t2[0] - c * t2[3] + d * t2[4]); + dest[1][3] = a * t3[0] - c * t3[3] + d * t3[4]; */ + v1 = _mm_add_ps(_mm_mul_ps(x3, t4), + _mm_sub_ps(_mm_mul_ps(x0, t0), + _mm_mul_ps(x2, t3))); + v1 = _mm_xor_ps(v1, _mm_set_ps(0.f, -0.f, 0.f, -0.f)); + + /* + dest[2][0] = e * t1[1] - f * t1[3] + h * t1[5]; + dest[2][1] =-(a * t1[1] - b * t1[3] + d * t1[5]); + dest[2][2] = a * t2[1] - b * t2[3] + d * t2[5]; + dest[2][3] =-(a * t3[1] - b * t3[3] + d * t3[5]);*/ + v2 = _mm_add_ps(_mm_mul_ps(x3, t5), + _mm_sub_ps(_mm_mul_ps(x0, t1), + _mm_mul_ps(x1, t3))); + v2 = _mm_xor_ps(v2, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + + /* + dest[3][0] =-(e * t1[2] - f * t1[4] + g * t1[5]); + dest[3][1] = a * t1[2] - b * t1[4] + c * t1[5]; + dest[3][2] =-(a * t2[2] - b * t2[4] + c * t2[5]); + dest[3][3] = a * t3[2] - b * t3[4] + c * t3[5]; */ + v3 = _mm_add_ps(_mm_mul_ps(x2, t5), + _mm_sub_ps(_mm_mul_ps(x0, t2), + _mm_mul_ps(x1, t4))); + v3 = _mm_xor_ps(v3, _mm_set_ps(0.f, -0.f, 0.f, -0.f)); + + /* determinant */ + x0 = _mm_shuffle_ps(v0, v1, _MM_SHUFFLE(0, 0, 0, 0)); + x1 = _mm_shuffle_ps(v2, v3, _MM_SHUFFLE(0, 0, 0, 0)); + x0 = _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 0, 2, 0)); + + x0 = _mm_mul_ps(x0, r0); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 0, 1)); + x0 = _mm_rcp_ps(x0); + + _mm_store_ps(dest[0], _mm_mul_ps(v0, x0)); + _mm_store_ps(dest[1], _mm_mul_ps(v1, x0)); + _mm_store_ps(dest[2], _mm_mul_ps(v2, x0)); + _mm_store_ps(dest[3], _mm_mul_ps(v3, x0)); +} + +CGLM_INLINE +void +glm_mat4_inv_sse2(mat4 mat, mat4 dest) { + __m128 r0, r1, r2, r3, + v0, v1, v2, v3, + t0, t1, t2, t3, t4, t5, + x0, x1, x2, x3, x4, x5, x6, x7; + + /* 127 <- 0 */ + r0 = _mm_load_ps(mat[0]); /* d c b a */ + r1 = _mm_load_ps(mat[1]); /* h g f e */ + r2 = _mm_load_ps(mat[2]); /* l k j i */ + r3 = _mm_load_ps(mat[3]); /* p o n m */ + + x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ + x1 = _mm_shuffle1_ps(x0, 1, 3, 3, 3); /* l p p p */ + x2 = _mm_shuffle1_ps(x0, 0, 2, 2, 2); /* k o o o */ + x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ + x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ + + /* t1[0] = k * p - o * l; + t1[0] = k * p - o * l; + t2[0] = g * p - o * h; + t3[0] = g * l - k * h; */ + t0 = _mm_sub_ps(_mm_mul_ps(x3, x1), _mm_mul_ps(x2, x0)); + + x4 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(2, 1, 2, 1)); /* o n k j */ + x4 = _mm_shuffle1_ps(x4, 0, 2, 2, 2); /* j n n n */ + x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ + + /* t1[1] = j * p - n * l; + t1[1] = j * p - n * l; + t2[1] = f * p - n * h; + t3[1] = f * l - j * h; */ + t1 = _mm_sub_ps(_mm_mul_ps(x5, x1), _mm_mul_ps(x4, x0)); + + /* t1[2] = j * o - n * k + t1[2] = j * o - n * k; + t2[2] = f * o - n * g; + t3[2] = f * k - j * g; */ + t2 = _mm_sub_ps(_mm_mul_ps(x5, x2), _mm_mul_ps(x4, x3)); + + x6 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(0, 0, 0, 0)); /* e e i i */ + x7 = _mm_shuffle2_ps(r3, r2, 0, 0, 0, 0, 2, 0, 0, 0); /* i m m m */ + + /* t1[3] = i * p - m * l; + t1[3] = i * p - m * l; + t2[3] = e * p - m * h; + t3[3] = e * l - i * h; */ + t3 = _mm_sub_ps(_mm_mul_ps(x6, x1), _mm_mul_ps(x7, x0)); + + /* t1[4] = i * o - m * k; + t1[4] = i * o - m * k; + t2[4] = e * o - m * g; + t3[4] = e * k - i * g; */ + t4 = _mm_sub_ps(_mm_mul_ps(x6, x2), _mm_mul_ps(x7, x3)); + + /* t1[5] = i * n - m * j; + t1[5] = i * n - m * j; + t2[5] = e * n - m * f; + t3[5] = e * j - i * f; */ + t5 = _mm_sub_ps(_mm_mul_ps(x6, x4), _mm_mul_ps(x7, x5)); + + x0 = _mm_shuffle2_ps(r1, r0, 0, 0, 0, 0, 2, 2, 2, 0); /* a a a e */ + x1 = _mm_shuffle2_ps(r1, r0, 1, 1, 1, 1, 2, 2, 2, 0); /* b b b f */ + x2 = _mm_shuffle2_ps(r1, r0, 2, 2, 2, 2, 2, 2, 2, 0); /* c c c g */ + x3 = _mm_shuffle2_ps(r1, r0, 3, 3, 3, 3, 2, 2, 2, 0); /* d d d h */ + + /* + dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; + dest[0][1] =-(b * t1[0] - c * t1[1] + d * t1[2]); + dest[0][2] = b * t2[0] - c * t2[1] + d * t2[2]; + dest[0][3] =-(b * t3[0] - c * t3[1] + d * t3[2]); */ + v0 = _mm_add_ps(_mm_mul_ps(x3, t2), + _mm_sub_ps(_mm_mul_ps(x1, t0), + _mm_mul_ps(x2, t1))); + v0 = _mm_xor_ps(v0, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + + /* + dest[1][0] =-(e * t1[0] - g * t1[3] + h * t1[4]); + dest[1][1] = a * t1[0] - c * t1[3] + d * t1[4]; + dest[1][2] =-(a * t2[0] - c * t2[3] + d * t2[4]); + dest[1][3] = a * t3[0] - c * t3[3] + d * t3[4]; */ + v1 = _mm_add_ps(_mm_mul_ps(x3, t4), + _mm_sub_ps(_mm_mul_ps(x0, t0), + _mm_mul_ps(x2, t3))); + v1 = _mm_xor_ps(v1, _mm_set_ps(0.f, -0.f, 0.f, -0.f)); + + /* + dest[2][0] = e * t1[1] - f * t1[3] + h * t1[5]; + dest[2][1] =-(a * t1[1] - b * t1[3] + d * t1[5]); + dest[2][2] = a * t2[1] - b * t2[3] + d * t2[5]; + dest[2][3] =-(a * t3[1] - b * t3[3] + d * t3[5]);*/ + v2 = _mm_add_ps(_mm_mul_ps(x3, t5), + _mm_sub_ps(_mm_mul_ps(x0, t1), + _mm_mul_ps(x1, t3))); + v2 = _mm_xor_ps(v2, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + + /* + dest[3][0] =-(e * t1[2] - f * t1[4] + g * t1[5]); + dest[3][1] = a * t1[2] - b * t1[4] + c * t1[5]; + dest[3][2] =-(a * t2[2] - b * t2[4] + c * t2[5]); + dest[3][3] = a * t3[2] - b * t3[4] + c * t3[5]; */ + v3 = _mm_add_ps(_mm_mul_ps(x2, t5), + _mm_sub_ps(_mm_mul_ps(x0, t2), + _mm_mul_ps(x1, t4))); + v3 = _mm_xor_ps(v3, _mm_set_ps(0.f, -0.f, 0.f, -0.f)); + + /* determinant */ + x0 = _mm_shuffle_ps(v0, v1, _MM_SHUFFLE(0, 0, 0, 0)); + x1 = _mm_shuffle_ps(v2, v3, _MM_SHUFFLE(0, 0, 0, 0)); + x0 = _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 0, 2, 0)); + + x0 = _mm_mul_ps(x0, r0); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 0, 1)); + x0 = _mm_div_ps(_mm_set1_ps(1.0f), x0); + + _mm_store_ps(dest[0], _mm_mul_ps(v0, x0)); + _mm_store_ps(dest[1], _mm_mul_ps(v1, x0)); + _mm_store_ps(dest[2], _mm_mul_ps(v2, x0)); + _mm_store_ps(dest[3], _mm_mul_ps(v3, x0)); +} + +#endif +#endif /* cglm_mat_sse_h */ diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h new file mode 100644 index 0000000..b3420a7 --- /dev/null +++ b/include/cglm/simd/sse2/quat.h @@ -0,0 +1,69 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_quat_simd_h +#define cglm_quat_simd_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_quat_slerp_sse2(versor q, + versor r, + float t, + versor dest) { + /* https://en.wikipedia.org/wiki/Slerp */ + float cosTheta, sinTheta, angle, a, b, c; + + __m128 xmm_q; + + xmm_q = _mm_load_ps(q); + + cosTheta = glm_vec4_dot(q, r); + if (cosTheta < 0.0f) { + _mm_store_ps(q, + _mm_xor_ps(xmm_q, + _mm_set1_ps(-0.f))) ; + + cosTheta = -cosTheta; + } + + if (cosTheta >= 1.0f) { + _mm_store_ps(dest, xmm_q); + return; + } + + sinTheta = sqrtf(1.0f - cosTheta * cosTheta); + + c = 1.0f - t; + + /* LERP */ + if (sinTheta < 0.001f) { + _mm_store_ps(dest, _mm_add_ps(_mm_mul_ps(_mm_set1_ps(c), + xmm_q), + _mm_mul_ps(_mm_set1_ps(t), + _mm_load_ps(r)))); + return; + } + + /* SLERP */ + angle = acosf(cosTheta); + a = sinf(c * angle); + b = sinf(t * angle); + + _mm_store_ps(dest, + _mm_div_ps(_mm_add_ps(_mm_mul_ps(_mm_set1_ps(a), + xmm_q), + _mm_mul_ps(_mm_set1_ps(b), + _mm_load_ps(r))), + _mm_set1_ps(sinTheta))); +} + +#endif +#endif /* cglm_quat_simd_h */ diff --git a/include/cglm/types.h b/include/cglm/types.h new file mode 100644 index 0000000..a4170c4 --- /dev/null +++ b/include/cglm/types.h @@ -0,0 +1,30 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_types_h +#define cglm_types_h + +#if defined(_MSC_VER) +# define CGLM_ALIGN(X) /* __declspec(align(X)) */ +#else +# define CGLM_ALIGN(X) __attribute((aligned(X))) +#endif + +typedef float vec3[3]; +typedef int ivec3[3]; +typedef CGLM_ALIGN(16) float vec4[4]; + +typedef vec3 mat3[3]; +typedef vec4 mat4[4]; + +typedef vec4 versor; + +#define CGLM_PI (float)M_PI +#define CGLM_PI_2 (float)M_PI_2 +#define CGLM_PI_4 (float)M_PI_4 + +#endif /* cglm_types_h */ diff --git a/include/cglm/util.h b/include/cglm/util.h new file mode 100644 index 0000000..d1b62a2 --- /dev/null +++ b/include/cglm/util.h @@ -0,0 +1,64 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE int glm_sign(int val); + CGLM_INLINE float glm_rad(float deg); + CGLM_INLINE float glm_deg(float rad); + CGLM_INLINE void glm_make_rad(float *deg); + CGLM_INLINE void glm_make_deg(float *rad); + CGLM_INLINE float glm_pow2(float x); + */ + +#ifndef cglm_util_h +#define cglm_util_h + +#include "common.h" + +/*! + * @brief get sign of 32 bit integer as +1 or -1 + * + * @param val integer value + */ +CGLM_INLINE +int +glm_sign(int val) { + return ((val >> 31) - (-val >> 31)); +} + +CGLM_INLINE +float +glm_rad(float deg) { + return deg * CGLM_PI / 180.0f; +} + +CGLM_INLINE +float +glm_deg(float rad) { + return rad * 180.0f / CGLM_PI; +} + +CGLM_INLINE +void +glm_make_rad(float *deg) { + *deg = *deg * CGLM_PI / 180.0f; +} + +CGLM_INLINE +void +glm_make_deg(float *rad) { + *rad = *rad * 180.0f / CGLM_PI; +} + +CGLM_INLINE +float +glm_pow2(float x) { + return x * x; +} + +#endif /* cglm_util_h */ diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h new file mode 100644 index 0000000..41c1749 --- /dev/null +++ b/include/cglm/vec3-ext.h @@ -0,0 +1,163 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE void glm_vec_mulv(vec3 a, vec3 b, vec3 d); + CGLM_INLINE void glm_vec_broadcast(float val, vec3 d); + CGLM_INLINE bool glm_vec_eq(vec3 v, float val); + CGLM_INLINE bool glm_vec_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec_eq_all(vec3 v); + CGLM_INLINE bool glm_vec_eqv(vec3 v1, vec3 v2); + CGLM_INLINE bool glm_vec_eqv_eps(vec3 v1, vec3 v2); + CGLM_INLINE float glm_vec_max(vec3 v); + CGLM_INLINE float glm_vec_min(vec3 v); + */ + +#ifndef cglm_vec3_ext_h +#define cglm_vec3_ext_h + +#include "common.h" +#include +#include +#include + +/*! + * @brief multiplies individual items, just for convenient like SIMD + * + * @param a vec1 + * @param b vec2 + * @param d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) + */ +CGLM_INLINE +void +glm_vec_mulv(vec3 a, vec3 b, vec3 d) { + d[0] = a[0] * b[0]; + d[1] = a[1] * b[1]; + d[2] = a[2] * b[2]; +} + +/*! + * @brief fill a vector with specified value + * + * @param val value + * @param d dest + */ +CGLM_INLINE +void +glm_vec_broadcast(float val, vec3 d) { + d[0] = d[1] = d[2] = val; +} + +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec_eq(vec3 v, float val) { + return v[0] == val && v[0] == v[1] && v[0] == v[2]; +} + +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec_eq_eps(vec4 v, float val) { + return fabsf(v[0] - val) <= FLT_EPSILON + && fabsf(v[1] - val) <= FLT_EPSILON + && fabsf(v[2] - val) <= FLT_EPSILON; +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param v vector + */ +CGLM_INLINE +bool +glm_vec_eq_all(vec3 v) { + return v[0] == v[1] && v[0] == v[2]; +} + +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param v1 vector + * @param v2 vector + */ +CGLM_INLINE +bool +glm_vec_eqv(vec3 v1, vec3 v2) { + return v1[0] == v2[0] + && v1[1] == v2[1] + && v1[2] == v2[2]; +} + +/*! + * @brief check if vector is equal to another (with epsilon) + * + * @param v1 vector + * @param v2 vector + */ +CGLM_INLINE +bool +glm_vec_eqv_eps(vec3 v1, vec3 v2) { + return fabsf(v1[0] - v2[0]) <= FLT_EPSILON + && fabsf(v1[1] - v2[1]) <= FLT_EPSILON + && fabsf(v1[2] - v2[2]) <= FLT_EPSILON; +} + +/*! + * @brief max value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec_max(vec3 v) { + float max; + + max = v[0]; + if (v[1] > max) + max = v[1]; + if (v[2] > max) + max = v[2]; + + return max; +} + +/*! + * @brief min value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec_min(vec3 v) { + float min; + + min = v[0]; + if (v[1] < min) + min = v[1]; + if (v[2] < min) + min = v[2]; + + return min; +} + +#endif /* cglm_vec3_ext_h */ diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h new file mode 100644 index 0000000..0d6bc07 --- /dev/null +++ b/include/cglm/vec3.h @@ -0,0 +1,538 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot) + * all functions without suffix are vec3 functions + */ + +/* + Macros: + glm_vec_dup(v, dest) + GLM_VEC3_ONE_INIT + GLM_VEC3_ONE + GLM_YUP + GLM_ZUP + GLM_XUP + + Functions: + CGLM_INLINE void glm_vec3(vec4 v4, vec3 dest); + CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest); + CGLM_INLINE float glm_vec_dot(vec3 a, vec3 b); + CGLM_INLINE void glm_vec_cross(vec3 a, vec3 b, vec3 d); + CGLM_INLINE float glm_vec_norm2(vec3 v); + CGLM_INLINE float glm_vec_norm(vec3 vec); + CGLM_INLINE void glm_vec_add(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec_scale(vec3 v, float s, vec3 dest); + CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest); + CGLM_INLINE void glm_vec_flipsign(vec3 v); + CGLM_INLINE void glm_vec_inv(vec3 v); + CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec_normalize(vec3 v); + CGLM_INLINE void glm_vec_normalize_to(vec3 vec, vec3 dest); + CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2); + CGLM_INLINE float glm_vec_angle(vec3 v1, vec3 v2); + CGLM_INLINE void glm_vec_rotate(vec3 v, float angle, vec3 axis); + CGLM_INLINE void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec_proj(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_center(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest); + + Convenient: + CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); + CGLM_INLINE float glm_dot(vec3 a, vec3 b); + CGLM_INLINE void glm_normalize(vec3 v); + CGLM_INLINE void glm_normalize_to(vec3 v, vec3 dest); + */ + +#ifndef cglm_vec3_h +#define cglm_vec3_h + +#include "common.h" +#include "vec3-ext.h" +#include "util.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glm_vec_dup(v, dest) glm_vec_copy(v, dest) + +#define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} +#define GLM_VEC3_ONE (vec3)GLM_VEC3_ONE_INIT + +#define GLM_YUP (vec3){0.0f, 1.0f, 0.0f} +#define GLM_ZUP (vec3){0.0f, 0.0f, 1.0f} +#define GLM_XUP (vec3){1.0f, 0.0f, 0.0f} + +/*! + * @brief init vec3 using vec4 + * + * @param[in] v4 vector4 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3(vec4 v4, vec3 dest) { + dest[0] = v4[0]; + dest[1] = v4[1]; + dest[2] = v4[2]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec_copy(vec3 a, vec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief vec3 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_vec_dot(vec3 a, vec3 b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +} + +/*! + * @brief vec3 cross product + * + * @param[in] a source 1 + * @param[in] b source 2 + * @param[out] d destination + */ +CGLM_INLINE +void +glm_vec_cross(vec3 a, vec3 b, vec3 d) { + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + d[0] = a[1] * b[2] - a[2] * b[1]; + d[1] = a[2] * b[0] - a[0] * b[2]; + d[2] = a[0] * b[1] - a[1] * b[0]; +} + +/*! + * @brief norm * norm (magnitude) of vec + * + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * not good name for this func + * + * @param[in] v vector + * + * @return norm * norm + */ +CGLM_INLINE +float +glm_vec_norm2(vec3 v) { + return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; +} + +/*! + * @brief norm (magnitude) of vec3 + * + * @param[in] vec vector + * + * @return norm + */ +CGLM_INLINE +float +glm_vec_norm(vec3 vec) { + return sqrtf(glm_vec_norm2(vec)); +} + +/*! + * @brief add v2 vector to v1 vector store result in dest + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_add(vec3 v1, vec3 v2, vec3 dest) { + dest[0] = v1[0] + v2[0]; + dest[1] = v1[1] + v2[1]; + dest[2] = v1[2] + v2[2]; +} + +/*! + * @brief subtract v2 vector from v1 vector store result in dest + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) { + dest[0] = v1[0] - v2[0]; + dest[1] = v1[1] - v2[1]; + dest[2] = v1[2] - v2[2]; +} + +/*! + * @brief multiply/scale vec3 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_scale(vec3 v, float s, vec3 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; +} + +/*! + * @brief make vec3 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_scale_as(vec3 v, float s, vec3 dest) { + float norm; + norm = glm_vec_norm(v); + + if (norm == 0) { + glm_vec_copy(v, dest); + return; + } + + glm_vec_scale(v, s / norm, dest); +} + +/*! + * @brief flip sign of all vec3 members + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec_flipsign(vec3 v) { + v[0] = -v[0]; + v[1] = -v[1]; + v[2] = -v[2]; +} + +/*! + * @brief make vector as inverse/opposite of itself + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec_inv(vec3 v) { + glm_vec_flipsign(v); +} + +/*! + * @brief inverse/opposite vector + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec_inv_to(vec3 v, vec3 dest) { + glm_vec_copy(v, dest); + glm_vec_flipsign(dest); +} + +/*! + * @brief normalize vec3 and store result in same vec + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec_normalize(vec3 v) { + float norm; + + norm = glm_vec_norm(v); + + if (norm == 0.0f) { + v[0] = v[1] = v[2] = 0.0f; + return; + } + + glm_vec_scale(v, 1.0f / norm, v); +} + +/*! + * @brief normalize vec3 to dest + * + * @param[in] vec source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec_normalize_to(vec3 vec, vec3 dest) { + float norm; + + norm = glm_vec_norm(vec); + + if (norm == 0.0f) { + dest[0] = dest[1] = dest[2] = 0.0f; + return; + } + + glm_vec_scale(vec, 1.0f / norm, dest); +} + +/*! + * @brief angle betwen two vector + * + * @return angle as radians + */ +CGLM_INLINE +float +glm_vec_angle(vec3 v1, vec3 v2) { + float norm; + + /* maybe compiler generate approximation instruction (rcp) */ + norm = 1.0f / (glm_vec_norm(v1) * glm_vec_norm(v2)); + return acosf(glm_vec_dot(v1, v2) * norm); +} + +CGLM_INLINE +void +glm_quatv(versor q, + float angle, + vec3 v); + +/*! + * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula + * + * @param[in, out] v vector + * @param[in] axis axis vector (must be unit vector) + * @param[in] angle angle by radians + */ +CGLM_INLINE +void +glm_vec_rotate(vec3 v, float angle, vec3 axis) { + versor q; + vec3 v1, v2, v3; + float c, s; + + c = cosf(angle); + s = sinf(angle); + + /* Right Hand, Rodrigues' rotation formula: + v = v*cos(t) + (kxv)sin(t) + k*(k.v)(1 - cos(t)) + */ + + /* quaternion */ + glm_quatv(q, angle, v); + + glm_vec_scale(v, c, v1); + + glm_vec_cross(axis, v, v2); + glm_vec_scale(v2, s, v2); + + glm_vec_scale(axis, + glm_vec_dot(axis, v) * (1.0f - c), + v3); + + glm_vec_add(v1, v2, v1); + glm_vec_add(v1, v3, v); +} + +/*! + * @brief apply rotation matrix to vector + * + * @param[in] m affine matrix or rot matrix + * @param[in] v vector + * @param[out] dest rotated vector + */ +CGLM_INLINE +void +glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { + vec3 res, x, y, z; + + glm_vec_normalize_to(m[0], x); + glm_vec_normalize_to(m[1], y); + glm_vec_normalize_to(m[2], z); + + res[0] = x[0] * v[0] + y[0] * v[1] + z[0] * v[2]; + res[1] = x[1] * v[0] + y[1] * v[1] + z[1] * v[2]; + res[2] = x[2] * v[0] + y[2] * v[1] + z[2] * v[2]; + + glm_vec_copy(res, dest); +} + +/*! + * @brief project a vector onto b vector + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest projected vector + */ +CGLM_INLINE +void +glm_vec_proj(vec3 a, vec3 b, vec3 dest) { + glm_vec_scale(b, + glm_vec_dot(a, b) / glm_vec_norm2(b), + dest); +} + +/** + * @brief find center point of two vector + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest center point + */ +CGLM_INLINE +void +glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { + glm_vec_add(v1, v2, dest); + glm_vec_scale(dest, 0.5f, dest); +} + +/** + * @brief distance between two vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @return returns distance + */ +CGLM_INLINE +float +glm_vec_distance(vec3 v1, vec3 v2) { + return sqrtf(glm_pow2(v2[0] - v1[0]) + + glm_pow2(v2[1] - v1[1]) + + glm_pow2(v2[2] - v1[2])); +} + +/*! + * @brief max values of vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) { + if (v1[0] > v2[0]) + dest[0] = v1[0]; + else + dest[0] = v2[0]; + + if (v1[1] > v2[1]) + dest[1] = v1[1]; + else + dest[1] = v2[1]; + + if (v1[2] > v2[2]) + dest[2] = v1[2]; + else + dest[2] = v2[2]; +} + +/*! + * @brief min values of vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) { + if (v1[0] < v2[0]) + dest[0] = v1[0]; + else + dest[0] = v2[0]; + + if (v1[1] < v2[1]) + dest[1] = v1[1]; + else + dest[1] = v2[1]; + + if (v1[2] < v2[2]) + dest[2] = v1[2]; + else + dest[2] = v2[2]; +} + +/*! + * @brief vec3 cross product + * + * this is just convenient wrapper + * + * @param[in] a source 1 + * @param[in] b source 2 + * @param[out] d destination + */ +CGLM_INLINE +void +glm_cross(vec3 a, vec3 b, vec3 d) { + glm_vec_cross(a, b, d); +} + +/*! + * @brief vec3 dot product + * + * this is just convenient wrapper + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_dot(vec3 a, vec3 b) { + return glm_vec_dot(a, b); +} + +/*! + * @brief normalize vec3 and store result in same vec + * + * this is just convenient wrapper + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_normalize(vec3 v) { + glm_vec_normalize(v); +} + +/*! + * @brief normalize vec3 to dest + * + * this is just convenient wrapper + * + * @param[in] vec source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_normalize_to(vec3 v, vec3 dest) { + glm_vec_normalize_to(v, dest); +} + +#endif /* cglm_vec3_h */ diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h new file mode 100644 index 0000000..6410e41 --- /dev/null +++ b/include/cglm/vec4-ext.h @@ -0,0 +1,178 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); + CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); + CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_all(vec4 v); + CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); + CGLM_INLINE bool glm_vec4_eqv_eps(vec3 v1, vec3 v2); + CGLM_INLINE float glm_vec4_max(vec4 v); + CGLM_INLINE float glm_vec4_min(vec4 v); + */ + +#ifndef cglm_vec4_ext_h +#define cglm_vec4_ext_h + +#include "common.h" +#include "vec3-ext.h" +#include +#include +#include + +/*! + * @brief multiplies individual items, just for convenient like SIMD + * + * @param a v1 + * @param b v2 + * @param d v3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2], v1[3] * v2[3]) + */ +CGLM_INLINE +void +glm_vec4_mulv(vec4 a, vec4 b, vec4 d) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(d, _mm_mul_ps(_mm_load_ps(a), _mm_load_ps(b))); +#else + d[0] = a[0] * b[0]; + d[1] = a[1] * b[1]; + d[2] = a[2] * b[2]; + d[3] = a[3] * b[3]; +#endif +} + +/*! + * @brief fill a vector with specified value + * + * @param val value + * @param d dest + */ +CGLM_INLINE +void +glm_vec4_broadcast(float val, vec4 d) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(d, _mm_set1_ps(val)); +#else + d[0] = d[1] = d[2] = d[3] = val; +#endif +} + +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec4_eq(vec4 v, float val) { + return v[0] == val + && v[0] == v[1] + && v[0] == v[2] + && v[0] == v[3]; +} + +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec4_eq_eps(vec4 v, float val) { + return fabsf(v[0] - val) <= FLT_EPSILON + && fabsf(v[1] - val) <= FLT_EPSILON + && fabsf(v[2] - val) <= FLT_EPSILON + && fabsf(v[3] - val) <= FLT_EPSILON; +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param v vector + */ +CGLM_INLINE +bool +glm_vec4_eq_all(vec4 v) { + return v[0] == v[1] + && v[0] == v[2] + && v[0] == v[3]; +} + +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param v1 vector + * @param v2 vector + */ +CGLM_INLINE +bool +glm_vec4_eqv(vec4 v1, vec4 v2) { + return v1[0] == v2[0] + && v1[1] == v2[1] + && v1[2] == v2[2] + && v1[3] == v2[3]; +} + +/*! + * @brief check if vector is equal to another (with epsilon) + * + * @param v1 vector + * @param v2 vector + */ +CGLM_INLINE +bool +glm_vec4_eqv_eps(vec3 v1, vec3 v2) { + return fabsf(v1[0] - v2[0]) <= FLT_EPSILON + && fabsf(v1[1] - v2[1]) <= FLT_EPSILON + && fabsf(v1[2] - v2[2]) <= FLT_EPSILON + && fabsf(v1[3] - v2[3]) <= FLT_EPSILON; +} + +/*! + * @brief max value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec4_max(vec4 v) { + float max; + + max = glm_vec_max(v); + if (v[3] > max) + max = v[3]; + + return max; +} + +/*! + * @brief min value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec4_min(vec4 v) { + float min; + + min = glm_vec_min(v); + if (v[3] < min) + min = v[3]; + + return min; +} + +#endif /* cglm_vec4_ext_h */ + diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h new file mode 100644 index 0000000..275d49d --- /dev/null +++ b/include/cglm/vec4.h @@ -0,0 +1,402 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot) + * all functions without suffix are vec3 functions + */ + +/* + Macros: + glm_vec4_dup3(v, dest) + glm_vec4_dup(v, dest) + GLM_VEC4_ONE_INIT + GLM_VEC4_BLACK_INIT + GLM_VEC4_ONE + GLM_VEC4_BLACK + + Functions: + CGLM_INLINE void glm_vec4(vec3 v3, float last, vec4 dest); + CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); + CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest); + CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); + CGLM_INLINE float glm_vec4_norm2(vec4 v); + CGLM_INLINE float glm_vec4_norm(vec4 vec); + CGLM_INLINE void glm_vec4_add(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_flipsign(vec4 v); + CGLM_INLINE void glm_vec4_inv(vec4 v); + CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); + CGLM_INLINE void glm_vec4_normalize(vec4 v); + CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest); + CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); + CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest); + */ + +#ifndef cglm_vec4_h +#define cglm_vec4_h + +#include "common.h" +#include "vec4-ext.h" +#include "util.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) +#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) + +#define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} +#define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} + +#define GLM_VEC4_ONE (vec4)GLM_VEC4_ONE_INIT +#define GLM_VEC4_BLACK (vec4)GLM_VEC4_BLACK_INIT + +/*! + * @brief init vec4 using vec3 + * + * @param[in] v3 vector3 + * @param[in] last last item + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4(vec3 v3, float last, vec4 dest) { + dest[0] = v3[0]; + dest[1] = v3[1]; + dest[2] = v3[2]; + dest[3] = last; +} + +/*! + * @brief copy first 3 members of [a] to [dest] + * + * @param[in] a source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_copy3(vec4 a, vec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_copy(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_load_ps(v)); +#else + dest[0] = v[0]; + dest[1] = v[1]; + dest[2] = v[2]; + dest[3] = v[3]; +#endif +} + +/*! + * @brief vec4 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_vec4_dot(vec4 a, vec4 b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +} + +/*! + * @brief norm * norm (magnitude) of vec + * + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * not good name for this func + * + * @param[in] v vec4 + * + * @return norm * norm + */ +CGLM_INLINE +float +glm_vec4_norm2(vec4 v) { + return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; +} + +/*! + * @brief norm (magnitude) of vec4 + * + * @param[in] vec vector + * + * @return norm + */ +CGLM_INLINE +float +glm_vec4_norm(vec4 vec) { + return sqrtf(glm_vec4_norm2(vec)); +} + +/*! + * @brief add v2 vector to v1 vector store result in dest + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_add(vec4 v1, vec4 v2, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, + _mm_add_ps(_mm_load_ps(v1), + _mm_load_ps(v2))); +#else + dest[0] = v1[0] + v2[0]; + dest[1] = v1[1] + v2[1]; + dest[2] = v1[2] + v2[2]; + dest[3] = v1[3] + v2[3]; +#endif +} + +/*! + * @brief subtract v2 vector from v1 vector store result in dest + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, + _mm_sub_ps(_mm_load_ps(v1), + _mm_load_ps(v2))); +#else + dest[0] = v1[0] - v2[0]; + dest[1] = v1[1] - v2[1]; + dest[2] = v1[2] - v2[2]; + dest[3] = v1[3] - v2[3]; +#endif +} + +/*! + * @brief multiply/scale vec4 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_scale(vec4 v, float s, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, + _mm_mul_ps(_mm_load_ps(v), + _mm_set1_ps(s))); +#else + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; + dest[3] = v[3] * s; +#endif +} + +/*! + * @brief make vec4 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_scale_as(vec4 v, float s, vec4 dest) { + float norm; + norm = glm_vec4_norm(v); + + if (norm == 0) { + glm_vec4_copy(v, dest); + return; + } + + glm_vec4_scale(v, s / norm, dest); +} + +/*! + * @brief flip sign of all vec4 members + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_flipsign(vec4 v) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(v, _mm_xor_ps(_mm_load_ps(v), + _mm_set1_ps(-0.0f))); +#else + v[0] = -v[0]; + v[1] = -v[1]; + v[2] = -v[2]; + v[3] = -v[3]; +#endif +} + +/*! + * @brief make vector as inverse/opposite of itself + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_inv(vec4 v) { + glm_vec4_flipsign(v); +} + +/*! + * @brief inverse/opposite vector + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_inv_to(vec4 v, vec4 dest) { + glm_vec4_copy(v, dest); + glm_vec4_flipsign(dest); +} + +/*! + * @brief normalize vec4 and store result in same vec + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_normalize(vec4 v) { + float norm; + + norm = glm_vec4_norm(v); + + if (norm == 0.0f) { + v[0] = v[1] = v[2] = v[3] = 0.0f; + return; + } + + glm_vec4_scale(v, 1.0f / norm, v); +} + +/*! + * @brief normalize vec4 to dest + * + * @param[in] vec source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_normalize_to(vec4 vec, vec4 dest) { + float norm; + + norm = glm_vec4_norm(vec); + + if (norm == 0.0f) { + dest[0] = dest[1] = dest[2] = dest[3] = 0.0f; + return; + } + + glm_vec4_scale(vec, 1.0f / norm, dest); +} + +/** + * @brief distance between two vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @return returns distance + */ +CGLM_INLINE +float +glm_vec4_distance(vec4 v1, vec4 v2) { + return sqrtf(glm_pow2(v2[0] - v1[0]) + + glm_pow2(v2[1] - v1[1]) + + glm_pow2(v2[2] - v1[2]) + + glm_pow2(v2[3] - v1[3])); +} + +/*! + * @brief max values of vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { + if (v1[0] > v2[0]) + dest[0] = v1[0]; + else + dest[0] = v2[0]; + + if (v1[1] > v2[1]) + dest[1] = v1[1]; + else + dest[1] = v2[1]; + + if (v1[2] > v2[2]) + dest[2] = v1[2]; + else + dest[2] = v2[2]; + + if (v1[3] > v2[3]) + dest[3] = v1[3]; + else + dest[3] = v2[3]; +} + +/*! + * @brief min values of vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { + if (v1[0] < v2[0]) + dest[0] = v1[0]; + else + dest[0] = v2[0]; + + if (v1[1] < v2[1]) + dest[1] = v1[1]; + else + dest[1] = v2[1]; + + if (v1[2] < v2[2]) + dest[2] = v1[2]; + else + dest[2] = v2[2]; + + if (v1[3] < v2[3]) + dest[3] = v1[3]; + else + dest[3] = v2[3]; +} + +#endif /* cglm_vec4_h */ diff --git a/include/cglm/version.h b/include/cglm/version.h new file mode 100644 index 0000000..ce2f784 --- /dev/null +++ b/include/cglm/version.h @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_version_h +#define cglm_version_h + +#define CGLM_VERSION_MAJOR 0 +#define CGLM_VERSION_MINOR 3 +#define CGLM_VERSION_PATCH 3 + +#endif /* cglm_version_h */ diff --git a/include/cimgui.h b/include/cimgui.h new file mode 120000 index 0000000..76f81c7 --- /dev/null +++ b/include/cimgui.h @@ -0,0 +1 @@ +../lib/cimgui/cimgui/cimgui.h \ No newline at end of file diff --git a/include/ctexteditor.h b/include/ctexteditor.h new file mode 120000 index 0000000..0e32e27 --- /dev/null +++ b/include/ctexteditor.h @@ -0,0 +1 @@ +../lib/imguicolortextedit/ctexteditor.h \ No newline at end of file diff --git a/include/duk_config.h b/include/duk_config.h new file mode 100644 index 0000000..51e973f --- /dev/null +++ b/include/duk_config.h @@ -0,0 +1,3672 @@ +/* + * duk_config.h configuration header generated by genconfig.py. + * + * Git commit: 25420e773c5fbc50d5b46bf487fc45717e35b94f + * Git describe: v2.2.1 + * Git branch: v2.2-maintenance + * + * Supported platforms: + * - Mac OSX, iPhone, Darwin + * - Orbis + * - OpenBSD + * - Generic BSD + * - Atari ST TOS + * - AmigaOS + * - Durango (XboxOne) + * - Windows + * - Flashplayer (Crossbridge) + * - QNX + * - TI-Nspire + * - Emscripten + * - Linux + * - Solaris + * - AIX + * - HPUX + * - Generic POSIX + * - Cygwin + * - Generic UNIX + * - Generic fallback + * + * Supported architectures: + * - x86 + * - x64 + * - x32 + * - ARM 32-bit + * - ARM 64-bit + * - MIPS 32-bit + * - MIPS 64-bit + * - PowerPC 32-bit + * - PowerPC 64-bit + * - SPARC 32-bit + * - SPARC 64-bit + * - SuperH + * - Motorola 68k + * - Emscripten + * - Generic + * + * Supported compilers: + * - Clang + * - GCC + * - MSVC + * - Emscripten + * - TinyC + * - VBCC + * - Bruce's C compiler + * - Generic + * + */ + +#if !defined(DUK_CONFIG_H_INCLUDED) +#define DUK_CONFIG_H_INCLUDED + +/* + * Intermediate helper defines + */ + +/* DLL build detection */ +/* not configured for DLL build */ +#undef DUK_F_DLL_BUILD + +/* Apple OSX, iOS */ +#if defined(__APPLE__) +#define DUK_F_APPLE +#endif + +/* FreeBSD */ +#if defined(__FreeBSD__) || defined(__FreeBSD) +#define DUK_F_FREEBSD +#endif + +/* Orbis (PS4) variant */ +#if defined(DUK_F_FREEBSD) && defined(__ORBIS__) +#define DUK_F_ORBIS +#endif + +/* OpenBSD */ +#if defined(__OpenBSD__) || defined(__OpenBSD) +#define DUK_F_OPENBSD +#endif + +/* NetBSD */ +#if defined(__NetBSD__) || defined(__NetBSD) +#define DUK_F_NETBSD +#endif + +/* BSD variant */ +#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \ + defined(__bsdi__) || defined(__DragonFly__) +#define DUK_F_BSD +#endif + +/* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC + * apparently, so to use with VBCC user must define __TOS__ manually. + */ +#if defined(__TOS__) +#define DUK_F_TOS +#endif + +/* Motorola 68K. Not defined by VBCC, so user must define one of these + * manually when using VBCC. + */ +#if defined(__m68k__) || defined(M68000) || defined(__MC68K__) +#define DUK_F_M68K +#endif + +/* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must + * define 'AMIGA' manually when using VBCC. + */ +#if defined(AMIGA) || defined(__amigaos__) +#define DUK_F_AMIGAOS +#endif + +/* PowerPC */ +#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__) +#define DUK_F_PPC +#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64) +#define DUK_F_PPC64 +#else +#define DUK_F_PPC32 +#endif +#endif + +/* Durango (Xbox One) */ +#if defined(_DURANGO) || defined(_XBOX_ONE) +#define DUK_F_DURANGO +#endif + +/* Windows, both 32-bit and 64-bit */ +#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \ + defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) +#define DUK_F_WINDOWS +#if defined(_WIN64) || defined(WIN64) +#define DUK_F_WIN64 +#else +#define DUK_F_WIN32 +#endif +#endif + +/* Flash player (e.g. Crossbridge) */ +#if defined(__FLASHPLAYER__) +#define DUK_F_FLASHPLAYER +#endif + +/* QNX */ +#if defined(__QNX__) +#define DUK_F_QNX +#endif + +/* TI-Nspire (using Ndless) */ +#if defined(_TINSPIRE) +#define DUK_F_TINSPIRE +#endif + +/* Emscripten (provided explicitly by user), improve if possible */ +#if defined(EMSCRIPTEN) +#define DUK_F_EMSCRIPTEN +#endif + +/* BCC (Bruce's C compiler): this is a "torture target" for compilation */ +#if defined(__BCC__) || defined(__BCC_VERSION__) +#define DUK_F_BCC +#endif + +/* Linux */ +#if defined(__linux) || defined(__linux__) || defined(linux) +#define DUK_F_LINUX +#endif + +/* illumos / Solaris */ +#if defined(__sun) && defined(__SVR4) +#define DUK_F_SUN +#if defined(__SUNPRO_C) && (__SUNPRO_C < 0x550) +#define DUK_F_OLD_SOLARIS +/* Defines _ILP32 / _LP64 required by DUK_F_X86/DUK_F_X64. Platforms + * are processed before architectures, so this happens before the + * DUK_F_X86/DUK_F_X64 detection is emitted. + */ +#include +#endif +#endif + +/* AIX */ +#if defined(_AIX) +/* defined(__xlc__) || defined(__IBMC__): works but too wide */ +#define DUK_F_AIX +#endif + +/* HPUX */ +#if defined(__hpux) +#define DUK_F_HPUX +#if defined(__ia64) +#define DUK_F_HPUX_ITANIUM +#endif +#endif + +/* POSIX */ +#if defined(__posix) +#define DUK_F_POSIX +#endif + +/* Cygwin */ +#if defined(__CYGWIN__) +#define DUK_F_CYGWIN +#endif + +/* Generic Unix (includes Cygwin) */ +#if defined(__unix) || defined(__unix__) || defined(unix) || \ + defined(DUK_F_LINUX) || defined(DUK_F_BSD) +#define DUK_F_UNIX +#endif + +/* C++ */ +#undef DUK_F_CPP +#if defined(__cplusplus) +#define DUK_F_CPP +#endif + +/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers), + * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32. + * https://sites.google.com/site/x32abi/ + * + * With DUK_F_OLD_SOLARIS the header must be included + * before this. + */ +#if defined(__amd64__) || defined(__amd64) || \ + defined(__x86_64__) || defined(__x86_64) || \ + defined(_M_X64) || defined(_M_AMD64) +#if defined(__ILP32__) || defined(_ILP32) +#define DUK_F_X32 +#else +#define DUK_F_X64 +#endif +#elif defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(__i486__) || defined(__i586__) || defined(__i686__) || \ + defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \ + defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) +#if defined(__LP64__) || defined(_LP64) +/* This should not really happen, but would indicate x64. */ +#define DUK_F_X64 +#else +#define DUK_F_X86 +#endif +#endif + +/* ARM */ +#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM) || defined(__aarch64__) +#define DUK_F_ARM +#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) +#define DUK_F_ARM64 +#else +#define DUK_F_ARM32 +#endif +#endif + +/* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */ +#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \ + defined(_R3000) || defined(_R4000) || defined(_R5900) || \ + defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \ + defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \ + defined(__mips) || defined(__MIPS__) +#define DUK_F_MIPS +#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \ + defined(__mips64__) || defined(__mips_n64) +#define DUK_F_MIPS64 +#else +#define DUK_F_MIPS32 +#endif +#endif + +/* SPARC */ +#if defined(sparc) || defined(__sparc) || defined(__sparc__) +#define DUK_F_SPARC +#if defined(__LP64__) || defined(_LP64) +#define DUK_F_SPARC64 +#else +#define DUK_F_SPARC32 +#endif +#endif + +/* SuperH */ +#if defined(__sh__) || \ + defined(__sh1__) || defined(__SH1__) || \ + defined(__sh2__) || defined(__SH2__) || \ + defined(__sh3__) || defined(__SH3__) || \ + defined(__sh4__) || defined(__SH4__) || \ + defined(__sh5__) || defined(__SH5__) +#define DUK_F_SUPERH +#endif + +/* Clang */ +#if defined(__clang__) +#define DUK_F_CLANG +#endif + +/* C99 or above */ +#undef DUK_F_C99 +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define DUK_F_C99 +#endif + +/* C++11 or above */ +#undef DUK_F_CPP11 +#if defined(__cplusplus) && (__cplusplus >= 201103L) +#define DUK_F_CPP11 +#endif + +/* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */ +#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG) +#define DUK_F_GCC +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */ +#define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__) +#else +#error cannot figure out gcc version +#endif +#endif + +/* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */ +#if defined(__MINGW32__) || defined(__MINGW64__) +#define DUK_F_MINGW +#endif + +/* MSVC */ +#if defined(_MSC_VER) +/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx + * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g. + * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp + */ +#define DUK_F_MSVC +#if defined(_MSC_FULL_VER) +#if (_MSC_FULL_VER > 100000000) +#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER +#else +#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10) +#endif +#endif +#endif /* _MSC_VER */ + +/* TinyC */ +#if defined(__TINYC__) +/* http://bellard.org/tcc/tcc-doc.html#SEC9 */ +#define DUK_F_TINYC +#endif + +/* VBCC */ +#if defined(__VBCC__) +#define DUK_F_VBCC +#endif + +#if defined(ANDROID) || defined(__ANDROID__) +#define DUK_F_ANDROID +#endif + +/* Atari Mint */ +#if defined(__MINT__) +#define DUK_F_MINT +#endif + +/* + * Platform autodetection + */ + +/* Workaround for older C++ compilers before including , + * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366 + */ +#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS) +#define __STDC_LIMIT_MACROS +#endif +#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) +#define __STDC_CONSTANT_MACROS +#endif + +#if defined(DUK_F_APPLE) +/* --- Mac OSX, iPhone, Darwin --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */ +#if TARGET_IPHONE_SIMULATOR +#define DUK_USE_OS_STRING "iphone-sim" +#elif TARGET_OS_IPHONE +#define DUK_USE_OS_STRING "iphone" +#elif TARGET_OS_MAC +#define DUK_USE_OS_STRING "osx" +#else +#define DUK_USE_OS_STRING "osx-unknown" +#endif + +/* Use _setjmp() on Apple by default, see GH-55. */ +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) _setjmp((jb)) +#define DUK_LONGJMP(jb) _longjmp((jb), 1) +#elif defined(DUK_F_ORBIS) +/* --- Orbis --- */ +/* Orbis = PS4 */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_S +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "orbis" +#elif defined(DUK_F_OPENBSD) +/* --- OpenBSD --- */ +/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "openbsd" +#elif defined(DUK_F_BSD) +/* --- Generic BSD --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "bsd" +#elif defined(DUK_F_TOS) +/* --- Atari ST TOS --- */ +#define DUK_USE_DATE_NOW_TIME +#define DUK_USE_DATE_TZO_GMTIME +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include + +#define DUK_USE_OS_STRING "tos" + +/* TOS on M68K is always big endian. */ +#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K) +#define DUK_USE_BYTEORDER 3 +#endif +#elif defined(DUK_F_AMIGAOS) +/* --- AmigaOS --- */ +#if defined(DUK_F_M68K) +/* AmigaOS on M68k */ +#define DUK_USE_DATE_NOW_TIME +#define DUK_USE_DATE_TZO_GMTIME +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include +#elif defined(DUK_F_PPC) +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#if !defined(UINTPTR_MAX) +#define UINTPTR_MAX UINT_MAX +#endif +#else +#error AmigaOS but not M68K/PPC, not supported now +#endif + +#define DUK_USE_OS_STRING "amigaos" + +/* AmigaOS on M68K or PPC is always big endian. */ +#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC)) +#define DUK_USE_BYTEORDER 3 +#endif +#elif defined(DUK_F_DURANGO) +/* --- Durango (XboxOne) --- */ +/* Durango = XboxOne + * Configuration is nearly identical to Windows, except for + * DUK_USE_DATE_TZO_WINDOWS. + */ + +/* Initial fix: disable secure CRT related warnings when compiling Duktape + * itself (must be defined before including Windows headers). Don't define + * for user code including duktape.h. + */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +/* MSVC does not have sys/param.h */ +#define DUK_USE_DATE_NOW_WINDOWS +#define DUK_USE_DATE_TZO_WINDOWS_NO_DST +/* Note: PRS and FMT are intentionally left undefined for now. This means + * there is no platform specific date parsing/formatting but there is still + * the ISO 8601 standard format. + */ +#if defined(DUK_COMPILING_DUKTAPE) +/* Only include when compiling Duktape to avoid polluting application build + * with a lot of unnecessary defines. + */ +#include +#endif + +#define DUK_USE_OS_STRING "durango" + +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#elif defined(DUK_F_WINDOWS) +/* --- Windows --- */ +/* Windows version can't obviously be determined at compile time, + * but _WIN32_WINNT indicates the minimum version targeted: + * - https://msdn.microsoft.com/en-us/library/6sehtctf.aspx + */ + +/* Initial fix: disable secure CRT related warnings when compiling Duktape + * itself (must be defined before including Windows headers). Don't define + * for user code including duktape.h. + */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +/* Windows 32-bit and 64-bit are currently the same. */ +/* MSVC does not have sys/param.h */ + +#if defined(DUK_COMPILING_DUKTAPE) +/* Only include when compiling Duktape to avoid polluting application build + * with a lot of unnecessary defines. + */ +#include +#endif + +/* GetSystemTimePreciseAsFileTime() available from Windows 8: + * https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx + */ +#if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) || defined(DUK_USE_DATE_NOW_WINDOWS) +/* User forced provider. */ +#else +#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602) +#define DUK_USE_DATE_NOW_WINDOWS_SUBMS +#else +#define DUK_USE_DATE_NOW_WINDOWS +#endif +#endif + +#define DUK_USE_DATE_TZO_WINDOWS + +/* Note: PRS and FMT are intentionally left undefined for now. This means + * there is no platform specific date parsing/formatting but there is still + * the ISO 8601 standard format. + */ + +/* QueryPerformanceCounter() may go backwards in Windows XP, so enable for + * Vista and later: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions + */ +#if !defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) && \ + defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) +#define DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC +#endif + +#define DUK_USE_OS_STRING "windows" + +/* On Windows, assume we're little endian. Even Itanium which has a + * configurable endianness runs little endian in Windows. + */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#elif defined(DUK_F_FLASHPLAYER) +/* --- Flashplayer (Crossbridge) --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "flashplayer" + +#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER) +#define DUK_USE_BYTEORDER 1 +#endif +#elif defined(DUK_F_QNX) +/* --- QNX --- */ +#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE) +/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */ +#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200112L +#endif + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "qnx" +#elif defined(DUK_F_TINSPIRE) +/* --- TI-Nspire --- */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "tinspire" +#elif defined(DUK_F_EMSCRIPTEN) +/* --- Emscripten --- */ +#if defined(DUK_COMPILING_DUKTAPE) +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE /* e.g. getdate_r */ +#endif +#if !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif +#endif /* DUK_COMPILING_DUKTAPE */ + +#include +#if defined(DUK_F_BCC) +/* no endian.h */ +#else +#include +#endif /* DUK_F_BCC */ +#include +#include +#include +#include + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#define DUK_USE_OS_STRING "emscripten" +#elif defined(DUK_F_LINUX) +/* --- Linux --- */ +#if defined(DUK_COMPILING_DUKTAPE) +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE /* e.g. getdate_r */ +#endif +#if !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif +#endif /* DUK_COMPILING_DUKTAPE */ + +#include +#if defined(DUK_F_BCC) +/* no endian.h or stdint.h */ +#else +#include +#include +#endif /* DUK_F_BCC */ +#include +#include +#include + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#if 0 /* XXX: safe condition? */ +#define DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME +#endif + +#define DUK_USE_OS_STRING "linux" +#elif defined(DUK_F_SUN) +/* --- Solaris --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#include +#if defined(DUK_F_OLD_SOLARIS) +/* Old Solaris with no endian.h, stdint.h */ +#define DUK_F_NO_STDINT_H +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#else /* DUK_F_OLD_SOLARIS */ +#include +#endif /* DUK_F_OLD_SOLARIS */ + +#include +#include +#include + +#define DUK_USE_OS_STRING "solaris" +#elif defined(DUK_F_AIX) +/* --- AIX --- */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include + +#define DUK_USE_OS_STRING "aix" +#elif defined(DUK_F_HPUX) +/* --- HPUX --- */ +#define DUK_F_NO_STDINT_H +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include + +#define DUK_USE_OS_STRING "hpux" +#elif defined(DUK_F_POSIX) +/* --- Generic POSIX --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "posix" +#elif defined(DUK_F_CYGWIN) +/* --- Cygwin --- */ +/* don't use strptime() for now */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) _setjmp((jb)) +#define DUK_LONGJMP(jb) _longjmp((jb), 1) + +#define DUK_USE_OS_STRING "windows" +#elif defined(DUK_F_UNIX) +/* --- Generic UNIX --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#define DUK_USE_OS_STRING "unknown" +#else +/* --- Generic fallback --- */ +/* The most portable current time provider is time(), but it only has a + * one second resolution. + */ +#define DUK_USE_DATE_NOW_TIME + +/* The most portable way to figure out local time offset is gmtime(), + * but it's not thread safe so use with caution. + */ +#define DUK_USE_DATE_TZO_GMTIME + +/* Avoid custom date parsing and formatting for portability. */ +#undef DUK_USE_DATE_PRS_STRPTIME +#undef DUK_USE_DATE_FMT_STRFTIME + +/* Rely on C89 headers only; time.h must be here. */ +#include + +#define DUK_USE_OS_STRING "unknown" +#endif /* autodetect platform */ + +/* Shared includes: C89 */ +#include +#include +#include +#include /* varargs */ +#include +#include /* e.g. ptrdiff_t */ +#include +#include + +/* date.h is omitted, and included per platform */ + +/* Shared includes: stdint.h is C99 */ +#if defined(DUK_F_NO_STDINT_H) +/* stdint.h not available */ +#else +/* Technically C99 (C++11) but found in many systems. On some systems + * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before + * including stdint.h (see above). + */ +#include +#endif + +#if defined(DUK_F_CPP) +#include /* std::exception */ +#endif + +/* + * Architecture autodetection + */ + +#if defined(DUK_F_X86) +/* --- x86 --- */ +#define DUK_USE_ARCH_STRING "x86" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +/* XXX: This is technically not guaranteed because it's possible to configure + * an x86 to require aligned accesses with Alignment Check (AC) flag. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 1 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_X64) +/* --- x64 --- */ +#define DUK_USE_ARCH_STRING "x64" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +/* XXX: This is technically not guaranteed because it's possible to configure + * an x86 to require aligned accesses with Alignment Check (AC) flag. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 1 +#endif +#undef DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_X32) +/* --- x32 --- */ +#define DUK_USE_ARCH_STRING "x32" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +/* XXX: This is technically not guaranteed because it's possible to configure + * an x86 to require aligned accesses with Alignment Check (AC) flag. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 1 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_ARM32) +/* --- ARM 32-bit --- */ +#define DUK_USE_ARCH_STRING "arm32" +/* Byte order varies, so rely on autodetect. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 4 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_ARM64) +/* --- ARM 64-bit --- */ +#define DUK_USE_ARCH_STRING "arm64" +/* Byte order varies, so rely on autodetect. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_MIPS32) +/* --- MIPS 32-bit --- */ +#define DUK_USE_ARCH_STRING "mips32" +/* MIPS byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_MIPS64) +/* --- MIPS 64-bit --- */ +#define DUK_USE_ARCH_STRING "mips64" +/* MIPS byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_PPC32) +/* --- PowerPC 32-bit --- */ +#define DUK_USE_ARCH_STRING "ppc32" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_PPC64) +/* --- PowerPC 64-bit --- */ +#define DUK_USE_ARCH_STRING "ppc64" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_SPARC32) +/* --- SPARC 32-bit --- */ +#define DUK_USE_ARCH_STRING "sparc32" +/* SPARC byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_SPARC64) +/* --- SPARC 64-bit --- */ +#define DUK_USE_ARCH_STRING "sparc64" +/* SPARC byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_SUPERH) +/* --- SuperH --- */ +#define DUK_USE_ARCH_STRING "sh" +/* Byte order varies, rely on autodetection. */ +/* Based on 'make checkalign' there are no alignment requirements on + * Linux SH4, but align by 4 is probably a good basic default. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 4 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_M68K) +/* --- Motorola 68k --- */ +#define DUK_USE_ARCH_STRING "m68k" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#elif defined(DUK_F_EMSCRIPTEN) +/* --- Emscripten --- */ +#define DUK_USE_ARCH_STRING "emscripten" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL +#define DUK_F_PACKED_TVAL_PROVIDED +#else +/* --- Generic --- */ +/* These are necessary wild guesses. */ +#define DUK_USE_ARCH_STRING "generic" +/* Rely on autodetection for byte order, alignment, and packed tval. */ +#endif /* autodetect architecture */ + +/* + * Compiler autodetection + */ + +#if defined(DUK_F_CLANG) +/* --- Clang --- */ +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +/* C99 / C++11 and above: rely on va_copy() which is required. */ +#define DUK_VA_COPY(dest,src) va_copy(dest,src) +#else +/* Clang: assume we have __va_copy() in non-C99 mode. */ +#define DUK_VA_COPY(dest,src) __va_copy(dest,src) +#endif + +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif +#endif + +#define DUK_USE_BRANCH_HINTS +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unpredictable) +#define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x)) +#endif +#endif + +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +/* DUK_HOT */ +/* DUK_COLD */ + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#else +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#endif + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "clang" +#else +#define DUK_USE_COMPILER_STRING "clang" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS +#define DUK_USE_PACK_CLANG_ATTR +#elif defined(DUK_F_GCC) +/* --- GCC --- */ +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +/* C99 / C++11 and above: rely on va_copy() which is required. */ +#define DUK_VA_COPY(dest,src) va_copy(dest,src) +#else +/* GCC: assume we have __va_copy() in non-C99 mode. */ +#define DUK_VA_COPY(dest,src) __va_copy(dest,src) +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L) +/* since gcc-2.5 */ +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L) +/* since gcc-4.5 */ +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif + +#define DUK_USE_BRANCH_HINTS +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L) +/* GCC: test not very accurate; enable only in relatively recent builds + * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html) + */ +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#endif +/* XXX: equivalent of clang __builtin_unpredictable? */ + +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \ + defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \ + defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40300) +#define DUK_HOT __attribute__((hot)) +#define DUK_COLD __attribute__((cold)) +#endif + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000) +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#endif + +#if defined(DUK_F_MINGW) +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "mingw++" +#else +#define DUK_USE_COMPILER_STRING "mingw" +#endif +#else +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "g++" +#else +#define DUK_USE_COMPILER_STRING "gcc" +#endif +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__)) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600) +#define DUK_USE_GCC_PRAGMAS +#else +#undef DUK_USE_GCC_PRAGMAS +#endif + +#define DUK_USE_PACK_GCC_ATTR +#elif defined(DUK_F_MSVC) +/* --- MSVC --- */ +/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */ +#define DUK_NORETURN(decl) __declspec(noreturn) decl + +/* XXX: DUK_UNREACHABLE for msvc? */ + +#undef DUK_USE_BRANCH_HINTS + +/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */ +/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */ + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#endif + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "msvc++" +#else +#define DUK_USE_COMPILER_STRING "msvc" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) +#define DUK_USE_VARIADIC_MACROS +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) +/* VS2005+ should have variadic macros even when they're not C99. */ +#define DUK_USE_VARIADIC_MACROS +#endif + +#undef DUK_USE_UNION_INITIALIZERS +#if defined(_MSC_VER) && (_MSC_VER >= 1800) +/* VS2013+ supports union initializers but there's a bug involving union-inside-struct: + * https://connect.microsoft.com/VisualStudio/feedback/details/805981 + * The bug was fixed (at least) in VS2015 so check for VS2015 for now: + * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/ + * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too. + */ +#define DUK_USE_UNION_INITIALIZERS +#endif + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS + +#define DUK_USE_PACK_MSVC_PRAGMA + +/* These have been tested from VS2008 onwards; may work in older VS versions + * too but not enabled by default. + */ +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +#define DUK_NOINLINE __declspec(noinline) +#define DUK_INLINE __inline +#define DUK_ALWAYS_INLINE __forceinline +#endif + +#if defined(_MSC_VER) && (_MSC_VER >= 1900) +#define DUK_SNPRINTF snprintf +#define DUK_VSNPRINTF vsnprintf +#else +/* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does + * NOT NUL terminate on truncation, but Duktape code never assumes that. + * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 + */ +#define DUK_SNPRINTF _snprintf +#define DUK_VSNPRINTF _vsnprintf +#endif + +/* Avoid warning when doing DUK_UNREF(some_function). */ +#if defined(_MSC_VER) && (_MSC_VER < 1500) +#pragma warning(disable: 4100 4101 4550 4551) +#define DUK_UNREF(x) +#else +#define DUK_UNREF(x) do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0) +#endif + +/* Older versions of MSVC don't support the LL/ULL suffix. */ +#define DUK_U64_CONSTANT(x) x##ui64 +#define DUK_I64_CONSTANT(x) x##i64 +#elif defined(DUK_F_EMSCRIPTEN) +/* --- Emscripten --- */ +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif +#endif + +#define DUK_USE_BRANCH_HINTS +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unpredictable) +#define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x)) +#endif +#endif + +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static + +#define DUK_USE_COMPILER_STRING "emscripten" + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS +#define DUK_USE_PACK_CLANG_ATTR +#elif defined(DUK_F_TINYC) +/* --- TinyC --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "tinyc++" +#else +#define DUK_USE_COMPILER_STRING "tinyc" +#endif + +/* http://bellard.org/tcc/tcc-doc.html#SEC7 */ +#define DUK_USE_VARIADIC_MACROS + +#define DUK_USE_UNION_INITIALIZERS + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER +#elif defined(DUK_F_VBCC) +/* --- VBCC --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "vbcc-c++" +#else +#define DUK_USE_COMPILER_STRING "vbcc" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +/* VBCC supports C99 so check only for C99 for union initializer support. + * Designated union initializers would possibly work even without a C99 check. + */ +#undef DUK_USE_UNION_INITIALIZERS +#if defined(DUK_F_C99) +#define DUK_USE_UNION_INITIALIZERS +#endif + +#define DUK_USE_FLEX_ZEROSIZE +#define DUK_USE_PACK_DUMMY_MEMBER +#elif defined(DUK_F_BCC) +/* --- Bruce's C compiler --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "bcc++" +#else +#define DUK_USE_COMPILER_STRING "bcc" +#endif + +/* Most portable */ +#undef DUK_USE_VARIADIC_MACROS + +/* Most portable, wastes space */ +#undef DUK_USE_UNION_INITIALIZERS + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER + +/* BCC, assume we're on x86. */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#else +/* --- Generic --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "generic-c++" +#else +#define DUK_USE_COMPILER_STRING "generic" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */ +#undef DUK_USE_UNION_INITIALIZERS +#if defined(DUK_F_C99) +#define DUK_USE_UNION_INITIALIZERS +#endif + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER +#endif /* autodetect compiler */ + +/* uclibc */ +#if defined(__UCLIBC__) +#define DUK_F_UCLIBC +#endif + +/* + * Wrapper typedefs and constants for integer types, also sanity check types. + * + * C99 typedefs are quite good but not always available, and we want to avoid + * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for + * all C99 typedefs and Duktape code should only use these typedefs. Type + * detection when C99 is not supported is best effort and may end up detecting + * some types incorrectly. + * + * Pointer sizes are a portability problem: pointers to different types may + * have a different size and function pointers are very difficult to manage + * portably. + * + * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types + * + * Note: there's an interesting corner case when trying to define minimum + * signed integer value constants which leads to the current workaround of + * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt + * for a longer discussion. + * + * Note: avoid typecasts and computations in macro integer constants as they + * can then no longer be used in macro relational expressions (such as + * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on + * being able to compare DUK_SIZE_MAX against a limit. + */ + +/* XXX: add feature options to force basic types from outside? */ + +#if !defined(INT_MAX) +#error INT_MAX not defined +#endif + +/* Check that architecture is two's complement, standard C allows e.g. + * INT_MIN to be -2**31+1 (instead of -2**31). + */ +#if defined(INT_MAX) && defined(INT_MIN) +#if INT_MAX != -(INT_MIN + 1) +#error platform does not seem complement of two +#endif +#else +#error cannot check complement of two +#endif + +/* Pointer size determination based on __WORDSIZE or architecture when + * that's not available. + */ +#if defined(DUK_F_X86) || defined(DUK_F_X32) || \ + defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \ + defined(DUK_F_BCC) || \ + (defined(__WORDSIZE) && (__WORDSIZE == 32)) || \ + ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \ + defined(DUK_F_HPUX)) && defined(_ILP32)) || \ + defined(DUK_F_ARM32) +#define DUK_F_32BIT_PTRS +#elif defined(DUK_F_X64) || \ + (defined(__WORDSIZE) && (__WORDSIZE == 64)) || \ + ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \ + defined(DUK_F_HPUX)) && defined(_LP64)) || \ + defined(DUK_F_ARM64) +#define DUK_F_64BIT_PTRS +#else +/* not sure, not needed with C99 anyway */ +#endif + +/* Intermediate define for 'have inttypes.h' */ +#undef DUK_F_HAVE_INTTYPES +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)) +/* vbcc + AmigaOS has C99 but no inttypes.h */ +#define DUK_F_HAVE_INTTYPES +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +/* C++11 apparently ratified stdint.h */ +#define DUK_F_HAVE_INTTYPES +#endif + +/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise + * through automatic detection. + */ +#if defined(DUK_F_HAVE_INTTYPES) +/* C99 or compatible */ + +#define DUK_F_HAVE_64BIT +#include + +typedef uint8_t duk_uint8_t; +typedef int8_t duk_int8_t; +typedef uint16_t duk_uint16_t; +typedef int16_t duk_int16_t; +typedef uint32_t duk_uint32_t; +typedef int32_t duk_int32_t; +typedef uint64_t duk_uint64_t; +typedef int64_t duk_int64_t; +typedef uint_least8_t duk_uint_least8_t; +typedef int_least8_t duk_int_least8_t; +typedef uint_least16_t duk_uint_least16_t; +typedef int_least16_t duk_int_least16_t; +typedef uint_least32_t duk_uint_least32_t; +typedef int_least32_t duk_int_least32_t; +typedef uint_least64_t duk_uint_least64_t; +typedef int_least64_t duk_int_least64_t; +typedef uint_fast8_t duk_uint_fast8_t; +typedef int_fast8_t duk_int_fast8_t; +typedef uint_fast16_t duk_uint_fast16_t; +typedef int_fast16_t duk_int_fast16_t; +typedef uint_fast32_t duk_uint_fast32_t; +typedef int_fast32_t duk_int_fast32_t; +typedef uint_fast64_t duk_uint_fast64_t; +typedef int_fast64_t duk_int_fast64_t; +typedef uintptr_t duk_uintptr_t; +typedef intptr_t duk_intptr_t; +typedef uintmax_t duk_uintmax_t; +typedef intmax_t duk_intmax_t; + +#define DUK_UINT8_MIN 0 +#define DUK_UINT8_MAX UINT8_MAX +#define DUK_INT8_MIN INT8_MIN +#define DUK_INT8_MAX INT8_MAX +#define DUK_UINT_LEAST8_MIN 0 +#define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX +#define DUK_INT_LEAST8_MIN INT_LEAST8_MIN +#define DUK_INT_LEAST8_MAX INT_LEAST8_MAX +#define DUK_UINT_FAST8_MIN 0 +#define DUK_UINT_FAST8_MAX UINT_FAST8_MAX +#define DUK_INT_FAST8_MIN INT_FAST8_MIN +#define DUK_INT_FAST8_MAX INT_FAST8_MAX +#define DUK_UINT16_MIN 0 +#define DUK_UINT16_MAX UINT16_MAX +#define DUK_INT16_MIN INT16_MIN +#define DUK_INT16_MAX INT16_MAX +#define DUK_UINT_LEAST16_MIN 0 +#define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX +#define DUK_INT_LEAST16_MIN INT_LEAST16_MIN +#define DUK_INT_LEAST16_MAX INT_LEAST16_MAX +#define DUK_UINT_FAST16_MIN 0 +#define DUK_UINT_FAST16_MAX UINT_FAST16_MAX +#define DUK_INT_FAST16_MIN INT_FAST16_MIN +#define DUK_INT_FAST16_MAX INT_FAST16_MAX +#define DUK_UINT32_MIN 0 +#define DUK_UINT32_MAX UINT32_MAX +#define DUK_INT32_MIN INT32_MIN +#define DUK_INT32_MAX INT32_MAX +#define DUK_UINT_LEAST32_MIN 0 +#define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX +#define DUK_INT_LEAST32_MIN INT_LEAST32_MIN +#define DUK_INT_LEAST32_MAX INT_LEAST32_MAX +#define DUK_UINT_FAST32_MIN 0 +#define DUK_UINT_FAST32_MAX UINT_FAST32_MAX +#define DUK_INT_FAST32_MIN INT_FAST32_MIN +#define DUK_INT_FAST32_MAX INT_FAST32_MAX +#define DUK_UINT64_MIN 0 +#define DUK_UINT64_MAX UINT64_MAX +#define DUK_INT64_MIN INT64_MIN +#define DUK_INT64_MAX INT64_MAX +#define DUK_UINT_LEAST64_MIN 0 +#define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX +#define DUK_INT_LEAST64_MIN INT_LEAST64_MIN +#define DUK_INT_LEAST64_MAX INT_LEAST64_MAX +#define DUK_UINT_FAST64_MIN 0 +#define DUK_UINT_FAST64_MAX UINT_FAST64_MAX +#define DUK_INT_FAST64_MIN INT_FAST64_MIN +#define DUK_INT_FAST64_MAX INT_FAST64_MAX + +#define DUK_UINTPTR_MIN 0 +#define DUK_UINTPTR_MAX UINTPTR_MAX +#define DUK_INTPTR_MIN INTPTR_MIN +#define DUK_INTPTR_MAX INTPTR_MAX + +#define DUK_UINTMAX_MIN 0 +#define DUK_UINTMAX_MAX UINTMAX_MAX +#define DUK_INTMAX_MIN INTMAX_MIN +#define DUK_INTMAX_MAX INTMAX_MAX + +#define DUK_SIZE_MIN 0 +#define DUK_SIZE_MAX SIZE_MAX +#undef DUK_SIZE_MAX_COMPUTED + +#else /* C99 types */ + +/* When C99 types are not available, we use heuristic detection to get + * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least + * types are then assumed to be exactly the same for now: these could + * be improved per platform but C99 types are very often now available. + * 64-bit types are not available on all platforms; this is OK at least + * on 32-bit platforms. + * + * This detection code is necessarily a bit hacky and can provide typedefs + * and defines that won't work correctly on some exotic platform. + */ + +#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \ + (defined(UCHAR_MAX) && (UCHAR_MAX == 255)) +typedef unsigned char duk_uint8_t; +typedef signed char duk_int8_t; +#else +#error cannot detect 8-bit type +#endif + +#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL) +typedef unsigned short duk_uint16_t; +typedef signed short duk_int16_t; +#elif defined(UINT_MAX) && (UINT_MAX == 65535UL) +/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ +typedef unsigned int duk_uint16_t; +typedef signed int duk_int16_t; +#else +#error cannot detect 16-bit type +#endif + +#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL) +typedef unsigned int duk_uint32_t; +typedef signed int duk_int32_t; +#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL) +/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ +typedef unsigned long duk_uint32_t; +typedef signed long duk_int32_t; +#else +#error cannot detect 32-bit type +#endif + +/* 64-bit type detection is a bit tricky. + * + * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__ + * are used by at least GCC (even if system headers don't provide ULLONG_MAX). + * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__. + * + * ULL / LL constants are rejected / warned about by some compilers, even if + * the compiler has a 64-bit type and the compiler/system headers provide an + * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants. + * As a side effect we can only check that e.g. ULONG_MAX is larger than 32 + * bits but can't be sure it is exactly 64 bits. Self tests will catch such + * cases. + */ +#undef DUK_F_HAVE_64BIT +#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX) +#if (ULONG_MAX > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long duk_uint64_t; +typedef signed long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX) +#if (ULLONG_MAX > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__) +#if (__ULONG_LONG_MAX__ > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__) +#if (__LONG_LONG_MAX__ > 2147483647L) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MINGW) +#define DUK_F_HAVE_64BIT +typedef unsigned long duk_uint64_t; +typedef signed long duk_int64_t; +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MSVC) +#define DUK_F_HAVE_64BIT +typedef unsigned __int64 duk_uint64_t; +typedef signed __int64 duk_int64_t; +#endif +#if !defined(DUK_F_HAVE_64BIT) +/* cannot detect 64-bit type, not always needed so don't error */ +#endif + +typedef duk_uint8_t duk_uint_least8_t; +typedef duk_int8_t duk_int_least8_t; +typedef duk_uint16_t duk_uint_least16_t; +typedef duk_int16_t duk_int_least16_t; +typedef duk_uint32_t duk_uint_least32_t; +typedef duk_int32_t duk_int_least32_t; +typedef duk_uint8_t duk_uint_fast8_t; +typedef duk_int8_t duk_int_fast8_t; +typedef duk_uint16_t duk_uint_fast16_t; +typedef duk_int16_t duk_int_fast16_t; +typedef duk_uint32_t duk_uint_fast32_t; +typedef duk_int32_t duk_int_fast32_t; +#if defined(DUK_F_HAVE_64BIT) +typedef duk_uint64_t duk_uint_least64_t; +typedef duk_int64_t duk_int_least64_t; +typedef duk_uint64_t duk_uint_fast64_t; +typedef duk_int64_t duk_int_fast64_t; +#endif +#if defined(DUK_F_HAVE_64BIT) +typedef duk_uint64_t duk_uintmax_t; +typedef duk_int64_t duk_intmax_t; +#else +typedef duk_uint32_t duk_uintmax_t; +typedef duk_int32_t duk_intmax_t; +#endif + +/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and + * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are + * -not- portable. See code-issues.txt for a detailed discussion. + */ +#define DUK_UINT8_MIN 0UL +#define DUK_UINT8_MAX 0xffUL +#define DUK_INT8_MIN (-0x80L) +#define DUK_INT8_MAX 0x7fL +#define DUK_UINT_LEAST8_MIN 0UL +#define DUK_UINT_LEAST8_MAX 0xffUL +#define DUK_INT_LEAST8_MIN (-0x80L) +#define DUK_INT_LEAST8_MAX 0x7fL +#define DUK_UINT_FAST8_MIN 0UL +#define DUK_UINT_FAST8_MAX 0xffUL +#define DUK_INT_FAST8_MIN (-0x80L) +#define DUK_INT_FAST8_MAX 0x7fL +#define DUK_UINT16_MIN 0UL +#define DUK_UINT16_MAX 0xffffUL +#define DUK_INT16_MIN (-0x7fffL - 1L) +#define DUK_INT16_MAX 0x7fffL +#define DUK_UINT_LEAST16_MIN 0UL +#define DUK_UINT_LEAST16_MAX 0xffffUL +#define DUK_INT_LEAST16_MIN (-0x7fffL - 1L) +#define DUK_INT_LEAST16_MAX 0x7fffL +#define DUK_UINT_FAST16_MIN 0UL +#define DUK_UINT_FAST16_MAX 0xffffUL +#define DUK_INT_FAST16_MIN (-0x7fffL - 1L) +#define DUK_INT_FAST16_MAX 0x7fffL +#define DUK_UINT32_MIN 0UL +#define DUK_UINT32_MAX 0xffffffffUL +#define DUK_INT32_MIN (-0x7fffffffL - 1L) +#define DUK_INT32_MAX 0x7fffffffL +#define DUK_UINT_LEAST32_MIN 0UL +#define DUK_UINT_LEAST32_MAX 0xffffffffUL +#define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L) +#define DUK_INT_LEAST32_MAX 0x7fffffffL +#define DUK_UINT_FAST32_MIN 0UL +#define DUK_UINT_FAST32_MAX 0xffffffffUL +#define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L) +#define DUK_INT_FAST32_MAX 0x7fffffffL + +/* 64-bit constants. Since LL / ULL constants are not always available, + * use computed values. These values can't be used in preprocessor + * comparisons; flag them as such. + */ +#if defined(DUK_F_HAVE_64BIT) +#define DUK_UINT64_MIN ((duk_uint64_t) 0) +#define DUK_UINT64_MAX ((duk_uint64_t) -1) +#define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1))) +#define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1)) +#define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN +#define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX +#define DUK_INT_LEAST64_MIN DUK_INT64_MIN +#define DUK_INT_LEAST64_MAX DUK_INT64_MAX +#define DUK_UINT_FAST64_MIN DUK_UINT64_MIN +#define DUK_UINT_FAST64_MAX DUK_UINT64_MAX +#define DUK_INT_FAST64_MIN DUK_INT64_MIN +#define DUK_INT_FAST64_MAX DUK_INT64_MAX +#define DUK_UINT64_MIN_COMPUTED +#define DUK_UINT64_MAX_COMPUTED +#define DUK_INT64_MIN_COMPUTED +#define DUK_INT64_MAX_COMPUTED +#define DUK_UINT_LEAST64_MIN_COMPUTED +#define DUK_UINT_LEAST64_MAX_COMPUTED +#define DUK_INT_LEAST64_MIN_COMPUTED +#define DUK_INT_LEAST64_MAX_COMPUTED +#define DUK_UINT_FAST64_MIN_COMPUTED +#define DUK_UINT_FAST64_MAX_COMPUTED +#define DUK_INT_FAST64_MIN_COMPUTED +#define DUK_INT_FAST64_MAX_COMPUTED +#endif + +#if defined(DUK_F_HAVE_64BIT) +#define DUK_UINTMAX_MIN DUK_UINT64_MIN +#define DUK_UINTMAX_MAX DUK_UINT64_MAX +#define DUK_INTMAX_MIN DUK_INT64_MIN +#define DUK_INTMAX_MAX DUK_INT64_MAX +#define DUK_UINTMAX_MIN_COMPUTED +#define DUK_UINTMAX_MAX_COMPUTED +#define DUK_INTMAX_MIN_COMPUTED +#define DUK_INTMAX_MAX_COMPUTED +#else +#define DUK_UINTMAX_MIN 0UL +#define DUK_UINTMAX_MAX 0xffffffffUL +#define DUK_INTMAX_MIN (-0x7fffffffL - 1L) +#define DUK_INTMAX_MAX 0x7fffffffL +#endif + +/* This detection is not very reliable. */ +#if defined(DUK_F_32BIT_PTRS) +typedef duk_int32_t duk_intptr_t; +typedef duk_uint32_t duk_uintptr_t; +#define DUK_UINTPTR_MIN DUK_UINT32_MIN +#define DUK_UINTPTR_MAX DUK_UINT32_MAX +#define DUK_INTPTR_MIN DUK_INT32_MIN +#define DUK_INTPTR_MAX DUK_INT32_MAX +#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT) +typedef duk_int64_t duk_intptr_t; +typedef duk_uint64_t duk_uintptr_t; +#define DUK_UINTPTR_MIN DUK_UINT64_MIN +#define DUK_UINTPTR_MAX DUK_UINT64_MAX +#define DUK_INTPTR_MIN DUK_INT64_MIN +#define DUK_INTPTR_MAX DUK_INT64_MAX +#define DUK_UINTPTR_MIN_COMPUTED +#define DUK_UINTPTR_MAX_COMPUTED +#define DUK_INTPTR_MIN_COMPUTED +#define DUK_INTPTR_MAX_COMPUTED +#else +#error cannot determine intptr type +#endif + +/* SIZE_MAX may be missing so use an approximate value for it. */ +#undef DUK_SIZE_MAX_COMPUTED +#if !defined(SIZE_MAX) +#define DUK_SIZE_MAX_COMPUTED +#define SIZE_MAX ((size_t) (-1)) +#endif +#define DUK_SIZE_MIN 0 +#define DUK_SIZE_MAX SIZE_MAX + +#endif /* C99 types */ + +/* A few types are assumed to always exist. */ +typedef size_t duk_size_t; +typedef ptrdiff_t duk_ptrdiff_t; + +/* The best type for an "all around int" in Duktape internals is "at least + * 32 bit signed integer" which is most convenient. Same for unsigned type. + * Prefer 'int' when large enough, as it is almost always a convenient type. + */ +#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL) +typedef int duk_int_t; +typedef unsigned int duk_uint_t; +#define DUK_INT_MIN INT_MIN +#define DUK_INT_MAX INT_MAX +#define DUK_UINT_MIN 0 +#define DUK_UINT_MAX UINT_MAX +#else +typedef duk_int_fast32_t duk_int_t; +typedef duk_uint_fast32_t duk_uint_t; +#define DUK_INT_MIN DUK_INT_FAST32_MIN +#define DUK_INT_MAX DUK_INT_FAST32_MAX +#define DUK_UINT_MIN DUK_UINT_FAST32_MIN +#define DUK_UINT_MAX DUK_UINT_FAST32_MAX +#endif + +/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this + * distinction matters for the CPU. These types are used mainly in the + * executor where it might really matter. + */ +typedef duk_int_fast32_t duk_int_fast_t; +typedef duk_uint_fast32_t duk_uint_fast_t; +#define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN +#define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX +#define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN +#define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX + +/* Small integers (16 bits or more) can fall back to the 'int' type, but + * have a typedef so they are marked "small" explicitly. + */ +typedef int duk_small_int_t; +typedef unsigned int duk_small_uint_t; +#define DUK_SMALL_INT_MIN INT_MIN +#define DUK_SMALL_INT_MAX INT_MAX +#define DUK_SMALL_UINT_MIN 0 +#define DUK_SMALL_UINT_MAX UINT_MAX + +/* Fast variants of small integers, again for really fast paths like the + * executor. + */ +typedef duk_int_fast16_t duk_small_int_fast_t; +typedef duk_uint_fast16_t duk_small_uint_fast_t; +#define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN +#define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX +#define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN +#define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX + +/* Boolean values are represented with the platform 'unsigned int'. */ +typedef duk_small_uint_t duk_bool_t; +#define DUK_BOOL_MIN DUK_SMALL_UINT_MIN +#define DUK_BOOL_MAX DUK_SMALL_UINT_MAX + +/* Index values must have at least 32-bit signed range. */ +typedef duk_int_t duk_idx_t; +#define DUK_IDX_MIN DUK_INT_MIN +#define DUK_IDX_MAX DUK_INT_MAX + +/* Unsigned index variant. */ +typedef duk_uint_t duk_uidx_t; +#define DUK_UIDX_MIN DUK_UINT_MIN +#define DUK_UIDX_MAX DUK_UINT_MAX + +/* Array index values, could be exact 32 bits. + * Currently no need for signed duk_arridx_t. + */ +typedef duk_uint_t duk_uarridx_t; +#define DUK_UARRIDX_MIN DUK_UINT_MIN +#define DUK_UARRIDX_MAX DUK_UINT_MAX + +/* Duktape/C function return value, platform int is enough for now to + * represent 0, 1, or negative error code. Must be compatible with + * assigning truth values (e.g. duk_ret_t rc = (foo == bar);). + */ +typedef duk_small_int_t duk_ret_t; +#define DUK_RET_MIN DUK_SMALL_INT_MIN +#define DUK_RET_MAX DUK_SMALL_INT_MAX + +/* Error codes are represented with platform int. High bits are used + * for flags and such, so 32 bits are needed. + */ +typedef duk_int_t duk_errcode_t; +#define DUK_ERRCODE_MIN DUK_INT_MIN +#define DUK_ERRCODE_MAX DUK_INT_MAX + +/* Codepoint type. Must be 32 bits or more because it is used also for + * internal codepoints. The type is signed because negative codepoints + * are used as internal markers (e.g. to mark EOF or missing argument). + * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to + * ensure duk_uint32_t casts back and forth nicely. Almost everything + * else uses the signed one. + */ +typedef duk_int_t duk_codepoint_t; +typedef duk_uint_t duk_ucodepoint_t; +#define DUK_CODEPOINT_MIN DUK_INT_MIN +#define DUK_CODEPOINT_MAX DUK_INT_MAX +#define DUK_UCODEPOINT_MIN DUK_UINT_MIN +#define DUK_UCODEPOINT_MAX DUK_UINT_MAX + +/* IEEE float/double typedef. */ +typedef float duk_float_t; +typedef double duk_double_t; + +/* We're generally assuming that we're working on a platform with a 32-bit + * address space. If DUK_SIZE_MAX is a typecast value (which is necessary + * if SIZE_MAX is missing), the check must be avoided because the + * preprocessor can't do a comparison. + */ +#if !defined(DUK_SIZE_MAX) +#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX +#elif !defined(DUK_SIZE_MAX_COMPUTED) +#if DUK_SIZE_MAX < 0xffffffffUL +/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value + * which seems incorrect if size_t is (at least) an unsigned 32-bit type. + * However, it doesn't seem useful to error out compilation if this is the + * case. + */ +#endif +#endif + +/* Type used in public API declarations and user code. Typedef maps to + * 'struct duk_hthread' like the 'duk_hthread' typedef which is used + * exclusively in internals. + */ +typedef struct duk_hthread duk_context; + +/* Check whether we should use 64-bit integers or not. + * + * Quite incomplete now. Use 64-bit types if detected (C99 or other detection) + * unless they are known to be unreliable. For instance, 64-bit types are + * available on VBCC but seem to misbehave. + */ +#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC) +#define DUK_USE_64BIT_OPS +#else +#undef DUK_USE_64BIT_OPS +#endif + +/* + * Fill-ins for platform, architecture, and compiler + */ + +/* An abort()-like primitive is needed by the default fatal error handler. */ +#if !defined(DUK_ABORT) +#define DUK_ABORT abort +#endif + +#if !defined(DUK_SETJMP) +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) setjmp((jb)) +#define DUK_LONGJMP(jb) longjmp((jb), 1) +#endif + +#if 0 +/* sigsetjmp() alternative */ +#define DUK_JMPBUF_TYPE sigjmp_buf +#define DUK_SETJMP(jb) sigsetjmp((jb)) +#define DUK_LONGJMP(jb) siglongjmp((jb), 1) +#endif + +/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h + * (which is unfortunately named). May sometimes need replacement, e.g. + * some compilers don't handle zero length or NULL correctly in realloc(). + */ +#if !defined(DUK_ANSI_MALLOC) +#define DUK_ANSI_MALLOC malloc +#endif +#if !defined(DUK_ANSI_REALLOC) +#define DUK_ANSI_REALLOC realloc +#endif +#if !defined(DUK_ANSI_CALLOC) +#define DUK_ANSI_CALLOC calloc +#endif +#if !defined(DUK_ANSI_FREE) +#define DUK_ANSI_FREE free +#endif + +/* ANSI C (various versions) and some implementations require that the + * pointer arguments to memset(), memcpy(), and memmove() be valid values + * even when byte size is 0 (even a NULL pointer is considered invalid in + * this context). Zero-size operations as such are allowed, as long as their + * pointer arguments point to a valid memory area. The DUK_MEMSET(), + * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.: + * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be + * allowed. If these are not fulfilled, a macro wrapper is needed. + * + * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0 + * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html + * + * Not sure what's the required behavior when a pointer points just past the + * end of a buffer, which often happens in practice (e.g. zero size memmoves). + * For example, if allocation size is 3, the following pointer would not + * technically point to a valid memory byte: + * + * <-- alloc --> + * | 0 | 1 | 2 | ..... + * ^-- p=3, points after last valid byte (2) + */ +#if !defined(DUK_MEMCPY) +#if defined(DUK_F_UCLIBC) +/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide + * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html + */ +#define DUK_MEMCPY memmove +#else +#define DUK_MEMCPY memcpy +#endif +#endif +#if !defined(DUK_MEMMOVE) +#define DUK_MEMMOVE memmove +#endif +#if !defined(DUK_MEMCMP) +#define DUK_MEMCMP memcmp +#endif +#if !defined(DUK_MEMSET) +#define DUK_MEMSET memset +#endif +#if !defined(DUK_STRLEN) +#define DUK_STRLEN strlen +#endif +#if !defined(DUK_STRCMP) +#define DUK_STRCMP strcmp +#endif +#if !defined(DUK_STRNCMP) +#define DUK_STRNCMP strncmp +#endif +#if !defined(DUK_SPRINTF) +#define DUK_SPRINTF sprintf +#endif +#if !defined(DUK_SNPRINTF) +/* snprintf() is technically not part of C89 but usually available. */ +#define DUK_SNPRINTF snprintf +#endif +#if !defined(DUK_VSPRINTF) +#define DUK_VSPRINTF vsprintf +#endif +#if !defined(DUK_VSNPRINTF) +/* vsnprintf() is technically not part of C89 but usually available. */ +#define DUK_VSNPRINTF vsnprintf +#endif +#if !defined(DUK_SSCANF) +#define DUK_SSCANF sscanf +#endif +#if !defined(DUK_VSSCANF) +#define DUK_VSSCANF vsscanf +#endif +#if !defined(DUK_MEMZERO) +#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n)) +#endif + +#if !defined(DUK_DOUBLE_INFINITY) +#undef DUK_USE_COMPUTED_INFINITY +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600) +/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */ +#define DUK_DOUBLE_INFINITY (__builtin_inf()) +#elif defined(INFINITY) +#define DUK_DOUBLE_INFINITY ((double) INFINITY) +#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \ + !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX) +#define DUK_DOUBLE_INFINITY (1.0 / 0.0) +#else +/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity. + * Use a computed infinity (initialized when a heap is created at the + * latest). + */ +#define DUK_USE_COMPUTED_INFINITY +#define DUK_DOUBLE_INFINITY duk_computed_infinity +#endif +#endif + +#if !defined(DUK_DOUBLE_NAN) +#undef DUK_USE_COMPUTED_NAN +#if defined(NAN) +#define DUK_DOUBLE_NAN NAN +#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \ + !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX) +#define DUK_DOUBLE_NAN (0.0 / 0.0) +#else +/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN. + * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error. + * Use a computed NaN (initialized when a heap is created at the + * latest). + */ +#define DUK_USE_COMPUTED_NAN +#define DUK_DOUBLE_NAN duk_computed_nan +#endif +#endif + +/* Many platforms are missing fpclassify() and friends, so use replacements + * if necessary. The replacement constants (FP_NAN etc) can be anything but + * match Linux constants now. + */ +#undef DUK_USE_REPL_FPCLASSIFY +#undef DUK_USE_REPL_SIGNBIT +#undef DUK_USE_REPL_ISFINITE +#undef DUK_USE_REPL_ISNAN +#undef DUK_USE_REPL_ISINF + +/* Complex condition broken into separate parts. */ +#undef DUK_F_USE_REPL_ALL +#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \ + defined(FP_SUBNORMAL) && defined(FP_NORMAL)) +/* Missing some obvious constants. */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC) +/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K) +/* AmigaOS + M68K seems to have math issues even when using GCC cross + * compilation. Use replacements for all AmigaOS versions on M68K + * regardless of compiler. + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG) +/* Placeholder fix for (detection is wider than necessary): + * http://llvm.org/bugs/show_bug.cgi?id=17788 + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_UCLIBC) +/* At least some uclibc versions have broken floating point math. For + * example, fpclassify() can incorrectly classify certain NaN formats. + * To be safe, use replacements. + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AIX) +/* Older versions may be missing isnan(), etc. */ +#define DUK_F_USE_REPL_ALL +#endif + +#if defined(DUK_F_USE_REPL_ALL) +#define DUK_USE_REPL_FPCLASSIFY +#define DUK_USE_REPL_SIGNBIT +#define DUK_USE_REPL_ISFINITE +#define DUK_USE_REPL_ISNAN +#define DUK_USE_REPL_ISINF +#define DUK_FPCLASSIFY duk_repl_fpclassify +#define DUK_SIGNBIT duk_repl_signbit +#define DUK_ISFINITE duk_repl_isfinite +#define DUK_ISNAN duk_repl_isnan +#define DUK_ISINF duk_repl_isinf +#define DUK_FP_NAN 0 +#define DUK_FP_INFINITE 1 +#define DUK_FP_ZERO 2 +#define DUK_FP_SUBNORMAL 3 +#define DUK_FP_NORMAL 4 +#else +#define DUK_FPCLASSIFY fpclassify +#define DUK_SIGNBIT signbit +#define DUK_ISFINITE isfinite +#define DUK_ISNAN isnan +#define DUK_ISINF isinf +#define DUK_FP_NAN FP_NAN +#define DUK_FP_INFINITE FP_INFINITE +#define DUK_FP_ZERO FP_ZERO +#define DUK_FP_SUBNORMAL FP_SUBNORMAL +#define DUK_FP_NORMAL FP_NORMAL +#endif + +#if defined(DUK_F_USE_REPL_ALL) +#undef DUK_F_USE_REPL_ALL +#endif + +/* These functions don't currently need replacement but are wrapped for + * completeness. Because these are used as function pointers, they need + * to be defined as concrete C functions (not macros). + */ +#if !defined(DUK_FABS) +#define DUK_FABS fabs +#endif +#if !defined(DUK_FLOOR) +#define DUK_FLOOR floor +#endif +#if !defined(DUK_CEIL) +#define DUK_CEIL ceil +#endif +#if !defined(DUK_FMOD) +#define DUK_FMOD fmod +#endif +#if !defined(DUK_POW) +#define DUK_POW pow +#endif +#if !defined(DUK_ACOS) +#define DUK_ACOS acos +#endif +#if !defined(DUK_ASIN) +#define DUK_ASIN asin +#endif +#if !defined(DUK_ATAN) +#define DUK_ATAN atan +#endif +#if !defined(DUK_ATAN2) +#define DUK_ATAN2 atan2 +#endif +#if !defined(DUK_SIN) +#define DUK_SIN sin +#endif +#if !defined(DUK_COS) +#define DUK_COS cos +#endif +#if !defined(DUK_TAN) +#define DUK_TAN tan +#endif +#if !defined(DUK_EXP) +#define DUK_EXP exp +#endif +#if !defined(DUK_LOG) +#define DUK_LOG log +#endif +#if !defined(DUK_SQRT) +#define DUK_SQRT sqrt +#endif + +/* The functions below exist only in C99/C++11 or later and need a workaround + * for platforms that don't include them. MSVC isn't detected as C99, but + * these functions also exist in MSVC 2013 and later so include a clause for + * that too. Android doesn't have log2; disable all of these for Android. + */ +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))) && \ + !defined(DUK_F_ANDROID) && !defined(DUK_F_MINT) +#if !defined(DUK_CBRT) +#define DUK_CBRT cbrt +#endif +#if !defined(DUK_LOG2) +#define DUK_LOG2 log2 +#endif +#if !defined(DUK_LOG10) +#define DUK_LOG10 log10 +#endif +#if !defined(DUK_TRUNC) +#define DUK_TRUNC trunc +#endif +#endif /* DUK_F_C99 etc */ + +/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics, + * see test-bug-netbsd-math-pow.js. MinGW has similar (but different) + * issues, see test-bug-mingw-math-issues.js. Enable pow() workarounds + * for these targets. + */ +#undef DUK_USE_POW_WORKAROUNDS +#if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW) +#define DUK_USE_POW_WORKAROUNDS +#endif + +/* Similar workarounds for atan2() semantics issues. MinGW issues are + * documented in test-bug-mingw-math-issues.js. + */ +#undef DUK_USE_ATAN2_WORKAROUNDS +#if defined(DUK_F_MINGW) +#define DUK_USE_ATAN2_WORKAROUNDS +#endif + +/* Rely as little as possible on compiler behavior for NaN comparison, + * signed zero handling, etc. Currently never activated but may be needed + * for broken compilers. + */ +#undef DUK_USE_PARANOID_MATH + +/* There was a curious bug where test-bi-date-canceling.js would fail e.g. + * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations + * using doubles would be optimized which then broke some corner case tests. + * The problem goes away by adding 'volatile' to the datetime computations. + * Not sure what the actual triggering conditions are, but using this on + * non-C99 systems solves the known issues and has relatively little cost + * on other platforms. + */ +#undef DUK_USE_PARANOID_DATE_COMPUTATION +#if !defined(DUK_F_C99) +#define DUK_USE_PARANOID_DATE_COMPUTATION +#endif + +/* + * Byte order and double memory layout detection + * + * Endianness detection is a major portability hassle because the macros + * and headers are not standardized. There's even variance across UNIX + * platforms. Even with "standard" headers, details like underscore count + * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used + * (Crossbridge has a single underscore, for instance). + * + * The checks below are structured with this in mind: several approaches are + * used, and at the end we check if any of them worked. This allows generic + * approaches to be tried first, and platform/compiler specific hacks tried + * last. As a last resort, the user can force a specific endianness, as it's + * not likely that automatic detection will work on the most exotic platforms. + * + * Duktape supports little and big endian machines. There's also support + * for a hybrid used by some ARM machines where integers are little endian + * but IEEE double values use a mixed order (12345678 -> 43218765). This + * byte order for doubles is referred to as "mixed endian". + */ + +/* GCC and Clang provide endianness defines as built-in predefines, with + * leading and trailing double underscores (e.g. __BYTE_ORDER__). See + * output of "make gccpredefs" and "make clangpredefs". Clang doesn't + * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang. + * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + */ +#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) +#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define DUK_USE_BYTEORDER 1 +#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__) +#define DUK_USE_BYTEORDER 2 +#elif !defined(__FLOAT_WORD_ORDER__) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 1 +#else +/* Byte order is little endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__) +#define DUK_USE_BYTEORDER 3 +#elif !defined(__FLOAT_WORD_ORDER__) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 3 +#else +/* Byte order is big endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#else +/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit + * integer ordering and is not relevant. + */ +#endif /* integer byte order */ +#endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */ + +/* More or less standard endianness predefines provided by header files. + * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER + * will be big endian, see: http://lists.mysql.com/internals/443. + * On some platforms some defines may be present with an empty value which + * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453. + */ +#if !defined(DUK_USE_BYTEORDER) +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \ + defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \ + defined(__LITTLE_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN) +#define DUK_USE_BYTEORDER 1 +#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#define DUK_USE_BYTEORDER 2 +#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 1 +#else +/* Byte order is little endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \ + defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \ + defined(__BIG_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#define DUK_USE_BYTEORDER 3 +#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 3 +#else +/* Byte order is big endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#else +/* Cannot determine byte order. */ +#endif /* integer byte order */ +#endif /* !defined(DUK_USE_BYTEORDER) */ + +/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__: + * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - > 24) | \ + ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \ + ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \ + (((duk_uint32_t) (x)) << 24)) +#endif +#if !defined(DUK_BSWAP16) +#define DUK_BSWAP16(x) \ + ((duk_uint16_t) (x) >> 8) | \ + ((duk_uint16_t) (x) << 8) +#endif + +/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */ +/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */ + +#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE)) +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */ +#endif +#endif + +#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \ + defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER)) +#define DUK_USE_PACK_DUMMY_MEMBER +#endif + +#if 0 /* not defined by default */ +#undef DUK_USE_GCC_PRAGMAS +#endif + +#if !defined(DUK_U64_CONSTANT) +#define DUK_U64_CONSTANT(x) x##ULL +#endif +#if !defined(DUK_I64_CONSTANT) +#define DUK_I64_CONSTANT(x) x##LL +#endif + +/* Workaround for GH-323: avoid inlining control when compiling from + * multiple sources, as it causes compiler portability trouble. + */ +#if !defined(DUK_SINGLE_FILE) +#undef DUK_NOINLINE +#undef DUK_INLINE +#undef DUK_ALWAYS_INLINE +#define DUK_NOINLINE /*nop*/ +#define DUK_INLINE /*nop*/ +#define DUK_ALWAYS_INLINE /*nop*/ +#endif + +/* + * Check whether or not a packed duk_tval representation is possible. + * What's basically required is that pointers are 32-bit values + * (sizeof(void *) == 4). Best effort check, not always accurate. + * If guess goes wrong, crashes may result; self tests also verify + * the guess. + */ + +/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */ +#if !defined(DUK_F_PACKED_TVAL_PROVIDED) +#undef DUK_F_PACKED_TVAL_POSSIBLE + +/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) +#if (DUK_UINTPTR_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED) +#if (DUK_UINTPTR_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED) +#if (DUK_SIZE_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +#undef DUK_USE_PACKED_TVAL +#if defined(DUK_F_PACKED_TVAL_POSSIBLE) +#define DUK_USE_PACKED_TVAL +#endif + +#undef DUK_F_PACKED_TVAL_POSSIBLE +#endif /* DUK_F_PACKED_TVAL_PROVIDED */ +/* Object property allocation layout has implications for memory and code + * footprint and generated code size/speed. The best layout also depends + * on whether the platform has alignment requirements or benefits from + * having mostly aligned accesses. + */ +#undef DUK_USE_HOBJECT_LAYOUT_1 +#undef DUK_USE_HOBJECT_LAYOUT_2 +#undef DUK_USE_HOBJECT_LAYOUT_3 +#if (DUK_USE_ALIGN_BY == 1) +/* On platforms without any alignment issues, layout 1 is preferable + * because it compiles to slightly less code and provides direct access + * to property keys. + */ +#define DUK_USE_HOBJECT_LAYOUT_1 +#else +/* On other platforms use layout 2, which requires some padding but + * is a bit more natural than layout 3 in ordering the entries. Layout + * 3 is currently not used. + */ +#define DUK_USE_HOBJECT_LAYOUT_2 +#endif + +/* GCC/clang inaccurate math would break compliance and probably duk_tval, + * so refuse to compile. Relax this if -ffast-math is tested to work. + */ +#if defined(__FAST_MATH__) +#error __FAST_MATH__ defined, refusing to compile +#endif + +/* + * Autogenerated defaults + */ + +#define DUK_USE_ARRAY_BUILTIN +#define DUK_USE_ARRAY_FASTPATH +#define DUK_USE_ARRAY_PROP_FASTPATH +#undef DUK_USE_ASSERTIONS +#define DUK_USE_AUGMENT_ERROR_CREATE +#define DUK_USE_AUGMENT_ERROR_THROW +#define DUK_USE_AVOID_PLATFORM_FUNCPTRS +#define DUK_USE_BASE64_FASTPATH +#define DUK_USE_BOOLEAN_BUILTIN +#define DUK_USE_BUFFEROBJECT_SUPPORT +#undef DUK_USE_BUFLEN16 +#define DUK_USE_BYTECODE_DUMP_SUPPORT +#define DUK_USE_CACHE_ACTIVATION +#define DUK_USE_CACHE_CATCHER +#define DUK_USE_CALLSTACK_LIMIT 10000 +#define DUK_USE_COMMONJS_MODULES +#define DUK_USE_COMPILER_RECLIMIT 2500 +#define DUK_USE_COROUTINE_SUPPORT +#undef DUK_USE_CPP_EXCEPTIONS +#undef DUK_USE_DATAPTR16 +#undef DUK_USE_DATAPTR_DEC16 +#undef DUK_USE_DATAPTR_ENC16 +#define DUK_USE_DATE_BUILTIN +#undef DUK_USE_DATE_FORMAT_STRING +#undef DUK_USE_DATE_GET_LOCAL_TZOFFSET +#undef DUK_USE_DATE_GET_NOW +#undef DUK_USE_DATE_PARSE_STRING +#undef DUK_USE_DATE_PRS_GETDATE +#undef DUK_USE_DEBUG +#undef DUK_USE_DEBUGGER_DUMPHEAP +#undef DUK_USE_DEBUGGER_INSPECT +#undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT +#undef DUK_USE_DEBUGGER_SUPPORT +#define DUK_USE_DEBUGGER_THROW_NOTIFY +#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE +#define DUK_USE_DEBUG_BUFSIZE 65536L +#define DUK_USE_DEBUG_LEVEL 0 +#undef DUK_USE_DEBUG_WRITE +#define DUK_USE_DOUBLE_LINKED_HEAP +#define DUK_USE_DUKTAPE_BUILTIN +#define DUK_USE_ENCODING_BUILTINS +#define DUK_USE_ERRCREATE +#define DUK_USE_ERRTHROW +#define DUK_USE_ES6 +#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY +#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF +#define DUK_USE_ES6_PROXY +#define DUK_USE_ES6_REGEXP_SYNTAX +#define DUK_USE_ES6_UNICODE_ESCAPE +#define DUK_USE_ES7 +#define DUK_USE_ES7_EXP_OPERATOR +#define DUK_USE_ES8 +#define DUK_USE_ES9 +#define DUK_USE_ESBC_LIMITS +#define DUK_USE_ESBC_MAX_BYTES 2147418112L +#define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L +#undef DUK_USE_EXEC_FUN_LOCAL +#undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK +#undef DUK_USE_EXEC_PREFER_SIZE +#define DUK_USE_EXEC_REGCONST_OPTIMIZE +#undef DUK_USE_EXEC_TIMEOUT_CHECK +#undef DUK_USE_EXPLICIT_NULL_INIT +#undef DUK_USE_EXTSTR_FREE +#undef DUK_USE_EXTSTR_INTERN_CHECK +#undef DUK_USE_FASTINT +#define DUK_USE_FAST_REFCOUNT_DEFAULT +#undef DUK_USE_FATAL_HANDLER +#define DUK_USE_FATAL_MAXLEN 128 +#define DUK_USE_FINALIZER_SUPPORT +#undef DUK_USE_FINALIZER_TORTURE +#undef DUK_USE_FUNCPTR16 +#undef DUK_USE_FUNCPTR_DEC16 +#undef DUK_USE_FUNCPTR_ENC16 +#define DUK_USE_FUNCTION_BUILTIN +#define DUK_USE_FUNC_FILENAME_PROPERTY +#define DUK_USE_FUNC_NAME_PROPERTY +#undef DUK_USE_GC_TORTURE +#undef DUK_USE_GET_MONOTONIC_TIME +#undef DUK_USE_GET_RANDOM_DOUBLE +#undef DUK_USE_GLOBAL_BINDING +#define DUK_USE_GLOBAL_BUILTIN +#undef DUK_USE_HEAPPTR16 +#undef DUK_USE_HEAPPTR_DEC16 +#undef DUK_USE_HEAPPTR_ENC16 +#define DUK_USE_HEX_FASTPATH +#define DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT 2 +#define DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT 9 +#define DUK_USE_HOBJECT_ARRAY_MINGROW_ADD 16 +#define DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR 8 +#define DUK_USE_HOBJECT_ENTRY_MINGROW_ADD 16 +#define DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR 8 +#define DUK_USE_HOBJECT_HASH_PART +#define DUK_USE_HOBJECT_HASH_PROP_LIMIT 8 +#define DUK_USE_HSTRING_ARRIDX +#define DUK_USE_HSTRING_CLEN +#undef DUK_USE_HSTRING_EXTDATA +#define DUK_USE_HSTRING_LAZY_CLEN +#define DUK_USE_HTML_COMMENTS +#define DUK_USE_IDCHAR_FASTPATH +#undef DUK_USE_INJECT_HEAP_ALLOC_ERROR +#undef DUK_USE_INTERRUPT_COUNTER +#undef DUK_USE_INTERRUPT_DEBUG_FIXUP +#define DUK_USE_JC +#define DUK_USE_JSON_BUILTIN +#define DUK_USE_JSON_DECNUMBER_FASTPATH +#define DUK_USE_JSON_DECSTRING_FASTPATH +#define DUK_USE_JSON_DEC_RECLIMIT 1000 +#define DUK_USE_JSON_EATWHITE_FASTPATH +#define DUK_USE_JSON_ENC_RECLIMIT 1000 +#define DUK_USE_JSON_QUOTESTRING_FASTPATH +#undef DUK_USE_JSON_STRINGIFY_FASTPATH +#define DUK_USE_JSON_SUPPORT +#define DUK_USE_JX +#define DUK_USE_LEXER_SLIDING_WINDOW +#undef DUK_USE_LIGHTFUNC_BUILTINS +#define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256 +#define DUK_USE_MATH_BUILTIN +#define DUK_USE_NATIVE_CALL_RECLIMIT 1000 +#define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER +#define DUK_USE_NONSTD_ARRAY_MAP_TRAILER +#define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT +#undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY +#undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY +#define DUK_USE_NONSTD_FUNC_STMT +#define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT +#define DUK_USE_NONSTD_JSON_ESC_U2028_U2029 +#define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT +#define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT +#define DUK_USE_NUMBER_BUILTIN +#define DUK_USE_OBJECT_BUILTIN +#undef DUK_USE_OBJSIZES16 +#undef DUK_USE_PARANOID_ERRORS +#define DUK_USE_PC2LINE +#define DUK_USE_PERFORMANCE_BUILTIN +#undef DUK_USE_PREFER_SIZE +#undef DUK_USE_PROMISE_BUILTIN +#define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS +#undef DUK_USE_REFCOUNT16 +#define DUK_USE_REFCOUNT32 +#define DUK_USE_REFERENCE_COUNTING +#define DUK_USE_REFLECT_BUILTIN +#define DUK_USE_REGEXP_CANON_BITMAP +#undef DUK_USE_REGEXP_CANON_WORKAROUND +#define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000 +#define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000 +#define DUK_USE_REGEXP_SUPPORT +#undef DUK_USE_ROM_GLOBAL_CLONE +#undef DUK_USE_ROM_GLOBAL_INHERIT +#undef DUK_USE_ROM_OBJECTS +#define DUK_USE_ROM_PTRCOMP_FIRST 63488L +#undef DUK_USE_ROM_STRINGS +#define DUK_USE_SECTION_B +#undef DUK_USE_SELF_TESTS +#define DUK_USE_SHEBANG_COMMENTS +#undef DUK_USE_SHUFFLE_TORTURE +#define DUK_USE_SOURCE_NONBMP +#undef DUK_USE_STRHASH16 +#undef DUK_USE_STRHASH_DENSE +#define DUK_USE_STRHASH_SKIP_SHIFT 5 +#define DUK_USE_STRICT_DECL +#undef DUK_USE_STRICT_UTF8_SOURCE +#define DUK_USE_STRING_BUILTIN +#undef DUK_USE_STRLEN16 +#define DUK_USE_STRTAB_GROW_LIMIT 17 +#define DUK_USE_STRTAB_MAXSIZE 268435456L +#define DUK_USE_STRTAB_MINSIZE 1024 +#undef DUK_USE_STRTAB_PTRCOMP +#define DUK_USE_STRTAB_RESIZE_CHECK_MASK 255 +#define DUK_USE_STRTAB_SHRINK_LIMIT 6 +#undef DUK_USE_STRTAB_TORTURE +#undef DUK_USE_SYMBOL_BUILTIN +#define DUK_USE_TAILCALL +#define DUK_USE_TARGET_INFO "unknown" +#define DUK_USE_TRACEBACKS +#define DUK_USE_TRACEBACK_DEPTH 10 +#define DUK_USE_USER_DECLARE() /* no user declarations */ +#define DUK_USE_VALSTACK_GROW_SHIFT 2 +#define DUK_USE_VALSTACK_LIMIT 1000000L +#define DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT 2 +#define DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT 4 +#undef DUK_USE_VALSTACK_UNSAFE +#define DUK_USE_VERBOSE_ERRORS +#define DUK_USE_VERBOSE_EXECUTOR_ERRORS +#define DUK_USE_VOLUNTARY_GC +#define DUK_USE_ZERO_BUFFER_DATA + +/* + * You may add overriding #define/#undef directives below for + * customization. You of course cannot un-#include or un-typedef + * anything; these require direct changes above. + */ + +/* __OVERRIDE_DEFINES__ */ + +/* + * Date provider selection + * + * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll + * rely on an external provider. If this is not done, revert to previous + * behavior and use Unix/Windows built-in provider. + */ + +#if defined(DUK_COMPILING_DUKTAPE) + +#if defined(DUK_USE_DATE_GET_NOW) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday() +#elif defined(DUK_USE_DATE_NOW_TIME) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time() +#elif defined(DUK_USE_DATE_NOW_WINDOWS) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows() +#elif defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows_subms() +#else +#error no provider for DUK_USE_DATE_GET_NOW() +#endif + +#if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d)) +#elif defined(DUK_USE_DATE_TZO_WINDOWS) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d)) +#elif defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows_no_dst((d)) +#else +#error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET() +#endif + +#if defined(DUK_USE_DATE_PARSE_STRING) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_PRS_STRPTIME) +#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str)) +#elif defined(DUK_USE_DATE_PRS_GETDATE) +#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str)) +#else +/* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */ +#endif + +#if defined(DUK_USE_DATE_FORMAT_STRING) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_FMT_STRFTIME) +#define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \ + duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags)) +#else +/* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */ +#endif + +#if defined(DUK_USE_GET_MONOTONIC_TIME) +/* External provider already defined. */ +#elif defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) +#define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_clock_gettime() +#elif defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) +#define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_windows_qpc() +#else +/* No provider for DUK_USE_GET_MONOTONIC_TIME(), fall back to DUK_USE_DATE_GET_NOW(). */ +#endif + +#endif /* DUK_COMPILING_DUKTAPE */ + +/* + * Checks for legacy feature options (DUK_OPT_xxx) + */ + +#if defined(DUK_OPT_ASSERTIONS) +#error unsupported legacy feature option DUK_OPT_ASSERTIONS used +#endif +#if defined(DUK_OPT_BUFFEROBJECT_SUPPORT) +#error unsupported legacy feature option DUK_OPT_BUFFEROBJECT_SUPPORT used +#endif +#if defined(DUK_OPT_BUFLEN16) +#error unsupported legacy feature option DUK_OPT_BUFLEN16 used +#endif +#if defined(DUK_OPT_DATAPTR16) +#error unsupported legacy feature option DUK_OPT_DATAPTR16 used +#endif +#if defined(DUK_OPT_DATAPTR_DEC16) +#error unsupported legacy feature option DUK_OPT_DATAPTR_DEC16 used +#endif +#if defined(DUK_OPT_DATAPTR_ENC16) +#error unsupported legacy feature option DUK_OPT_DATAPTR_ENC16 used +#endif +#if defined(DUK_OPT_DDDPRINT) +#error unsupported legacy feature option DUK_OPT_DDDPRINT used +#endif +#if defined(DUK_OPT_DDPRINT) +#error unsupported legacy feature option DUK_OPT_DDPRINT used +#endif +#if defined(DUK_OPT_DEBUG) +#error unsupported legacy feature option DUK_OPT_DEBUG used +#endif +#if defined(DUK_OPT_DEBUGGER_DUMPHEAP) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_DUMPHEAP used +#endif +#if defined(DUK_OPT_DEBUGGER_FWD_LOGGING) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_FWD_LOGGING used +#endif +#if defined(DUK_OPT_DEBUGGER_FWD_PRINTALERT) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_FWD_PRINTALERT used +#endif +#if defined(DUK_OPT_DEBUGGER_SUPPORT) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_SUPPORT used +#endif +#if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_TRANSPORT_TORTURE used +#endif +#if defined(DUK_OPT_DEBUG_BUFSIZE) +#error unsupported legacy feature option DUK_OPT_DEBUG_BUFSIZE used +#endif +#if defined(DUK_OPT_DECLARE) +#error unsupported legacy feature option DUK_OPT_DECLARE used +#endif +#if defined(DUK_OPT_DEEP_C_STACK) +#error unsupported legacy feature option DUK_OPT_DEEP_C_STACK used +#endif +#if defined(DUK_OPT_DLL_BUILD) +#error unsupported legacy feature option DUK_OPT_DLL_BUILD used +#endif +#if defined(DUK_OPT_DPRINT) +#error unsupported legacy feature option DUK_OPT_DPRINT used +#endif +#if defined(DUK_OPT_DPRINT_COLORS) +#error unsupported legacy feature option DUK_OPT_DPRINT_COLORS used +#endif +#if defined(DUK_OPT_DPRINT_RDTSC) +#error unsupported legacy feature option DUK_OPT_DPRINT_RDTSC used +#endif +#if defined(DUK_OPT_EXEC_TIMEOUT_CHECK) +#error unsupported legacy feature option DUK_OPT_EXEC_TIMEOUT_CHECK used +#endif +#if defined(DUK_OPT_EXTERNAL_STRINGS) +#error unsupported legacy feature option DUK_OPT_EXTERNAL_STRINGS used +#endif +#if defined(DUK_OPT_EXTSTR_FREE) +#error unsupported legacy feature option DUK_OPT_EXTSTR_FREE used +#endif +#if defined(DUK_OPT_EXTSTR_INTERN_CHECK) +#error unsupported legacy feature option DUK_OPT_EXTSTR_INTERN_CHECK used +#endif +#if defined(DUK_OPT_FASTINT) +#error unsupported legacy feature option DUK_OPT_FASTINT used +#endif +#if defined(DUK_OPT_FORCE_ALIGN) +#error unsupported legacy feature option DUK_OPT_FORCE_ALIGN used +#endif +#if defined(DUK_OPT_FORCE_BYTEORDER) +#error unsupported legacy feature option DUK_OPT_FORCE_BYTEORDER used +#endif +#if defined(DUK_OPT_FUNCPTR16) +#error unsupported legacy feature option DUK_OPT_FUNCPTR16 used +#endif +#if defined(DUK_OPT_FUNCPTR_DEC16) +#error unsupported legacy feature option DUK_OPT_FUNCPTR_DEC16 used +#endif +#if defined(DUK_OPT_FUNCPTR_ENC16) +#error unsupported legacy feature option DUK_OPT_FUNCPTR_ENC16 used +#endif +#if defined(DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY) +#error unsupported legacy feature option DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY used +#endif +#if defined(DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY) +#error unsupported legacy feature option DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY used +#endif +#if defined(DUK_OPT_GC_TORTURE) +#error unsupported legacy feature option DUK_OPT_GC_TORTURE used +#endif +#if defined(DUK_OPT_HAVE_CUSTOM_H) +#error unsupported legacy feature option DUK_OPT_HAVE_CUSTOM_H used +#endif +#if defined(DUK_OPT_HEAPPTR16) +#error unsupported legacy feature option DUK_OPT_HEAPPTR16 used +#endif +#if defined(DUK_OPT_HEAPPTR_DEC16) +#error unsupported legacy feature option DUK_OPT_HEAPPTR_DEC16 used +#endif +#if defined(DUK_OPT_HEAPPTR_ENC16) +#error unsupported legacy feature option DUK_OPT_HEAPPTR_ENC16 used +#endif +#if defined(DUK_OPT_INTERRUPT_COUNTER) +#error unsupported legacy feature option DUK_OPT_INTERRUPT_COUNTER used +#endif +#if defined(DUK_OPT_JSON_STRINGIFY_FASTPATH) +#error unsupported legacy feature option DUK_OPT_JSON_STRINGIFY_FASTPATH used +#endif +#if defined(DUK_OPT_LIGHTFUNC_BUILTINS) +#error unsupported legacy feature option DUK_OPT_LIGHTFUNC_BUILTINS used +#endif +#if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY used +#endif +#if defined(DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY used +#endif +#if defined(DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT) +#error unsupported legacy feature option DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT used +#endif +#if defined(DUK_OPT_NO_AUGMENT_ERRORS) +#error unsupported legacy feature option DUK_OPT_NO_AUGMENT_ERRORS used +#endif +#if defined(DUK_OPT_NO_BROWSER_LIKE) +#error unsupported legacy feature option DUK_OPT_NO_BROWSER_LIKE used +#endif +#if defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_BUFFEROBJECT_SUPPORT used +#endif +#if defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_BYTECODE_DUMP_SUPPORT used +#endif +#if defined(DUK_OPT_NO_COMMONJS_MODULES) +#error unsupported legacy feature option DUK_OPT_NO_COMMONJS_MODULES used +#endif +#if defined(DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY used +#endif +#if defined(DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF) +#error unsupported legacy feature option DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF used +#endif +#if defined(DUK_OPT_NO_ES6_PROXY) +#error unsupported legacy feature option DUK_OPT_NO_ES6_PROXY used +#endif +#if defined(DUK_OPT_NO_FILE_IO) +#error unsupported legacy feature option DUK_OPT_NO_FILE_IO used +#endif +#if defined(DUK_OPT_NO_FUNC_STMT) +#error unsupported legacy feature option DUK_OPT_NO_FUNC_STMT used +#endif +#if defined(DUK_OPT_NO_JC) +#error unsupported legacy feature option DUK_OPT_NO_JC used +#endif +#if defined(DUK_OPT_NO_JSONC) +#error unsupported legacy feature option DUK_OPT_NO_JSONC used +#endif +#if defined(DUK_OPT_NO_JSONX) +#error unsupported legacy feature option DUK_OPT_NO_JSONX used +#endif +#if defined(DUK_OPT_NO_JX) +#error unsupported legacy feature option DUK_OPT_NO_JX used +#endif +#if defined(DUK_OPT_NO_MARK_AND_SWEEP) +#error unsupported legacy feature option DUK_OPT_NO_MARK_AND_SWEEP used +#endif +#if defined(DUK_OPT_NO_MS_STRINGTABLE_RESIZE) +#error unsupported legacy feature option DUK_OPT_NO_MS_STRINGTABLE_RESIZE used +#endif +#if defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT used +#endif +#if defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER used +#endif +#if defined(DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER used +#endif +#if defined(DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT used +#endif +#if defined(DUK_OPT_NO_NONSTD_FUNC_STMT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_FUNC_STMT used +#endif +#if defined(DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029 used +#endif +#if defined(DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT used +#endif +#if defined(DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY used +#endif +#if defined(DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF) +#error unsupported legacy feature option DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF used +#endif +#if defined(DUK_OPT_NO_OCTAL_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_OCTAL_SUPPORT used +#endif +#if defined(DUK_OPT_NO_PACKED_TVAL) +#error unsupported legacy feature option DUK_OPT_NO_PACKED_TVAL used +#endif +#if defined(DUK_OPT_NO_PC2LINE) +#error unsupported legacy feature option DUK_OPT_NO_PC2LINE used +#endif +#if defined(DUK_OPT_NO_REFERENCE_COUNTING) +#error unsupported legacy feature option DUK_OPT_NO_REFERENCE_COUNTING used +#endif +#if defined(DUK_OPT_NO_REGEXP_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_REGEXP_SUPPORT used +#endif +#if defined(DUK_OPT_NO_SECTION_B) +#error unsupported legacy feature option DUK_OPT_NO_SECTION_B used +#endif +#if defined(DUK_OPT_NO_SOURCE_NONBMP) +#error unsupported legacy feature option DUK_OPT_NO_SOURCE_NONBMP used +#endif +#if defined(DUK_OPT_NO_STRICT_DECL) +#error unsupported legacy feature option DUK_OPT_NO_STRICT_DECL used +#endif +#if defined(DUK_OPT_NO_TRACEBACKS) +#error unsupported legacy feature option DUK_OPT_NO_TRACEBACKS used +#endif +#if defined(DUK_OPT_NO_VERBOSE_ERRORS) +#error unsupported legacy feature option DUK_OPT_NO_VERBOSE_ERRORS used +#endif +#if defined(DUK_OPT_NO_VOLUNTARY_GC) +#error unsupported legacy feature option DUK_OPT_NO_VOLUNTARY_GC used +#endif +#if defined(DUK_OPT_NO_ZERO_BUFFER_DATA) +#error unsupported legacy feature option DUK_OPT_NO_ZERO_BUFFER_DATA used +#endif +#if defined(DUK_OPT_OBJSIZES16) +#error unsupported legacy feature option DUK_OPT_OBJSIZES16 used +#endif +#if defined(DUK_OPT_PANIC_HANDLER) +#error unsupported legacy feature option DUK_OPT_PANIC_HANDLER used +#endif +#if defined(DUK_OPT_REFCOUNT16) +#error unsupported legacy feature option DUK_OPT_REFCOUNT16 used +#endif +#if defined(DUK_OPT_SEGFAULT_ON_PANIC) +#error unsupported legacy feature option DUK_OPT_SEGFAULT_ON_PANIC used +#endif +#if defined(DUK_OPT_SELF_TESTS) +#error unsupported legacy feature option DUK_OPT_SELF_TESTS used +#endif +#if defined(DUK_OPT_SETJMP) +#error unsupported legacy feature option DUK_OPT_SETJMP used +#endif +#if defined(DUK_OPT_SHUFFLE_TORTURE) +#error unsupported legacy feature option DUK_OPT_SHUFFLE_TORTURE used +#endif +#if defined(DUK_OPT_SIGSETJMP) +#error unsupported legacy feature option DUK_OPT_SIGSETJMP used +#endif +#if defined(DUK_OPT_STRHASH16) +#error unsupported legacy feature option DUK_OPT_STRHASH16 used +#endif +#if defined(DUK_OPT_STRICT_UTF8_SOURCE) +#error unsupported legacy feature option DUK_OPT_STRICT_UTF8_SOURCE used +#endif +#if defined(DUK_OPT_STRLEN16) +#error unsupported legacy feature option DUK_OPT_STRLEN16 used +#endif +#if defined(DUK_OPT_STRTAB_CHAIN) +#error unsupported legacy feature option DUK_OPT_STRTAB_CHAIN used +#endif +#if defined(DUK_OPT_STRTAB_CHAIN_SIZE) +#error unsupported legacy feature option DUK_OPT_STRTAB_CHAIN_SIZE used +#endif +#if defined(DUK_OPT_TARGET_INFO) +#error unsupported legacy feature option DUK_OPT_TARGET_INFO used +#endif +#if defined(DUK_OPT_TRACEBACK_DEPTH) +#error unsupported legacy feature option DUK_OPT_TRACEBACK_DEPTH used +#endif +#if defined(DUK_OPT_UNDERSCORE_SETJMP) +#error unsupported legacy feature option DUK_OPT_UNDERSCORE_SETJMP used +#endif +#if defined(DUK_OPT_USER_INITJS) +#error unsupported legacy feature option DUK_OPT_USER_INITJS used +#endif + +/* + * Checks for config option consistency (DUK_USE_xxx) + */ + +#if defined(DUK_USE_32BIT_PTRS) +#error unsupported config option used (option has been removed): DUK_USE_32BIT_PTRS +#endif +#if defined(DUK_USE_ALIGN_4) +#error unsupported config option used (option has been removed): DUK_USE_ALIGN_4 +#endif +#if defined(DUK_USE_ALIGN_8) +#error unsupported config option used (option has been removed): DUK_USE_ALIGN_8 +#endif +#if defined(DUK_USE_BROWSER_LIKE) +#error unsupported config option used (option has been removed): DUK_USE_BROWSER_LIKE +#endif +#if defined(DUK_USE_BUILTIN_INITJS) +#error unsupported config option used (option has been removed): DUK_USE_BUILTIN_INITJS +#endif +#if defined(DUK_USE_BYTEORDER_FORCED) +#error unsupported config option used (option has been removed): DUK_USE_BYTEORDER_FORCED +#endif +#if defined(DUK_USE_DATAPTR_DEC16) && !defined(DUK_USE_DATAPTR16) +#error config option DUK_USE_DATAPTR_DEC16 requires option DUK_USE_DATAPTR16 (which is missing) +#endif +#if defined(DUK_USE_DATAPTR_ENC16) && !defined(DUK_USE_DATAPTR16) +#error config option DUK_USE_DATAPTR_ENC16 requires option DUK_USE_DATAPTR16 (which is missing) +#endif +#if defined(DUK_USE_DDDPRINT) +#error unsupported config option used (option has been removed): DUK_USE_DDDPRINT +#endif +#if defined(DUK_USE_DDPRINT) +#error unsupported config option used (option has been removed): DUK_USE_DDPRINT +#endif +#if defined(DUK_USE_DEBUGGER_FWD_LOGGING) +#error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_LOGGING +#endif +#if defined(DUK_USE_DEBUGGER_FWD_PRINTALERT) +#error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_PRINTALERT +#endif +#if defined(DUK_USE_DEBUGGER_SUPPORT) && !defined(DUK_USE_INTERRUPT_COUNTER) +#error config option DUK_USE_DEBUGGER_SUPPORT requires option DUK_USE_INTERRUPT_COUNTER (which is missing) +#endif +#if defined(DUK_USE_DEEP_C_STACK) +#error unsupported config option used (option has been removed): DUK_USE_DEEP_C_STACK +#endif +#if defined(DUK_USE_DOUBLE_BE) +#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_BE +#endif +#if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_LE) +#error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_LE (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_ME) +#error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_ME (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_LE) +#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_LE +#endif +#if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_BE) +#error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_BE (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_ME) +#error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_ME (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_ME) +#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_ME +#endif +#if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_LE) +#error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_LE (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_BE) +#error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_BE (which is also defined) +#endif +#if defined(DUK_USE_DPRINT) +#error unsupported config option used (option has been removed): DUK_USE_DPRINT +#endif +#if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG) +#error config option DUK_USE_DPRINT requires option DUK_USE_DEBUG (which is missing) +#endif +#if defined(DUK_USE_DPRINT_COLORS) +#error unsupported config option used (option has been removed): DUK_USE_DPRINT_COLORS +#endif +#if defined(DUK_USE_DPRINT_RDTSC) +#error unsupported config option used (option has been removed): DUK_USE_DPRINT_RDTSC +#endif +#if defined(DUK_USE_ES6_REGEXP_BRACES) +#error unsupported config option used (option has been removed): DUK_USE_ES6_REGEXP_BRACES +#endif +#if defined(DUK_USE_ESBC_MAX_BYTES) && !defined(DUK_USE_ESBC_LIMITS) +#error config option DUK_USE_ESBC_MAX_BYTES requires option DUK_USE_ESBC_LIMITS (which is missing) +#endif +#if defined(DUK_USE_ESBC_MAX_LINENUMBER) && !defined(DUK_USE_ESBC_LIMITS) +#error config option DUK_USE_ESBC_MAX_LINENUMBER requires option DUK_USE_ESBC_LIMITS (which is missing) +#endif +#if defined(DUK_USE_EXEC_TIMEOUT_CHECK) && !defined(DUK_USE_INTERRUPT_COUNTER) +#error config option DUK_USE_EXEC_TIMEOUT_CHECK requires option DUK_USE_INTERRUPT_COUNTER (which is missing) +#endif +#if defined(DUK_USE_EXTSTR_FREE) && !defined(DUK_USE_HSTRING_EXTDATA) +#error config option DUK_USE_EXTSTR_FREE requires option DUK_USE_HSTRING_EXTDATA (which is missing) +#endif +#if defined(DUK_USE_EXTSTR_INTERN_CHECK) && !defined(DUK_USE_HSTRING_EXTDATA) +#error config option DUK_USE_EXTSTR_INTERN_CHECK requires option DUK_USE_HSTRING_EXTDATA (which is missing) +#endif +#if defined(DUK_USE_FASTINT) && !defined(DUK_USE_64BIT_OPS) +#error config option DUK_USE_FASTINT requires option DUK_USE_64BIT_OPS (which is missing) +#endif +#if defined(DUK_USE_FILE_IO) +#error unsupported config option used (option has been removed): DUK_USE_FILE_IO +#endif +#if defined(DUK_USE_FULL_TVAL) +#error unsupported config option used (option has been removed): DUK_USE_FULL_TVAL +#endif +#if defined(DUK_USE_FUNCPTR_DEC16) && !defined(DUK_USE_FUNCPTR16) +#error config option DUK_USE_FUNCPTR_DEC16 requires option DUK_USE_FUNCPTR16 (which is missing) +#endif +#if defined(DUK_USE_FUNCPTR_ENC16) && !defined(DUK_USE_FUNCPTR16) +#error config option DUK_USE_FUNCPTR_ENC16 requires option DUK_USE_FUNCPTR16 (which is missing) +#endif +#if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) +#error unsupported config option used (option has been removed): DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS +#endif +#if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG) +#error config option DUK_USE_HEAPPTR16 conflicts with option DUK_USE_DEBUG (which is also defined) +#endif +#if defined(DUK_USE_HEAPPTR_DEC16) && !defined(DUK_USE_HEAPPTR16) +#error config option DUK_USE_HEAPPTR_DEC16 requires option DUK_USE_HEAPPTR16 (which is missing) +#endif +#if defined(DUK_USE_HEAPPTR_ENC16) && !defined(DUK_USE_HEAPPTR16) +#error config option DUK_USE_HEAPPTR_ENC16 requires option DUK_USE_HEAPPTR16 (which is missing) +#endif +#if defined(DUK_USE_INTEGER_BE) +#error unsupported config option used (option has been removed): DUK_USE_INTEGER_BE +#endif +#if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_LE) +#error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_LE (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_ME) +#error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_ME (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_LE) +#error unsupported config option used (option has been removed): DUK_USE_INTEGER_LE +#endif +#if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_BE) +#error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_BE (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_ME) +#error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_ME (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_ME) +#error unsupported config option used (option has been removed): DUK_USE_INTEGER_ME +#endif +#if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_LE) +#error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_LE (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_BE) +#error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_BE (which is also defined) +#endif +#if defined(DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE) +#error unsupported config option used (option has been removed): DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE +#endif +#if defined(DUK_USE_MARK_AND_SWEEP) +#error unsupported config option used (option has been removed): DUK_USE_MARK_AND_SWEEP +#endif +#if defined(DUK_USE_MATH_FMAX) +#error unsupported config option used (option has been removed): DUK_USE_MATH_FMAX +#endif +#if defined(DUK_USE_MATH_FMIN) +#error unsupported config option used (option has been removed): DUK_USE_MATH_FMIN +#endif +#if defined(DUK_USE_MATH_ROUND) +#error unsupported config option used (option has been removed): DUK_USE_MATH_ROUND +#endif +#if defined(DUK_USE_MS_STRINGTABLE_RESIZE) +#error unsupported config option used (option has been removed): DUK_USE_MS_STRINGTABLE_RESIZE +#endif +#if defined(DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE) +#error unsupported config option used (option has been removed): DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE +#endif +#if defined(DUK_USE_NO_DOUBLE_ALIASING_SELFTEST) +#error unsupported config option used (option has been removed): DUK_USE_NO_DOUBLE_ALIASING_SELFTEST +#endif +#if defined(DUK_USE_OCTAL_SUPPORT) +#error unsupported config option used (option has been removed): DUK_USE_OCTAL_SUPPORT +#endif +#if defined(DUK_USE_PACKED_TVAL_POSSIBLE) +#error unsupported config option used (option has been removed): DUK_USE_PACKED_TVAL_POSSIBLE +#endif +#if defined(DUK_USE_PANIC_ABORT) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_ABORT +#endif +#if defined(DUK_USE_PANIC_EXIT) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_EXIT +#endif +#if defined(DUK_USE_PANIC_HANDLER) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_HANDLER +#endif +#if defined(DUK_USE_PANIC_SEGFAULT) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_SEGFAULT +#endif +#if defined(DUK_USE_POW_NETBSD_WORKAROUND) +#error unsupported config option used (option has been removed): DUK_USE_POW_NETBSD_WORKAROUND +#endif +#if defined(DUK_USE_RDTSC) +#error unsupported config option used (option has been removed): DUK_USE_RDTSC +#endif +#if defined(DUK_USE_REFZERO_FINALIZER_TORTURE) +#error unsupported config option used (option has been removed): DUK_USE_REFZERO_FINALIZER_TORTURE +#endif +#if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_STRINGS) +#error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_STRINGS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_OBJECTS) +#error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_OBJECTS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_CLONE) && defined(DUK_USE_ROM_GLOBAL_INHERIT) +#error config option DUK_USE_ROM_GLOBAL_CLONE conflicts with option DUK_USE_ROM_GLOBAL_INHERIT (which is also defined) +#endif +#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_STRINGS) +#error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_STRINGS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_OBJECTS) +#error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_OBJECTS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && defined(DUK_USE_ROM_GLOBAL_CLONE) +#error config option DUK_USE_ROM_GLOBAL_INHERIT conflicts with option DUK_USE_ROM_GLOBAL_CLONE (which is also defined) +#endif +#if defined(DUK_USE_ROM_OBJECTS) && !defined(DUK_USE_ROM_STRINGS) +#error config option DUK_USE_ROM_OBJECTS requires option DUK_USE_ROM_STRINGS (which is missing) +#endif +#if defined(DUK_USE_ROM_STRINGS) && !defined(DUK_USE_ROM_OBJECTS) +#error config option DUK_USE_ROM_STRINGS requires option DUK_USE_ROM_OBJECTS (which is missing) +#endif +#if defined(DUK_USE_SETJMP) +#error unsupported config option used (option has been removed): DUK_USE_SETJMP +#endif +#if defined(DUK_USE_SIGSETJMP) +#error unsupported config option used (option has been removed): DUK_USE_SIGSETJMP +#endif +#if defined(DUK_USE_STRTAB_CHAIN) +#error unsupported config option used (option has been removed): DUK_USE_STRTAB_CHAIN +#endif +#if defined(DUK_USE_STRTAB_CHAIN_SIZE) +#error unsupported config option used (option has been removed): DUK_USE_STRTAB_CHAIN_SIZE +#endif +#if defined(DUK_USE_STRTAB_CHAIN_SIZE) && !defined(DUK_USE_STRTAB_CHAIN) +#error config option DUK_USE_STRTAB_CHAIN_SIZE requires option DUK_USE_STRTAB_CHAIN (which is missing) +#endif +#if defined(DUK_USE_STRTAB_PROBE) +#error unsupported config option used (option has been removed): DUK_USE_STRTAB_PROBE +#endif +#if defined(DUK_USE_STRTAB_PTRCOMP) && !defined(DUK_USE_HEAPPTR16) +#error config option DUK_USE_STRTAB_PTRCOMP requires option DUK_USE_HEAPPTR16 (which is missing) +#endif +#if defined(DUK_USE_TAILCALL) && defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) +#error config option DUK_USE_TAILCALL conflicts with option DUK_USE_NONSTD_FUNC_CALLER_PROPERTY (which is also defined) +#endif +#if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE) +#error unsupported config option used (option has been removed): DUK_USE_UNALIGNED_ACCESSES_POSSIBLE +#endif +#if defined(DUK_USE_UNDERSCORE_SETJMP) +#error unsupported config option used (option has been removed): DUK_USE_UNDERSCORE_SETJMP +#endif +#if defined(DUK_USE_USER_INITJS) +#error unsupported config option used (option has been removed): DUK_USE_USER_INITJS +#endif + +#if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus) +#error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler +#endif + +/* + * Convert DUK_USE_BYTEORDER, from whatever source, into currently used + * internal defines. If detection failed, #error out. + */ + +#if defined(DUK_USE_BYTEORDER) +#if (DUK_USE_BYTEORDER == 1) +#define DUK_USE_INTEGER_LE +#define DUK_USE_DOUBLE_LE +#elif (DUK_USE_BYTEORDER == 2) +#define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */ +#define DUK_USE_DOUBLE_ME +#elif (DUK_USE_BYTEORDER == 3) +#define DUK_USE_INTEGER_BE +#define DUK_USE_DOUBLE_BE +#else +#error unsupported: byte order invalid +#endif /* byte order */ +#else +#error unsupported: byte order detection failed +#endif /* defined(DUK_USE_BYTEORDER) */ + +#endif /* DUK_CONFIG_H_INCLUDED */ diff --git a/include/duk_module_duktape.h b/include/duk_module_duktape.h new file mode 120000 index 0000000..bfda4c2 --- /dev/null +++ b/include/duk_module_duktape.h @@ -0,0 +1 @@ +../lib/duktape/extras/module-duktape/duk_module_duktape.h \ No newline at end of file diff --git a/include/duktape.h b/include/duktape.h new file mode 120000 index 0000000..3815c40 --- /dev/null +++ b/include/duktape.h @@ -0,0 +1 @@ +../lib/duktape/src/duktape.h \ No newline at end of file diff --git a/include/imgui_impl_glfw_vulkan.h b/include/imgui_impl_glfw_vulkan.h new file mode 120000 index 0000000..5810898 --- /dev/null +++ b/include/imgui_impl_glfw_vulkan.h @@ -0,0 +1 @@ +../lib/cimgui/imgui/examples/vulkan_example/imgui_impl_glfw_vulkan.h \ No newline at end of file diff --git a/include/list.h b/include/list.h new file mode 100644 index 0000000..a1ee4f3 --- /dev/null +++ b/include/list.h @@ -0,0 +1,520 @@ +/** + * http://www.mcs.anl.gov/~kazutomo/list/list.h + * + * I grub it from linux kernel source code and fix it for user space + * program. Of course, this is a GPL licensed header file. + * + * Here is a recipe to cook list.h for user space program + * + * 1. copy list.h from linux/include/list.h + * 2. remove + * - #ifdef __KERNE__ and its #endif + * - all #include line + * - prefetch() and rcu related functions + * 3. add macro offsetof() and container_of + * + * - kazutomo@mcs.anl.gov + */ +#ifndef _LINUX_LIST_H +#define _LINUX_LIST_H + +#include +/** + * @name from other kernel headers + */ +/*@{*/ + +/** + * Get offset of a member + */ +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER) +#endif + +/** + * Casts a member of a structure out to the containing structure + * @param ptr the pointer to the member. + * @param type the type of the container struct this is embedded in. + * @param member the name of the member within the struct. + * + */ +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); \ + }) +/*@}*/ + +/* + * These are non-NULL pointers that will result in page faults + * under normal circumstances, used to verify that nobody uses + * non-initialized list entries. + */ +#define LIST_POISON1 ((void *)0x00100100) +#define LIST_POISON2 ((void *)0x00200200) + +/** + * Simple doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ +struct list_head { + struct list_head *next, *prev; +}; + +#define LIST_HEAD_INIT(name) \ + { &(name), &(name) } + +#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) + +#define INIT_LIST_HEAD(ptr) \ + do { \ + (ptr)->next = (ptr); \ + (ptr)->prev = (ptr); \ + } while (0) + +/* + * Insert a new entry between two known consecutive entries. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static inline void __list_add(struct list_head *new, struct list_head *prev, + struct list_head *next) { + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +/** + * list_add - add a new entry + * @new: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void list_add(struct list_head *new, struct list_head *head) { + __list_add(new, head, head->next); +} + +/** + * list_add_tail - add a new entry + * @new: new entry to be added + * @head: list head to add it before + * + * Insert a new entry before the specified head. + * This is useful for implementing queues. + */ +static inline void list_add_tail(struct list_head *new, + struct list_head *head) { + __list_add(new, head->prev, head); +} + +/* + * Delete a list entry by making the prev/next entries + * point to each other. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static inline void __list_del(struct list_head *prev, struct list_head *next) { + next->prev = prev; + prev->next = next; +} + +/** + * list_del - deletes entry from list. + * @entry: the element to delete from the list. + * Note: list_empty on entry does not return true after this, the entry is + * in an undefined state. + */ +static inline void list_del(struct list_head *entry) { + __list_del(entry->prev, entry->next); + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; +} + +/** + * list_del_init - deletes entry from list and reinitialize it. + * @entry: the element to delete from the list. + */ +static inline void list_del_init(struct list_head *entry) { + __list_del(entry->prev, entry->next); + INIT_LIST_HEAD(entry); +} + +/** + * list_move - delete from one list and add as another's head + * @list: the entry to move + * @head: the head that will precede our entry + */ +static inline void list_move(struct list_head *list, struct list_head *head) { + __list_del(list->prev, list->next); + list_add(list, head); +} + +/** + * list_move_tail - delete from one list and add as another's tail + * @list: the entry to move + * @head: the head that will follow our entry + */ +static inline void list_move_tail(struct list_head *list, + struct list_head *head) { + __list_del(list->prev, list->next); + list_add_tail(list, head); +} + +/** + * list_empty - tests whether a list is empty + * @head: the list to test. + */ +static inline int list_empty(const struct list_head *head) { + return head->next == head; +} + +static inline void __list_splice(struct list_head *list, + struct list_head *head) { + struct list_head *first = list->next; + struct list_head *last = list->prev; + struct list_head *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; +} + +/** + * list_splice - join two lists + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice(struct list_head *list, struct list_head *head) { + if (!list_empty(list)) + __list_splice(list, head); +} + +/** + * list_splice_init - join two lists and reinitialise the emptied list. + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * The list at @list is reinitialised + */ +static inline void list_splice_init(struct list_head *list, + struct list_head *head) { + if (!list_empty(list)) { + __list_splice(list, head); + INIT_LIST_HEAD(list); + } +} + +/** + * list_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. + */ +#define list_entry(ptr, type, member) container_of(ptr, type, member) + +/** + * list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop counter. + * @head: the head for your list. + */ + +#define list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +/** + * __list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop counter. + * @head: the head for your list. + * + * This variant differs from list_for_each() in that it's the + * simplest possible list iteration code, no prefetching is done. + * Use this for code that knows the list to be very short (empty + * or 1 entry) most of the time. + */ +#define __list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +/** + * list_for_each_prev - iterate over a list backwards + * @pos: the &struct list_head to use as a loop counter. + * @head: the head for your list. + */ +#define list_for_each_prev(pos, head) \ + for (pos = (head)->prev; prefetch(pos->prev), pos != (head); pos = pos->prev) + +/** + * list_for_each_safe - iterate over a list safe against removal of list + * entry + * @pos: the &struct list_head to use as a loop counter. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_safe(pos, n, head) \ + for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next) + +/** + * list_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop counter. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop counter. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_prepare_entry - prepare a pos entry for use as a start point in + * list_for_each_entry_continue + * @pos: the type * to use as a start point + * @head: the head of the list + * @member: the name of the list_struct within the struct. + */ +#define list_prepare_entry(pos, head, member) \ + ((pos) ?: list_entry(head, typeof(*pos), member)) + +/** + * list_for_each_entry_continue - iterate over list of given type + * continuing after existing point + * @pos: the type * to use as a loop counter. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_safe - iterate over list of given type safe against + * removal of list entry + * @pos: the type * to use as a loop counter. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_continue - iterate over list of given type + * continuing after existing point safe against removal of + *list entry + * @pos: the type * to use as a loop counter. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_reverse - iterate backwards over list of given type + *safe against removal of list entry + * @pos: the type * to use as a loop counter. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +#define HLIST_HEAD_INIT \ + { .first = NULL } +#define HLIST_HEAD(name) struct hlist_head name = {.first = NULL} +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) +#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL) + +static inline int hlist_unhashed(const struct hlist_node *h) { + return !h->pprev; +} + +static inline int hlist_empty(const struct hlist_head *h) { return !h->first; } + +static inline void __hlist_del(struct hlist_node *n) { + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + *pprev = next; + if (next) + next->pprev = pprev; +} + +static inline void hlist_del(struct hlist_node *n) { + __hlist_del(n); + n->next = LIST_POISON1; + n->pprev = LIST_POISON2; +} + +static inline void hlist_del_init(struct hlist_node *n) { + if (n->pprev) { + __hlist_del(n); + INIT_HLIST_NODE(n); + } +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) { + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +/* next must be != NULL */ +static inline void hlist_add_before(struct hlist_node *n, + struct hlist_node *next) { + n->pprev = next->pprev; + n->next = next; + next->pprev = &n->next; + *(n->pprev) = n; +} + +static inline void hlist_add_after(struct hlist_node *n, + struct hlist_node *next) { + next->next = n->next; + n->next = next; + next->pprev = &n->next; + + if (next->next) + next->next->pprev = &next->next; +} + +#define hlist_entry(ptr, type, member) container_of(ptr, type, member) + +#define hlist_for_each(pos, head) \ + for (pos = (head)->first; pos && ({ \ + prefetch(pos->next); \ + 1; \ + }); \ + pos = pos->next) + +#define hlist_for_each_safe(pos, n, head) \ + for (pos = (head)->first; pos && ({ \ + n = pos->next; \ + 1; \ + }); \ + pos = n) + +/** + * hlist_for_each_entry - iterate over list of given type + * @tpos: the type * to use as a loop counter. + * @pos: the &struct hlist_node to use as a loop counter. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(tpos, pos, head, member) \ + for (pos = (head)->first; pos && ({ \ + prefetch(pos->next); \ + 1; \ + }) && \ + ({ \ + tpos = hlist_entry(pos, typeof(*tpos), member); \ + 1; \ + }); \ + pos = pos->next) + +/** + * hlist_for_each_entry_continue - iterate over a hlist continuing after + * existing point + * @tpos: the type * to use as a loop counter. + * @pos: the &struct hlist_node to use as a loop counter. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_continue(tpos, pos, member) \ + for (pos = (pos)->next; pos && ({ \ + prefetch(pos->next); \ + 1; \ + }) && \ + ({ \ + tpos = hlist_entry(pos, typeof(*tpos), member); \ + 1; \ + }); \ + pos = pos->next) + +/** + * hlist_for_each_entry_from - iterate over a hlist continuing from existing + * point + * @tpos: the type * to use as a loop counter. + * @pos: the &struct hlist_node to use as a loop counter. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_from(tpos, pos, member) \ + for (; pos && ({ \ + prefetch(pos->next); \ + 1; \ + }) && \ + ({ \ + tpos = hlist_entry(pos, typeof(*tpos), member); \ + 1; \ + }); \ + pos = pos->next) + +/** + * hlist_for_each_entry_safe - iterate over list of given type safe against + * removal of list entry + * @tpos: the type * to use as a loop counter. + * @pos: the &struct hlist_node to use as a loop counter. + * @n: another &struct hlist_node to use as temporary storage + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ + for (pos = (head)->first; pos && ({ \ + n = pos->next; \ + 1; \ + }) && \ + ({ \ + tpos = hlist_entry(pos, typeof(*tpos), member); \ + 1; \ + }); \ + pos = n) + +#endif diff --git a/include/spirv/unified1/spirv.h b/include/spirv/unified1/spirv.h new file mode 100644 index 0000000..012f886 --- /dev/null +++ b/include/spirv/unified1/spirv.h @@ -0,0 +1,1072 @@ +/* +** Copyright (c) 2014-2018 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a copy +** of this software and/or associated documentation files (the "Materials"), +** to deal in the Materials without restriction, including without limitation +** the rights to use, copy, modify, merge, publish, distribute, sublicense, +** and/or sell copies of the Materials, and to permit persons to whom the +** Materials are 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 Materials. +** +** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS +** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND +** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/ +** +** THE MATERIALS ARE 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 MATERIALS OR THE USE OR OTHER DEALINGS +** IN THE MATERIALS. +*/ + +/* +** This header is automatically generated by the same tool that creates +** the Binary Section of the SPIR-V specification. +*/ + +/* +** Enumeration tokens for SPIR-V, in various styles: +** C, C++, C++11, JSON, Lua, Python +** +** - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL +** - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL +** - C++11 will use enum classes in the spv namespace, e.g.: spv::SourceLanguage::GLSL +** - Lua will use tables, e.g.: spv.SourceLanguage.GLSL +** - Python will use dictionaries, e.g.: spv['SourceLanguage']['GLSL'] +** +** Some tokens act like mask values, which can be OR'd together, +** while others are mutually exclusive. The mask-like ones have +** "Mask" in their name, and a parallel enum that has the shift +** amount (1 << x) for each corresponding enumerant. +*/ + +#ifndef spirv_H +#define spirv_H + +typedef unsigned int SpvId; + +#define SPV_VERSION 0x10300 +#define SPV_REVISION 1 + +static const unsigned int SpvMagicNumber = 0x07230203; +static const unsigned int SpvVersion = 0x00010300; +static const unsigned int SpvRevision = 1; +static const unsigned int SpvOpCodeMask = 0xffff; +static const unsigned int SpvWordCountShift = 16; + +typedef enum SpvSourceLanguage_ { + SpvSourceLanguageUnknown = 0, + SpvSourceLanguageESSL = 1, + SpvSourceLanguageGLSL = 2, + SpvSourceLanguageOpenCL_C = 3, + SpvSourceLanguageOpenCL_CPP = 4, + SpvSourceLanguageHLSL = 5, + SpvSourceLanguageMax = 0x7fffffff, +} SpvSourceLanguage; + +typedef enum SpvExecutionModel_ { + SpvExecutionModelVertex = 0, + SpvExecutionModelTessellationControl = 1, + SpvExecutionModelTessellationEvaluation = 2, + SpvExecutionModelGeometry = 3, + SpvExecutionModelFragment = 4, + SpvExecutionModelGLCompute = 5, + SpvExecutionModelKernel = 6, + SpvExecutionModelMax = 0x7fffffff, +} SpvExecutionModel; + +typedef enum SpvAddressingModel_ { + SpvAddressingModelLogical = 0, + SpvAddressingModelPhysical32 = 1, + SpvAddressingModelPhysical64 = 2, + SpvAddressingModelMax = 0x7fffffff, +} SpvAddressingModel; + +typedef enum SpvMemoryModel_ { + SpvMemoryModelSimple = 0, + SpvMemoryModelGLSL450 = 1, + SpvMemoryModelOpenCL = 2, + SpvMemoryModelMax = 0x7fffffff, +} SpvMemoryModel; + +typedef enum SpvExecutionMode_ { + SpvExecutionModeInvocations = 0, + SpvExecutionModeSpacingEqual = 1, + SpvExecutionModeSpacingFractionalEven = 2, + SpvExecutionModeSpacingFractionalOdd = 3, + SpvExecutionModeVertexOrderCw = 4, + SpvExecutionModeVertexOrderCcw = 5, + SpvExecutionModePixelCenterInteger = 6, + SpvExecutionModeOriginUpperLeft = 7, + SpvExecutionModeOriginLowerLeft = 8, + SpvExecutionModeEarlyFragmentTests = 9, + SpvExecutionModePointMode = 10, + SpvExecutionModeXfb = 11, + SpvExecutionModeDepthReplacing = 12, + SpvExecutionModeDepthGreater = 14, + SpvExecutionModeDepthLess = 15, + SpvExecutionModeDepthUnchanged = 16, + SpvExecutionModeLocalSize = 17, + SpvExecutionModeLocalSizeHint = 18, + SpvExecutionModeInputPoints = 19, + SpvExecutionModeInputLines = 20, + SpvExecutionModeInputLinesAdjacency = 21, + SpvExecutionModeTriangles = 22, + SpvExecutionModeInputTrianglesAdjacency = 23, + SpvExecutionModeQuads = 24, + SpvExecutionModeIsolines = 25, + SpvExecutionModeOutputVertices = 26, + SpvExecutionModeOutputPoints = 27, + SpvExecutionModeOutputLineStrip = 28, + SpvExecutionModeOutputTriangleStrip = 29, + SpvExecutionModeVecTypeHint = 30, + SpvExecutionModeContractionOff = 31, + SpvExecutionModeInitializer = 33, + SpvExecutionModeFinalizer = 34, + SpvExecutionModeSubgroupSize = 35, + SpvExecutionModeSubgroupsPerWorkgroup = 36, + SpvExecutionModeSubgroupsPerWorkgroupId = 37, + SpvExecutionModeLocalSizeId = 38, + SpvExecutionModeLocalSizeHintId = 39, + SpvExecutionModePostDepthCoverage = 4446, + SpvExecutionModeStencilRefReplacingEXT = 5027, + SpvExecutionModeMax = 0x7fffffff, +} SpvExecutionMode; + +typedef enum SpvStorageClass_ { + SpvStorageClassUniformConstant = 0, + SpvStorageClassInput = 1, + SpvStorageClassUniform = 2, + SpvStorageClassOutput = 3, + SpvStorageClassWorkgroup = 4, + SpvStorageClassCrossWorkgroup = 5, + SpvStorageClassPrivate = 6, + SpvStorageClassFunction = 7, + SpvStorageClassGeneric = 8, + SpvStorageClassPushConstant = 9, + SpvStorageClassAtomicCounter = 10, + SpvStorageClassImage = 11, + SpvStorageClassStorageBuffer = 12, + SpvStorageClassMax = 0x7fffffff, +} SpvStorageClass; + +typedef enum SpvDim_ { + SpvDim1D = 0, + SpvDim2D = 1, + SpvDim3D = 2, + SpvDimCube = 3, + SpvDimRect = 4, + SpvDimBuffer = 5, + SpvDimSubpassData = 6, + SpvDimMax = 0x7fffffff, +} SpvDim; + +typedef enum SpvSamplerAddressingMode_ { + SpvSamplerAddressingModeNone = 0, + SpvSamplerAddressingModeClampToEdge = 1, + SpvSamplerAddressingModeClamp = 2, + SpvSamplerAddressingModeRepeat = 3, + SpvSamplerAddressingModeRepeatMirrored = 4, + SpvSamplerAddressingModeMax = 0x7fffffff, +} SpvSamplerAddressingMode; + +typedef enum SpvSamplerFilterMode_ { + SpvSamplerFilterModeNearest = 0, + SpvSamplerFilterModeLinear = 1, + SpvSamplerFilterModeMax = 0x7fffffff, +} SpvSamplerFilterMode; + +typedef enum SpvImageFormat_ { + SpvImageFormatUnknown = 0, + SpvImageFormatRgba32f = 1, + SpvImageFormatRgba16f = 2, + SpvImageFormatR32f = 3, + SpvImageFormatRgba8 = 4, + SpvImageFormatRgba8Snorm = 5, + SpvImageFormatRg32f = 6, + SpvImageFormatRg16f = 7, + SpvImageFormatR11fG11fB10f = 8, + SpvImageFormatR16f = 9, + SpvImageFormatRgba16 = 10, + SpvImageFormatRgb10A2 = 11, + SpvImageFormatRg16 = 12, + SpvImageFormatRg8 = 13, + SpvImageFormatR16 = 14, + SpvImageFormatR8 = 15, + SpvImageFormatRgba16Snorm = 16, + SpvImageFormatRg16Snorm = 17, + SpvImageFormatRg8Snorm = 18, + SpvImageFormatR16Snorm = 19, + SpvImageFormatR8Snorm = 20, + SpvImageFormatRgba32i = 21, + SpvImageFormatRgba16i = 22, + SpvImageFormatRgba8i = 23, + SpvImageFormatR32i = 24, + SpvImageFormatRg32i = 25, + SpvImageFormatRg16i = 26, + SpvImageFormatRg8i = 27, + SpvImageFormatR16i = 28, + SpvImageFormatR8i = 29, + SpvImageFormatRgba32ui = 30, + SpvImageFormatRgba16ui = 31, + SpvImageFormatRgba8ui = 32, + SpvImageFormatR32ui = 33, + SpvImageFormatRgb10a2ui = 34, + SpvImageFormatRg32ui = 35, + SpvImageFormatRg16ui = 36, + SpvImageFormatRg8ui = 37, + SpvImageFormatR16ui = 38, + SpvImageFormatR8ui = 39, + SpvImageFormatMax = 0x7fffffff, +} SpvImageFormat; + +typedef enum SpvImageChannelOrder_ { + SpvImageChannelOrderR = 0, + SpvImageChannelOrderA = 1, + SpvImageChannelOrderRG = 2, + SpvImageChannelOrderRA = 3, + SpvImageChannelOrderRGB = 4, + SpvImageChannelOrderRGBA = 5, + SpvImageChannelOrderBGRA = 6, + SpvImageChannelOrderARGB = 7, + SpvImageChannelOrderIntensity = 8, + SpvImageChannelOrderLuminance = 9, + SpvImageChannelOrderRx = 10, + SpvImageChannelOrderRGx = 11, + SpvImageChannelOrderRGBx = 12, + SpvImageChannelOrderDepth = 13, + SpvImageChannelOrderDepthStencil = 14, + SpvImageChannelOrdersRGB = 15, + SpvImageChannelOrdersRGBx = 16, + SpvImageChannelOrdersRGBA = 17, + SpvImageChannelOrdersBGRA = 18, + SpvImageChannelOrderABGR = 19, + SpvImageChannelOrderMax = 0x7fffffff, +} SpvImageChannelOrder; + +typedef enum SpvImageChannelDataType_ { + SpvImageChannelDataTypeSnormInt8 = 0, + SpvImageChannelDataTypeSnormInt16 = 1, + SpvImageChannelDataTypeUnormInt8 = 2, + SpvImageChannelDataTypeUnormInt16 = 3, + SpvImageChannelDataTypeUnormShort565 = 4, + SpvImageChannelDataTypeUnormShort555 = 5, + SpvImageChannelDataTypeUnormInt101010 = 6, + SpvImageChannelDataTypeSignedInt8 = 7, + SpvImageChannelDataTypeSignedInt16 = 8, + SpvImageChannelDataTypeSignedInt32 = 9, + SpvImageChannelDataTypeUnsignedInt8 = 10, + SpvImageChannelDataTypeUnsignedInt16 = 11, + SpvImageChannelDataTypeUnsignedInt32 = 12, + SpvImageChannelDataTypeHalfFloat = 13, + SpvImageChannelDataTypeFloat = 14, + SpvImageChannelDataTypeUnormInt24 = 15, + SpvImageChannelDataTypeUnormInt101010_2 = 16, + SpvImageChannelDataTypeMax = 0x7fffffff, +} SpvImageChannelDataType; + +typedef enum SpvImageOperandsShift_ { + SpvImageOperandsBiasShift = 0, + SpvImageOperandsLodShift = 1, + SpvImageOperandsGradShift = 2, + SpvImageOperandsConstOffsetShift = 3, + SpvImageOperandsOffsetShift = 4, + SpvImageOperandsConstOffsetsShift = 5, + SpvImageOperandsSampleShift = 6, + SpvImageOperandsMinLodShift = 7, + SpvImageOperandsMax = 0x7fffffff, +} SpvImageOperandsShift; + +typedef enum SpvImageOperandsMask_ { + SpvImageOperandsMaskNone = 0, + SpvImageOperandsBiasMask = 0x00000001, + SpvImageOperandsLodMask = 0x00000002, + SpvImageOperandsGradMask = 0x00000004, + SpvImageOperandsConstOffsetMask = 0x00000008, + SpvImageOperandsOffsetMask = 0x00000010, + SpvImageOperandsConstOffsetsMask = 0x00000020, + SpvImageOperandsSampleMask = 0x00000040, + SpvImageOperandsMinLodMask = 0x00000080, +} SpvImageOperandsMask; + +typedef enum SpvFPFastMathModeShift_ { + SpvFPFastMathModeNotNaNShift = 0, + SpvFPFastMathModeNotInfShift = 1, + SpvFPFastMathModeNSZShift = 2, + SpvFPFastMathModeAllowRecipShift = 3, + SpvFPFastMathModeFastShift = 4, + SpvFPFastMathModeMax = 0x7fffffff, +} SpvFPFastMathModeShift; + +typedef enum SpvFPFastMathModeMask_ { + SpvFPFastMathModeMaskNone = 0, + SpvFPFastMathModeNotNaNMask = 0x00000001, + SpvFPFastMathModeNotInfMask = 0x00000002, + SpvFPFastMathModeNSZMask = 0x00000004, + SpvFPFastMathModeAllowRecipMask = 0x00000008, + SpvFPFastMathModeFastMask = 0x00000010, +} SpvFPFastMathModeMask; + +typedef enum SpvFPRoundingMode_ { + SpvFPRoundingModeRTE = 0, + SpvFPRoundingModeRTZ = 1, + SpvFPRoundingModeRTP = 2, + SpvFPRoundingModeRTN = 3, + SpvFPRoundingModeMax = 0x7fffffff, +} SpvFPRoundingMode; + +typedef enum SpvLinkageType_ { + SpvLinkageTypeExport = 0, + SpvLinkageTypeImport = 1, + SpvLinkageTypeMax = 0x7fffffff, +} SpvLinkageType; + +typedef enum SpvAccessQualifier_ { + SpvAccessQualifierReadOnly = 0, + SpvAccessQualifierWriteOnly = 1, + SpvAccessQualifierReadWrite = 2, + SpvAccessQualifierMax = 0x7fffffff, +} SpvAccessQualifier; + +typedef enum SpvFunctionParameterAttribute_ { + SpvFunctionParameterAttributeZext = 0, + SpvFunctionParameterAttributeSext = 1, + SpvFunctionParameterAttributeByVal = 2, + SpvFunctionParameterAttributeSret = 3, + SpvFunctionParameterAttributeNoAlias = 4, + SpvFunctionParameterAttributeNoCapture = 5, + SpvFunctionParameterAttributeNoWrite = 6, + SpvFunctionParameterAttributeNoReadWrite = 7, + SpvFunctionParameterAttributeMax = 0x7fffffff, +} SpvFunctionParameterAttribute; + +typedef enum SpvDecoration_ { + SpvDecorationRelaxedPrecision = 0, + SpvDecorationSpecId = 1, + SpvDecorationBlock = 2, + SpvDecorationBufferBlock = 3, + SpvDecorationRowMajor = 4, + SpvDecorationColMajor = 5, + SpvDecorationArrayStride = 6, + SpvDecorationMatrixStride = 7, + SpvDecorationGLSLShared = 8, + SpvDecorationGLSLPacked = 9, + SpvDecorationCPacked = 10, + SpvDecorationBuiltIn = 11, + SpvDecorationNoPerspective = 13, + SpvDecorationFlat = 14, + SpvDecorationPatch = 15, + SpvDecorationCentroid = 16, + SpvDecorationSample = 17, + SpvDecorationInvariant = 18, + SpvDecorationRestrict = 19, + SpvDecorationAliased = 20, + SpvDecorationVolatile = 21, + SpvDecorationConstant = 22, + SpvDecorationCoherent = 23, + SpvDecorationNonWritable = 24, + SpvDecorationNonReadable = 25, + SpvDecorationUniform = 26, + SpvDecorationSaturatedConversion = 28, + SpvDecorationStream = 29, + SpvDecorationLocation = 30, + SpvDecorationComponent = 31, + SpvDecorationIndex = 32, + SpvDecorationBinding = 33, + SpvDecorationDescriptorSet = 34, + SpvDecorationOffset = 35, + SpvDecorationXfbBuffer = 36, + SpvDecorationXfbStride = 37, + SpvDecorationFuncParamAttr = 38, + SpvDecorationFPRoundingMode = 39, + SpvDecorationFPFastMathMode = 40, + SpvDecorationLinkageAttributes = 41, + SpvDecorationNoContraction = 42, + SpvDecorationInputAttachmentIndex = 43, + SpvDecorationAlignment = 44, + SpvDecorationMaxByteOffset = 45, + SpvDecorationAlignmentId = 46, + SpvDecorationMaxByteOffsetId = 47, + SpvDecorationExplicitInterpAMD = 4999, + SpvDecorationOverrideCoverageNV = 5248, + SpvDecorationPassthroughNV = 5250, + SpvDecorationViewportRelativeNV = 5252, + SpvDecorationSecondaryViewportRelativeNV = 5256, + SpvDecorationHlslCounterBufferGOOGLE = 5634, + SpvDecorationHlslSemanticGOOGLE = 5635, + SpvDecorationMax = 0x7fffffff, +} SpvDecoration; + +typedef enum SpvBuiltIn_ { + SpvBuiltInPosition = 0, + SpvBuiltInPointSize = 1, + SpvBuiltInClipDistance = 3, + SpvBuiltInCullDistance = 4, + SpvBuiltInVertexId = 5, + SpvBuiltInInstanceId = 6, + SpvBuiltInPrimitiveId = 7, + SpvBuiltInInvocationId = 8, + SpvBuiltInLayer = 9, + SpvBuiltInViewportIndex = 10, + SpvBuiltInTessLevelOuter = 11, + SpvBuiltInTessLevelInner = 12, + SpvBuiltInTessCoord = 13, + SpvBuiltInPatchVertices = 14, + SpvBuiltInFragCoord = 15, + SpvBuiltInPointCoord = 16, + SpvBuiltInFrontFacing = 17, + SpvBuiltInSampleId = 18, + SpvBuiltInSamplePosition = 19, + SpvBuiltInSampleMask = 20, + SpvBuiltInFragDepth = 22, + SpvBuiltInHelperInvocation = 23, + SpvBuiltInNumWorkgroups = 24, + SpvBuiltInWorkgroupSize = 25, + SpvBuiltInWorkgroupId = 26, + SpvBuiltInLocalInvocationId = 27, + SpvBuiltInGlobalInvocationId = 28, + SpvBuiltInLocalInvocationIndex = 29, + SpvBuiltInWorkDim = 30, + SpvBuiltInGlobalSize = 31, + SpvBuiltInEnqueuedWorkgroupSize = 32, + SpvBuiltInGlobalOffset = 33, + SpvBuiltInGlobalLinearId = 34, + SpvBuiltInSubgroupSize = 36, + SpvBuiltInSubgroupMaxSize = 37, + SpvBuiltInNumSubgroups = 38, + SpvBuiltInNumEnqueuedSubgroups = 39, + SpvBuiltInSubgroupId = 40, + SpvBuiltInSubgroupLocalInvocationId = 41, + SpvBuiltInVertexIndex = 42, + SpvBuiltInInstanceIndex = 43, + SpvBuiltInSubgroupEqMask = 4416, + SpvBuiltInSubgroupEqMaskKHR = 4416, + SpvBuiltInSubgroupGeMask = 4417, + SpvBuiltInSubgroupGeMaskKHR = 4417, + SpvBuiltInSubgroupGtMask = 4418, + SpvBuiltInSubgroupGtMaskKHR = 4418, + SpvBuiltInSubgroupLeMask = 4419, + SpvBuiltInSubgroupLeMaskKHR = 4419, + SpvBuiltInSubgroupLtMask = 4420, + SpvBuiltInSubgroupLtMaskKHR = 4420, + SpvBuiltInBaseVertex = 4424, + SpvBuiltInBaseInstance = 4425, + SpvBuiltInDrawIndex = 4426, + SpvBuiltInDeviceIndex = 4438, + SpvBuiltInViewIndex = 4440, + SpvBuiltInBaryCoordNoPerspAMD = 4992, + SpvBuiltInBaryCoordNoPerspCentroidAMD = 4993, + SpvBuiltInBaryCoordNoPerspSampleAMD = 4994, + SpvBuiltInBaryCoordSmoothAMD = 4995, + SpvBuiltInBaryCoordSmoothCentroidAMD = 4996, + SpvBuiltInBaryCoordSmoothSampleAMD = 4997, + SpvBuiltInBaryCoordPullModelAMD = 4998, + SpvBuiltInFragStencilRefEXT = 5014, + SpvBuiltInViewportMaskNV = 5253, + SpvBuiltInSecondaryPositionNV = 5257, + SpvBuiltInSecondaryViewportMaskNV = 5258, + SpvBuiltInPositionPerViewNV = 5261, + SpvBuiltInViewportMaskPerViewNV = 5262, + SpvBuiltInFullyCoveredEXT = 5264, + SpvBuiltInMax = 0x7fffffff, +} SpvBuiltIn; + +typedef enum SpvSelectionControlShift_ { + SpvSelectionControlFlattenShift = 0, + SpvSelectionControlDontFlattenShift = 1, + SpvSelectionControlMax = 0x7fffffff, +} SpvSelectionControlShift; + +typedef enum SpvSelectionControlMask_ { + SpvSelectionControlMaskNone = 0, + SpvSelectionControlFlattenMask = 0x00000001, + SpvSelectionControlDontFlattenMask = 0x00000002, +} SpvSelectionControlMask; + +typedef enum SpvLoopControlShift_ { + SpvLoopControlUnrollShift = 0, + SpvLoopControlDontUnrollShift = 1, + SpvLoopControlDependencyInfiniteShift = 2, + SpvLoopControlDependencyLengthShift = 3, + SpvLoopControlMax = 0x7fffffff, +} SpvLoopControlShift; + +typedef enum SpvLoopControlMask_ { + SpvLoopControlMaskNone = 0, + SpvLoopControlUnrollMask = 0x00000001, + SpvLoopControlDontUnrollMask = 0x00000002, + SpvLoopControlDependencyInfiniteMask = 0x00000004, + SpvLoopControlDependencyLengthMask = 0x00000008, +} SpvLoopControlMask; + +typedef enum SpvFunctionControlShift_ { + SpvFunctionControlInlineShift = 0, + SpvFunctionControlDontInlineShift = 1, + SpvFunctionControlPureShift = 2, + SpvFunctionControlConstShift = 3, + SpvFunctionControlMax = 0x7fffffff, +} SpvFunctionControlShift; + +typedef enum SpvFunctionControlMask_ { + SpvFunctionControlMaskNone = 0, + SpvFunctionControlInlineMask = 0x00000001, + SpvFunctionControlDontInlineMask = 0x00000002, + SpvFunctionControlPureMask = 0x00000004, + SpvFunctionControlConstMask = 0x00000008, +} SpvFunctionControlMask; + +typedef enum SpvMemorySemanticsShift_ { + SpvMemorySemanticsAcquireShift = 1, + SpvMemorySemanticsReleaseShift = 2, + SpvMemorySemanticsAcquireReleaseShift = 3, + SpvMemorySemanticsSequentiallyConsistentShift = 4, + SpvMemorySemanticsUniformMemoryShift = 6, + SpvMemorySemanticsSubgroupMemoryShift = 7, + SpvMemorySemanticsWorkgroupMemoryShift = 8, + SpvMemorySemanticsCrossWorkgroupMemoryShift = 9, + SpvMemorySemanticsAtomicCounterMemoryShift = 10, + SpvMemorySemanticsImageMemoryShift = 11, + SpvMemorySemanticsMax = 0x7fffffff, +} SpvMemorySemanticsShift; + +typedef enum SpvMemorySemanticsMask_ { + SpvMemorySemanticsMaskNone = 0, + SpvMemorySemanticsAcquireMask = 0x00000002, + SpvMemorySemanticsReleaseMask = 0x00000004, + SpvMemorySemanticsAcquireReleaseMask = 0x00000008, + SpvMemorySemanticsSequentiallyConsistentMask = 0x00000010, + SpvMemorySemanticsUniformMemoryMask = 0x00000040, + SpvMemorySemanticsSubgroupMemoryMask = 0x00000080, + SpvMemorySemanticsWorkgroupMemoryMask = 0x00000100, + SpvMemorySemanticsCrossWorkgroupMemoryMask = 0x00000200, + SpvMemorySemanticsAtomicCounterMemoryMask = 0x00000400, + SpvMemorySemanticsImageMemoryMask = 0x00000800, +} SpvMemorySemanticsMask; + +typedef enum SpvMemoryAccessShift_ { + SpvMemoryAccessVolatileShift = 0, + SpvMemoryAccessAlignedShift = 1, + SpvMemoryAccessNontemporalShift = 2, + SpvMemoryAccessMax = 0x7fffffff, +} SpvMemoryAccessShift; + +typedef enum SpvMemoryAccessMask_ { + SpvMemoryAccessMaskNone = 0, + SpvMemoryAccessVolatileMask = 0x00000001, + SpvMemoryAccessAlignedMask = 0x00000002, + SpvMemoryAccessNontemporalMask = 0x00000004, +} SpvMemoryAccessMask; + +typedef enum SpvScope_ { + SpvScopeCrossDevice = 0, + SpvScopeDevice = 1, + SpvScopeWorkgroup = 2, + SpvScopeSubgroup = 3, + SpvScopeInvocation = 4, + SpvScopeMax = 0x7fffffff, +} SpvScope; + +typedef enum SpvGroupOperation_ { + SpvGroupOperationReduce = 0, + SpvGroupOperationInclusiveScan = 1, + SpvGroupOperationExclusiveScan = 2, + SpvGroupOperationClusteredReduce = 3, + SpvGroupOperationMax = 0x7fffffff, +} SpvGroupOperation; + +typedef enum SpvKernelEnqueueFlags_ { + SpvKernelEnqueueFlagsNoWait = 0, + SpvKernelEnqueueFlagsWaitKernel = 1, + SpvKernelEnqueueFlagsWaitWorkGroup = 2, + SpvKernelEnqueueFlagsMax = 0x7fffffff, +} SpvKernelEnqueueFlags; + +typedef enum SpvKernelProfilingInfoShift_ { + SpvKernelProfilingInfoCmdExecTimeShift = 0, + SpvKernelProfilingInfoMax = 0x7fffffff, +} SpvKernelProfilingInfoShift; + +typedef enum SpvKernelProfilingInfoMask_ { + SpvKernelProfilingInfoMaskNone = 0, + SpvKernelProfilingInfoCmdExecTimeMask = 0x00000001, +} SpvKernelProfilingInfoMask; + +typedef enum SpvCapability_ { + SpvCapabilityMatrix = 0, + SpvCapabilityShader = 1, + SpvCapabilityGeometry = 2, + SpvCapabilityTessellation = 3, + SpvCapabilityAddresses = 4, + SpvCapabilityLinkage = 5, + SpvCapabilityKernel = 6, + SpvCapabilityVector16 = 7, + SpvCapabilityFloat16Buffer = 8, + SpvCapabilityFloat16 = 9, + SpvCapabilityFloat64 = 10, + SpvCapabilityInt64 = 11, + SpvCapabilityInt64Atomics = 12, + SpvCapabilityImageBasic = 13, + SpvCapabilityImageReadWrite = 14, + SpvCapabilityImageMipmap = 15, + SpvCapabilityPipes = 17, + SpvCapabilityGroups = 18, + SpvCapabilityDeviceEnqueue = 19, + SpvCapabilityLiteralSampler = 20, + SpvCapabilityAtomicStorage = 21, + SpvCapabilityInt16 = 22, + SpvCapabilityTessellationPointSize = 23, + SpvCapabilityGeometryPointSize = 24, + SpvCapabilityImageGatherExtended = 25, + SpvCapabilityStorageImageMultisample = 27, + SpvCapabilityUniformBufferArrayDynamicIndexing = 28, + SpvCapabilitySampledImageArrayDynamicIndexing = 29, + SpvCapabilityStorageBufferArrayDynamicIndexing = 30, + SpvCapabilityStorageImageArrayDynamicIndexing = 31, + SpvCapabilityClipDistance = 32, + SpvCapabilityCullDistance = 33, + SpvCapabilityImageCubeArray = 34, + SpvCapabilitySampleRateShading = 35, + SpvCapabilityImageRect = 36, + SpvCapabilitySampledRect = 37, + SpvCapabilityGenericPointer = 38, + SpvCapabilityInt8 = 39, + SpvCapabilityInputAttachment = 40, + SpvCapabilitySparseResidency = 41, + SpvCapabilityMinLod = 42, + SpvCapabilitySampled1D = 43, + SpvCapabilityImage1D = 44, + SpvCapabilitySampledCubeArray = 45, + SpvCapabilitySampledBuffer = 46, + SpvCapabilityImageBuffer = 47, + SpvCapabilityImageMSArray = 48, + SpvCapabilityStorageImageExtendedFormats = 49, + SpvCapabilityImageQuery = 50, + SpvCapabilityDerivativeControl = 51, + SpvCapabilityInterpolationFunction = 52, + SpvCapabilityTransformFeedback = 53, + SpvCapabilityGeometryStreams = 54, + SpvCapabilityStorageImageReadWithoutFormat = 55, + SpvCapabilityStorageImageWriteWithoutFormat = 56, + SpvCapabilityMultiViewport = 57, + SpvCapabilitySubgroupDispatch = 58, + SpvCapabilityNamedBarrier = 59, + SpvCapabilityPipeStorage = 60, + SpvCapabilityGroupNonUniform = 61, + SpvCapabilityGroupNonUniformVote = 62, + SpvCapabilityGroupNonUniformArithmetic = 63, + SpvCapabilityGroupNonUniformBallot = 64, + SpvCapabilityGroupNonUniformShuffle = 65, + SpvCapabilityGroupNonUniformShuffleRelative = 66, + SpvCapabilityGroupNonUniformClustered = 67, + SpvCapabilityGroupNonUniformQuad = 68, + SpvCapabilitySubgroupBallotKHR = 4423, + SpvCapabilityDrawParameters = 4427, + SpvCapabilitySubgroupVoteKHR = 4431, + SpvCapabilityStorageBuffer16BitAccess = 4433, + SpvCapabilityStorageUniformBufferBlock16 = 4433, + SpvCapabilityStorageUniform16 = 4434, + SpvCapabilityUniformAndStorageBuffer16BitAccess = 4434, + SpvCapabilityStoragePushConstant16 = 4435, + SpvCapabilityStorageInputOutput16 = 4436, + SpvCapabilityDeviceGroup = 4437, + SpvCapabilityMultiView = 4439, + SpvCapabilityVariablePointersStorageBuffer = 4441, + SpvCapabilityVariablePointers = 4442, + SpvCapabilityAtomicStorageOps = 4445, + SpvCapabilitySampleMaskPostDepthCoverage = 4447, + SpvCapabilityFloat16ImageAMD = 5008, + SpvCapabilityImageGatherBiasLodAMD = 5009, + SpvCapabilityFragmentMaskAMD = 5010, + SpvCapabilityStencilExportEXT = 5013, + SpvCapabilityImageReadWriteLodAMD = 5015, + SpvCapabilitySampleMaskOverrideCoverageNV = 5249, + SpvCapabilityGeometryShaderPassthroughNV = 5251, + SpvCapabilityShaderViewportIndexLayerEXT = 5254, + SpvCapabilityShaderViewportIndexLayerNV = 5254, + SpvCapabilityShaderViewportMaskNV = 5255, + SpvCapabilityShaderStereoViewNV = 5259, + SpvCapabilityPerViewAttributesNV = 5260, + SpvCapabilityFragmentFullyCoveredEXT = 5265, + SpvCapabilitySubgroupShuffleINTEL = 5568, + SpvCapabilitySubgroupBufferBlockIOINTEL = 5569, + SpvCapabilitySubgroupImageBlockIOINTEL = 5570, + SpvCapabilityMax = 0x7fffffff, +} SpvCapability; + +typedef enum SpvOp_ { + SpvOpNop = 0, + SpvOpUndef = 1, + SpvOpSourceContinued = 2, + SpvOpSource = 3, + SpvOpSourceExtension = 4, + SpvOpName = 5, + SpvOpMemberName = 6, + SpvOpString = 7, + SpvOpLine = 8, + SpvOpExtension = 10, + SpvOpExtInstImport = 11, + SpvOpExtInst = 12, + SpvOpMemoryModel = 14, + SpvOpEntryPoint = 15, + SpvOpExecutionMode = 16, + SpvOpCapability = 17, + SpvOpTypeVoid = 19, + SpvOpTypeBool = 20, + SpvOpTypeInt = 21, + SpvOpTypeFloat = 22, + SpvOpTypeVector = 23, + SpvOpTypeMatrix = 24, + SpvOpTypeImage = 25, + SpvOpTypeSampler = 26, + SpvOpTypeSampledImage = 27, + SpvOpTypeArray = 28, + SpvOpTypeRuntimeArray = 29, + SpvOpTypeStruct = 30, + SpvOpTypeOpaque = 31, + SpvOpTypePointer = 32, + SpvOpTypeFunction = 33, + SpvOpTypeEvent = 34, + SpvOpTypeDeviceEvent = 35, + SpvOpTypeReserveId = 36, + SpvOpTypeQueue = 37, + SpvOpTypePipe = 38, + SpvOpTypeForwardPointer = 39, + SpvOpConstantTrue = 41, + SpvOpConstantFalse = 42, + SpvOpConstant = 43, + SpvOpConstantComposite = 44, + SpvOpConstantSampler = 45, + SpvOpConstantNull = 46, + SpvOpSpecConstantTrue = 48, + SpvOpSpecConstantFalse = 49, + SpvOpSpecConstant = 50, + SpvOpSpecConstantComposite = 51, + SpvOpSpecConstantOp = 52, + SpvOpFunction = 54, + SpvOpFunctionParameter = 55, + SpvOpFunctionEnd = 56, + SpvOpFunctionCall = 57, + SpvOpVariable = 59, + SpvOpImageTexelPointer = 60, + SpvOpLoad = 61, + SpvOpStore = 62, + SpvOpCopyMemory = 63, + SpvOpCopyMemorySized = 64, + SpvOpAccessChain = 65, + SpvOpInBoundsAccessChain = 66, + SpvOpPtrAccessChain = 67, + SpvOpArrayLength = 68, + SpvOpGenericPtrMemSemantics = 69, + SpvOpInBoundsPtrAccessChain = 70, + SpvOpDecorate = 71, + SpvOpMemberDecorate = 72, + SpvOpDecorationGroup = 73, + SpvOpGroupDecorate = 74, + SpvOpGroupMemberDecorate = 75, + SpvOpVectorExtractDynamic = 77, + SpvOpVectorInsertDynamic = 78, + SpvOpVectorShuffle = 79, + SpvOpCompositeConstruct = 80, + SpvOpCompositeExtract = 81, + SpvOpCompositeInsert = 82, + SpvOpCopyObject = 83, + SpvOpTranspose = 84, + SpvOpSampledImage = 86, + SpvOpImageSampleImplicitLod = 87, + SpvOpImageSampleExplicitLod = 88, + SpvOpImageSampleDrefImplicitLod = 89, + SpvOpImageSampleDrefExplicitLod = 90, + SpvOpImageSampleProjImplicitLod = 91, + SpvOpImageSampleProjExplicitLod = 92, + SpvOpImageSampleProjDrefImplicitLod = 93, + SpvOpImageSampleProjDrefExplicitLod = 94, + SpvOpImageFetch = 95, + SpvOpImageGather = 96, + SpvOpImageDrefGather = 97, + SpvOpImageRead = 98, + SpvOpImageWrite = 99, + SpvOpImage = 100, + SpvOpImageQueryFormat = 101, + SpvOpImageQueryOrder = 102, + SpvOpImageQuerySizeLod = 103, + SpvOpImageQuerySize = 104, + SpvOpImageQueryLod = 105, + SpvOpImageQueryLevels = 106, + SpvOpImageQuerySamples = 107, + SpvOpConvertFToU = 109, + SpvOpConvertFToS = 110, + SpvOpConvertSToF = 111, + SpvOpConvertUToF = 112, + SpvOpUConvert = 113, + SpvOpSConvert = 114, + SpvOpFConvert = 115, + SpvOpQuantizeToF16 = 116, + SpvOpConvertPtrToU = 117, + SpvOpSatConvertSToU = 118, + SpvOpSatConvertUToS = 119, + SpvOpConvertUToPtr = 120, + SpvOpPtrCastToGeneric = 121, + SpvOpGenericCastToPtr = 122, + SpvOpGenericCastToPtrExplicit = 123, + SpvOpBitcast = 124, + SpvOpSNegate = 126, + SpvOpFNegate = 127, + SpvOpIAdd = 128, + SpvOpFAdd = 129, + SpvOpISub = 130, + SpvOpFSub = 131, + SpvOpIMul = 132, + SpvOpFMul = 133, + SpvOpUDiv = 134, + SpvOpSDiv = 135, + SpvOpFDiv = 136, + SpvOpUMod = 137, + SpvOpSRem = 138, + SpvOpSMod = 139, + SpvOpFRem = 140, + SpvOpFMod = 141, + SpvOpVectorTimesScalar = 142, + SpvOpMatrixTimesScalar = 143, + SpvOpVectorTimesMatrix = 144, + SpvOpMatrixTimesVector = 145, + SpvOpMatrixTimesMatrix = 146, + SpvOpOuterProduct = 147, + SpvOpDot = 148, + SpvOpIAddCarry = 149, + SpvOpISubBorrow = 150, + SpvOpUMulExtended = 151, + SpvOpSMulExtended = 152, + SpvOpAny = 154, + SpvOpAll = 155, + SpvOpIsNan = 156, + SpvOpIsInf = 157, + SpvOpIsFinite = 158, + SpvOpIsNormal = 159, + SpvOpSignBitSet = 160, + SpvOpLessOrGreater = 161, + SpvOpOrdered = 162, + SpvOpUnordered = 163, + SpvOpLogicalEqual = 164, + SpvOpLogicalNotEqual = 165, + SpvOpLogicalOr = 166, + SpvOpLogicalAnd = 167, + SpvOpLogicalNot = 168, + SpvOpSelect = 169, + SpvOpIEqual = 170, + SpvOpINotEqual = 171, + SpvOpUGreaterThan = 172, + SpvOpSGreaterThan = 173, + SpvOpUGreaterThanEqual = 174, + SpvOpSGreaterThanEqual = 175, + SpvOpULessThan = 176, + SpvOpSLessThan = 177, + SpvOpULessThanEqual = 178, + SpvOpSLessThanEqual = 179, + SpvOpFOrdEqual = 180, + SpvOpFUnordEqual = 181, + SpvOpFOrdNotEqual = 182, + SpvOpFUnordNotEqual = 183, + SpvOpFOrdLessThan = 184, + SpvOpFUnordLessThan = 185, + SpvOpFOrdGreaterThan = 186, + SpvOpFUnordGreaterThan = 187, + SpvOpFOrdLessThanEqual = 188, + SpvOpFUnordLessThanEqual = 189, + SpvOpFOrdGreaterThanEqual = 190, + SpvOpFUnordGreaterThanEqual = 191, + SpvOpShiftRightLogical = 194, + SpvOpShiftRightArithmetic = 195, + SpvOpShiftLeftLogical = 196, + SpvOpBitwiseOr = 197, + SpvOpBitwiseXor = 198, + SpvOpBitwiseAnd = 199, + SpvOpNot = 200, + SpvOpBitFieldInsert = 201, + SpvOpBitFieldSExtract = 202, + SpvOpBitFieldUExtract = 203, + SpvOpBitReverse = 204, + SpvOpBitCount = 205, + SpvOpDPdx = 207, + SpvOpDPdy = 208, + SpvOpFwidth = 209, + SpvOpDPdxFine = 210, + SpvOpDPdyFine = 211, + SpvOpFwidthFine = 212, + SpvOpDPdxCoarse = 213, + SpvOpDPdyCoarse = 214, + SpvOpFwidthCoarse = 215, + SpvOpEmitVertex = 218, + SpvOpEndPrimitive = 219, + SpvOpEmitStreamVertex = 220, + SpvOpEndStreamPrimitive = 221, + SpvOpControlBarrier = 224, + SpvOpMemoryBarrier = 225, + SpvOpAtomicLoad = 227, + SpvOpAtomicStore = 228, + SpvOpAtomicExchange = 229, + SpvOpAtomicCompareExchange = 230, + SpvOpAtomicCompareExchangeWeak = 231, + SpvOpAtomicIIncrement = 232, + SpvOpAtomicIDecrement = 233, + SpvOpAtomicIAdd = 234, + SpvOpAtomicISub = 235, + SpvOpAtomicSMin = 236, + SpvOpAtomicUMin = 237, + SpvOpAtomicSMax = 238, + SpvOpAtomicUMax = 239, + SpvOpAtomicAnd = 240, + SpvOpAtomicOr = 241, + SpvOpAtomicXor = 242, + SpvOpPhi = 245, + SpvOpLoopMerge = 246, + SpvOpSelectionMerge = 247, + SpvOpLabel = 248, + SpvOpBranch = 249, + SpvOpBranchConditional = 250, + SpvOpSwitch = 251, + SpvOpKill = 252, + SpvOpReturn = 253, + SpvOpReturnValue = 254, + SpvOpUnreachable = 255, + SpvOpLifetimeStart = 256, + SpvOpLifetimeStop = 257, + SpvOpGroupAsyncCopy = 259, + SpvOpGroupWaitEvents = 260, + SpvOpGroupAll = 261, + SpvOpGroupAny = 262, + SpvOpGroupBroadcast = 263, + SpvOpGroupIAdd = 264, + SpvOpGroupFAdd = 265, + SpvOpGroupFMin = 266, + SpvOpGroupUMin = 267, + SpvOpGroupSMin = 268, + SpvOpGroupFMax = 269, + SpvOpGroupUMax = 270, + SpvOpGroupSMax = 271, + SpvOpReadPipe = 274, + SpvOpWritePipe = 275, + SpvOpReservedReadPipe = 276, + SpvOpReservedWritePipe = 277, + SpvOpReserveReadPipePackets = 278, + SpvOpReserveWritePipePackets = 279, + SpvOpCommitReadPipe = 280, + SpvOpCommitWritePipe = 281, + SpvOpIsValidReserveId = 282, + SpvOpGetNumPipePackets = 283, + SpvOpGetMaxPipePackets = 284, + SpvOpGroupReserveReadPipePackets = 285, + SpvOpGroupReserveWritePipePackets = 286, + SpvOpGroupCommitReadPipe = 287, + SpvOpGroupCommitWritePipe = 288, + SpvOpEnqueueMarker = 291, + SpvOpEnqueueKernel = 292, + SpvOpGetKernelNDrangeSubGroupCount = 293, + SpvOpGetKernelNDrangeMaxSubGroupSize = 294, + SpvOpGetKernelWorkGroupSize = 295, + SpvOpGetKernelPreferredWorkGroupSizeMultiple = 296, + SpvOpRetainEvent = 297, + SpvOpReleaseEvent = 298, + SpvOpCreateUserEvent = 299, + SpvOpIsValidEvent = 300, + SpvOpSetUserEventStatus = 301, + SpvOpCaptureEventProfilingInfo = 302, + SpvOpGetDefaultQueue = 303, + SpvOpBuildNDRange = 304, + SpvOpImageSparseSampleImplicitLod = 305, + SpvOpImageSparseSampleExplicitLod = 306, + SpvOpImageSparseSampleDrefImplicitLod = 307, + SpvOpImageSparseSampleDrefExplicitLod = 308, + SpvOpImageSparseSampleProjImplicitLod = 309, + SpvOpImageSparseSampleProjExplicitLod = 310, + SpvOpImageSparseSampleProjDrefImplicitLod = 311, + SpvOpImageSparseSampleProjDrefExplicitLod = 312, + SpvOpImageSparseFetch = 313, + SpvOpImageSparseGather = 314, + SpvOpImageSparseDrefGather = 315, + SpvOpImageSparseTexelsResident = 316, + SpvOpNoLine = 317, + SpvOpAtomicFlagTestAndSet = 318, + SpvOpAtomicFlagClear = 319, + SpvOpImageSparseRead = 320, + SpvOpSizeOf = 321, + SpvOpTypePipeStorage = 322, + SpvOpConstantPipeStorage = 323, + SpvOpCreatePipeFromPipeStorage = 324, + SpvOpGetKernelLocalSizeForSubgroupCount = 325, + SpvOpGetKernelMaxNumSubgroups = 326, + SpvOpTypeNamedBarrier = 327, + SpvOpNamedBarrierInitialize = 328, + SpvOpMemoryNamedBarrier = 329, + SpvOpModuleProcessed = 330, + SpvOpExecutionModeId = 331, + SpvOpDecorateId = 332, + SpvOpGroupNonUniformElect = 333, + SpvOpGroupNonUniformAll = 334, + SpvOpGroupNonUniformAny = 335, + SpvOpGroupNonUniformAllEqual = 336, + SpvOpGroupNonUniformBroadcast = 337, + SpvOpGroupNonUniformBroadcastFirst = 338, + SpvOpGroupNonUniformBallot = 339, + SpvOpGroupNonUniformInverseBallot = 340, + SpvOpGroupNonUniformBallotBitExtract = 341, + SpvOpGroupNonUniformBallotBitCount = 342, + SpvOpGroupNonUniformBallotFindLSB = 343, + SpvOpGroupNonUniformBallotFindMSB = 344, + SpvOpGroupNonUniformShuffle = 345, + SpvOpGroupNonUniformShuffleXor = 346, + SpvOpGroupNonUniformShuffleUp = 347, + SpvOpGroupNonUniformShuffleDown = 348, + SpvOpGroupNonUniformIAdd = 349, + SpvOpGroupNonUniformFAdd = 350, + SpvOpGroupNonUniformIMul = 351, + SpvOpGroupNonUniformFMul = 352, + SpvOpGroupNonUniformSMin = 353, + SpvOpGroupNonUniformUMin = 354, + SpvOpGroupNonUniformFMin = 355, + SpvOpGroupNonUniformSMax = 356, + SpvOpGroupNonUniformUMax = 357, + SpvOpGroupNonUniformFMax = 358, + SpvOpGroupNonUniformBitwiseAnd = 359, + SpvOpGroupNonUniformBitwiseOr = 360, + SpvOpGroupNonUniformBitwiseXor = 361, + SpvOpGroupNonUniformLogicalAnd = 362, + SpvOpGroupNonUniformLogicalOr = 363, + SpvOpGroupNonUniformLogicalXor = 364, + SpvOpGroupNonUniformQuadBroadcast = 365, + SpvOpGroupNonUniformQuadSwap = 366, + SpvOpSubgroupBallotKHR = 4421, + SpvOpSubgroupFirstInvocationKHR = 4422, + SpvOpSubgroupAllKHR = 4428, + SpvOpSubgroupAnyKHR = 4429, + SpvOpSubgroupAllEqualKHR = 4430, + SpvOpSubgroupReadInvocationKHR = 4432, + SpvOpGroupIAddNonUniformAMD = 5000, + SpvOpGroupFAddNonUniformAMD = 5001, + SpvOpGroupFMinNonUniformAMD = 5002, + SpvOpGroupUMinNonUniformAMD = 5003, + SpvOpGroupSMinNonUniformAMD = 5004, + SpvOpGroupFMaxNonUniformAMD = 5005, + SpvOpGroupUMaxNonUniformAMD = 5006, + SpvOpGroupSMaxNonUniformAMD = 5007, + SpvOpFragmentMaskFetchAMD = 5011, + SpvOpFragmentFetchAMD = 5012, + SpvOpSubgroupShuffleINTEL = 5571, + SpvOpSubgroupShuffleDownINTEL = 5572, + SpvOpSubgroupShuffleUpINTEL = 5573, + SpvOpSubgroupShuffleXorINTEL = 5574, + SpvOpSubgroupBlockReadINTEL = 5575, + SpvOpSubgroupBlockWriteINTEL = 5576, + SpvOpSubgroupImageBlockReadINTEL = 5577, + SpvOpSubgroupImageBlockWriteINTEL = 5578, + SpvOpDecorateStringGOOGLE = 5632, + SpvOpMemberDecorateStringGOOGLE = 5633, + SpvOpMax = 0x7fffffff, +} SpvOp; + +#endif // #ifndef spirv_H + diff --git a/include/whereami.h b/include/whereami.h new file mode 120000 index 0000000..0ddacf7 --- /dev/null +++ b/include/whereami.h @@ -0,0 +1 @@ +../lib/whereami/src/whereami.h \ No newline at end of file diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..6effeb7 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,30 @@ +all: libcimgui.a imguicolortextedit/libtexteditor.a libduktape.a libwhereami.a + +OBJSCIMGUI = cimgui/cimgui/cimgui.o cimgui/cimgui/fontAtlas.o cimgui/cimgui/drawList.o cimgui/cimgui/listClipper.o cimgui/imgui/imgui.o cimgui/imgui/imgui_draw.o cimgui/imgui/imgui_demo.o cimgui/imgui/examples/vulkan_example/imgui_impl_glfw_vulkan.o + +cimgui/imgui/examples/vulkan_example/imgui_impl_glfw_vulkan.o: CXXFLAGS= -Icimgui/imgui -I../include + +%.a: + $(AR) rcUu $@ $+ + ranlib $@ + +libcimgui.a: $(OBJSCIMGUI) + +override CFLAGS += -I../include +libduktape.a: duktape/src/duktape.o duktape/extras/module-duktape/duk_module_duktape.o +libwhereami.a: whereami/src/whereami.o + +imguicolortextedit/libtexteditor.a: export CXXFLAGS= -I../cimgui/imgui -I../../include +imguicolortextedit/libtexteditor.a: imguicolortextedit/Makefile imguicolortextedit/TextEditor.h imguicolortextedit/TextEditor.cpp imguicolortextedit/ctexteditor.cpp imguicolortextedit/ctexteditor.h + $(MAKE) -C imguicolortextedit libtexteditor.a + +bin/dukdump: bin/Makefile bin/dindukdump.c libduktape.a + $(MAKE) -C bin dukdump + +clean: + rm -f $(OBJSCIMGUI) libcimgui.a duktape/src/duktape.o libduktape.a libwhereami.a + rm -f duktape/src/duktape.o whereami/src/whereami.o + $(MAKE) -C imguicolortextedit clean + $(MAKE) -C bin clean + +.PHONY: all clean diff --git a/lib/bin/.gitignore b/lib/bin/.gitignore new file mode 100644 index 0000000..0218008 --- /dev/null +++ b/lib/bin/.gitignore @@ -0,0 +1 @@ +/duk_cmdline diff --git a/lib/bin/Makefile b/lib/bin/Makefile new file mode 100644 index 0000000..7946f50 --- /dev/null +++ b/lib/bin/Makefile @@ -0,0 +1,14 @@ +CFLAGS = -I../../include + +all: duk_cmdline + +../libduktape.a: + $(MAKE) -C .. libduktape.a + +duk_cmdline: CFLAGS = -I../../include -DDUK_CMDLINE_PRINTALERT_SUPPORT +duk_cmdline: ../libduktape.a duk_print_alert.o -lm + +clean: + rm -f duk_cmdline + +.PHONY: clean ../libduktape.a diff --git a/lib/bin/duk_cmdline.c b/lib/bin/duk_cmdline.c new file mode 120000 index 0000000..3971a93 --- /dev/null +++ b/lib/bin/duk_cmdline.c @@ -0,0 +1 @@ +../duktape/examples/cmdline/duk_cmdline.c \ No newline at end of file diff --git a/lib/bin/duk_cmdline.h b/lib/bin/duk_cmdline.h new file mode 120000 index 0000000..63691c4 --- /dev/null +++ b/lib/bin/duk_cmdline.h @@ -0,0 +1 @@ +../duktape/examples/cmdline/duk_cmdline.h \ No newline at end of file diff --git a/lib/bin/duk_print_alert.c b/lib/bin/duk_print_alert.c new file mode 120000 index 0000000..f6958a0 --- /dev/null +++ b/lib/bin/duk_print_alert.c @@ -0,0 +1 @@ +../duktape/extras/print-alert/duk_print_alert.c \ No newline at end of file diff --git a/lib/bin/duk_print_alert.h b/lib/bin/duk_print_alert.h new file mode 120000 index 0000000..fba7767 --- /dev/null +++ b/lib/bin/duk_print_alert.h @@ -0,0 +1 @@ +../duktape/extras/print-alert/duk_print_alert.h \ No newline at end of file diff --git a/lib/cimgui b/lib/cimgui new file mode 120000 index 0000000..830c151 --- /dev/null +++ b/lib/cimgui @@ -0,0 +1 @@ +cimgui-1.53.1 \ No newline at end of file diff --git a/lib/cimgui-1.53.1/.gitignore b/lib/cimgui-1.53.1/.gitignore new file mode 100644 index 0000000..64888c8 --- /dev/null +++ b/lib/cimgui-1.53.1/.gitignore @@ -0,0 +1,38 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +cimgui/Debug/ +cimgui/cimgui.opensdf +cimgui/cimgui.sdf +cimgui/cimgui.v12.suo +cimgui/Release/ +.idea +CMakeLists.txt +cimgui/.vs/ +cimgui/cimgui.vcxproj.user +cimgui/x64/ diff --git a/lib/cimgui-1.53.1/.gitmodules b/lib/cimgui-1.53.1/.gitmodules new file mode 100644 index 0000000..e3ede80 --- /dev/null +++ b/lib/cimgui-1.53.1/.gitmodules @@ -0,0 +1,3 @@ +[submodule "imgui"] + path = imgui + url = https://github.com/ocornut/imgui.git diff --git a/lib/cimgui-1.53.1/.travis.yml b/lib/cimgui-1.53.1/.travis.yml new file mode 100644 index 0000000..6a0d159 --- /dev/null +++ b/lib/cimgui-1.53.1/.travis.yml @@ -0,0 +1,12 @@ +language: cpp + +os: + - linux + +compiler: + - gcc + - clang + +script: + - make -C cimgui + - $CC cimgui/cimgui.h # Make sure we can include in a plain C compiler diff --git a/lib/cimgui-1.53.1/LICENSE b/lib/cimgui-1.53.1/LICENSE new file mode 100644 index 0000000..2e7afa8 --- /dev/null +++ b/lib/cimgui-1.53.1/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Stephan Dilly + +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. + diff --git a/lib/cimgui-1.53.1/README.md b/lib/cimgui-1.53.1/README.md new file mode 100644 index 0000000..8dfe2db --- /dev/null +++ b/lib/cimgui-1.53.1/README.md @@ -0,0 +1,26 @@ +# cimgui [![Build Status](https://travis-ci.org/Extrawurst/cimgui.svg)](https://travis-ci.org/Extrawurst/cimgui) + +![sample](screenshot.png) + +This is a thin c-api wrapper for the excellent C++ intermediate gui [imgui](https://github.com/ocornut/imgui). +Most of the functions have wrapper counterparts now, missing stuff is added on a as-needed basis (PR welcome). +This library is intended as a intermediate layer to be able to use imgui from other languages that can interface with C (like D - see [D-binding](https://github.com/Extrawurst/DerelictImgui)) + +Notes: +* currently this wrapper is based on version [1.53 of imgui](https://github.com/ocornut/imgui/releases/tag/v1.53) +* does not compile with pure C compiler yet (for writing bindings in languages that are able to use C-ABI it is enough though, see D-bindings) + +# usage + +* clone +* make using makefile on linux/osx +* use whatever method is in ImGui c++ namespace in the original [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h) by prepending `ig` +* methods have the same parameter list and return values (where possible) + +# example bindings based on cimgui + +* [DerelictImgui](https://github.com/Extrawurst/DerelictImgui) +* [ImGui.NET](https://github.com/mellinoe/ImGui.NET) +* [imgui-rs](https://github.com/Gekkio/imgui-rs) +* [imgui-pas](https://github.com/dpethes/imgui-pas) +* [odin-dear_imgui](https://github.com/ThisDrunkDane/odin-dear_imgui) diff --git a/lib/cimgui-1.53.1/cimgui/.vscode/settings.json b/lib/cimgui-1.53.1/cimgui/.vscode/settings.json new file mode 100644 index 0000000..b9685b2 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/.vscode/settings.json @@ -0,0 +1,4 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "editor.formatOnSave": false, +} \ No newline at end of file diff --git a/lib/cimgui-1.53.1/cimgui/Makefile b/lib/cimgui-1.53.1/cimgui/Makefile new file mode 100644 index 0000000..807a2c5 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/Makefile @@ -0,0 +1,57 @@ +# +# Cross Platform Makefile +# Compatible with Ubuntu 14.04.1 and Mac OS X + +OBJS = cimgui.o +OBJS += fontAtlas.o +OBJS += drawList.o +OBJS += listClipper.o +#OBJS += test.o +OBJS += ../imgui/imgui.o +OBJS += ../imgui/imgui_draw.o +OBJS += ../imgui/imgui_demo.o + +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S), Linux) #LINUX + ECHO_MESSAGE = "Linux" + + OUTPUTNAME = cimgui.so + CXXFLAGS = -I../../ + CXXFLAGS += -Wall + CXXFLAGS += -shared -fPIC + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(UNAME_S), Darwin) #APPLE + ECHO_MESSAGE = "Mac OS X" + + OUTPUTNAME = cimgui.dylib + CXXFLAGS = -I/usr/local/include + CXXFLAGS += -Wall + LINKFLAGS = -dynamiclib + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(OS), Windows_NT) + ECHO_MESSAGE = "Windows" + + OUTPUTNAME = cimgui.dll + CXXFLAGS = -I../../ + CXXFLAGS += -Wall + CXXFLAGS += -shared + LINKFLAGS = -limm32 + CFLAGS = $(CXXFLAGS) +endif + +.cpp.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +all:imgui_example + @echo Build complete for $(ECHO_MESSAGE) + +imgui_example:$(OBJS) + $(CXX) -o $(OUTPUTNAME) $(OBJS) $(CXXFLAGS) $(LINKFLAGS) + +clean: + rm $(OBJS) diff --git a/lib/cimgui-1.53.1/cimgui/cimgui.cpp b/lib/cimgui-1.53.1/cimgui/cimgui.cpp new file mode 100644 index 0000000..5e5ad0a --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/cimgui.cpp @@ -0,0 +1,1892 @@ + +#include "../imgui/imgui.h" +#include "cimgui.h" + +// to use placement new +#define IMGUI_DEFINE_PLACEMENT_NEW +#include "../imgui/imgui_internal.h" + +CIMGUI_API ImGuiIO *igGetIO() +{ + return &ImGui::GetIO(); +} + +CIMGUI_API ImGuiStyle *igGetStyle() +{ + return &ImGui::GetStyle(); +} + +CIMGUI_API ImDrawData *igGetDrawData() +{ + return ImGui::GetDrawData(); +} + +CIMGUI_API void igNewFrame() +{ + ImGui::NewFrame(); +} + +CIMGUI_API void igRender() +{ + ImGui::Render(); +} + +CIMGUI_API void igEndFrame() +{ + ImGui::EndFrame(); +} + +CIMGUI_API void igShutdown() +{ + ImGui::Shutdown(); +} + +CIMGUI_API void igShowUserGuide() +{ + ImGui::ShowUserGuide(); +} + +CIMGUI_API void igShowStyleEditor(ImGuiStyle *ref) +{ + ImGui::ShowStyleEditor(ref); +} + +CIMGUI_API void igShowDemoWindow(bool *opened) +{ + ImGui::ShowDemoWindow(opened); +} + +IMGUI_API void igShowMetricsWindow(bool *opened) +{ + ImGui::ShowMetricsWindow(opened); +} + +CIMGUI_API void igShowStyleSelector(CONST char *label) +{ + ImGui::ShowStyleSelector(label); +} + +CIMGUI_API void igShowFontSelector(CONST char *label) +{ + ImGui::ShowFontSelector(label); +} + +// Window + +CIMGUI_API bool igBegin(CONST char *name, bool *p_opened, ImGuiWindowFlags flags) +{ + return ImGui::Begin(name, p_opened, flags); +} + +CIMGUI_API bool igBegin2(CONST char *name, bool *p_opened, CONST ImVec2 size_on_first_use, float bg_alpha, ImGuiWindowFlags flags) +{ + return ImGui::Begin(name, p_opened, size_on_first_use, bg_alpha, flags); +} + +CIMGUI_API void igEnd() +{ + ImGui::End(); +} + +CIMGUI_API bool igBeginChild(CONST char *str_id, CONST ImVec2 size, bool border, ImGuiWindowFlags extra_flags) +{ + return ImGui::BeginChild(str_id, size, border, extra_flags); +} + +CIMGUI_API bool igBeginChildEx(ImGuiID id, CONST ImVec2 size, bool border, ImGuiWindowFlags extra_flags) +{ + return ImGui::BeginChild(id, size, border, extra_flags); +} + +CIMGUI_API void igEndChild() +{ + ImGui::EndChild(); +} + +CIMGUI_API void igGetContentRegionMax(ImVec2 *out) +{ + *out = ImGui::GetContentRegionMax(); +} + +CIMGUI_API void igGetContentRegionAvail(struct ImVec2 *out) +{ + *out = ImGui::GetContentRegionAvail(); +} + +CIMGUI_API float igGetContentRegionAvailWidth() +{ + return ImGui::GetContentRegionAvailWidth(); +} + +CIMGUI_API void igGetWindowContentRegionMin(ImVec2 *out) +{ + *out = ImGui::GetWindowContentRegionMin(); +} + +CIMGUI_API void igGetWindowContentRegionMax(ImVec2 *out) +{ + *out = ImGui::GetWindowContentRegionMax(); +} + +CIMGUI_API float igGetWindowContentRegionWidth() +{ + return ImGui::GetWindowContentRegionWidth(); +} + +CIMGUI_API ImDrawList *igGetWindowDrawList() +{ + return ImGui::GetWindowDrawList(); +} + +CIMGUI_API void igGetWindowPos(ImVec2 *out) +{ + *out = ImGui::GetWindowPos(); +} + +CIMGUI_API void igGetWindowSize(ImVec2 *out) +{ + *out = ImGui::GetWindowSize(); +} + +CIMGUI_API float igGetWindowWidth() +{ + return ImGui::GetWindowWidth(); +} + +CIMGUI_API float igGetWindowHeight() +{ + return ImGui::GetWindowHeight(); +} + +CIMGUI_API bool igIsWindowCollapsed() +{ + return ImGui::IsWindowCollapsed(); +} + +CIMGUI_API bool igIsWindowAppearing() +{ + return ImGui::IsWindowAppearing(); +} + +CIMGUI_API void igSetWindowFontScale(float scale) +{ + ImGui::SetWindowFontScale(scale); +} + +CIMGUI_API void igSetNextWindowPos(CONST struct ImVec2 pos, ImGuiCond cond, CONST struct ImVec2 pivot) +{ + ImGui::SetNextWindowPos(pos, cond, pivot); +} + +CIMGUI_API void igSetNextWindowSize(CONST ImVec2 size, ImGuiCond cond) +{ + ImGui::SetNextWindowSize(size, cond); +} + +CIMGUI_API void igSetNextWindowSizeConstraints(CONST struct ImVec2 size_min, CONST struct ImVec2 size_max, ImGuiSizeConstraintCallback custom_callback, void *custom_callback_data) +{ + ImGui::SetNextWindowSizeConstraints(size_min, size_max, custom_callback, custom_callback_data); +} + +CIMGUI_API void igSetNextWindowContentSize(CONST ImVec2 size) +{ + ImGui::SetNextWindowContentSize(size); +} + +CIMGUI_API void igSetNextWindowCollapsed(bool collapsed, ImGuiCond cond) +{ + ImGui::SetNextWindowCollapsed(collapsed, cond); +} + +CIMGUI_API void igSetNextWindowFocus() +{ + ImGui::SetNextWindowFocus(); +} + +CIMGUI_API void igSetWindowPos(CONST ImVec2 pos, ImGuiCond cond) +{ + ImGui::SetWindowPos(pos, cond); +} + +CIMGUI_API void igSetWindowSize(CONST ImVec2 size, ImGuiCond cond) +{ + ImGui::SetWindowSize(size, cond); +} + +CIMGUI_API void igSetWindowCollapsed(bool collapsed, ImGuiCond cond) +{ + ImGui::SetWindowCollapsed(collapsed, cond); +} + +CIMGUI_API void igSetWindowFocus() +{ + ImGui::SetWindowFocus(); +} + +CIMGUI_API void igSetWindowPosByName(CONST char *name, CONST ImVec2 pos, ImGuiCond cond) +{ + ImGui::SetWindowPos(name, pos, cond); +} + +CIMGUI_API void igSetWindowSize2(CONST char *name, CONST ImVec2 size, ImGuiCond cond) +{ + ImGui::SetWindowSize(name, size, cond); +} + +CIMGUI_API void igSetWindowCollapsed2(CONST char *name, bool collapsed, ImGuiCond cond) +{ + ImGui::SetWindowCollapsed(name, collapsed, cond); +} + +CIMGUI_API void igSetWindowFocus2(CONST char *name) +{ + ImGui::SetWindowFocus(name); +} + +CIMGUI_API float igGetScrollX() +{ + return ImGui::GetScrollX(); +} + +CIMGUI_API float igGetScrollY() +{ + return ImGui::GetScrollY(); +} + +CIMGUI_API float igGetScrollMaxX() +{ + return ImGui::GetScrollMaxX(); +} + +CIMGUI_API float igGetScrollMaxY() +{ + return ImGui::GetScrollMaxY(); +} + +CIMGUI_API void igSetScrollX(float scroll_x) +{ + return ImGui::SetScrollX(scroll_x); +} + +CIMGUI_API void igSetScrollY(float scroll_y) +{ + return ImGui::SetScrollY(scroll_y); +} + +CIMGUI_API void igSetScrollHere(float center_y_ratio) +{ + ImGui::SetScrollHere(center_y_ratio); +} + +CIMGUI_API void igSetScrollFromPosY(float pos_y, float center_y_ratio) +{ + return ImGui::SetScrollFromPosY(pos_y, center_y_ratio); +} + +CIMGUI_API void igSetStateStorage(ImGuiStorage *tree) +{ + ImGui::SetStateStorage(tree); +} + +CIMGUI_API ImGuiStorage *igGetStateStorage() +{ + return ImGui::GetStateStorage(); +} + +// Parameters stacks (shared) +CIMGUI_API void igPushFont(ImFont *font) +{ + ImGui::PushFont(font); +} + +CIMGUI_API void igPopFont() +{ + return ImGui::PopFont(); +} + +CIMGUI_API void igPushStyleColorU32(ImGuiCol idx, ImU32 col) +{ + return ImGui::PushStyleColor(idx, col); +} + +CIMGUI_API void igPushStyleColor(ImGuiCol idx, CONST ImVec4 col) +{ + return ImGui::PushStyleColor(idx, col); +} + +CIMGUI_API void igPopStyleColor(int count) +{ + return ImGui::PopStyleColor(count); +} + +CIMGUI_API void igPushStyleVar(ImGuiStyleVar idx, float val) +{ + return ImGui::PushStyleVar(idx, val); +} + +CIMGUI_API void igPushStyleVarVec(ImGuiStyleVar idx, CONST ImVec2 val) +{ + return ImGui::PushStyleVar(idx, val); +} + +CIMGUI_API void igPopStyleVar(int count) +{ + return ImGui::PopStyleVar(count); +} + +CIMGUI_API void igGetStyleColorVec4(ImVec4 *pOut, ImGuiCol idx) +{ + *pOut = ImGui::GetStyleColorVec4(idx); +} + +CIMGUI_API ImFont *igGetFont() +{ + return ImGui::GetFont(); +} + +CIMGUI_API float igGetFontSize() +{ + return ImGui::GetFontSize(); +} + +CIMGUI_API void igGetFontTexUvWhitePixel(ImVec2 *pOut) +{ + *pOut = ImGui::GetFontTexUvWhitePixel(); +} + +CIMGUI_API ImU32 igGetColorU32(ImGuiCol idx, float alpha_mul) +{ + return ImGui::GetColorU32(idx, alpha_mul); +} + +CIMGUI_API ImU32 igGetColorU32Vec(CONST ImVec4 *col) +{ + return ImGui::GetColorU32(*col); +} + +CIMGUI_API ImU32 igGetColorU32U32(ImU32 col) +{ + return ImGui::GetColorU32(col); +} + +// Parameters stacks (current window) +CIMGUI_API void igPushItemWidth(float item_width) +{ + return ImGui::PushItemWidth(item_width); +} + +CIMGUI_API void igPopItemWidth() +{ + return ImGui::PopItemWidth(); +} + +CIMGUI_API float igCalcItemWidth() +{ + return ImGui::CalcItemWidth(); +} + +CIMGUI_API void igPushAllowKeyboardFocus(bool v) +{ + return ImGui::PushAllowKeyboardFocus(v); +} + +CIMGUI_API void igPopAllowKeyboardFocus() +{ + return ImGui::PopAllowKeyboardFocus(); +} + +CIMGUI_API void igPushTextWrapPos(float wrap_pos_x) +{ + return ImGui::PushTextWrapPos(wrap_pos_x); +} + +CIMGUI_API void igPopTextWrapPos() +{ + return ImGui::PopTextWrapPos(); +} + +CIMGUI_API void igPushButtonRepeat(bool repeat) +{ + return ImGui::PushButtonRepeat(repeat); +} + +CIMGUI_API void igPopButtonRepeat() +{ + return ImGui::PopButtonRepeat(); +} + +// Tooltip +CIMGUI_API void igSetTooltip(CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::SetTooltipV(fmt, args); + va_end(args); +} + +CIMGUI_API void igSetTooltipV(CONST char *fmt, va_list args) +{ + ImGui::SetTooltipV(fmt, args); +} + +CIMGUI_API void igBeginTooltip() +{ + return ImGui::BeginTooltip(); +} + +CIMGUI_API void igEndTooltip() +{ + return ImGui::EndTooltip(); +} + +// Popup +CIMGUI_API void igOpenPopup(CONST char *str_id) +{ + return ImGui::OpenPopup(str_id); +} + +CIMGUI_API bool igOpenPopupOnItemClick(const char *str_id, int mouse_button) +{ + return ImGui::OpenPopupOnItemClick(str_id, mouse_button); +} + +CIMGUI_API bool igBeginPopup(CONST char *str_id) +{ + return ImGui::BeginPopup(str_id); +} + +CIMGUI_API bool igBeginPopupModal(CONST char *name, bool *p_open, ImGuiWindowFlags extra_flags) +{ + return ImGui::BeginPopupModal(name, p_open, extra_flags); +} + +CIMGUI_API bool igBeginPopupContextItem(CONST char *str_id, int mouse_button) +{ + return ImGui::BeginPopupContextItem(str_id, mouse_button); +} + +CIMGUI_API bool igBeginPopupContextWindow(CONST char *str_id, int mouse_button, bool also_over_items) +{ + return ImGui::BeginPopupContextWindow(str_id, mouse_button, also_over_items); +} + +CIMGUI_API bool igBeginPopupContextVoid(CONST char *str_id, int mouse_button) +{ + return ImGui::BeginPopupContextVoid(str_id, mouse_button); +} + +CIMGUI_API void igEndPopup() +{ + return ImGui::EndPopup(); +} + +CIMGUI_API bool igIsPopupOpen(CONST char *str_id) +{ + return ImGui::IsPopupOpen(str_id); +} + +CIMGUI_API void igCloseCurrentPopup() +{ + return ImGui::CloseCurrentPopup(); +} + +// Layout + +CIMGUI_API void igSeparator() +{ + return ImGui::Separator(); +} + +CIMGUI_API void igSameLine(float pos_x, float spacing_w) +{ + return ImGui::SameLine(pos_x, spacing_w); +} + +CIMGUI_API void igNewLine() +{ + return ImGui::NewLine(); +} + +CIMGUI_API void igSpacing() +{ + return ImGui::Spacing(); +} + +CIMGUI_API void igDummy(CONST ImVec2 *size) +{ + return ImGui::Dummy(*size); +} + +CIMGUI_API void igIndent(float indent_w) +{ + return ImGui::Indent(indent_w); +} + +CIMGUI_API void igUnindent(float indent_w) +{ + return ImGui::Unindent(indent_w); +} + +CIMGUI_API void igBeginGroup() +{ + return ImGui::BeginGroup(); +} + +CIMGUI_API void igEndGroup() +{ + return ImGui::EndGroup(); +} + +CIMGUI_API void igGetCursorPos(ImVec2 *pOut) +{ + *pOut = ImGui::GetCursorPos(); +} + +CIMGUI_API float igGetCursorPosX() +{ + return ImGui::GetCursorPosX(); +} + +CIMGUI_API float igGetCursorPosY() +{ + return ImGui::GetCursorPosY(); +} + +CIMGUI_API void igSetCursorPos(CONST ImVec2 local_pos) +{ + return ImGui::SetCursorPos(local_pos); +} + +CIMGUI_API void igSetCursorPosX(float x) +{ + return ImGui::SetCursorPosX(x); +} + +CIMGUI_API void igSetCursorPosY(float y) +{ + return ImGui::SetCursorPosY(y); +} + +CIMGUI_API void igGetCursorStartPos(ImVec2 *pOut) +{ + *pOut = ImGui::GetCursorStartPos(); +} + +CIMGUI_API void igGetCursorScreenPos(ImVec2 *pOut) +{ + *pOut = ImGui::GetCursorScreenPos(); +} + +CIMGUI_API void igSetCursorScreenPos(CONST ImVec2 pos) +{ + return ImGui::SetCursorScreenPos(pos); +} + +CIMGUI_API void igAlignTextToFramePadding() +{ + return ImGui::AlignTextToFramePadding(); +} + +CIMGUI_API float igGetTextLineHeight() +{ + return ImGui::GetTextLineHeight(); +} + +CIMGUI_API float igGetTextLineHeightWithSpacing() +{ + return ImGui::GetTextLineHeightWithSpacing(); +} + +CIMGUI_API float igGetFrameHeight() +{ + return ImGui::GetFrameHeight(); +} + +CIMGUI_API float igGetFrameHeightWithSpacing() +{ + return ImGui::GetFrameHeightWithSpacing(); +} + +//Columns + +CIMGUI_API void igColumns(int count, CONST char *id, bool border) +{ + return ImGui::Columns(count, id, border); +} + +CIMGUI_API void igNextColumn() +{ + return ImGui::NextColumn(); +} + +CIMGUI_API int igGetColumnIndex() +{ + return ImGui::GetColumnIndex(); +} + +CIMGUI_API float igGetColumnWidth(int column_index) +{ + return ImGui::GetColumnWidth(column_index); +} + +CIMGUI_API void igSetColumnWidth(int column_index, float width) +{ + return ImGui::SetColumnWidth(column_index, width); +} + +CIMGUI_API float igGetColumnOffset(int column_index) +{ + return ImGui::GetColumnOffset(column_index); +} + +CIMGUI_API void igSetColumnOffset(int column_index, float offset_x) +{ + return ImGui::SetColumnOffset(column_index, offset_x); +} + +CIMGUI_API int igGetColumnsCount() +{ + return ImGui::GetColumnsCount(); +} + +// ID scopes +// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them +// You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide') +CIMGUI_API void igPushIDStr(CONST char *str_id) +{ + return ImGui::PushID(str_id); +} + +CIMGUI_API void igPushIDStrRange(CONST char *str_begin, CONST char *str_end) +{ + return ImGui::PushID(str_begin, str_end); +} + +CIMGUI_API void igPushIDPtr(CONST void *ptr_id) +{ + return ImGui::PushID(ptr_id); +} + +CIMGUI_API void igPushIDInt(int int_id) +{ + return ImGui::PushID(int_id); +} + +CIMGUI_API void igPopID() +{ + return ImGui::PopID(); +} + +CIMGUI_API ImGuiID igGetIDStr(CONST char *str_id) +{ + return ImGui::GetID(str_id); +} + +CIMGUI_API ImGuiID igGetIDStrRange(CONST char *str_begin, CONST char *str_end) +{ + return ImGui::GetID(str_begin, str_end); +} + +CIMGUI_API ImGuiID igGetIDPtr(CONST void *ptr_id) +{ + return ImGui::GetID(ptr_id); +} + +// Widgets +CIMGUI_API void igText(CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::TextV(fmt, args); + va_end(args); +} + +CIMGUI_API void igTextV(CONST char *fmt, va_list args) +{ + ImGui::TextV(fmt, args); +} + +CIMGUI_API void igTextColored(CONST ImVec4 col, CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::TextColoredV(col, fmt, args); + va_end(args); +} + +CIMGUI_API void igTextColoredV(CONST ImVec4 col, CONST char *fmt, va_list args) +{ + ImGui::TextColoredV(col, fmt, args); +} + +CIMGUI_API void igTextDisabled(CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::TextDisabledV(fmt, args); + va_end(args); +} + +CIMGUI_API void igTextDisabledV(CONST char *fmt, va_list args) +{ + return ImGui::TextDisabledV(fmt, args); +} + +CIMGUI_API void igTextWrapped(CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::TextWrappedV(fmt, args); + va_end(args); +} + +CIMGUI_API void igTextWrappedV(CONST char *fmt, va_list args) +{ + ImGui::TextWrappedV(fmt, args); +} + +CIMGUI_API void igTextUnformatted(CONST char *text, CONST char *text_end) +{ + return ImGui::TextUnformatted(text, text_end); +} + +CIMGUI_API void igLabelText(CONST char *label, CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::LabelTextV(label, fmt, args); + va_end(args); +} + +CIMGUI_API void igLabelTextV(CONST char *label, CONST char *fmt, va_list args) +{ + ImGui::LabelTextV(label, fmt, args); +} + +CIMGUI_API void igBullet() +{ + return ImGui::Bullet(); +} + +CIMGUI_API void igBulletText(CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ImGui::BulletTextV(fmt, args); + va_end(args); +} + +CIMGUI_API void igBulletTextV(CONST char *fmt, va_list args) +{ + ImGui::BulletTextV(fmt, args); +} + +CIMGUI_API bool igButton(CONST char *label, CONST ImVec2 size) +{ + return ImGui::Button(label, size); +} + +CIMGUI_API bool igSmallButton(CONST char *label) +{ + return ImGui::SmallButton(label); +} + +CIMGUI_API bool igInvisibleButton(CONST char *str_id, CONST ImVec2 size) +{ + return ImGui::InvisibleButton(str_id, size); +} + +CIMGUI_API void igImage(ImTextureID user_texture_id, CONST ImVec2 size, CONST ImVec2 uv0, CONST ImVec2 uv1, CONST ImVec4 tint_col, CONST ImVec4 border_col) +{ + return ImGui::Image(user_texture_id, size, uv0, uv1, tint_col, border_col); +} + +CIMGUI_API bool igImageButton(ImTextureID user_texture_id, CONST ImVec2 size, CONST ImVec2 uv0, CONST ImVec2 uv1, int frame_padding, CONST ImVec4 bg_col, CONST ImVec4 tint_col) +{ + return ImGui::ImageButton(user_texture_id, size, uv0, uv1, frame_padding, bg_col, tint_col); +} + +CIMGUI_API bool igCheckbox(CONST char *label, bool *v) +{ + return ImGui::Checkbox(label, v); +} + +CIMGUI_API bool igCheckboxFlags(CONST char *label, unsigned int *flags, unsigned int flags_value) +{ + return ImGui::CheckboxFlags(label, flags, flags_value); +} + +CIMGUI_API bool igRadioButtonBool(CONST char *label, bool active) +{ + return ImGui::RadioButton(label, active); +} + +CIMGUI_API bool igRadioButton(CONST char *label, int *v, int v_button) +{ + return ImGui::RadioButton(label, v, v_button); +} + +CIMGUI_API void igPlotLines(CONST char *label, CONST float *values, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride) +{ + return ImGui::PlotLines(label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); +} + +CIMGUI_API void igPlotLines2(CONST char *label, float (*values_getter)(void *data, int idx), void *data, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, ImVec2 graph_size) +{ + return ImGui::PlotLines(label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); +} + +CIMGUI_API void igPlotHistogram(CONST char *label, CONST float *values, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride) +{ + return ImGui::PlotHistogram(label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); +} + +CIMGUI_API void igPlotHistogram2(CONST char *label, float (*values_getter)(void *data, int idx), void *data, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, ImVec2 graph_size) +{ + return ImGui::PlotHistogram(label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); +} + +CIMGUI_API void igProgressBar(float fraction, CONST ImVec2 *size_arg, CONST char *overlay) +{ + return ImGui::ProgressBar(fraction, *size_arg, overlay); +} + +// Widgets: Sliders (tip: ctrl+click on a slider to input text) +CIMGUI_API bool igSliderFloat(CONST char *label, float *v, float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::SliderFloat(label, v, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igSliderFloat2(CONST char *label, float v[2], float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::SliderFloat2(label, v, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igSliderFloat3(CONST char *label, float v[3], float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::SliderFloat3(label, v, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igSliderFloat4(CONST char *label, float v[4], float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::SliderFloat4(label, v, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igSliderAngle(CONST char *label, float *v_rad, float v_degrees_min, float v_degrees_max) +{ + return ImGui::SliderAngle(label, v_rad, v_degrees_min, v_degrees_max); +} + +CIMGUI_API bool igSliderInt(CONST char *label, int *v, int v_min, int v_max, CONST char *display_format) +{ + return ImGui::SliderInt(label, v, v_min, v_max, display_format); +} + +CIMGUI_API bool igSliderInt2(CONST char *label, int v[2], int v_min, int v_max, CONST char *display_format) +{ + return ImGui::SliderInt2(label, v, v_min, v_max, display_format); +} + +CIMGUI_API bool igSliderInt3(CONST char *label, int v[3], int v_min, int v_max, CONST char *display_format) +{ + return ImGui::SliderInt3(label, v, v_min, v_max, display_format); +} + +CIMGUI_API bool igSliderInt4(CONST char *label, int v[4], int v_min, int v_max, CONST char *display_format) +{ + return ImGui::SliderInt4(label, v, v_min, v_max, display_format); +} + +CIMGUI_API bool igVSliderFloat(CONST char *label, CONST ImVec2 size, float *v, float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::VSliderFloat(label, size, v, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igVSliderInt(CONST char *label, CONST ImVec2 size, int *v, int v_min, int v_max, CONST char *display_format) +{ + return ImGui::VSliderInt(label, size, v, v_min, v_max, display_format); +} + +CIMGUI_API bool igBeginCombo(CONST char *label, CONST char *preview_value, ImGuiComboFlags flags) +{ + return ImGui::BeginCombo(label, preview_value, flags); +} + +CIMGUI_API void igEndCombo() +{ + return ImGui::EndCombo(); +} + +CIMGUI_API bool igCombo(CONST char *label, int *current_item, CONST char *CONST *items, int items_count, int popup_max_height_in_items) +{ + return ImGui::Combo(label, current_item, items, items_count, popup_max_height_in_items); +} + +CIMGUI_API bool igCombo2(CONST char *label, int *current_item, CONST char *items_separated_by_zeros, int popup_max_height_in_items) +{ + return ImGui::Combo(label, current_item, items_separated_by_zeros, popup_max_height_in_items); +} + +CIMGUI_API bool igCombo3(CONST char *label, int *current_item, bool (*items_getter)(void *data, int idx, CONST char **out_text), void *data, int items_count, int popup_max_height_in_items) +{ + return ImGui::Combo(label, current_item, items_getter, data, items_count, popup_max_height_in_items); +} + +// Widgets: Color Editor/Picker (tip: the ColorEdit* functions have a little colored preview square that can be left-clicked to open a picker, and right-clicked to open an option menu.) +CIMGUI_API bool igColorEdit3(CONST char *label, float col[3], ImGuiColorEditFlags flags) +{ + return ImGui::ColorEdit3(label, col, flags); +} + +CIMGUI_API bool igColorEdit4(CONST char *label, float col[4], ImGuiColorEditFlags flags) +{ + return ImGui::ColorEdit4(label, col, flags); +} + +CIMGUI_API bool igColorPicker3(CONST char *label, float col[3], ImGuiColorEditFlags flags) +{ + return ImGui::ColorPicker3(label, col, flags); +} + +CIMGUI_API bool igColorPicker4(CONST char *label, float col[4], ImGuiColorEditFlags flags, CONST float *ref_col) +{ + return ImGui::ColorPicker4(label, col, flags, ref_col); +} + +CIMGUI_API bool igColorButton(CONST char *desc_id, CONST ImVec4 col, ImGuiColorEditFlags flags, CONST ImVec2 size) +{ + return ImGui::ColorButton(desc_id, col, flags, size); +} + +CIMGUI_API void igSetColorEditOptions(ImGuiColorEditFlags flags) +{ + return ImGui::SetColorEditOptions(flags); +} + +// Widgets: Drags (tip: ctrl+click on a drag box to input text) +CIMGUI_API bool igDragFloat(CONST char *label, float *v, float v_speed, float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::DragFloat(label, v, v_speed, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igDragFloat2(CONST char *label, float v[2], float v_speed, float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::DragFloat2(label, v, v_speed, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igDragFloat3(CONST char *label, float v[3], float v_speed, float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::DragFloat3(label, v, v_speed, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igDragFloat4(CONST char *label, float v[4], float v_speed, float v_min, float v_max, CONST char *display_format, float power) +{ + return ImGui::DragFloat4(label, v, v_speed, v_min, v_max, display_format, power); +} + +CIMGUI_API bool igDragFloatRange2(CONST char *label, float *v_current_min, float *v_current_max, float v_speed, float v_min, float v_max, CONST char *display_format, CONST char *display_format_max, float power) +{ + return ImGui::DragFloatRange2(label, v_current_min, v_current_max, v_speed, v_min, v_max, display_format, display_format_max, power); +} + +CIMGUI_API bool igDragInt(CONST char *label, int *v, float v_speed, int v_min, int v_max, CONST char *display_format) +{ + return ImGui::DragInt(label, v, v_speed, v_min, v_max, display_format); +} + +CIMGUI_API bool igDragInt2(CONST char *label, int v[2], float v_speed, int v_min, int v_max, CONST char *display_format) +{ + return ImGui::DragInt2(label, v, v_speed, v_min, v_max, display_format); +} + +CIMGUI_API bool igDragInt3(CONST char *label, int v[3], float v_speed, int v_min, int v_max, CONST char *display_format) +{ + return ImGui::DragInt3(label, v, v_speed, v_min, v_max, display_format); +} + +CIMGUI_API bool igDragInt4(CONST char *label, int v[4], float v_speed, int v_min, int v_max, CONST char *display_format) +{ + return ImGui::DragInt4(label, v, v_speed, v_min, v_max, display_format); +} + +CIMGUI_API bool igDragIntRange2(CONST char *label, int *v_current_min, int *v_current_max, float v_speed, int v_min, int v_max, CONST char *display_format, CONST char *display_format_max) +{ + return ImGui::DragIntRange2(label, v_current_min, v_current_max, v_speed, v_min, v_max, display_format, display_format_max); +} + +// Widgets: Input +CIMGUI_API bool igInputText(CONST char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void *user_data) +{ + return ImGui::InputText(label, buf, buf_size, flags, callback, user_data); +} + +CIMGUI_API bool igInputTextMultiline(CONST char *label, char *buf, size_t buf_size, CONST ImVec2 size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void *user_data) +{ + return ImGui::InputTextMultiline(label, buf, buf_size, size, flags, callback, user_data); +} + +CIMGUI_API bool igInputFloat(CONST char *label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputFloat(label, v, step, step_fast, decimal_precision, extra_flags); +} + +CIMGUI_API bool igInputFloat2(CONST char *label, float v[2], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputFloat2(label, v, decimal_precision, extra_flags); +} + +CIMGUI_API bool igInputFloat3(CONST char *label, float v[3], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputFloat3(label, v, decimal_precision, extra_flags); +} + +CIMGUI_API bool igInputFloat4(CONST char *label, float v[4], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputFloat4(label, v, decimal_precision, extra_flags); +} + +CIMGUI_API bool igInputInt(CONST char *label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputInt(label, v, step, step_fast, extra_flags); +} + +CIMGUI_API bool igInputInt2(CONST char *label, int v[2], ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputInt2(label, v, extra_flags); +} + +CIMGUI_API bool igInputInt3(CONST char *label, int v[3], ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputInt3(label, v, extra_flags); +} + +CIMGUI_API bool igInputInt4(CONST char *label, int v[4], ImGuiInputTextFlags extra_flags) +{ + return ImGui::InputInt4(label, v, extra_flags); +} + +// Widgets: Trees +CIMGUI_API bool igTreeNode(CONST char *label) +{ + return ImGui::TreeNode(label); +} + +CIMGUI_API bool igTreeNodeStr(CONST char *str_id, CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool res = ImGui::TreeNodeV(str_id, fmt, args); + va_end(args); + + return res; +} + +CIMGUI_API bool igTreeNodePtr(CONST void *ptr_id, CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool res = ImGui::TreeNodeV(ptr_id, fmt, args); + va_end(args); + + return res; +} + +CIMGUI_API bool igTreeNodeStrV(CONST char *str_id, CONST char *fmt, va_list args) +{ + return ImGui::TreeNodeV(str_id, fmt, args); +} + +CIMGUI_API bool igTreeNodePtrV(CONST void *ptr_id, CONST char *fmt, va_list args) +{ + return ImGui::TreeNodeV(ptr_id, fmt, args); +} + +CIMGUI_API bool igTreeNodeEx(CONST char *label, ImGuiTreeNodeFlags flags) +{ + return ImGui::TreeNodeEx(label, flags); +} + +CIMGUI_API bool igTreeNodeExStr(CONST char *str_id, ImGuiTreeNodeFlags flags, CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool res = ImGui::TreeNodeExV(str_id, flags, fmt, args); + va_end(args); + + return res; +} + +CIMGUI_API bool igTreeNodeExPtr(CONST void *ptr_id, ImGuiTreeNodeFlags flags, CONST char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool res = ImGui::TreeNodeExV(ptr_id, flags, fmt, args); + va_end(args); + + return res; +} + +CIMGUI_API bool igTreeNodeExV(CONST char *str_id, ImGuiTreeNodeFlags flags, CONST char *fmt, va_list args) +{ + return ImGui::TreeNodeExV(str_id, flags, fmt, args); +} + +CIMGUI_API bool igTreeNodeExVPtr(CONST void *ptr_id, ImGuiTreeNodeFlags flags, CONST char *fmt, va_list args) +{ + return ImGui::TreeNodeExV(ptr_id, flags, fmt, args); +} + +CIMGUI_API void igTreePushStr(CONST char *str_id) +{ + return ImGui::TreePush(str_id); +} + +CIMGUI_API void igTreePushPtr(CONST void *ptr_id) +{ + return ImGui::TreePush(ptr_id); +} + +CIMGUI_API void igTreePop() +{ + return ImGui::TreePop(); +} + +CIMGUI_API void igTreeAdvanceToLabelPos() +{ + return ImGui::TreeAdvanceToLabelPos(); +} + +CIMGUI_API float igGetTreeNodeToLabelSpacing() +{ + return ImGui::GetTreeNodeToLabelSpacing(); +} + +CIMGUI_API void igSetNextTreeNodeOpen(bool opened, ImGuiCond cond) +{ + return ImGui::SetNextTreeNodeOpen(opened, cond); +} + +CIMGUI_API bool igCollapsingHeader(CONST char *label, ImGuiTreeNodeFlags flags) +{ + return ImGui::CollapsingHeader(label, flags); +} + +CIMGUI_API bool igCollapsingHeaderEx(CONST char *label, bool *p_open, ImGuiTreeNodeFlags flags) +{ + return ImGui::CollapsingHeader(label, p_open, flags); +} + +// Widgets: Selectable / Lists +CIMGUI_API bool igSelectable(CONST char *label, bool selected, ImGuiSelectableFlags flags, CONST ImVec2 size) +{ + return ImGui::Selectable(label, selected, flags, size); +} + +CIMGUI_API bool igSelectableEx(CONST char *label, bool *p_selected, ImGuiSelectableFlags flags, CONST ImVec2 size) +{ + return ImGui::Selectable(label, p_selected, flags, size); +} + +CIMGUI_API bool igListBox(CONST char *label, int *current_item, CONST char *CONST *items, int items_count, int height_in_items) +{ + return ImGui::ListBox(label, current_item, items, items_count, height_in_items); +} + +CIMGUI_API bool igListBox2(CONST char *label, int *current_item, bool (*items_getter)(void *data, int idx, CONST char **out_text), void *data, int items_count, int height_in_items) +{ + return ImGui::ListBox(label, current_item, items_getter, data, items_count, height_in_items); +} + +CIMGUI_API bool igListBoxHeader(CONST char *label, CONST ImVec2 size) +{ + return ImGui::ListBoxHeader(label, size); +} + +CIMGUI_API bool igListBoxHeader2(CONST char *label, int items_count, int height_in_items) +{ + return ImGui::ListBoxHeader(label, items_count, height_in_items); +} + +CIMGUI_API void igListBoxFooter() +{ + return ImGui::ListBoxFooter(); +} + +CIMGUI_API bool igBeginMainMenuBar() +{ + return ImGui::BeginMainMenuBar(); +} + +CIMGUI_API void igEndMainMenuBar() +{ + return ImGui::EndMainMenuBar(); +} + +CIMGUI_API bool igBeginMenuBar() +{ + return ImGui::BeginMenuBar(); +} + +CIMGUI_API void igEndMenuBar() +{ + return ImGui::EndMenuBar(); +} + +CIMGUI_API bool igBeginMenu(CONST char *label, bool enabled) +{ + return ImGui::BeginMenu(label, enabled); +} + +CIMGUI_API void igEndMenu() +{ + return ImGui::EndMenu(); +} + +CIMGUI_API bool igMenuItem(CONST char *label, CONST char *shortcut, bool selected, bool enabled) +{ + return ImGui::MenuItem(label, shortcut, selected, enabled); +} + +CIMGUI_API bool igMenuItemPtr(CONST char *label, CONST char *shortcut, bool *p_selected, bool enabled) +{ + return ImGui::MenuItem(label, shortcut, p_selected, enabled); +} + +// Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare your own within the ImGui namespace!) +CIMGUI_API void igValueBool(CONST char *prefix, bool b) +{ + ImGui::Value(prefix, b); +} + +CIMGUI_API void igValueInt(CONST char *prefix, int v) +{ + ImGui::Value(prefix, v); +} + +CIMGUI_API void igValueUInt(CONST char *prefix, unsigned int v) +{ + ImGui::Value(prefix, v); +} + +CIMGUI_API void igValueFloat(CONST char *prefix, float v, CONST char *float_format) +{ + ImGui::Value(prefix, v, float_format); +} + +// Logging: all text output from interface is redirected to tty/file/clipboard. Tree nodes are automatically opened. +CIMGUI_API void igLogToTTY(int max_depth) +{ + ImGui::LogToTTY(max_depth); +} + +CIMGUI_API void igLogToFile(int max_depth, CONST char *filename) +{ + ImGui::LogToFile(max_depth, filename); +} + +CIMGUI_API void igLogToClipboard(int max_depth) +{ + ImGui::LogToClipboard(max_depth); +} + +CIMGUI_API void igLogFinish() +{ + ImGui::LogFinish(); +} + +CIMGUI_API void igLogButtons() +{ + ImGui::LogButtons(); +} + +CIMGUI_API void igLogText(CONST char *fmt, ...) +{ + char buffer[256]; + va_list args; + va_start(args, fmt); + vsnprintf(buffer, 256, fmt, args); + va_end(args); + + ImGui::LogText("%s", buffer); +} + +CIMGUI_API bool igBeginDragDropSource(ImGuiDragDropFlags flags, int mouse_button) +{ + return ImGui::BeginDragDropSource(flags, mouse_button); +} + +CIMGUI_API bool igSetDragDropPayload(CONST char *type, CONST void *data, size_t size, ImGuiCond cond) +{ + return ImGui::SetDragDropPayload(type, data, size, cond); +} + +CIMGUI_API void igEndDragDropSource() +{ + ImGui::EndDragDropSource(); +} + +CIMGUI_API bool igBeginDragDropTarget() +{ + return ImGui::BeginDragDropTarget(); +} + +CIMGUI_API CONST struct ImGuiPayload *igAcceptDragDropPayload(CONST char *type, ImGuiDragDropFlags flags) +{ + return ImGui::AcceptDragDropPayload(type, flags); +} + +CIMGUI_API void igEndDragDropTarget() +{ + ImGui::EndDragDropTarget(); +} + +CIMGUI_API void igPushClipRect(CONST struct ImVec2 clip_rect_min, CONST struct ImVec2 clip_rect_max, bool intersect_with_current_clip_rect) +{ + return ImGui::PushClipRect(clip_rect_min, clip_rect_max, intersect_with_current_clip_rect); +} + +CIMGUI_API void igPopClipRect() +{ + return ImGui::PopClipRect(); +} + +CIMGUI_API void igStyleColorsClassic(struct ImGuiStyle *dst) +{ + ImGui::StyleColorsClassic(dst); +} + +CIMGUI_API void igStyleColorsDark(struct ImGuiStyle *dst) +{ + ImGui::StyleColorsDark(dst); +} + +CIMGUI_API void igStyleColorsLight(struct ImGuiStyle *dst) +{ + ImGui::StyleColorsLight(dst); +} + +CIMGUI_API void igSetItemDefaultFocus() +{ + ImGui::SetItemDefaultFocus(); +} + +CIMGUI_API void igSetKeyboardFocusHere(int offset) +{ + ImGui::SetKeyboardFocusHere(offset); +} + +// Utilities +CIMGUI_API bool igIsItemHovered(ImGuiHoveredFlags flags) +{ + return ImGui::IsItemHovered(flags); +} + +CIMGUI_API bool igIsItemActive() +{ + return ImGui::IsItemActive(); +} + +CIMGUI_API bool igIsItemClicked(int mouse_button) +{ + return ImGui::IsItemClicked(mouse_button); +} + +CIMGUI_API bool igIsItemVisible() +{ + return ImGui::IsItemVisible(); +} + +CIMGUI_API bool igIsAnyItemHovered() +{ + return ImGui::IsAnyItemHovered(); +} + +CIMGUI_API bool igIsAnyItemActive() +{ + return ImGui::IsAnyItemActive(); +} + +CIMGUI_API void igGetItemRectMin(ImVec2 *pOut) +{ + *pOut = ImGui::GetItemRectMin(); +} + +CIMGUI_API void igGetItemRectMax(ImVec2 *pOut) +{ + *pOut = ImGui::GetItemRectMax(); +} + +CIMGUI_API void igGetItemRectSize(ImVec2 *pOut) +{ + *pOut = ImGui::GetItemRectSize(); +} + +CIMGUI_API void igSetItemAllowOverlap() +{ + ImGui::SetItemAllowOverlap(); +} + +CIMGUI_API bool igIsWindowFocused(ImGuiFocusedFlags flags) +{ + return ImGui::IsWindowFocused(flags); +} + +CIMGUI_API bool igIsWindowHovered(ImGuiHoveredFlags) +{ + return ImGui::IsWindowHovered(); +} + +CIMGUI_API bool igIsAnyWindowFocused() +{ + return ImGui::IsAnyWindowFocused(); +} + +CIMGUI_API bool igIsAnyWindowHovered() +{ + return ImGui::IsAnyWindowHovered(); +} + +CIMGUI_API bool igIsRectVisible(CONST ImVec2 item_size) +{ + return ImGui::IsRectVisible(item_size); +} + +CIMGUI_API bool igIsRectVisible2(CONST struct ImVec2 *rect_min, CONST struct ImVec2 *rect_max) +{ + return ImGui::IsRectVisible(*rect_min, *rect_max); +} + +CIMGUI_API int igGetKeyIndex(ImGuiKey imgui_key) +{ + return ImGui::GetKeyIndex(imgui_key); +} + +CIMGUI_API bool igIsKeyDown(int user_key_index) +{ + return ImGui::IsKeyDown(user_key_index); +} + +CIMGUI_API bool igIsKeyPressed(int user_key_index, bool repeat) +{ + return ImGui::IsKeyPressed(user_key_index, repeat); +} + +CIMGUI_API bool igIsKeyReleased(int user_key_index) +{ + return ImGui::IsKeyReleased(user_key_index); +} + +CIMGUI_API int igGetKeyPressedAmount(int key_index, float repeat_delay, float rate) +{ + return ImGui::GetKeyPressedAmount(key_index, repeat_delay, rate); +} + +CIMGUI_API bool igIsMouseDown(int button) +{ + return ImGui::IsMouseDown(button); +} + +CIMGUI_API bool igIsMouseClicked(int button, bool repeat) +{ + return ImGui::IsMouseClicked(button, repeat); +} + +CIMGUI_API bool igIsMouseDoubleClicked(int button) +{ + return ImGui::IsMouseDoubleClicked(button); +} + +CIMGUI_API bool igIsMouseReleased(int button) +{ + return ImGui::IsMouseReleased(button); +} + +CIMGUI_API bool igIsMouseDragging(int button, float lock_threshold) +{ + return ImGui::IsMouseDragging(button, lock_threshold); +} + +CIMGUI_API bool igIsMouseHoveringRect(CONST ImVec2 r_min, CONST ImVec2 r_max, bool clip) +{ + return ImGui::IsMouseHoveringRect(r_min, r_max, clip); +} + +CIMGUI_API bool igIsMousePosValid(CONST struct ImVec2 *mouse_pos) +{ + return ImGui::IsMousePosValid(mouse_pos); +} + +CIMGUI_API void igGetMousePos(ImVec2 *pOut) +{ + *pOut = ImGui::GetMousePos(); +} + +CIMGUI_API void igGetMousePosOnOpeningCurrentPopup(ImVec2 *pOut) +{ + *pOut = ImGui::GetMousePosOnOpeningCurrentPopup(); +} + +CIMGUI_API void igGetMouseDragDelta(ImVec2 *pOut, int button, float lock_threshold) +{ + *pOut = ImGui::GetMouseDragDelta(button, lock_threshold); +} + +CIMGUI_API void igResetMouseDragDelta(int button) +{ + ImGui::ResetMouseDragDelta(button); +} + +CIMGUI_API ImGuiMouseCursor igGetMouseCursor() +{ + return ImGui::GetMouseCursor(); +} + +CIMGUI_API void igSetMouseCursor(ImGuiMouseCursor type) +{ + ImGui::SetMouseCursor(type); +} + +CIMGUI_API void igCaptureKeyboardFromApp(bool capture) +{ + return ImGui::CaptureKeyboardFromApp(capture); +} + +CIMGUI_API void igCaptureMouseFromApp(bool capture) +{ + return ImGui::CaptureMouseFromApp(capture); +} + +CIMGUI_API void *igMemAlloc(size_t sz) +{ + return ImGui::MemAlloc(sz); +} + +CIMGUI_API void igMemFree(void *ptr) +{ + return ImGui::MemFree(ptr); +} + +CIMGUI_API CONST char *igGetClipboardText() +{ + return ImGui::GetClipboardText(); +} + +CIMGUI_API void igSetClipboardText(CONST char *text) +{ + return ImGui::SetClipboardText(text); +} + +CIMGUI_API float igGetTime() +{ + return ImGui::GetTime(); +} + +CIMGUI_API int igGetFrameCount() +{ + return ImGui::GetFrameCount(); +} + +CIMGUI_API struct ImDrawList *igGetOverlayDrawList() +{ + return ImGui::GetOverlayDrawList(); +} + +CIMGUI_API struct ImDrawListSharedData *igGetDrawListSharedData() +{ + return ImGui::GetDrawListSharedData(); +} + +CIMGUI_API CONST char *igGetStyleColorName(ImGuiCol idx) +{ + return ImGui::GetStyleColorName(idx); +} + +CIMGUI_API void igCalcItemRectClosestPoint(ImVec2 *pOut, CONST ImVec2 pos, bool on_edge, float outward) +{ + *pOut = ImGui::CalcItemRectClosestPoint(pos, on_edge, outward); +} + +CIMGUI_API void igCalcTextSize(ImVec2 *pOut, CONST char *text, CONST char *text_end, bool hide_text_after_double_hash, float wrap_width) +{ + *pOut = ImGui::CalcTextSize(text, text_end, hide_text_after_double_hash, wrap_width); +} + +CIMGUI_API void igCalcListClipping(int items_count, float items_height, int *out_items_display_start, int *out_items_display_end) +{ + ImGui::CalcListClipping(items_count, items_height, out_items_display_start, out_items_display_end); +} + +CIMGUI_API bool igBeginChildFrame(ImGuiID id, CONST ImVec2 size, ImGuiWindowFlags extra_flags) +{ + return ImGui::BeginChildFrame(id, size, extra_flags); +} + +CIMGUI_API void igEndChildFrame() +{ + ImGui::EndChildFrame(); +} + +CIMGUI_API void igColorConvertU32ToFloat4(ImVec4 *pOut, ImU32 in) +{ + *pOut = ImGui::ColorConvertU32ToFloat4(in); +} + +CIMGUI_API ImU32 igColorConvertFloat4ToU32(CONST ImVec4 in) +{ + return ImGui::ColorConvertFloat4ToU32(in); +} + +CIMGUI_API void igColorConvertRGBtoHSV(float r, float g, float b, float *out_h, float *out_s, float *out_v) +{ + ImGui::ColorConvertRGBtoHSV(r, g, b, *out_h, *out_s, *out_v); +} + +CIMGUI_API void igColorConvertHSVtoRGB(float h, float s, float v, float *out_r, float *out_g, float *out_b) +{ + ImGui::ColorConvertHSVtoRGB(h, s, v, *out_r, *out_g, *out_b); +} + +CIMGUI_API CONST char *igGetVersion() +{ + return ImGui::GetVersion(); +} + +CIMGUI_API ImGuiContext *igCreateContext(void *(*malloc_fn)(size_t), void (*free_fn)(void *)) +{ + return ImGui::CreateContext(malloc_fn, free_fn); +} + +CIMGUI_API void igDestroyContext(ImGuiContext *ctx) +{ + return ImGui::DestroyContext(ctx); +} + +CIMGUI_API ImGuiContext *igGetCurrentContext() +{ + return ImGui::GetCurrentContext(); +} + +CIMGUI_API void igSetCurrentContext(ImGuiContext *ctx) +{ + return ImGui::SetCurrentContext(ctx); +} + +CIMGUI_API void ImGuiIO_AddInputCharacter(unsigned short c) +{ + ImGui::GetIO().AddInputCharacter(c); +} + +CIMGUI_API void ImGuiIO_AddInputCharactersUTF8(CONST char *utf8_chars) +{ + return ImGui::GetIO().AddInputCharactersUTF8(utf8_chars); +} + +CIMGUI_API void ImGuiIO_ClearInputCharacters() +{ + return ImGui::GetIO().ClearInputCharacters(); +} + +CIMGUI_API struct ImGuiTextFilter *ImGuiTextFilter_Create(const char *default_filter) +{ + ImGuiTextFilter *filter = (ImGuiTextFilter *)ImGui::MemAlloc(sizeof(ImGuiTextFilter)); + IM_PLACEMENT_NEW(filter) + ImGuiTextFilter(default_filter); + return filter; +} + +CIMGUI_API void ImGuiTextFilter_Destroy(struct ImGuiTextFilter *filter) +{ + filter->~ImGuiTextFilter(); + ImGui::MemFree(filter); +} + +CIMGUI_API void ImGuiTextFilter_Clear(struct ImGuiTextFilter *filter) +{ + filter->Clear(); +} + +CIMGUI_API bool ImGuiTextFilter_Draw(struct ImGuiTextFilter *filter, const char *label, float width) +{ + return filter->Draw(label, width); +} + +CIMGUI_API bool ImGuiTextFilter_PassFilter(const struct ImGuiTextFilter *filter, const char *text, const char *text_end) +{ + return filter->PassFilter(text, text_end); +} + +CIMGUI_API bool ImGuiTextFilter_IsActive(const struct ImGuiTextFilter *filter) +{ + return filter->IsActive(); +} + +CIMGUI_API void ImGuiTextFilter_Build(struct ImGuiTextFilter *filter) +{ + filter->Build(); +} + +CIMGUI_API const char *ImGuiTextFilter_GetInputBuf(struct ImGuiTextFilter *filter) +{ + return filter->InputBuf; +} + +CIMGUI_API struct ImGuiTextBuffer *ImGuiTextBuffer_Create() +{ + ImGuiTextBuffer *buffer = (ImGuiTextBuffer *)ImGui::MemAlloc(sizeof(ImGuiTextBuffer)); + IM_PLACEMENT_NEW(buffer) + ImGuiTextBuffer(); + return buffer; +} + +CIMGUI_API void ImGuiTextBuffer_Destroy(struct ImGuiTextBuffer *buffer) +{ + buffer->~ImGuiTextBuffer(); + ImGui::MemFree(buffer); +} + +CIMGUI_API char ImGuiTextBuffer_index(struct ImGuiTextBuffer *buffer, int i) +{ + return (*buffer)[i]; +} + +CIMGUI_API const char *ImGuiTextBuffer_begin(const struct ImGuiTextBuffer *buffer) +{ + return buffer->begin(); +} + +CIMGUI_API const char *ImGuiTextBuffer_end(const struct ImGuiTextBuffer *buffer) +{ + return buffer->end(); +} + +CIMGUI_API int ImGuiTextBuffer_size(const struct ImGuiTextBuffer *buffer) +{ + return buffer->size(); +} + +CIMGUI_API bool ImGuiTextBuffer_empty(struct ImGuiTextBuffer *buffer) +{ + return buffer->empty(); +} + +CIMGUI_API void ImGuiTextBuffer_clear(struct ImGuiTextBuffer *buffer) +{ + buffer->clear(); +} + +CIMGUI_API const char *ImGuiTextBuffer_c_str(const struct ImGuiTextBuffer *buffer) +{ + return buffer->c_str(); +} + +CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + buffer->appendfv(fmt, args); + va_end(args); +} + +CIMGUI_API void ImGuiTextBuffer_appendfv(struct ImGuiTextBuffer *buffer, const char *fmt, va_list args) +{ + buffer->appendfv(fmt, args); +} + +CIMGUI_API struct ImGuiStorage *ImGuiStorage_Create() +{ + ImGuiStorage *storage = (ImGuiStorage *)ImGui::MemAlloc(sizeof(ImGuiStorage)); + IM_PLACEMENT_NEW(storage) + ImGuiStorage(); + return storage; +} + +CIMGUI_API void ImGuiStorage_Destroy(struct ImGuiStorage *storage) +{ + storage->~ImGuiStorage(); + ImGui::MemFree(storage); +} + +CIMGUI_API void ImGuiStorage_Clear(struct ImGuiStorage *storage) +{ + storage->Clear(); +} + +CIMGUI_API int ImGuiStorage_GetInt(struct ImGuiStorage *storage, ImGuiID key, int default_val) +{ + return storage->GetInt(key, default_val); +} + +CIMGUI_API void ImGuiStorage_SetInt(struct ImGuiStorage *storage, ImGuiID key, int val) +{ + storage->SetInt(key, val); +} + +CIMGUI_API bool ImGuiStorage_GetBool(struct ImGuiStorage *storage, ImGuiID key, bool default_val) +{ + return storage->GetBool(key, default_val); +} + +CIMGUI_API void ImGuiStorage_SetBool(struct ImGuiStorage *storage, ImGuiID key, bool val) +{ + storage->SetBool(key, val); +} + +CIMGUI_API float ImGuiStorage_GetFloat(struct ImGuiStorage *storage, ImGuiID key, float default_val) +{ + return storage->GetFloat(key, default_val); +} + +CIMGUI_API void ImGuiStorage_SetFloat(struct ImGuiStorage *storage, ImGuiID key, float val) +{ + storage->SetFloat(key, val); +} + +CIMGUI_API void *ImGuiStorage_GetVoidPtr(struct ImGuiStorage *storage, ImGuiID key) +{ + return storage->GetVoidPtr(key); +} + +CIMGUI_API void ImGuiStorage_SetVoidPtr(struct ImGuiStorage *storage, ImGuiID key, void *val) +{ + storage->SetVoidPtr(key, val); +} + +CIMGUI_API int *ImGuiStorage_GetIntRef(struct ImGuiStorage *storage, ImGuiID key, int default_val) +{ + return storage->GetIntRef(key, default_val); +} + +CIMGUI_API bool *ImGuiStorage_GetBoolRef(struct ImGuiStorage *storage, ImGuiID key, bool default_val) +{ + return storage->GetBoolRef(key, default_val); +} + +CIMGUI_API float *ImGuiStorage_GetFloatRef(struct ImGuiStorage *storage, ImGuiID key, float default_val) +{ + return storage->GetFloatRef(key, default_val); +} + +CIMGUI_API void **ImGuiStorage_GetVoidPtrRef(struct ImGuiStorage *storage, ImGuiID key, void *default_val) +{ + return storage->GetVoidPtrRef(key, default_val); +} + +CIMGUI_API void ImGuiStorage_SetAllInt(struct ImGuiStorage *storage, int val) +{ + storage->SetAllInt(val); +} + +CIMGUI_API void ImGuiTextEditCallbackData_DeleteChars(struct ImGuiTextEditCallbackData *data, int pos, int bytes_count) +{ + data->DeleteChars(pos, bytes_count); +} + +CIMGUI_API void ImGuiTextEditCallbackData_InsertChars(struct ImGuiTextEditCallbackData *data, int pos, const char *text, const char *text_end) +{ + data->InsertChars(pos, text, text_end); +} + +CIMGUI_API bool ImGuiTextEditCallbackData_HasSelection(struct ImGuiTextEditCallbackData *data) +{ + return data->HasSelection(); +} diff --git a/lib/cimgui-1.53.1/cimgui/cimgui.h b/lib/cimgui-1.53.1/cimgui/cimgui.h new file mode 100644 index 0000000..ef974c2 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/cimgui.h @@ -0,0 +1,1138 @@ +#ifndef __CIMGUI_H__ +#define __CIMGUI_H__ +#include + +#if defined _WIN32 || defined __CYGWIN__ +#ifdef CIMGUI_NO_EXPORT +#define API +#else +#define API __declspec(dllexport) +#endif +#ifndef __GNUC__ +#define snprintf sprintf_s +#endif +#else +#define API +#endif + +#if defined __cplusplus +#define EXTERN extern "C" +#else +#include +#include +#define EXTERN extern +#endif + +#define CIMGUI_API EXTERN API +#define CONST const + +struct ImGuiIO; +struct ImGuiStyle; +struct ImDrawData; +struct ImVec2; +struct ImVec4; +struct ImGuiTextEditCallbackData; +struct ImGuiSizeConstraintCallbackData; +struct ImDrawList; +struct ImGuiStorage; +struct ImFont; +struct ImFontConfig; +struct ImFontAtlas; +struct ImDrawCmd; +struct ImGuiListClipper; +struct ImGuiTextFilter; +struct ImGuiPayload; + +#if defined __cplusplus +#define IMFONTGLYPH ImFontGlyph +#else +struct Glyph; +#define IMFONTGLYPH Glyph +#endif + +typedef unsigned short ImDrawIdx; +typedef unsigned int ImU32; +typedef unsigned short ImWchar; +typedef void *ImTextureID; +typedef ImU32 ImGuiID; +typedef int ImGuiCol; +typedef int ImGuiStyleVar; +typedef int ImGuiKey; +typedef int ImGuiColorEditFlags; +typedef int ImGuiMouseCursor; +typedef int ImGuiWindowFlags; +typedef int ImGuiCond; +typedef int ImGuiColumnsFlags; +typedef int ImGuiInputTextFlags; +typedef int ImGuiSelectableFlags; +typedef int ImGuiTreeNodeFlags; +typedef int ImGuiHoveredFlags; +typedef int ImGuiComboFlags; +typedef int ImGuiDragDropFlags; +typedef int ImGuiFocusedFlags; +typedef int ImDrawCornerFlags; +typedef int ImDrawListFlags; +typedef int (*ImGuiTextEditCallback)(struct ImGuiTextEditCallbackData *data); +typedef void (*ImGuiSizeConstraintCallback)(struct ImGuiSizeConstraintCallbackData *data); +typedef void (*ImDrawCallback)(CONST struct ImDrawList *parent_list, CONST struct ImDrawCmd *cmd); +#ifdef _MSC_VER +typedef unsigned __int64 ImU64; +#else +typedef unsigned long long ImU64; +#endif + +#ifndef IMGUI_VERSION +struct ImVec2 +{ + float x, y; +}; + +struct ImVec4 +{ + float x, y, z, w; +}; + +enum +{ + ImGuiWindowFlags_NoTitleBar = 1 << 0, + ImGuiWindowFlags_NoResize = 1 << 1, + ImGuiWindowFlags_NoMove = 1 << 2, + ImGuiWindowFlags_NoScrollbar = 1 << 3, + ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, + ImGuiWindowFlags_NoCollapse = 1 << 5, + ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, + //ImGuiWindowFlags_ShowBorders = 1 << 7, + ImGuiWindowFlags_NoSavedSettings = 1 << 8, + ImGuiWindowFlags_NoInputs = 1 << 9, + ImGuiWindowFlags_MenuBar = 1 << 10, + ImGuiWindowFlags_HorizontalScrollbar = 1 << 11, + ImGuiWindowFlags_NoFocusOnAppearing = 1 << 12, + ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, + ImGuiWindowFlags_AlwaysVerticalScrollbar = 1 << 14, + ImGuiWindowFlags_AlwaysHorizontalScrollbar = 1 << 15, + ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16, + ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, +}; + +enum +{ + ImGuiInputTextFlags_CharsDecimal = 1 << 0, + ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, + ImGuiInputTextFlags_CharsUppercase = 1 << 2, + ImGuiInputTextFlags_CharsNoBlank = 1 << 3, + ImGuiInputTextFlags_AutoSelectAll = 1 << 4, + ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, + ImGuiInputTextFlags_CallbackCompletion = 1 << 6, + ImGuiInputTextFlags_CallbackHistory = 1 << 7, + ImGuiInputTextFlags_CallbackAlways = 1 << 8, + ImGuiInputTextFlags_CallbackCharFilter = 1 << 9, + ImGuiInputTextFlags_AllowTabInput = 1 << 10, + ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11, + ImGuiInputTextFlags_NoHorizontalScroll = 1 << 12, + ImGuiInputTextFlags_AlwaysInsertMode = 1 << 13, + ImGuiInputTextFlags_ReadOnly = 1 << 14, + ImGuiInputTextFlags_Password = 1 << 15, + ImGuiInputTextFlags_NoUndoRedo = 1 << 16, +}; + +enum +{ + ImGuiTreeNodeFlags_Selected = 1 << 0, + ImGuiTreeNodeFlags_Framed = 1 << 1, + ImGuiTreeNodeFlags_AllowItemOverlap = 1 << 2, + ImGuiTreeNodeFlags_NoTreePushOnOpen = 1 << 3, + ImGuiTreeNodeFlags_NoAutoOpenOnLog = 1 << 4, + ImGuiTreeNodeFlags_DefaultOpen = 1 << 5, + ImGuiTreeNodeFlags_OpenOnDoubleClick = 1 << 6, + ImGuiTreeNodeFlags_OpenOnArrow = 1 << 7, + ImGuiTreeNodeFlags_Leaf = 1 << 8, + ImGuiTreeNodeFlags_Bullet = 1 << 9, + ImGuiTreeNodeFlags_FramePadding = 1 << 10, + ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoAutoOpenOnLog +}; + +enum +{ + ImGuiSelectableFlags_DontClosePopups = 1 << 0, + ImGuiSelectableFlags_SpanAllColumns = 1 << 1, + ImGuiSelectableFlags_AllowDoubleClick = 1 << 2 +}; + +enum ImGuiComboFlags_ +{ + ImGuiComboFlags_PopupAlignLeft = 1 << 0, + ImGuiComboFlags_HeightSmall = 1 << 1, + ImGuiComboFlags_HeightRegular = 1 << 2, + ImGuiComboFlags_HeightLarge = 1 << 3, + ImGuiComboFlags_HeightLargest = 1 << 4, + ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest +}; + +enum ImGuiFocusedFlags_ +{ + ImGuiFocusedFlags_ChildWindows = 1 << 0, + ImGuiFocusedFlags_RootWindow = 1 << 1, + ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows +}; + +enum ImGuiHoveredFlags_ +{ + ImGuiHoveredFlags_ChildWindows = 1 << 0, + ImGuiHoveredFlags_RootWindow = 1 << 1, + ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 2, + //ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 3, + ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 4, + ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 5, + ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, + ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows +}; + +enum ImGuiDragDropFlags_ +{ + ImGuiDragDropFlags_SourceNoPreviewTooltip = 1 << 0, + ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, + ImGuiDragDropFlags_SourceNoHoldToOpenOthers = 1 << 2, + ImGuiDragDropFlags_SourceAllowNullID = 1 << 3, + ImGuiDragDropFlags_SourceExtern = 1 << 4, + ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, + ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, + ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect +}; + +enum +{ + ImGuiKey_Tab, + ImGuiKey_LeftArrow, + ImGuiKey_RightArrow, + ImGuiKey_UpArrow, + ImGuiKey_DownArrow, + ImGuiKey_PageUp, + ImGuiKey_PageDown, + ImGuiKey_Home, + ImGuiKey_End, + ImGuiKey_Delete, + ImGuiKey_Backspace, + ImGuiKey_Enter, + ImGuiKey_Escape, + ImGuiKey_A, + ImGuiKey_C, + ImGuiKey_V, + ImGuiKey_X, + ImGuiKey_Y, + ImGuiKey_Z, + ImGuiKey_COUNT +}; + +enum +{ + ImGuiCol_Text, + ImGuiCol_TextDisabled, + ImGuiCol_WindowBg, + ImGuiCol_ChildBg, + ImGuiCol_PopupBg, + ImGuiCol_Border, + ImGuiCol_BorderShadow, + ImGuiCol_FrameBg, + ImGuiCol_FrameBgHovered, + ImGuiCol_FrameBgActive, + ImGuiCol_TitleBg, + ImGuiCol_TitleBgActive, + ImGuiCol_TitleBgCollapsed, + ImGuiCol_MenuBarBg, + ImGuiCol_ScrollbarBg, + ImGuiCol_ScrollbarGrab, + ImGuiCol_ScrollbarGrabHovered, + ImGuiCol_ScrollbarGrabActive, + ImGuiCol_CheckMark, + ImGuiCol_SliderGrab, + ImGuiCol_SliderGrabActive, + ImGuiCol_Button, + ImGuiCol_ButtonHovered, + ImGuiCol_ButtonActive, + ImGuiCol_Header, + ImGuiCol_HeaderHovered, + ImGuiCol_HeaderActive, + ImGuiCol_Separator, + ImGuiCol_SeparatorHovered, + ImGuiCol_SeparatorActive, + ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGripHovered, + ImGuiCol_ResizeGripActive, + ImGuiCol_CloseButton, + ImGuiCol_CloseButtonHovered, + ImGuiCol_CloseButtonActive, + ImGuiCol_PlotLines, + ImGuiCol_PlotLinesHovered, + ImGuiCol_PlotHistogram, + ImGuiCol_PlotHistogramHovered, + ImGuiCol_TextSelectedBg, + ImGuiCol_ModalWindowDarkening, + ImGuiCol_DragDropTarget, + ImGuiCol_COUNT +}; + +enum +{ + ImGuiStyleVar_Alpha, + ImGuiStyleVar_WindowPadding, + ImGuiStyleVar_WindowRounding, + ImGuiStyleVar_WindowBorderSize, + ImGuiStyleVar_WindowMinSize, + ImGuiStyleVar_ChildRounding, + ImGuiStyleVar_ChildBorderSize, + ImGuiStyleVar_PopupRounding, + ImGuiStyleVar_PopupBorderSize, + ImGuiStyleVar_FramePadding, + ImGuiStyleVar_FrameRounding, + ImGuiStyleVar_FrameBorderSize, + ImGuiStyleVar_ItemSpacing, + ImGuiStyleVar_ItemInnerSpacing, + ImGuiStyleVar_IndentSpacing, + ImGuiStyleVar_GrabMinSize, + ImGuiStyleVar_ButtonTextAlign, + ImGuiStyleVar_Count_ +}; + +enum +{ + ImGuiColorEditFlags_NoAlpha = 1 << 1, + ImGuiColorEditFlags_NoPicker = 1 << 2, + ImGuiColorEditFlags_NoOptions = 1 << 3, + ImGuiColorEditFlags_NoSmallPreview = 1 << 4, + ImGuiColorEditFlags_NoInputs = 1 << 5, + ImGuiColorEditFlags_NoTooltip = 1 << 6, + ImGuiColorEditFlags_NoLabel = 1 << 7, + ImGuiColorEditFlags_NoSidePreview = 1 << 8, + ImGuiColorEditFlags_AlphaBar = 1 << 9, + ImGuiColorEditFlags_AlphaPreview = 1 << 10, + ImGuiColorEditFlags_AlphaPreviewHalf = 1 << 11, + ImGuiColorEditFlags_HDR = 1 << 12, + ImGuiColorEditFlags_RGB = 1 << 13, + ImGuiColorEditFlags_HSV = 1 << 14, + ImGuiColorEditFlags_HEX = 1 << 15, + ImGuiColorEditFlags_Uint8 = 1 << 16, + ImGuiColorEditFlags_Float = 1 << 17, + ImGuiColorEditFlags_PickerHueBar = 1 << 18, + ImGuiColorEditFlags_PickerHueWheel = 1 << 19 +}; + +enum +{ + ImGuiMouseCursor_None = -1, + ImGuiMouseCursor_Arrow = 0, + ImGuiMouseCursor_TextInput, + ImGuiMouseCursor_Move, + ImGuiMouseCursor_ResizeNS, + ImGuiMouseCursor_ResizeEW, + ImGuiMouseCursor_ResizeNESW, + ImGuiMouseCursor_ResizeNWSE, + ImGuiMouseCursor_Count_ +}; + +enum +{ + ImGuiCond_Always = 1 << 0, + ImGuiCond_Once = 1 << 1, + ImGuiCond_FirstUseEver = 1 << 2, + ImGuiCond_Appearing = 1 << 3 +}; + +enum ImDrawCornerFlags_ +{ + ImDrawCornerFlags_TopLeft = 1 << 0, + ImDrawCornerFlags_TopRight = 1 << 1, + ImDrawCornerFlags_BotLeft = 1 << 2, + ImDrawCornerFlags_BotRight = 1 << 3, + ImDrawCornerFlags_Top = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight, + ImDrawCornerFlags_Bot = ImDrawCornerFlags_BotLeft | ImDrawCornerFlags_BotRight, + ImDrawCornerFlags_Left = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft, + ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight, + ImDrawCornerFlags_All = 0xF +}; + +enum ImDrawListFlags_ +{ + ImDrawListFlags_AntiAliasedLines = 1 << 0, + ImDrawListFlags_AntiAliasedFill = 1 << 1 +}; + +struct ImGuiStyle +{ + float Alpha; + struct ImVec2 WindowPadding; + float WindowRounding; + float WindowBorderSize; + struct ImVec2 WindowMinSize; + struct ImVec2 WindowTitleAlign; + float ChildRounding; + float ChildBorderSize; + float PopupRounding; + float PopupBorderSize; + struct ImVec2 FramePadding; + float FrameRounding; + float FrameBorderSize; + struct ImVec2 ItemSpacing; + struct ImVec2 ItemInnerSpacing; + struct ImVec2 TouchExtraPadding; + float IndentSpacing; + float ColumnsMinSpacing; + float ScrollbarSize; + float ScrollbarRounding; + float GrabMinSize; + float GrabRounding; + struct ImVec2 ButtonTextAlign; + struct ImVec2 DisplayWindowPadding; + struct ImVec2 DisplaySafeAreaPadding; + bool AntiAliasedLines; + bool AntiAliasedFill; + float CurveTessellationTol; + struct ImVec4 Colors[ImGuiCol_COUNT]; +}; + +struct ImGuiIO +{ + struct ImVec2 DisplaySize; + float DeltaTime; + float IniSavingRate; + CONST char *IniFilename; + CONST char *LogFilename; + float MouseDoubleClickTime; + float MouseDoubleClickMaxDist; + float MouseDragThreshold; + int KeyMap[ImGuiKey_COUNT]; + float KeyRepeatDelay; + float KeyRepeatRate; + void *UserData; + struct ImFontAtlas *Fonts; + float FontGlobalScale; + bool FontAllowUserScaling; + struct ImFont *FontDefault; + struct ImVec2 DisplayFramebufferScale; + struct ImVec2 DisplayVisibleMin; + struct ImVec2 DisplayVisibleMax; + bool OptMacOSXBehaviors; + bool OptCursorBlink; + void (*RenderDrawListsFn)(struct ImDrawData *data); + CONST char *(*GetClipboardTextFn)(void *user_data); + void (*SetClipboardTextFn)(void *user_data, CONST char *text); + void *ClipboardUserData; + void *(*MemAllocFn)(size_t sz); + void (*MemFreeFn)(void *ptr); + void (*ImeSetInputScreenPosFn)(int x, int y); + void *ImeWindowHandle; + struct ImVec2 MousePos; + bool MouseDown[5]; + float MouseWheel; + bool MouseDrawCursor; + bool KeyCtrl; + bool KeyShift; + bool KeyAlt; + bool KeySuper; + bool KeysDown[512]; + ImWchar InputCharacters[16 + 1]; + bool WantCaptureMouse; + bool WantCaptureKeyboard; + bool WantTextInput; + float Framerate; + int MetricsAllocs; + int MetricsRenderVertices; + int MetricsRenderIndices; + int MetricsActiveWindows; + struct ImVec2 MouseDelta; + struct ImVec2 MousePosPrev; + bool MouseClicked[5]; + struct ImVec2 MouseClickedPos[5]; + float MouseClickedTime[5]; + bool MouseDoubleClicked[5]; + bool MouseReleased[5]; + bool MouseDownOwned[5]; + float MouseDownDuration[5]; + float MouseDownDurationPrev[5]; + struct ImVec2 MouseDragMaxDistanceAbs[5]; + float MouseDragMaxDistanceSqr[5]; + float KeysDownDuration[512]; + float KeysDownDurationPrev[512]; +}; + +struct ImGuiTextEditCallbackData +{ + ImGuiInputTextFlags EventFlag; + ImGuiInputTextFlags Flags; + void *UserData; + bool ReadOnly; + ImWchar EventChar; + ImGuiKey EventKey; + char *Buf; + int BufTextLen; + int BufSize; + bool BufDirty; + int CursorPos; + int SelectionStart; + int SelectionEnd; +}; + +struct ImGuiSizeConstraintCallbackData +{ + void *UserData; + struct ImVec2 Pos; + struct ImVec2 CurrentSize; + struct ImVec2 DesiredSize; +}; + +struct ImDrawCmd +{ + unsigned int ElemCount; + struct ImVec4 ClipRect; + ImTextureID TextureId; + ImDrawCallback UserCallback; + void *UserCallbackData; +}; + +struct ImDrawData +{ + bool Valid; + struct ImDrawList **CmdLists; + int CmdListsCount; + int TotalVtxCount; + int TotalIdxCount; +}; + +struct ImDrawVert +{ + struct ImVec2 pos; + struct ImVec2 uv; + ImU32 col; +}; + +struct ImFontConfig +{ + void *FontData; + int FontDataSize; + bool FontDataOwnedByAtlas; + int FontNo; + float SizePixels; + int OversampleH, OversampleV; + bool PixelSnapH; + struct ImVec2 GlyphExtraSpacing; + struct ImVec2 GlyphOffset; + CONST ImWchar *GlyphRanges; + bool MergeMode; + unsigned int RasterizerFlags; + float RasterizerMultiply; + char Name[32]; + struct ImFont *DstFont; +}; + +struct ImGuiListClipper +{ + float StartPosY; + float ItemsHeight; + int ItemsCount, StepNo, DisplayStart, DisplayEnd; +}; + +struct ImGuiPayload +{ + CONST void *Data; + int DataSize; + + ImGuiID SourceId; + ImGuiID SourceParentId; + int DataFrameCount; + char DataType[8 + 1]; + bool Preview; + bool Delivery; +}; +#endif // IMGUI_VERSION + +// Main +CIMGUI_API struct ImGuiIO *igGetIO(); +CIMGUI_API struct ImGuiStyle *igGetStyle(); +CIMGUI_API struct ImDrawData *igGetDrawData(); +CIMGUI_API void igNewFrame(); +CIMGUI_API void igRender(); +CIMGUI_API void igEndFrame(); +CIMGUI_API void igShutdown(); + +// Demo/Debug/Info +CIMGUI_API void igShowDemoWindow(bool *opened); +CIMGUI_API void igShowMetricsWindow(bool *opened); +CIMGUI_API void igShowStyleEditor(struct ImGuiStyle *ref); +CIMGUI_API void igShowStyleSelector(CONST char *label); +CIMGUI_API void igShowFontSelector(CONST char *label); +CIMGUI_API void igShowUserGuide(); + +// Window +CIMGUI_API bool igBegin(CONST char *name, bool *p_open, ImGuiWindowFlags flags); +//Is going to be obsolete, +//CIMGUI_API bool igBegin2(CONST char* name, bool* p_open, CONST struct ImVec2 size_on_first_use, float bg_alpha, ImGuiWindowFlags flags); +CIMGUI_API void igEnd(); +CIMGUI_API bool igBeginChild(CONST char *str_id, CONST struct ImVec2 size, bool border, ImGuiWindowFlags extra_flags); +CIMGUI_API bool igBeginChildEx(ImGuiID id, CONST struct ImVec2 size, bool border, ImGuiWindowFlags extra_flags); +CIMGUI_API void igEndChild(); +CIMGUI_API void igGetContentRegionMax(struct ImVec2 *out); +CIMGUI_API void igGetContentRegionAvail(struct ImVec2 *out); +CIMGUI_API float igGetContentRegionAvailWidth(); +CIMGUI_API void igGetWindowContentRegionMin(struct ImVec2 *out); +CIMGUI_API void igGetWindowContentRegionMax(struct ImVec2 *out); +CIMGUI_API float igGetWindowContentRegionWidth(); +CIMGUI_API struct ImDrawList *igGetWindowDrawList(); +CIMGUI_API void igGetWindowPos(struct ImVec2 *out); +CIMGUI_API void igGetWindowSize(struct ImVec2 *out); +CIMGUI_API float igGetWindowWidth(); +CIMGUI_API float igGetWindowHeight(); +CIMGUI_API bool igIsWindowCollapsed(); +CIMGUI_API bool igIsWindowAppearing(); +CIMGUI_API void igSetWindowFontScale(float scale); + +CIMGUI_API void igSetNextWindowPos(CONST struct ImVec2 pos, ImGuiCond cond, CONST struct ImVec2 pivot); +CIMGUI_API void igSetNextWindowSize(CONST struct ImVec2 size, ImGuiCond cond); +CIMGUI_API void igSetNextWindowSizeConstraints(CONST struct ImVec2 size_min, CONST struct ImVec2 size_max, ImGuiSizeConstraintCallback custom_callback, void *custom_callback_data); +CIMGUI_API void igSetNextWindowContentSize(CONST struct ImVec2 size); +CIMGUI_API void igSetNextWindowCollapsed(bool collapsed, ImGuiCond cond); +CIMGUI_API void igSetNextWindowFocus(); +CIMGUI_API void igSetWindowPos(CONST struct ImVec2 pos, ImGuiCond cond); +CIMGUI_API void igSetWindowSize(CONST struct ImVec2 size, ImGuiCond cond); +CIMGUI_API void igSetWindowCollapsed(bool collapsed, ImGuiCond cond); +CIMGUI_API void igSetWindowFocus(); +CIMGUI_API void igSetWindowPosByName(CONST char *name, CONST struct ImVec2 pos, ImGuiCond cond); +CIMGUI_API void igSetWindowSize2(CONST char *name, CONST struct ImVec2 size, ImGuiCond cond); +CIMGUI_API void igSetWindowCollapsed2(CONST char *name, bool collapsed, ImGuiCond cond); +CIMGUI_API void igSetWindowFocus2(CONST char *name); + +CIMGUI_API float igGetScrollX(); +CIMGUI_API float igGetScrollY(); +CIMGUI_API float igGetScrollMaxX(); +CIMGUI_API float igGetScrollMaxY(); +CIMGUI_API void igSetScrollX(float scroll_x); +CIMGUI_API void igSetScrollY(float scroll_y); +CIMGUI_API void igSetScrollHere(float center_y_ratio); +CIMGUI_API void igSetScrollFromPosY(float pos_y, float center_y_ratio); +CIMGUI_API void igSetStateStorage(struct ImGuiStorage *tree); +CIMGUI_API struct ImGuiStorage *igGetStateStorage(); + +// Parameters stacks (shared) +CIMGUI_API void igPushFont(struct ImFont *font); +CIMGUI_API void igPopFont(); +CIMGUI_API void igPushStyleColorU32(ImGuiCol idx, ImU32 col); +CIMGUI_API void igPushStyleColor(ImGuiCol idx, CONST struct ImVec4 col); +CIMGUI_API void igPopStyleColor(int count); +CIMGUI_API void igPushStyleVar(ImGuiStyleVar idx, float val); +CIMGUI_API void igPushStyleVarVec(ImGuiStyleVar idx, CONST struct ImVec2 val); +CIMGUI_API void igPopStyleVar(int count); +CIMGUI_API void igGetStyleColorVec4(struct ImVec4 *pOut, ImGuiCol idx); +CIMGUI_API struct ImFont *igGetFont(); +CIMGUI_API float igGetFontSize(); +CIMGUI_API void igGetFontTexUvWhitePixel(struct ImVec2 *pOut); +CIMGUI_API ImU32 igGetColorU32(ImGuiCol idx, float alpha_mul); +CIMGUI_API ImU32 igGetColorU32Vec(CONST struct ImVec4 *col); +CIMGUI_API ImU32 igGetColorU32U32(ImU32 col); + +// Parameters stacks (current window) +CIMGUI_API void igPushItemWidth(float item_width); +CIMGUI_API void igPopItemWidth(); +CIMGUI_API float igCalcItemWidth(); +CIMGUI_API void igPushTextWrapPos(float wrap_pos_x); +CIMGUI_API void igPopTextWrapPos(); +CIMGUI_API void igPushAllowKeyboardFocus(bool v); +CIMGUI_API void igPopAllowKeyboardFocus(); +CIMGUI_API void igPushButtonRepeat(bool repeat); +CIMGUI_API void igPopButtonRepeat(); + +// Cursor / Layout +CIMGUI_API void igSeparator(); +CIMGUI_API void igSameLine(float pos_x, float spacing_w); +CIMGUI_API void igNewLine(); +CIMGUI_API void igSpacing(); +CIMGUI_API void igDummy(CONST struct ImVec2 *size); +CIMGUI_API void igIndent(float indent_w); +CIMGUI_API void igUnindent(float indent_w); +CIMGUI_API void igBeginGroup(); +CIMGUI_API void igEndGroup(); +CIMGUI_API void igGetCursorPos(struct ImVec2 *pOut); +CIMGUI_API float igGetCursorPosX(); +CIMGUI_API float igGetCursorPosY(); +CIMGUI_API void igSetCursorPos(CONST struct ImVec2 local_pos); +CIMGUI_API void igSetCursorPosX(float x); +CIMGUI_API void igSetCursorPosY(float y); +CIMGUI_API void igGetCursorStartPos(struct ImVec2 *pOut); +CIMGUI_API void igGetCursorScreenPos(struct ImVec2 *pOut); +CIMGUI_API void igSetCursorScreenPos(CONST struct ImVec2 pos); +CIMGUI_API void igAlignTextToFramePadding(); +CIMGUI_API float igGetTextLineHeight(); +CIMGUI_API float igGetTextLineHeightWithSpacing(); +CIMGUI_API float igGetFrameHeight(); +CIMGUI_API float igGetFrameHeightWithSpacing(); + +//Columns +CIMGUI_API void igColumns(int count, CONST char *id, bool border); +CIMGUI_API void igNextColumn(); +CIMGUI_API int igGetColumnIndex(); +CIMGUI_API float igGetColumnWidth(int column_index); // get column width (in pixels). pass -1 to use current column +CIMGUI_API void igSetColumnWidth(int column_index, float width); +CIMGUI_API float igGetColumnOffset(int column_index); +CIMGUI_API void igSetColumnOffset(int column_index, float offset_x); +CIMGUI_API int igGetColumnsCount(); + +// ID scopes +// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them +// You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide') +CIMGUI_API void igPushIDStr(CONST char *str_id); +CIMGUI_API void igPushIDStrRange(CONST char *str_begin, CONST char *str_end); +CIMGUI_API void igPushIDPtr(CONST void *ptr_id); +CIMGUI_API void igPushIDInt(int int_id); +CIMGUI_API void igPopID(); +CIMGUI_API ImGuiID igGetIDStr(CONST char *str_id); +CIMGUI_API ImGuiID igGetIDStrRange(CONST char *str_begin, CONST char *str_end); +CIMGUI_API ImGuiID igGetIDPtr(CONST void *ptr_id); + +// Widgets: Text +CIMGUI_API void igTextUnformatted(CONST char *text, CONST char *text_end); +CIMGUI_API void igText(CONST char *fmt, ...); +CIMGUI_API void igTextV(CONST char *fmt, va_list args); +CIMGUI_API void igTextColored(CONST struct ImVec4 col, CONST char *fmt, ...); +CIMGUI_API void igTextColoredV(CONST struct ImVec4 col, CONST char *fmt, va_list args); +CIMGUI_API void igTextDisabled(CONST char *fmt, ...); +CIMGUI_API void igTextDisabledV(CONST char *fmt, va_list args); +CIMGUI_API void igTextWrapped(CONST char *fmt, ...); +CIMGUI_API void igTextWrappedV(CONST char *fmt, va_list args); +CIMGUI_API void igLabelText(CONST char *label, CONST char *fmt, ...); +CIMGUI_API void igLabelTextV(CONST char *label, CONST char *fmt, va_list args); +CIMGUI_API void igBulletText(CONST char *fmt, ...); +CIMGUI_API void igBulletTextV(CONST char *fmt, va_list args); +CIMGUI_API void igBullet(); + +// Widgets: Main +CIMGUI_API bool igButton(CONST char *label, CONST struct ImVec2 size); +CIMGUI_API bool igSmallButton(CONST char *label); +CIMGUI_API bool igInvisibleButton(CONST char *str_id, CONST struct ImVec2 size); +CIMGUI_API void igImage(ImTextureID user_texture_id, CONST struct ImVec2 size, CONST struct ImVec2 uv0, CONST struct ImVec2 uv1, CONST struct ImVec4 tint_col, CONST struct ImVec4 border_col); +CIMGUI_API bool igImageButton(ImTextureID user_texture_id, CONST struct ImVec2 size, CONST struct ImVec2 uv0, CONST struct ImVec2 uv1, int frame_padding, CONST struct ImVec4 bg_col, CONST struct ImVec4 tint_col); +CIMGUI_API bool igCheckbox(CONST char *label, bool *v); +CIMGUI_API bool igCheckboxFlags(CONST char *label, unsigned int *flags, unsigned int flags_value); +CIMGUI_API bool igRadioButtonBool(CONST char *label, bool active); +CIMGUI_API bool igRadioButton(CONST char *label, int *v, int v_button); +CIMGUI_API void igPlotLines(CONST char *label, CONST float *values, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, struct ImVec2 graph_size, int stride); +CIMGUI_API void igPlotLines2(CONST char *label, float (*values_getter)(void *data, int idx), void *data, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, struct ImVec2 graph_size); +CIMGUI_API void igPlotHistogram(CONST char *label, CONST float *values, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, struct ImVec2 graph_size, int stride); +CIMGUI_API void igPlotHistogram2(CONST char *label, float (*values_getter)(void *data, int idx), void *data, int values_count, int values_offset, CONST char *overlay_text, float scale_min, float scale_max, struct ImVec2 graph_size); +CIMGUI_API void igProgressBar(float fraction, CONST struct ImVec2 *size_arg, CONST char *overlay); + +CIMGUI_API bool igBeginCombo(CONST char *label, CONST char *preview_value, ImGuiComboFlags flags); +CIMGUI_API void igEndCombo(); +CIMGUI_API bool igCombo(CONST char *label, int *current_item, CONST char *CONST *items, int items_count, int popup_max_height_in_items); +CIMGUI_API bool igCombo2(CONST char *label, int *current_item, CONST char *items_separated_by_zeros, int popup_max_height_in_items); +CIMGUI_API bool igCombo3(CONST char *label, int *current_item, bool (*items_getter)(void *data, int idx, CONST char **out_text), void *data, int items_count, int popup_max_height_in_items); + +// Widgets: Drags (tip: ctrl+click on a drag box to input with keyboard. manually input values aren't clamped, can go off-bounds) +// For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x +CIMGUI_API bool igDragFloat(CONST char *label, float *v, float v_speed, float v_min, float v_max, CONST char *display_format, float power); // If v_max >= v_max we have no bound +CIMGUI_API bool igDragFloat2(CONST char *label, float v[2], float v_speed, float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igDragFloat3(CONST char *label, float v[3], float v_speed, float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igDragFloat4(CONST char *label, float v[4], float v_speed, float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igDragFloatRange2(CONST char *label, float *v_current_min, float *v_current_max, float v_speed, float v_min, float v_max, CONST char *display_format, CONST char *display_format_max, float power); +CIMGUI_API bool igDragInt(CONST char *label, int *v, float v_speed, int v_min, int v_max, CONST char *display_format); // If v_max >= v_max we have no bound +CIMGUI_API bool igDragInt2(CONST char *label, int v[2], float v_speed, int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igDragInt3(CONST char *label, int v[3], float v_speed, int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igDragInt4(CONST char *label, int v[4], float v_speed, int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igDragIntRange2(CONST char *label, int *v_current_min, int *v_current_max, float v_speed, int v_min, int v_max, CONST char *display_format, CONST char *display_format_max); + +// Widgets: Input with Keyboard +CIMGUI_API bool igInputText(CONST char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void *user_data); +CIMGUI_API bool igInputTextMultiline(CONST char *label, char *buf, size_t buf_size, CONST struct ImVec2 size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void *user_data); +CIMGUI_API bool igInputFloat(CONST char *label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputFloat2(CONST char *label, float v[2], int decimal_precision, ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputFloat3(CONST char *label, float v[3], int decimal_precision, ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputFloat4(CONST char *label, float v[4], int decimal_precision, ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputInt(CONST char *label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputInt2(CONST char *label, int v[2], ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputInt3(CONST char *label, int v[3], ImGuiInputTextFlags extra_flags); +CIMGUI_API bool igInputInt4(CONST char *label, int v[4], ImGuiInputTextFlags extra_flags); + +// Widgets: Sliders (tip: ctrl+click on a slider to input with keyboard. manually input values aren't clamped, can go off-bounds) +CIMGUI_API bool igSliderFloat(CONST char *label, float *v, float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igSliderFloat2(CONST char *label, float v[2], float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igSliderFloat3(CONST char *label, float v[3], float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igSliderFloat4(CONST char *label, float v[4], float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igSliderAngle(CONST char *label, float *v_rad, float v_degrees_min, float v_degrees_max); +CIMGUI_API bool igSliderInt(CONST char *label, int *v, int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igSliderInt2(CONST char *label, int v[2], int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igSliderInt3(CONST char *label, int v[3], int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igSliderInt4(CONST char *label, int v[4], int v_min, int v_max, CONST char *display_format); +CIMGUI_API bool igVSliderFloat(CONST char *label, CONST struct ImVec2 size, float *v, float v_min, float v_max, CONST char *display_format, float power); +CIMGUI_API bool igVSliderInt(CONST char *label, CONST struct ImVec2 size, int *v, int v_min, int v_max, CONST char *display_format); + +// Widgets: Color Editor/Picker (tip: the ColorEdit* functions have a little colored preview square that can be left-clicked to open a picker, and right-clicked to open an option menu.) +// Note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can the pass the address of a first float element out of a contiguous structure, e.g. &myvector.x +CIMGUI_API bool igColorEdit3(CONST char *label, float col[3], ImGuiColorEditFlags flags); +CIMGUI_API bool igColorEdit4(CONST char *label, float col[4], ImGuiColorEditFlags flags); +CIMGUI_API bool igColorPicker3(CONST char *label, float col[3], ImGuiColorEditFlags flags); +CIMGUI_API bool igColorPicker4(CONST char *label, float col[4], ImGuiColorEditFlags flags, CONST float *ref_col); +CIMGUI_API bool igColorButton(CONST char *desc_id, CONST struct ImVec4 col, ImGuiColorEditFlags flags, CONST struct ImVec2 size); +CIMGUI_API void igSetColorEditOptions(ImGuiColorEditFlags flags); + +// Widgets: Trees +CIMGUI_API bool igTreeNode(CONST char *label); +CIMGUI_API bool igTreeNodeStr(CONST char *str_id, CONST char *fmt, ...); +CIMGUI_API bool igTreeNodePtr(CONST void *ptr_id, CONST char *fmt, ...); +CIMGUI_API bool igTreeNodeStrV(CONST char *str_id, CONST char *fmt, va_list args); +CIMGUI_API bool igTreeNodePtrV(CONST void *ptr_id, CONST char *fmt, va_list args); +CIMGUI_API bool igTreeNodeEx(CONST char *label, ImGuiTreeNodeFlags flags); +CIMGUI_API bool igTreeNodeExStr(CONST char *str_id, ImGuiTreeNodeFlags flags, CONST char *fmt, ...); +CIMGUI_API bool igTreeNodeExPtr(CONST void *ptr_id, ImGuiTreeNodeFlags flags, CONST char *fmt, ...); +CIMGUI_API bool igTreeNodeExV(CONST char *str_id, ImGuiTreeNodeFlags flags, CONST char *fmt, va_list args); +CIMGUI_API bool igTreeNodeExVPtr(CONST void *ptr_id, ImGuiTreeNodeFlags flags, CONST char *fmt, va_list args); +CIMGUI_API void igTreePushStr(CONST char *str_id); +CIMGUI_API void igTreePushPtr(CONST void *ptr_id); +CIMGUI_API void igTreePop(); +CIMGUI_API void igTreeAdvanceToLabelPos(); +CIMGUI_API float igGetTreeNodeToLabelSpacing(); +CIMGUI_API void igSetNextTreeNodeOpen(bool opened, ImGuiCond cond); +CIMGUI_API bool igCollapsingHeader(CONST char *label, ImGuiTreeNodeFlags flags); +CIMGUI_API bool igCollapsingHeaderEx(CONST char *label, bool *p_open, ImGuiTreeNodeFlags flags); + +// Widgets: Selectable / Lists +CIMGUI_API bool igSelectable(CONST char *label, bool selected, ImGuiSelectableFlags flags, CONST struct ImVec2 size); +CIMGUI_API bool igSelectableEx(CONST char *label, bool *p_selected, ImGuiSelectableFlags flags, CONST struct ImVec2 size); +CIMGUI_API bool igListBox(CONST char *label, int *current_item, CONST char *CONST *items, int items_count, int height_in_items); +CIMGUI_API bool igListBox2(CONST char *label, int *current_item, bool (*items_getter)(void *data, int idx, CONST char **out_text), void *data, int items_count, int height_in_items); +CIMGUI_API bool igListBoxHeader(CONST char *label, CONST struct ImVec2 size); +CIMGUI_API bool igListBoxHeader2(CONST char *label, int items_count, int height_in_items); +CIMGUI_API void igListBoxFooter(); + +// Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare your own within the ImGui namespace!) +CIMGUI_API void igValueBool(CONST char *prefix, bool b); +CIMGUI_API void igValueInt(CONST char *prefix, int v); +CIMGUI_API void igValueUInt(CONST char *prefix, unsigned int v); +CIMGUI_API void igValueFloat(CONST char *prefix, float v, CONST char *float_format); + +// Tooltip +CIMGUI_API void igSetTooltip(CONST char *fmt, ...); +CIMGUI_API void igSetTooltipV(CONST char *fmt, va_list args); +CIMGUI_API void igBeginTooltip(); +CIMGUI_API void igEndTooltip(); + +// Widgets: Menus +CIMGUI_API bool igBeginMainMenuBar(); +CIMGUI_API void igEndMainMenuBar(); +CIMGUI_API bool igBeginMenuBar(); +CIMGUI_API void igEndMenuBar(); +CIMGUI_API bool igBeginMenu(CONST char *label, bool enabled); +CIMGUI_API void igEndMenu(); +CIMGUI_API bool igMenuItem(CONST char *label, CONST char *shortcut, bool selected, bool enabled); +CIMGUI_API bool igMenuItemPtr(CONST char *label, CONST char *shortcut, bool *p_selected, bool enabled); + +// Popup +CIMGUI_API void igOpenPopup(CONST char *str_id); +CIMGUI_API bool igOpenPopupOnItemClick(CONST char *str_id, int mouse_button); +CIMGUI_API bool igBeginPopup(CONST char *str_id); +CIMGUI_API bool igBeginPopupModal(CONST char *name, bool *p_open, ImGuiWindowFlags extra_flags); +CIMGUI_API bool igBeginPopupContextItem(CONST char *str_id, int mouse_button); +CIMGUI_API bool igBeginPopupContextWindow(CONST char *str_id, int mouse_button, bool also_over_items); +CIMGUI_API bool igBeginPopupContextVoid(CONST char *str_id, int mouse_button); +CIMGUI_API void igEndPopup(); +CIMGUI_API bool igIsPopupOpen(CONST char *str_id); +CIMGUI_API void igCloseCurrentPopup(); + +// Logging: all text output from interface is redirected to tty/file/clipboard. Tree nodes are automatically opened. +CIMGUI_API void igLogToTTY(int max_depth); +CIMGUI_API void igLogToFile(int max_depth, CONST char *filename); +CIMGUI_API void igLogToClipboard(int max_depth); +CIMGUI_API void igLogFinish(); +CIMGUI_API void igLogButtons(); +CIMGUI_API void igLogText(CONST char *fmt, ...); + +CIMGUI_API bool igBeginDragDropSource(ImGuiDragDropFlags flags, int mouse_button); +CIMGUI_API bool igSetDragDropPayload(CONST char *type, CONST void *data, size_t size, ImGuiCond cond); +CIMGUI_API void igEndDragDropSource(); +CIMGUI_API bool igBeginDragDropTarget(); +CIMGUI_API CONST struct ImGuiPayload *igAcceptDragDropPayload(CONST char *type, ImGuiDragDropFlags flags); +CIMGUI_API void igEndDragDropTarget(); + +// Clipping +CIMGUI_API void igPushClipRect(CONST struct ImVec2 clip_rect_min, CONST struct ImVec2 clip_rect_max, bool intersect_with_current_clip_rect); +CIMGUI_API void igPopClipRect(); + +// Styles +CIMGUI_API void igStyleColorsClassic(struct ImGuiStyle *dst); +CIMGUI_API void igStyleColorsDark(struct ImGuiStyle *dst); +CIMGUI_API void igStyleColorsLight(struct ImGuiStyle *dst); + +CIMGUI_API void igSetItemDefaultFocus(); +CIMGUI_API void igSetKeyboardFocusHere(int offset); + +// Utilities +CIMGUI_API bool igIsItemHovered(ImGuiHoveredFlags flags); +CIMGUI_API bool igIsItemActive(); +CIMGUI_API bool igIsItemClicked(int mouse_button); +CIMGUI_API bool igIsItemVisible(); +CIMGUI_API bool igIsAnyItemHovered(); +CIMGUI_API bool igIsAnyItemActive(); +CIMGUI_API void igGetItemRectMin(struct ImVec2 *pOut); +CIMGUI_API void igGetItemRectMax(struct ImVec2 *pOut); +CIMGUI_API void igGetItemRectSize(struct ImVec2 *pOut); +CIMGUI_API void igSetItemAllowOverlap(); +CIMGUI_API bool igIsWindowFocused(ImGuiFocusedFlags flags); +CIMGUI_API bool igIsWindowHovered(ImGuiHoveredFlags falgs); +CIMGUI_API bool igIsAnyWindowFocused(); +CIMGUI_API bool igIsAnyWindowHovered(); +CIMGUI_API bool igIsRectVisible(CONST struct ImVec2 item_size); +CIMGUI_API bool igIsRectVisible2(CONST struct ImVec2 *rect_min, CONST struct ImVec2 *rect_max); +CIMGUI_API float igGetTime(); +CIMGUI_API int igGetFrameCount(); + +CIMGUI_API struct ImDrawList *igGetOverlayDrawList(); +CIMGUI_API struct ImDrawListSharedData *igGetDrawListSharedData(); + +CIMGUI_API CONST char *igGetStyleColorName(ImGuiCol idx); +CIMGUI_API void igCalcItemRectClosestPoint(struct ImVec2 *pOut, CONST struct ImVec2 pos, bool on_edge, float outward); +CIMGUI_API void igCalcTextSize(struct ImVec2 *pOut, CONST char *text, CONST char *text_end, bool hide_text_after_double_hash, float wrap_width); +CIMGUI_API void igCalcListClipping(int items_count, float items_height, int *out_items_display_start, int *out_items_display_end); + +CIMGUI_API bool igBeginChildFrame(ImGuiID id, CONST struct ImVec2 size, ImGuiWindowFlags extra_flags); +CIMGUI_API void igEndChildFrame(); + +CIMGUI_API void igColorConvertU32ToFloat4(struct ImVec4 *pOut, ImU32 in); +CIMGUI_API ImU32 igColorConvertFloat4ToU32(CONST struct ImVec4 in); +CIMGUI_API void igColorConvertRGBtoHSV(float r, float g, float b, float *out_h, float *out_s, float *out_v); +CIMGUI_API void igColorConvertHSVtoRGB(float h, float s, float v, float *out_r, float *out_g, float *out_b); + +// Inputs +CIMGUI_API int igGetKeyIndex(ImGuiKey imgui_key); +CIMGUI_API bool igIsKeyDown(int user_key_index); +CIMGUI_API bool igIsKeyPressed(int user_key_index, bool repeat); +CIMGUI_API bool igIsKeyReleased(int user_key_index); +CIMGUI_API int igGetKeyPressedAmount(int key_index, float repeat_delay, float rate); +CIMGUI_API bool igIsMouseDown(int button); +CIMGUI_API bool igIsMouseClicked(int button, bool repeat); +CIMGUI_API bool igIsMouseDoubleClicked(int button); +CIMGUI_API bool igIsMouseReleased(int button); +CIMGUI_API bool igIsMouseDragging(int button, float lock_threshold); +CIMGUI_API bool igIsMouseHoveringRect(CONST struct ImVec2 r_min, CONST struct ImVec2 r_max, bool clip); +CIMGUI_API bool igIsMousePosValid(CONST struct ImVec2 *mouse_pos); +; +CIMGUI_API void igGetMousePos(struct ImVec2 *pOut); +CIMGUI_API void igGetMousePosOnOpeningCurrentPopup(struct ImVec2 *pOut); +CIMGUI_API void igGetMouseDragDelta(struct ImVec2 *pOut, int button, float lock_threshold); +CIMGUI_API void igResetMouseDragDelta(int button); +CIMGUI_API ImGuiMouseCursor igGetMouseCursor(); +CIMGUI_API void igSetMouseCursor(ImGuiMouseCursor type); +CIMGUI_API void igCaptureKeyboardFromApp(bool capture); +CIMGUI_API void igCaptureMouseFromApp(bool capture); + +// Helpers functions to access functions pointers in ImGui::GetIO() +CIMGUI_API void *igMemAlloc(size_t sz); +CIMGUI_API void igMemFree(void *ptr); +CIMGUI_API CONST char *igGetClipboardText(); +CIMGUI_API void igSetClipboardText(CONST char *text); + +// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself +CIMGUI_API CONST char *igGetVersion(); +CIMGUI_API struct ImGuiContext *igCreateContext(void *(*malloc_fn)(size_t), void (*free_fn)(void *)); +CIMGUI_API void igDestroyContext(struct ImGuiContext *ctx); +CIMGUI_API struct ImGuiContext *igGetCurrentContext(); +CIMGUI_API void igSetCurrentContext(struct ImGuiContext *ctx); + +CIMGUI_API void ImFontConfig_DefaultConstructor(struct ImFontConfig *config); + +// ImGuiIO +CIMGUI_API void ImGuiIO_AddInputCharacter(unsigned short c); +CIMGUI_API void ImGuiIO_AddInputCharactersUTF8(CONST char *utf8_chars); +CIMGUI_API void ImGuiIO_ClearInputCharacters(); + +// ImGuiTextFilter +CIMGUI_API struct ImGuiTextFilter *ImGuiTextFilter_Create(CONST char *default_filter); +CIMGUI_API void ImGuiTextFilter_Destroy(struct ImGuiTextFilter *filter); +CIMGUI_API void ImGuiTextFilter_Clear(struct ImGuiTextFilter *filter); +CIMGUI_API bool ImGuiTextFilter_Draw(struct ImGuiTextFilter *filter, CONST char *label, float width); +CIMGUI_API bool ImGuiTextFilter_PassFilter(CONST struct ImGuiTextFilter *filter, CONST char *text, CONST char *text_end); +CIMGUI_API bool ImGuiTextFilter_IsActive(CONST struct ImGuiTextFilter *filter); +CIMGUI_API void ImGuiTextFilter_Build(struct ImGuiTextFilter *filter); +CIMGUI_API CONST char *ImGuiTextFilter_GetInputBuf(struct ImGuiTextFilter *filter); + +// ImGuiTextBuffer +CIMGUI_API struct ImGuiTextBuffer *ImGuiTextBuffer_Create(); +CIMGUI_API void ImGuiTextBuffer_Destroy(struct ImGuiTextBuffer *buffer); +CIMGUI_API char ImGuiTextBuffer_index(struct ImGuiTextBuffer *buffer, int i); +CIMGUI_API CONST char *ImGuiTextBuffer_begin(CONST struct ImGuiTextBuffer *buffer); +CIMGUI_API CONST char *ImGuiTextBuffer_end(CONST struct ImGuiTextBuffer *buffer); +CIMGUI_API int ImGuiTextBuffer_size(CONST struct ImGuiTextBuffer *buffer); +CIMGUI_API bool ImGuiTextBuffer_empty(struct ImGuiTextBuffer *buffer); +CIMGUI_API void ImGuiTextBuffer_clear(struct ImGuiTextBuffer *buffer); +CIMGUI_API CONST char *ImGuiTextBuffer_c_str(CONST struct ImGuiTextBuffer *buffer); +CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, CONST char *fmt, ...); +CIMGUI_API void ImGuiTextBuffer_appendfv(struct ImGuiTextBuffer *buffer, CONST char *fmt, va_list args); + +// ImGuiStorage +CIMGUI_API struct ImGuiStorage *ImGuiStorage_Create(); +CIMGUI_API void ImGuiStorage_Destroy(struct ImGuiStorage *storage); +CIMGUI_API int ImGuiStorage_GetInt(struct ImGuiStorage *storage, ImGuiID key, int default_val); +CIMGUI_API void ImGuiStorage_SetInt(struct ImGuiStorage *storage, ImGuiID key, int val); +CIMGUI_API bool ImGuiStorage_GetBool(struct ImGuiStorage *storage, ImGuiID key, bool default_val); +CIMGUI_API void ImGuiStorage_SetBool(struct ImGuiStorage *storage, ImGuiID key, bool val); +CIMGUI_API float ImGuiStorage_GetFloat(struct ImGuiStorage *storage, ImGuiID key, float default_val); +CIMGUI_API void ImGuiStorage_SetFloat(struct ImGuiStorage *storage, ImGuiID key, float val); +CIMGUI_API void *ImGuiStorage_GetVoidPtr(struct ImGuiStorage *storage, ImGuiID key); +CIMGUI_API void ImGuiStorage_SetVoidPtr(struct ImGuiStorage *storage, ImGuiID key, void *val); +CIMGUI_API int *ImGuiStorage_GetIntRef(struct ImGuiStorage *storage, ImGuiID key, int default_val); +CIMGUI_API bool *ImGuiStorage_GetBoolRef(struct ImGuiStorage *storage, ImGuiID key, bool default_val); +CIMGUI_API float *ImGuiStorage_GetFloatRef(struct ImGuiStorage *storage, ImGuiID key, float default_val); +CIMGUI_API void **ImGuiStorage_GetVoidPtrRef(struct ImGuiStorage *storage, ImGuiID key, void *default_val); +CIMGUI_API void ImGuiStorage_SetAllInt(struct ImGuiStorage *storage, int val); + +// ImGuiTextEditCallbackData +CIMGUI_API void ImGuiTextEditCallbackData_DeleteChars(struct ImGuiTextEditCallbackData *data, int pos, int bytes_count); +CIMGUI_API void ImGuiTextEditCallbackData_InsertChars(struct ImGuiTextEditCallbackData *data, int pos, CONST char *text, CONST char *text_end); +CIMGUI_API bool ImGuiTextEditCallbackData_HasSelection(struct ImGuiTextEditCallbackData *data); + +// ImGuiListClipper +CIMGUI_API bool ImGuiListClipper_Step(struct ImGuiListClipper *clipper); +CIMGUI_API void ImGuiListClipper_Begin(struct ImGuiListClipper *clipper, int count, float items_height); +CIMGUI_API void ImGuiListClipper_End(struct ImGuiListClipper *clipper); +CIMGUI_API int ImGuiListClipper_GetDisplayStart(struct ImGuiListClipper *clipper); +CIMGUI_API int ImGuiListClipper_GetDisplayEnd(struct ImGuiListClipper *clipper); + +//ImDrawList +CIMGUI_API int ImDrawList_GetVertexBufferSize(struct ImDrawList *list); +CIMGUI_API struct ImDrawVert *ImDrawList_GetVertexPtr(struct ImDrawList *list, int n); +CIMGUI_API int ImDrawList_GetIndexBufferSize(struct ImDrawList *list); +CIMGUI_API ImDrawIdx *ImDrawList_GetIndexPtr(struct ImDrawList *list, int n); +CIMGUI_API int ImDrawList_GetCmdSize(struct ImDrawList *list); +CIMGUI_API struct ImDrawCmd *ImDrawList_GetCmdPtr(struct ImDrawList *list, int n); + +CIMGUI_API void ImDrawList_Clear(struct ImDrawList *list); +CIMGUI_API void ImDrawList_ClearFreeMemory(struct ImDrawList *list); +CIMGUI_API void ImDrawList_PushClipRect(struct ImDrawList *list, struct ImVec2 clip_rect_min, struct ImVec2 clip_rect_max, bool intersect_with_current_clip_rect); +CIMGUI_API void ImDrawList_PushClipRectFullScreen(struct ImDrawList *list); +CIMGUI_API void ImDrawList_PopClipRect(struct ImDrawList *list); +CIMGUI_API void ImDrawList_PushTextureID(struct ImDrawList *list, CONST ImTextureID texture_id); +CIMGUI_API void ImDrawList_PopTextureID(struct ImDrawList *list); +CIMGUI_API void ImDrawList_GetClipRectMin(struct ImVec2 *pOut, struct ImDrawList *list); +CIMGUI_API void ImDrawList_GetClipRectMax(struct ImVec2 *pOut, struct ImDrawList *list); + +// Primitives +CIMGUI_API void ImDrawList_AddLine(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col, float thickness); +CIMGUI_API void ImDrawList_AddRect(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col, float rounding, int rounding_corners_flags, float thickness); +CIMGUI_API void ImDrawList_AddRectFilled(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col, float rounding, int rounding_corners_flags); +CIMGUI_API void ImDrawList_AddRectFilledMultiColor(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); +CIMGUI_API void ImDrawList_AddQuad(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, ImU32 col, float thickness); +CIMGUI_API void ImDrawList_AddQuadFilled(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, ImU32 col); +CIMGUI_API void ImDrawList_AddTriangle(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, ImU32 col, float thickness); +CIMGUI_API void ImDrawList_AddTriangleFilled(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, ImU32 col); +CIMGUI_API void ImDrawList_AddCircle(struct ImDrawList *list, CONST struct ImVec2 centre, float radius, ImU32 col, int num_segments, float thickness); +CIMGUI_API void ImDrawList_AddCircleFilled(struct ImDrawList *list, CONST struct ImVec2 centre, float radius, ImU32 col, int num_segments); +CIMGUI_API void ImDrawList_AddText(struct ImDrawList *list, CONST struct ImVec2 pos, ImU32 col, CONST char *text_begin, CONST char *text_end); +CIMGUI_API void ImDrawList_AddTextExt(struct ImDrawList *list, CONST struct ImFont *font, float font_size, CONST struct ImVec2 pos, ImU32 col, CONST char *text_begin, CONST char *text_end, float wrap_width, CONST struct ImVec4 *cpu_fine_clip_rect); +CIMGUI_API void ImDrawList_AddImage(struct ImDrawList *list, ImTextureID user_texture_id, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, ImU32 col); +CIMGUI_API void ImDrawList_AddImageQuad(struct ImDrawList *list, ImTextureID user_texture_id, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, CONST struct ImVec2 uv_c, CONST struct ImVec2 uv_d, ImU32 col); +CIMGUI_API void ImDrawList_AddImageRounded(struct ImDrawList *list, ImTextureID user_texture_id, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, ImU32 col, float rounding, int rounding_corners); +CIMGUI_API void ImDrawList_AddPolyline(struct ImDrawList *list, CONST struct ImVec2 *points, CONST int num_points, ImU32 col, bool closed, float thickness); +CIMGUI_API void ImDrawList_AddConvexPolyFilled(struct ImDrawList *list, CONST struct ImVec2 *points, CONST int num_points, ImU32 col); +CIMGUI_API void ImDrawList_AddBezierCurve(struct ImDrawList *list, CONST struct ImVec2 pos0, CONST struct ImVec2 cp0, CONST struct ImVec2 cp1, CONST struct ImVec2 pos1, ImU32 col, float thickness, int num_segments); + +// Stateful path API, add points then finish with PathFill() or PathStroke() +CIMGUI_API void ImDrawList_PathClear(struct ImDrawList *list); +CIMGUI_API void ImDrawList_PathLineTo(struct ImDrawList *list, CONST struct ImVec2 pos); +CIMGUI_API void ImDrawList_PathLineToMergeDuplicate(struct ImDrawList *list, CONST struct ImVec2 pos); +CIMGUI_API void ImDrawList_PathFillConvex(struct ImDrawList *list, ImU32 col); +CIMGUI_API void ImDrawList_PathStroke(struct ImDrawList *list, ImU32 col, bool closed, float thickness); +CIMGUI_API void ImDrawList_PathArcTo(struct ImDrawList *list, CONST struct ImVec2 centre, float radius, float a_min, float a_max, int num_segments); +CIMGUI_API void ImDrawList_PathArcToFast(struct ImDrawList *list, CONST struct ImVec2 centre, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle +CIMGUI_API void ImDrawList_PathBezierCurveTo(struct ImDrawList *list, CONST struct ImVec2 p1, CONST struct ImVec2 p2, CONST struct ImVec2 p3, int num_segments); +CIMGUI_API void ImDrawList_PathRect(struct ImDrawList *list, CONST struct ImVec2 rect_min, CONST struct ImVec2 rect_max, float rounding, int rounding_corners_flags); + +// Channels +CIMGUI_API void ImDrawList_ChannelsSplit(struct ImDrawList *list, int channels_count); +CIMGUI_API void ImDrawList_ChannelsMerge(struct ImDrawList *list); +CIMGUI_API void ImDrawList_ChannelsSetCurrent(struct ImDrawList *list, int channel_index); + +// Advanced +CIMGUI_API void ImDrawList_AddCallback(struct ImDrawList *list, ImDrawCallback callback, void *callback_data); // Your rendering function must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles. +CIMGUI_API void ImDrawList_AddDrawCmd(struct ImDrawList *list); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible + +// Internal helpers +CIMGUI_API void ImDrawList_PrimReserve(struct ImDrawList *list, int idx_count, int vtx_count); +CIMGUI_API void ImDrawList_PrimRect(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col); +CIMGUI_API void ImDrawList_PrimRectUV(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, ImU32 col); +CIMGUI_API void ImDrawList_PrimQuadUV(struct ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, CONST struct ImVec2 uv_c, CONST struct ImVec2 uv_d, ImU32 col); +CIMGUI_API void ImDrawList_PrimWriteVtx(struct ImDrawList *list, CONST struct ImVec2 pos, CONST struct ImVec2 uv, ImU32 col); +CIMGUI_API void ImDrawList_PrimWriteIdx(struct ImDrawList *list, ImDrawIdx idx); +CIMGUI_API void ImDrawList_PrimVtx(struct ImDrawList *list, CONST struct ImVec2 pos, CONST struct ImVec2 uv, ImU32 col); +CIMGUI_API void ImDrawList_UpdateClipRect(struct ImDrawList *list); +CIMGUI_API void ImDrawList_UpdateTextureID(struct ImDrawList *list); + +// ImDrawData +CIMGUI_API void ImDrawData_DeIndexAllBuffers(struct ImDrawData *drawData); +CIMGUI_API void ImDrawData_ScaleClipRects(struct ImDrawData *drawData, CONST struct ImVec2 sc); + +// ImFontAtlas +CIMGUI_API void ImFontAtlas_GetTexDataAsRGBA32(struct ImFontAtlas *atlas, unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel); +CIMGUI_API void ImFontAtlas_GetTexDataAsAlpha8(struct ImFontAtlas *atlas, unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel); +CIMGUI_API void ImFontAtlas_SetTexID(struct ImFontAtlas *atlas, ImTextureID id); +CIMGUI_API struct ImFont *ImFontAtlas_AddFont(struct ImFontAtlas *atlas, CONST struct ImFontConfig *font_cfg); +CIMGUI_API struct ImFont *ImFontAtlas_AddFontDefault(struct ImFontAtlas *atlas, CONST struct ImFontConfig *font_cfg); +CIMGUI_API struct ImFont *ImFontAtlas_AddFontFromFileTTF(struct ImFontAtlas *atlas, CONST char *filename, float size_pixels, CONST struct ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges); +CIMGUI_API struct ImFont *ImFontAtlas_AddFontFromMemoryTTF(struct ImFontAtlas *atlas, void *font_data, int font_size, float size_pixels, CONST struct ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges); +CIMGUI_API struct ImFont *ImFontAtlas_AddFontFromMemoryCompressedTTF(struct ImFontAtlas *atlas, CONST void *compressed_font_data, int compressed_font_size, float size_pixels, CONST struct ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges); +CIMGUI_API struct ImFont *ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(struct ImFontAtlas *atlas, CONST char *compressed_font_data_base85, float size_pixels, CONST struct ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges); +CIMGUI_API void ImFontAtlas_ClearTexData(struct ImFontAtlas *atlas); +CIMGUI_API void ImFontAtlas_Clear(struct ImFontAtlas *atlas); +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesDefault(struct ImFontAtlas *atlas); +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesKorean(struct ImFontAtlas *atlas); +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesJapanese(struct ImFontAtlas *atlas); +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesChinese(struct ImFontAtlas *atlas); +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesCyrillic(struct ImFontAtlas *atlas); +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesThai(struct ImFontAtlas *atlas); + +CIMGUI_API ImTextureID ImFontAtlas_GetTexID(struct ImFontAtlas *atlas); +CIMGUI_API unsigned char *ImFontAtlas_GetTexPixelsAlpha8(struct ImFontAtlas *atlas); +CIMGUI_API unsigned int *ImFontAtlas_GetTexPixelsRGBA32(struct ImFontAtlas *atlas); +CIMGUI_API int ImFontAtlas_GetTexWidth(struct ImFontAtlas *atlas); +CIMGUI_API int ImFontAtlas_GetTexHeight(struct ImFontAtlas *atlas); +CIMGUI_API int ImFontAtlas_GetTexDesiredWidth(struct ImFontAtlas *atlas); +CIMGUI_API void ImFontAtlas_SetTexDesiredWidth(struct ImFontAtlas *atlas, int TexDesiredWidth_); +CIMGUI_API int ImFontAtlas_GetTexGlyphPadding(struct ImFontAtlas *atlas); +CIMGUI_API void ImFontAtlas_SetTexGlyphPadding(struct ImFontAtlas *atlas, int TexGlyphPadding_); +CIMGUI_API void ImFontAtlas_GetTexUvWhitePixel(struct ImFontAtlas *atlas, struct ImVec2 *pOut); + +// ImFontAtlas::Fonts; +CIMGUI_API int ImFontAtlas_Fonts_size(struct ImFontAtlas *atlas); +CIMGUI_API struct ImFont *ImFontAtlas_Fonts_index(struct ImFontAtlas *atlas, int index); + +// ImFont +CIMGUI_API float ImFont_GetFontSize(CONST struct ImFont *font); +CIMGUI_API void ImFont_SetFontSize(struct ImFont *font, float FontSize_); +CIMGUI_API float ImFont_GetScale(CONST struct ImFont *font); +CIMGUI_API void ImFont_SetScale(struct ImFont *font, float Scale_); +CIMGUI_API void ImFont_GetDisplayOffset(CONST struct ImFont *font, struct ImVec2 *pOut); +CIMGUI_API CONST struct IMFONTGLYPH *ImFont_GetFallbackGlyph(CONST struct ImFont *font); +CIMGUI_API void ImFont_SetFallbackGlyph(struct ImFont *font, CONST struct IMFONTGLYPH *FallbackGlyph_); +CIMGUI_API float ImFont_GetFallbackAdvanceX(CONST struct ImFont *font); +CIMGUI_API ImWchar ImFont_GetFallbackChar(CONST struct ImFont *font); +CIMGUI_API short ImFont_GetConfigDataCount(CONST struct ImFont *font); +CIMGUI_API struct ImFontConfig *ImFont_GetConfigData(struct ImFont *font); +CIMGUI_API struct ImFontAtlas *ImFont_GetContainerAtlas(struct ImFont *font); +CIMGUI_API float ImFont_GetAscent(CONST struct ImFont *font); +CIMGUI_API float ImFont_GetDescent(CONST struct ImFont *font); +CIMGUI_API int ImFont_GetMetricsTotalSurface(CONST struct ImFont *font); +CIMGUI_API void ImFont_ClearOutputData(struct ImFont *font); +CIMGUI_API void ImFont_BuildLookupTable(struct ImFont *font); +CIMGUI_API CONST struct IMFONTGLYPH *ImFont_FindGlyph(CONST struct ImFont *font, ImWchar c); +CIMGUI_API void ImFont_SetFallbackChar(struct ImFont *font, ImWchar c); +CIMGUI_API float ImFont_GetCharAdvance(CONST struct ImFont *font, ImWchar c); +CIMGUI_API bool ImFont_IsLoaded(CONST struct ImFont *font); +CIMGUI_API CONST char *ImFont_GetDebugName(CONST struct ImFont *font); +CIMGUI_API void ImFont_CalcTextSizeA(CONST struct ImFont *font, struct ImVec2 *pOut, float size, float max_width, float wrap_width, CONST char *text_begin, CONST char *text_end, CONST char **remaining); // utf8 +CIMGUI_API CONST char *ImFont_CalcWordWrapPositionA(CONST struct ImFont *font, float scale, CONST char *text, CONST char *text_end, float wrap_width); +CIMGUI_API void ImFont_RenderChar(CONST struct ImFont *font, struct ImDrawList *draw_list, float size, struct ImVec2 pos, ImU32 col, unsigned short c); +CIMGUI_API void ImFont_RenderText(CONST struct ImFont *font, struct ImDrawList *draw_list, float size, struct ImVec2 pos, ImU32 col, CONST struct ImVec4 *clip_rect, CONST char *text_begin, CONST char *text_end, float wrap_width, bool cpu_fine_clip); +// ImFont::Glyph +CIMGUI_API int ImFont_Glyphs_size(CONST struct ImFont *font); +CIMGUI_API struct IMFONTGLYPH *ImFont_Glyphs_index(struct ImFont *font, int index); +// ImFont::IndexXAdvance +CIMGUI_API int ImFont_IndexXAdvance_size(CONST struct ImFont *font); +CIMGUI_API float ImFont_IndexXAdvance_index(CONST struct ImFont *font, int index); +// ImFont::IndexLookup +CIMGUI_API int ImFont_IndexLookup_size(CONST struct ImFont *font); +CIMGUI_API unsigned short ImFont_IndexLookup_index(CONST struct ImFont *font, int index); + +#endif // __CIMGUI_H__ diff --git a/lib/cimgui-1.53.1/cimgui/cimgui.sln b/lib/cimgui-1.53.1/cimgui/cimgui.sln new file mode 100644 index 0000000..bc9063c --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/cimgui.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cimgui", "cimgui.vcxproj", "{EDE48926-0595-4488-B1A0-32CA71397271}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EDE48926-0595-4488-B1A0-32CA71397271}.Debug|Win32.ActiveCfg = Debug|Win32 + {EDE48926-0595-4488-B1A0-32CA71397271}.Debug|Win32.Build.0 = Debug|Win32 + {EDE48926-0595-4488-B1A0-32CA71397271}.Debug|x64.ActiveCfg = Debug|x64 + {EDE48926-0595-4488-B1A0-32CA71397271}.Debug|x64.Build.0 = Debug|x64 + {EDE48926-0595-4488-B1A0-32CA71397271}.Release|Win32.ActiveCfg = Release|Win32 + {EDE48926-0595-4488-B1A0-32CA71397271}.Release|Win32.Build.0 = Release|Win32 + {EDE48926-0595-4488-B1A0-32CA71397271}.Release|x64.ActiveCfg = Release|x64 + {EDE48926-0595-4488-B1A0-32CA71397271}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/lib/cimgui-1.53.1/cimgui/cimgui.vcxproj b/lib/cimgui-1.53.1/cimgui/cimgui.vcxproj new file mode 100644 index 0000000..fdc8510 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/cimgui.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {EDE48926-0595-4488-B1A0-32CA71397271} + Win32Proj + cimgui + + + + DynamicLibrary + true + v140 + Unicode + + + DynamicLibrary + true + v140 + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;CIMGUI_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;CIMGUI_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;CIMGUI_EXPORTS;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;CIMGUI_EXPORTS;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/cimgui/cimgui.vcxproj.filters b/lib/cimgui-1.53.1/cimgui/cimgui.vcxproj.filters new file mode 100644 index 0000000..2023c37 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/cimgui.vcxproj.filters @@ -0,0 +1,48 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/cimgui/drawList.cpp b/lib/cimgui-1.53.1/cimgui/drawList.cpp new file mode 100644 index 0000000..362e2fe --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/drawList.cpp @@ -0,0 +1,293 @@ + +#include "../imgui/imgui.h" +#include "cimgui.h" + +CIMGUI_API void ImDrawData_DeIndexAllBuffers(ImDrawData *drawData) +{ + return drawData->DeIndexAllBuffers(); +} + +CIMGUI_API void ImDrawData_ScaleClipRects(ImDrawData *drawData, const struct ImVec2 sc) +{ + return drawData->ScaleClipRects(sc); +} + +CIMGUI_API int ImDrawList_GetVertexBufferSize(ImDrawList *list) +{ + return list->VtxBuffer.size(); +} + +CIMGUI_API ImDrawVert *ImDrawList_GetVertexPtr(ImDrawList *list, int n) +{ + return &list->VtxBuffer[n]; +} + +CIMGUI_API int ImDrawList_GetIndexBufferSize(ImDrawList *list) +{ + return list->IdxBuffer.size(); +} + +CIMGUI_API ImDrawIdx *ImDrawList_GetIndexPtr(ImDrawList *list, int n) +{ + return &list->IdxBuffer[n]; +} + +CIMGUI_API int ImDrawList_GetCmdSize(ImDrawList *list) +{ + return list->CmdBuffer.size(); +} + +CIMGUI_API ImDrawCmd *ImDrawList_GetCmdPtr(ImDrawList *list, int n) +{ + return &list->CmdBuffer[n]; +} + +CIMGUI_API void ImDrawList_Clear(ImDrawList *list) +{ + return list->Clear(); +} + +CIMGUI_API void ImDrawList_ClearFreeMemory(ImDrawList *list) +{ + return list->ClearFreeMemory(); +} + +CIMGUI_API void ImDrawList_PushClipRect(ImDrawList *list, struct ImVec2 clip_rect_min, struct ImVec2 clip_rect_max, bool intersect_with_current_clip_rect) +{ + return list->PushClipRect(clip_rect_min, clip_rect_max, intersect_with_current_clip_rect); +} + +CIMGUI_API void ImDrawList_PushClipRectFullScreen(ImDrawList *list) +{ + return list->PushClipRectFullScreen(); +} + +CIMGUI_API void ImDrawList_PopClipRect(ImDrawList *list) +{ + return list->PopClipRect(); +} + +CIMGUI_API void ImDrawList_PushTextureID(ImDrawList *list, CONST ImTextureID texture_id) +{ + return list->PushTextureID(texture_id); +} + +CIMGUI_API void ImDrawList_PopTextureID(ImDrawList *list) +{ + return list->PopTextureID(); +} + +CIMGUI_API void ImDrawList_GetClipRectMin(ImVec2 *pOut, ImDrawList *list) +{ + *pOut = list->GetClipRectMin(); +} + +CIMGUI_API void ImDrawList_GetClipRectMax(ImVec2 *pOut, ImDrawList *list) +{ + *pOut = list->GetClipRectMax(); +} + +CIMGUI_API void ImDrawList_AddLine(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col, float thickness) +{ + return list->AddLine(a, b, col, thickness); +} + +CIMGUI_API void ImDrawList_AddRect(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col, float rounding, int rounding_corners_flags, float thickness) +{ + return list->AddRect(a, b, col, rounding, rounding_corners_flags, thickness); +} + +CIMGUI_API void ImDrawList_AddRectFilled(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col, float rounding, int rounding_corners_flags) +{ + return list->AddRectFilled(a, b, col, rounding, rounding_corners_flags); +} + +CIMGUI_API void ImDrawList_AddRectFilledMultiColor(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left) +{ + return list->AddRectFilledMultiColor(a, b, col_upr_left, col_upr_right, col_bot_right, col_bot_left); +} + +CIMGUI_API void ImDrawList_AddQuad(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, ImU32 col, float thickness) +{ + return list->AddQuad(a, b, c, d, col, thickness); +} + +CIMGUI_API void ImDrawList_AddQuadFilled(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, ImU32 col) +{ + return list->AddQuadFilled(a, b, c, d, col); +} + +CIMGUI_API void ImDrawList_AddTriangle(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, ImU32 col, float thickness) +{ + return list->AddTriangle(a, b, c, col, thickness); +} + +CIMGUI_API void ImDrawList_AddTriangleFilled(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, ImU32 col) +{ + return list->AddTriangleFilled(a, b, c, col); +} + +CIMGUI_API void ImDrawList_AddCircle(ImDrawList *list, CONST struct ImVec2 centre, float radius, ImU32 col, int num_segments, float thickness) +{ + return list->AddCircle(centre, radius, col, num_segments, thickness); +} + +CIMGUI_API void ImDrawList_AddCircleFilled(ImDrawList *list, CONST struct ImVec2 centre, float radius, ImU32 col, int num_segments) +{ + return list->AddCircleFilled(centre, radius, col, num_segments); +} + +CIMGUI_API void ImDrawList_AddText(ImDrawList *list, CONST struct ImVec2 pos, ImU32 col, CONST char *text_begin, CONST char *text_end) +{ + return list->AddText(pos, col, text_begin, text_end); +} + +CIMGUI_API void ImDrawList_AddTextExt(ImDrawList *list, CONST ImFont *font, float font_size, CONST struct ImVec2 pos, ImU32 col, CONST char *text_begin, CONST char *text_end, float wrap_width, CONST ImVec4 *cpu_fine_clip_rect) +{ + return list->AddText(font, font_size, pos, col, text_begin, text_end, wrap_width, cpu_fine_clip_rect); +} + +CIMGUI_API void ImDrawList_AddImage(ImDrawList *list, ImTextureID user_texture_id, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, ImU32 col) +{ + return list->AddImage(user_texture_id, a, b, uv_a, uv_b, col); +} + +CIMGUI_API void ImDrawList_AddImageQuad(struct ImDrawList *list, ImTextureID user_texture_id, CONST struct ImVec2 a, CONST ImVec2 b, CONST ImVec2 c, CONST ImVec2 d, CONST ImVec2 uv_a, CONST ImVec2 uv_b, CONST ImVec2 uv_c, CONST ImVec2 uv_d, ImU32 col) +{ + return list->AddImageQuad(user_texture_id, a, b, c, d, uv_a, uv_b, uv_c, uv_d, col); +} + +CIMGUI_API void ImDrawList_AddImageRounded(struct ImDrawList *list, ImTextureID user_texture_id, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, ImU32 col, float rounding, int rounding_corners) +{ + list->AddImageRounded(user_texture_id, a, b, uv_a, uv_b, col, rounding, rounding_corners); +} + +CIMGUI_API void ImDrawList_AddPolyline(ImDrawList *list, CONST ImVec2 *points, CONST int num_points, ImU32 col, bool closed, float thickness) +{ + return list->AddPolyline(points, num_points, col, closed, thickness); +} + +CIMGUI_API void ImDrawList_AddConvexPolyFilled(ImDrawList *list, CONST ImVec2 *points, CONST int num_points, ImU32 col) +{ + return list->AddConvexPolyFilled(points, num_points, col); +} + +CIMGUI_API void ImDrawList_AddBezierCurve(ImDrawList *list, CONST struct ImVec2 pos0, CONST struct ImVec2 cp0, CONST struct ImVec2 cp1, CONST struct ImVec2 pos1, ImU32 col, float thickness, int num_segments) +{ + return list->AddBezierCurve(pos0, cp0, cp1, pos1, col, thickness, num_segments); +} + +CIMGUI_API void ImDrawList_PathClear(ImDrawList *list) +{ + return list->PathClear(); +} + +CIMGUI_API void ImDrawList_PathLineTo(ImDrawList *list, CONST struct ImVec2 pos) +{ + return list->PathLineTo(pos); +} + +CIMGUI_API void ImDrawList_PathLineToMergeDuplicate(ImDrawList *list, CONST struct ImVec2 pos) +{ + return list->PathLineToMergeDuplicate(pos); +} + +CIMGUI_API void ImDrawList_PathFillConvex(ImDrawList *list, ImU32 col) +{ + return list->PathFillConvex(col); +} + +CIMGUI_API void ImDrawList_PathStroke(ImDrawList *list, ImU32 col, bool closed, float thickness) +{ + return list->PathStroke(col, closed, thickness); +} + +CIMGUI_API void ImDrawList_PathArcTo(ImDrawList *list, CONST struct ImVec2 centre, float radius, float a_min, float a_max, int num_segments) +{ + return list->PathArcTo(centre, radius, a_min, a_max, num_segments); +} + +CIMGUI_API void ImDrawList_PathArcToFast(ImDrawList *list, CONST struct ImVec2 centre, float radius, int a_min_of_12, int a_max_of_12) +{ + return list->PathArcToFast(centre, radius, a_min_of_12, a_max_of_12); +} + +CIMGUI_API void ImDrawList_PathBezierCurveTo(ImDrawList *list, CONST struct ImVec2 p1, CONST struct ImVec2 p2, CONST struct ImVec2 p3, int num_segments) +{ + return list->PathBezierCurveTo(p1, p2, p3, num_segments); +} + +CIMGUI_API void ImDrawList_PathRect(ImDrawList *list, CONST struct ImVec2 rect_min, CONST struct ImVec2 rect_max, float rounding, int rounding_corners_flags) +{ + return list->PathRect(rect_min, rect_max, rounding, rounding_corners_flags); +} + +CIMGUI_API void ImDrawList_ChannelsSplit(ImDrawList *list, int channels_count) +{ + return list->ChannelsSplit(channels_count); +} + +CIMGUI_API void ImDrawList_ChannelsMerge(ImDrawList *list) +{ + return list->ChannelsMerge(); +} + +CIMGUI_API void ImDrawList_ChannelsSetCurrent(ImDrawList *list, int channel_index) +{ + return list->ChannelsSetCurrent(channel_index); +} + +CIMGUI_API void ImDrawList_AddCallback(ImDrawList *list, ImDrawCallback callback, void *callback_data) +{ + return list->AddCallback(callback, callback_data); +} + +CIMGUI_API void ImDrawList_AddDrawCmd(ImDrawList *list) +{ + return list->AddDrawCmd(); +} + +CIMGUI_API void ImDrawList_PrimReserve(ImDrawList *list, int idx_count, int vtx_count) +{ + return list->PrimReserve(idx_count, vtx_count); +} + +CIMGUI_API void ImDrawList_PrimRect(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, ImU32 col) +{ + return list->PrimRect(a, b, col); +} + +CIMGUI_API void ImDrawList_PrimRectUV(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, ImU32 col) +{ + return list->PrimRectUV(a, b, uv_a, uv_b, col); +} + +CIMGUI_API void ImDrawList_PrimQuadUV(ImDrawList *list, CONST struct ImVec2 a, CONST struct ImVec2 b, CONST struct ImVec2 c, CONST struct ImVec2 d, CONST struct ImVec2 uv_a, CONST struct ImVec2 uv_b, CONST struct ImVec2 uv_c, CONST struct ImVec2 uv_d, ImU32 col) +{ + return list->PrimQuadUV(a, b, c, d, uv_a, uv_b, uv_c, uv_d, col); +} + +CIMGUI_API void ImDrawList_PrimVtx(ImDrawList *list, CONST struct ImVec2 pos, CONST struct ImVec2 uv, ImU32 col) +{ + return list->PrimVtx(pos, uv, col); +} + +CIMGUI_API void ImDrawList_PrimWriteVtx(ImDrawList *list, CONST struct ImVec2 pos, CONST struct ImVec2 uv, ImU32 col) +{ + return list->PrimWriteVtx(pos, uv, col); +} + +CIMGUI_API void ImDrawList_PrimWriteIdx(ImDrawList *list, ImDrawIdx idx) +{ + return list->PrimWriteIdx(idx); +} + +CIMGUI_API void ImDrawList_UpdateClipRect(ImDrawList *list) +{ + return list->UpdateClipRect(); +} + +CIMGUI_API void ImDrawList_UpdateTextureID(ImDrawList *list) +{ + return list->UpdateTextureID(); +} diff --git a/lib/cimgui-1.53.1/cimgui/fontAtlas.cpp b/lib/cimgui-1.53.1/cimgui/fontAtlas.cpp new file mode 100644 index 0000000..92d5658 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/fontAtlas.cpp @@ -0,0 +1,328 @@ + +#include "../imgui/imgui.h" +#include "cimgui.h" + +CIMGUI_API void ImFontConfig_DefaultConstructor(ImFontConfig *config) +{ + *config = ImFontConfig(); +} + +CIMGUI_API void ImFontAtlas_GetTexDataAsRGBA32(ImFontAtlas *atlas, unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel) +{ + atlas->GetTexDataAsRGBA32(out_pixels, out_width, out_height, out_bytes_per_pixel); +} + +CIMGUI_API void ImFontAtlas_GetTexDataAsAlpha8(ImFontAtlas *atlas, unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel) +{ + atlas->GetTexDataAsAlpha8(out_pixels, out_width, out_height, out_bytes_per_pixel); +} + +CIMGUI_API void ImFontAtlas_SetTexID(ImFontAtlas *atlas, ImTextureID id) +{ + atlas->TexID = id; +} + +CIMGUI_API ImFont *ImFontAtlas_AddFont(ImFontAtlas *atlas, CONST ImFontConfig *font_cfg) +{ + return atlas->AddFont(font_cfg); +} + +CIMGUI_API ImFont *ImFontAtlas_AddFontDefault(ImFontAtlas *atlas, CONST ImFontConfig *font_cfg) +{ + return atlas->AddFontDefault(font_cfg); +} + +CIMGUI_API ImFont *ImFontAtlas_AddFontFromFileTTF(ImFontAtlas *atlas, CONST char *filename, float size_pixels, CONST ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges) +{ + return atlas->AddFontFromFileTTF(filename, size_pixels, font_cfg, glyph_ranges); +} + +CIMGUI_API ImFont *ImFontAtlas_AddFontFromMemoryTTF(ImFontAtlas *atlas, void *font_data, int font_size, float size_pixels, CONST ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges) +{ + return atlas->AddFontFromMemoryTTF(font_data, font_size, size_pixels, font_cfg, glyph_ranges); +} + +CIMGUI_API ImFont *ImFontAtlas_AddFontFromMemoryCompressedTTF(ImFontAtlas *atlas, CONST void *compressed_font_data, int compressed_font_size, float size_pixels, CONST ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges) +{ + return atlas->AddFontFromMemoryCompressedTTF(compressed_font_data, compressed_font_size, size_pixels, font_cfg, glyph_ranges); +} + +CIMGUI_API ImFont *ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(ImFontAtlas *atlas, CONST char *compressed_font_data_base85, float size_pixels, CONST ImFontConfig *font_cfg, CONST ImWchar *glyph_ranges) +{ + return atlas->AddFontFromMemoryCompressedBase85TTF(compressed_font_data_base85, size_pixels, font_cfg, glyph_ranges); +} + +CIMGUI_API void ImFontAtlas_ClearTexData(ImFontAtlas *atlas) +{ + return atlas->ClearTexData(); +} + +CIMGUI_API void ImFontAtlas_ClearInputData(ImFontAtlas *atlas) +{ + return atlas->ClearInputData(); +} + +CIMGUI_API void ImFontAtlas_ClearFonts(ImFontAtlas *atlas) +{ + return atlas->ClearFonts(); +} + +CIMGUI_API void ImFontAtlas_Clear(ImFontAtlas *atlas) +{ + return atlas->Clear(); +} + +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesDefault(struct ImFontAtlas *atlas) +{ + return atlas->GetGlyphRangesDefault(); +} + +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesKorean(struct ImFontAtlas *atlas) +{ + return atlas->GetGlyphRangesKorean(); +} + +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesJapanese(struct ImFontAtlas *atlas) +{ + return atlas->GetGlyphRangesJapanese(); +} + +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesChinese(struct ImFontAtlas *atlas) +{ + return atlas->GetGlyphRangesChinese(); +} + +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesCyrillic(struct ImFontAtlas *atlas) +{ + return atlas->GetGlyphRangesCyrillic(); +} + +CIMGUI_API CONST ImWchar *ImFontAtlas_GetGlyphRangesThai(struct ImFontAtlas *atlas) +{ + return atlas->GetGlyphRangesThai(); +} + +CIMGUI_API ImTextureID ImFontAtlas_GetTexID(struct ImFontAtlas *atlas) +{ + return atlas->TexID; +} + +CIMGUI_API unsigned char *ImFontAtlas_GetTexPixelsAlpha8(struct ImFontAtlas *atlas) +{ + return atlas->TexPixelsAlpha8; +} + +CIMGUI_API unsigned int *ImFontAtlas_GetTexPixelsRGBA32(struct ImFontAtlas *atlas) +{ + return atlas->TexPixelsRGBA32; +} + +CIMGUI_API int ImFontAtlas_GetTexWidth(struct ImFontAtlas *atlas) +{ + return atlas->TexWidth; +} + +CIMGUI_API int ImFontAtlas_GetTexHeight(struct ImFontAtlas *atlas) +{ + return atlas->TexHeight; +} + +CIMGUI_API int ImFontAtlas_GetTexDesiredWidth(struct ImFontAtlas *atlas) +{ + return atlas->TexDesiredWidth; +} + +CIMGUI_API void ImFontAtlas_SetTexDesiredWidth(struct ImFontAtlas *atlas, int TexDesiredWidth_) +{ + atlas->TexDesiredWidth = TexDesiredWidth_; +} + +CIMGUI_API int ImFontAtlas_GetTexGlyphPadding(struct ImFontAtlas *atlas) +{ + return atlas->TexGlyphPadding; +} + +CIMGUI_API void ImFontAtlas_SetTexGlyphPadding(struct ImFontAtlas *atlas, int TexGlyphPadding_) +{ + atlas->TexGlyphPadding = TexGlyphPadding_; +} + +CIMGUI_API void ImFontAtlas_GetTexUvWhitePixel(struct ImFontAtlas *atlas, ImVec2 *pOut) +{ + *pOut = atlas->TexUvWhitePixel; +} + +// ImFontAtlas::Fonts; +CIMGUI_API int ImFontAtlas_Fonts_size(struct ImFontAtlas *atlas) +{ + return atlas->Fonts.size(); +} + +CIMGUI_API ImFont *ImFontAtlas_Fonts_index(struct ImFontAtlas *atlas, int index) +{ + return atlas->Fonts[index]; +} + +// ImFont +CIMGUI_API float ImFont_GetFontSize(CONST struct ImFont *font) +{ + return font->FontSize; +} + +CIMGUI_API void ImFont_SetFontSize(struct ImFont *font, float FontSize_) +{ + font->FontSize = FontSize_; +} + +CIMGUI_API float ImFont_GetScale(CONST struct ImFont *font) +{ + return font->Scale; +} + +CIMGUI_API void ImFont_SetScale(struct ImFont *font, float Scale_) +{ + font->Scale = Scale_; +} + +CIMGUI_API void ImFont_GetDisplayOffset(CONST struct ImFont *font, ImVec2 *pOut) +{ + *pOut = font->DisplayOffset; +} + +CIMGUI_API CONST struct IMFONTGLYPH *ImFont_GetFallbackGlyph(CONST struct ImFont *font) +{ + return font->FallbackGlyph; +} + +CIMGUI_API void ImFont_SetFallbackGlyph(struct ImFont *font, CONST struct IMFONTGLYPH *FallbackGlyph_) +{ + font->FallbackGlyph = FallbackGlyph_; +} + +CIMGUI_API float ImFont_GetFallbackAdvanceX(CONST struct ImFont *font) +{ + return font->FallbackAdvanceX; +} + +CIMGUI_API ImWchar ImFont_GetFallbackChar(CONST struct ImFont *font) +{ + return font->FallbackChar; +} + +CIMGUI_API short ImFont_GetConfigDataCount(CONST struct ImFont *font) +{ + return font->ConfigDataCount; +} + +CIMGUI_API struct ImFontConfig *ImFont_GetConfigData(struct ImFont *font) +{ + return font->ConfigData; +} + +CIMGUI_API struct ImFontAtlas *ImFont_GetContainerAtlas(struct ImFont *font) +{ + return font->ContainerAtlas; +} + +CIMGUI_API float ImFont_GetAscent(CONST struct ImFont *font) +{ + return font->Ascent; +} + +CIMGUI_API float ImFont_GetDescent(CONST struct ImFont *font) +{ + return font->Descent; +} + +CIMGUI_API int ImFont_GetMetricsTotalSurface(CONST struct ImFont *font) +{ + return font->MetricsTotalSurface; +} + +CIMGUI_API void ImFont_ClearOutputData(struct ImFont *font) +{ + font->ClearOutputData(); +} + +CIMGUI_API void ImFont_BuildLookupTable(struct ImFont *font) +{ + font->BuildLookupTable(); +} + +CIMGUI_API CONST struct IMFONTGLYPH *ImFont_FindGlyph(CONST struct ImFont *font, ImWchar c) +{ + return font->FindGlyph(c); +} + +CIMGUI_API void ImFont_SetFallbackChar(struct ImFont *font, ImWchar c) +{ + font->SetFallbackChar(c); +} + +CIMGUI_API float ImFont_GetCharAdvance(CONST struct ImFont *font, ImWchar c) +{ + return font->GetCharAdvance(c); +} + +CIMGUI_API bool ImFont_IsLoaded(CONST struct ImFont *font) +{ + return font->IsLoaded(); +} + +CIMGUI_API CONST char *ImFont_GetDebugName(CONST struct ImFont *font) +{ + return font->GetDebugName(); +} + +CIMGUI_API void ImFont_CalcTextSizeA(CONST struct ImFont *font, ImVec2 *pOut, float size, float max_width, float wrap_width, CONST char *text_begin, CONST char *text_end, CONST char **remaining) +{ + *pOut = font->CalcTextSizeA(size, max_width, wrap_width, text_begin, text_end, remaining); +} + +CIMGUI_API CONST char *ImFont_CalcWordWrapPositionA(CONST struct ImFont *font, float scale, CONST char *text, CONST char *text_end, float wrap_width) +{ + return font->CalcWordWrapPositionA(scale, text, text_end, wrap_width); +} + +CIMGUI_API void ImFont_RenderChar(CONST struct ImFont *font, ImDrawList *draw_list, float size, ImVec2 pos, ImU32 col, unsigned short c) +{ + return font->RenderChar(draw_list, size, pos, col, c); +} + +CIMGUI_API void ImFont_RenderText(CONST struct ImFont *font, ImDrawList *draw_list, float size, ImVec2 pos, ImU32 col, CONST ImVec4 *clip_rect, CONST char *text_begin, CONST char *text_end, float wrap_width, bool cpu_fine_clip) +{ + return font->RenderText(draw_list, size, pos, col, *clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip); +} + +// ImFont::Glyph +CIMGUI_API int ImFont_Glyphs_size(CONST struct ImFont *font) +{ + return font->Glyphs.size(); +} + +CIMGUI_API struct IMFONTGLYPH *ImFont_Glyphs_index(struct ImFont *font, int index) +{ + return &font->Glyphs[index]; +} + +// ImFont::IndexXAdvance +CIMGUI_API int ImFont_IndexXAdvance_size(CONST struct ImFont *font) +{ + return font->IndexAdvanceX.size(); +} + +CIMGUI_API float ImFont_IndexXAdvance_index(CONST struct ImFont *font, int index) +{ + return font->IndexAdvanceX[index]; +} + +// ImFont::IndexLookup +CIMGUI_API int ImFont_IndexLookup_size(CONST struct ImFont *font) +{ + return font->IndexLookup.size(); +} + +CIMGUI_API unsigned short ImFont_IndexLookup_index(CONST struct ImFont *font, int index) +{ + return font->IndexLookup[index]; +} diff --git a/lib/cimgui-1.53.1/cimgui/listClipper.cpp b/lib/cimgui-1.53.1/cimgui/listClipper.cpp new file mode 100644 index 0000000..aea0a21 --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/listClipper.cpp @@ -0,0 +1,27 @@ +#include "../imgui/imgui.h" +#include "cimgui.h" + +CIMGUI_API void ImGuiListClipper_Begin(ImGuiListClipper* clipper, int count, float items_height) +{ + clipper->Begin(count, items_height); +} + +CIMGUI_API void ImGuiListClipper_End(ImGuiListClipper* clipper) +{ + clipper->End(); +} + +CIMGUI_API bool ImGuiListClipper_Step(ImGuiListClipper* clipper) +{ + return clipper->Step(); +} + +CIMGUI_API int ImGuiListClipper_GetDisplayStart(ImGuiListClipper* clipper) +{ + return clipper->DisplayStart; +} + +CIMGUI_API int ImGuiListClipper_GetDisplayEnd(ImGuiListClipper* clipper) +{ + return clipper->DisplayEnd; +} diff --git a/lib/cimgui-1.53.1/cimgui/test.c b/lib/cimgui-1.53.1/cimgui/test.c new file mode 100644 index 0000000..8e6badf --- /dev/null +++ b/lib/cimgui-1.53.1/cimgui/test.c @@ -0,0 +1,2 @@ + +#include "cimgui.h" \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui b/lib/cimgui-1.53.1/imgui new file mode 120000 index 0000000..2fc3134 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui @@ -0,0 +1 @@ +imgui-1.53 \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/.travis.yml b/lib/cimgui-1.53.1/imgui-1.53/.travis.yml new file mode 100644 index 0000000..044b87a --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/.travis.yml @@ -0,0 +1,18 @@ +language: cpp + +os: + - linux + - osx + +compiler: + - gcc + - clang + +before_install: + - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-add-repository --yes ppa:zoogie/sdl2-snapshots && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libxrandr-dev libxi-dev libxxf86vm-dev libsdl2-dev; fi + - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glfw3 && brew install sdl2; fi + +script: + - make -C examples/opengl2_example + - make -C examples/opengl3_example + - make -C examples/sdl_opengl3_example diff --git a/lib/cimgui-1.53.1/imgui-1.53/LICENSE.txt b/lib/cimgui-1.53.1/imgui-1.53/LICENSE.txt new file mode 100644 index 0000000..5a9b98b --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014-2017 Omar Cornut and ImGui contributors + +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. diff --git a/lib/cimgui-1.53.1/imgui-1.53/README.md b/lib/cimgui-1.53.1/imgui-1.53/README.md new file mode 100644 index 0000000..6ababf5 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/README.md @@ -0,0 +1,253 @@ +dear imgui, +===== +[![Build Status](https://travis-ci.org/ocornut/imgui.svg?branch=master)](https://travis-ci.org/ocornut/imgui) +[![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720) + +(This library is free but needs your support to sustain its development. There are lots of desirable new features and maintenance to do. If you are an individual using dear imgui, please consider donating via Patreon or PayPal. If your company is using dear imgui, please consider financial support (e.g. sponsoring a few weeks/months of development). I can invoice for private support, custom development etc. E-mail: omarcornut at gmail.) + +Monthly donations via Patreon: +
[![Patreon](https://cloud.githubusercontent.com/assets/8225057/5990484/70413560-a9ab-11e4-8942-1a63607c0b00.png)](http://www.patreon.com/imgui) + +One-off donations via PayPal: +
[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Q73FPZ9C526U) + +Dear ImGui is a bloat-free graphical user interface library for C++. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies). + +Dear ImGui is designed to enable fast iteration and empower programmers to create content creation tools and visualization/ debug tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and thus lacks certain features normally found in more high-level libraries. + +Dear ImGui is particularly suited to integration in realtime 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard. + +Dear ImGui is self-contained within a few files that you can easily copy and compile into your application/engine: + + - imgui.cpp + - imgui.h + - imgui_demo.cpp + - imgui_draw.cpp + - imgui_internal.h + - imconfig.h (empty by default, user-editable) + - stb_rect_pack.h + - stb_textedit.h + - stb_truetype.h + +No specific build process is required. You can add the .cpp files to your project or #include them from an existing file. + +Your code passes mouse/keyboard inputs and settings to Dear ImGui (see example applications for more details). After Dear ImGui is setup, you can use it like in this example: + +![screenshot of sample code alongside its output with dear imgui](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/code_sample_01.png) + +Dear ImGui outputs vertex buffers and simple command-lists that you can render in your application. The number of draw calls and state changes is typically very small. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate dear imgui with your existing codebase. + +_A common misunderstanding is to think that immediate mode gui == immediate mode rendering, which usually implies hammering your driver/GPU with a bunch of inefficient draw calls and state changes, as the gui functions are called by the user. This is NOT what Dear ImGui does. Dear ImGui outputs vertex buffers and a small list of draw calls batches. It never touches your GPU directly. The draw call batches are decently optimal and you can render them later, in your app or even remotely._ + +Dear ImGui allows you create elaborate tools as well as very short-lived ones. On the extreme side of short-liveness: using the Edit&Continue feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. + +Binaries/Demo +------------- + +You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: +- [imgui-demo-binaries-20171013.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20171013.zip) (Windows binaries, Dear ImGui 1.52 WIP built 2017/10/13, 5 executables) + +Bindings +-------- + +Integrating Dear ImGui within your custom engine is a matter of wiring mouse/keyboard inputs and providing a render function that can bind a texture and render simple textured triangles. The examples/ folder is populated with applications doing just that. If you are an experienced programmer it should take you less than an hour to integrate Dear ImGui in your custom engine, but make sure to spend time reading the FAQ, the comments and other documentation! + +_NB: those third-party bindings may be more or less maintained, more or less close to the spirit of original API and therefore I cannot give much guarantee about them. People who create language bindings sometimes haven't used the C++ API themselves (for the good reason that they aren't C++ users). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ + +Languages: +- C (cimgui): https://github.com/Extrawurst/cimgui +- C#/.Net (ImGui.NET): https://github.com/mellinoe/ImGui.NET +- ChaiScript: https://github.com/JuJuBoSc/imgui-chaiscript +- D (DerelictImgui): https://github.com/Extrawurst/DerelictImgui +- Go (go-imgui): https://github.com/Armored-Dragon/go-imgui +- Lua: https://github.com/patrickriordan/imgui_lua_bindings +- Odin: https://github.com/ThisDrunkDane/odin-dear_imgui +- Pascal (imgui-pas): https://github.com/dpethes/imgui-pas +- Python (CyImGui): https://github.com/chromy/cyimgui +- Python (pyimgui): https://github.com/swistakm/pyimgui +- Rust (imgui-rs): https://github.com/Gekkio/imgui-rs + +Frameworks: +- Main ImGui repository include examples for DirectX9, DirectX10, DirectX11, OpenGL2/3, Vulkan, Allegro 5, SDL+GL2/3, iOS and Marmalade: https://github.com/ocornut/imgui/tree/master/examples +- Unmerged PR: DirectX12: https://github.com/ocornut/imgui/pull/301 +- Unmerged PR: SDL2 + OpenGLES + Emscripten: https://github.com/ocornut/imgui/pull/336 +- Unmerged PR: FreeGlut + OpenGL2: https://github.com/ocornut/imgui/pull/801 +- Unmerged PR: Native Win32 and OSX: https://github.com/ocornut/imgui/pull/281 +- Unmerged PR: Android: https://github.com/ocornut/imgui/pull/421 +- Cinder: https://github.com/simongeilfus/Cinder-ImGui +- cocos2d-x: https://github.com/c0i/imguix https://github.com/ocornut/imgui/issues/551 +- Flexium/SFML (FlexGUI): https://github.com/DXsmiley/FlexGUI +- GML/GameMakerStudio2 (ImGuiGML): https://marketplace.yoyogames.com/assets/6221/imguigml +- Irrlicht (IrrIMGUI): https://github.com/ZahlGraf/IrrIMGUI +- Ogre: https://bitbucket.org/LMCrashy/ogreimgui/src +- openFrameworks (ofxImGui): https://github.com/jvcleave/ofxImGui +- OpenSceneGraph/OSG: https://gist.github.com/fulezi/d2442ca7626bf270226014501357042c +- LÖVE: https://github.com/slages/love-imgui +- NanoRT (software raytraced) https://github.com/syoyo/imgui/tree/nanort/examples/raytrace_example +- Qt3d https://github.com/alpqr/imgui-qt3d +- Unreal Engine 4: https://github.com/segross/UnrealImGui or https://github.com/sronsse/UnrealEngine_ImGui +- SFML: https://github.com/EliasD/imgui-sfml or https://github.com/Mischa-Alff/imgui-backends + +For other bindings: see [this page](https://github.com/ocornut/imgui/wiki/Links/). +Please contact me with the Issues tracker or Twitter to fix/update this list. + +Gallery +------- + +See the [Screenshots Thread](https://github.com/ocornut/imgui/issues/123) for some user creations. +Also see the [Mega screenshots](https://github.com/ocornut/imgui/issues/1273) for an idea of the available features. + +![screenshot 1](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v148/examples_01.png) +[![screenshot game](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v149/gallery_TheDragonsTrap-01-thumb.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) +![screenshot 2](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v148/examples_02.png) + +[![screenshot profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v148/profiler-880.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v148/profiler.png) + +![screenshot picker](https://user-images.githubusercontent.com/8225057/29062188-471e95ba-7c53-11e7-9618-c4484c0b75fe.PNG) + +![screenshot 5](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v151/menus.png) +![screenshot 6](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v143/skinning_sample_02.png) +![screenshot 7](https://cloud.githubusercontent.com/assets/8225057/7903336/96f0fb7c-07d0-11e5-95d6-41c6a1595e5a.png) + +Dear ImGui can load TTF/OTF fonts. UTF-8 is supported for text display and input. Here using Arial Unicode font to display Japanese. Initialize custom font with: +``` +ImGuiIO& io = ImGui::GetIO(); +io.Fonts->AddFontFromFileTTF("ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + +// For Microsoft IME, pass your HWND to enable IME positioning: +io.ImeWindowHandle = my_hwnd; +``` +![Japanese screenshot](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/code_sample_01_jp.png) + +References +---------- + +The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works. +- [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html). +- [A presentation by Rickard Gustafsson and Johannes Algelind](http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf). +- [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/). +- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861). +- [Nicolas Guillemot's CppCon'16 flashtalk about Dear ImGui](https://www.youtube.com/watch?v=LSRJ1jZq90k). +- [Thierry Excoffier's Zero Memory Widget](http://perso.univ-lyon1.fr/thierry.excoffier/ZMW/). + +See the [Software using dear imgui page](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) for an incomplete list of software which are publicly known to use dear migui. + +See the [Links page](https://github.com/ocornut/imgui/wiki/Links) for third-party bindings to different languages and frameworks. + +Frequently Asked Question (FAQ) +------------------------------- + +Where is the documentation? + +- The documentation is at the top of imgui.cpp + effectively imgui.h. +- Example code is in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function. It covers most features of ImGui so you can read the code and call the function itself to see its output. +- Standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder. +- We obviously needs better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort. + +Which version should I get? + +I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master. The library is fairly stable and regressions tend to be fixed fast when reported. You may also want to checkout the [navigation branch](https://github.com/ocornut/imgui/tree/navigation) if you want to use Dear ImGui with a gamepad (it is also possible to map keyboard inputs to some degree). The Navigation branch is being kept up to date with Master. + +Why the odd dual naming, "dear imgui" vs "ImGui"? + +The library started its life and is best known as "ImGui" only due to the fact that I didn't give it a proper name when I released it. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations. It seemed confusing and unfair to hog the name. To reduce the ambiguity without affecting existing codebases, I have decided on an alternate, longer name "dear imgui" that people can use to refer to this specific library in ambiguous situations. + +What is ImTextureID and how do I display an image? +
I integrated Dear ImGui in my engine and the text or lines are blurry.. +
I integrated Dear ImGui in my engine and some elements are disappearing when I move windows around.. +
How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on labels/IDs. +
How can I tell when Dear ImGui wants my mouse/keyboard inputs VS when I can pass them to my application? +
How can I load a different font than the default? +
How can I easily use icons in my application? +
How can I load multiple fonts? +
How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic? +
How can I preserve my Dear ImGui context across reloading a DLL? (loss of the global/static variables) +
How can I use the drawing facilities without an Dear ImGui window? (using ImDrawList API) + +See the FAQ in imgui.cpp for answers. + +How do you use Dear ImGui on a platform that may not have a mouse or keyboard? + +I recommend using [Synergy](http://synergy-project.org) ([sources](https://github.com/symless/synergy)). In particular, the _src/micro/uSynergy.c_ file contains a small client that you can use on any platform to connect to your host PC. You can seamlessly use your PC input devices from a video game console or a tablet. Dear ImGui allows to increase the hit box of widgets (via the _style.TouchPadding_ setting) to accommodate a little for the lack of precision of touch inputs, but it is recommended you use a mouse to allow optimising for screen real-estate. You can also checkout the beta [navigation branch](https://github.com/ocornut/imgui/tree/navigation) which provides support for using Dear ImGui with a game controller. + +Can you create elaborate/serious tools with Dear ImGui? + +Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). + +Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might requires you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. + +Is Dear ImGui fast? + +Probably fast enough for most uses. Down to the foundation of its visual design, Dear ImGui is engineered to be fairly performant both in term of CPU and GPU usage. Running elaborate code and creating elaborate UI will of course have a cost but Dear ImGui aims to minimize it. + +Mileage may vary but the following screenshot can give you a rough idea of the cost of running and rendering UI code (In the case of a trivial demo application like this one, your driver/os setup are likely to be the bottleneck. Testing performance as part of a real application is recommended). + +![performance screenshot](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v138/performance_01.png) + +This is showing framerate for the full application loop on my 2011 iMac running Windows 7, OpenGL, AMD Radeon HD 6700M with an optimized executable. In contrast, librairies featuring higher-quality rendering and layouting techniques may have a higher resources footprint. + +If you intend to display large lists of items (say, 1000+) it can be beneficial for your code to perform clipping manually - one way is using helpers such as ImGuiListClipper - in order to avoid submitting them to Dear ImGui in the first place. Even though ImGui will discard your clipped items it still needs to calculate their size and that overhead will add up if you have thousands of items. If you can handle clipping and height positionning yourself then browsing a list with millions of items isn't a problem. + +Can you reskin the look of Dear ImGui? + +You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Below is a screenshot from [LumixEngine](https://github.com/nem0/LumixEngine) with custom colors + a docking/tabs extension (both of which you can find in the Issues section and will eventually be merged): + +![LumixEngine](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v151/lumix-201710-rearranged.png) + +Why using C++ (as opposed to C)? + +Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost-insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. + +There is an reasonably maintained [c-api for ImGui](https://github.com/Extrawurst/cimgui) by Stephan Dilly designed for binding in other languages. I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Links](https://github.com/ocornut/imgui/wiki/Links) for third-party bindings to other languages. + +Support dear imgui +------------------ + +How can I help financing further development of Dear ImGui? + +Your contributions are keeping the library alive. If you are an individual using dear imgui, please consider donating to enable me to spend more time improving the library. + +Monthly donations via Patreon: +
[![Patreon](https://cloud.githubusercontent.com/assets/8225057/5990484/70413560-a9ab-11e4-8942-1a63607c0b00.png)](http://www.patreon.com/imgui) + +One-off donations via PayPal: +
[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Q73FPZ9C526U) + +If your company uses dear imgui, please consider financial support (e.g. sponsoring a few weeks/months of development). I can invoice for private support, custom development etc. E-mail: omarcornut at gmail. Thanks! + +Credits +------- + +Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com). + +I first discovered imgui principles at [Q-Games](http://www.q-games.com) where Atman had dropped his own simple imgui implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating on it. + +Embeds [ProggyClean.ttf](http://upperbounds.net) font by Tristan Grimmer (MIT license). + +Embeds [stb_textedit.h, stb_truetype.h, stb_rectpack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). + +Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. And everybody posting feedback, questions and patches on the GitHub. + +Ongoing dear imgui development is financially supported on [**Patreon**](http://www.patreon.com/imgui). + +Double-chocolate sponsors: +- Media Molecule +- Mobigame +- Insomniac Games (sponsored the gamepad/keyboard navigation branch) +- Aras Pranckevičius +- Lizardcube +- Greggman + +Salty caramel supporters: +- Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Recognition Robotics, Chris Genova, ikrima, Glenn Fiedler, Geoffrey Evans, Dakko Dakko, Mercury Labs, Singularity Demo Group, Mischa Alff, Sebastien Ronsse. + +Caramel supporters: +- Michel Courtine, César Leblic, Dale Kim, Alex Evans, Rui Figueira, Paul Patrashcu, Jerome Lanquetot, Ctrl Alt Ninja, Paul Fleming, Neil Henning, Stephan Dilly, Neil Blakey-Milner, Aleksei, NeiloGD, Justin Paver, FiniteSol, Vincent Pancaldi, James Billot, Robin Hübner, furrtek, Eric, Simon Barratt, Game Atelier, Julian Bosch, Simon Lundmark, Vincent Hamm, Farhan Wali, Jeff Roberts, Matt Reyer, Colin Riley, Victor Martins, Josh Simmons, Garrett Hoofman, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Kit framework, Josh Faust, Martin Donlon, Quinton, Felix, Andrew Belt, Codecat, Cort Stratton, Claudio Canepa, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Roger Clark, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Miloš Tošić. + +And other supporters; thanks! +(Please contact me or PR if you would like to be added or removed from this list) + +License +------- + +Dear ImGui is licensed under the MIT License, see LICENSE for more information. diff --git a/lib/cimgui-1.53.1/imgui-1.53/TODO.txt b/lib/cimgui-1.53.1/imgui-1.53/TODO.txt new file mode 100644 index 0000000..c052aeb --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/TODO.txt @@ -0,0 +1,259 @@ +dear imgui +ISSUES & TODO LIST + +Issue numbers (#) refer to github issues listed at https://github.com/ocornut/imgui/issues/XXXX +The list below consist mostly of ideas noted down before they are requested/discussed by users (at which point they usually exist on the github issue tracker). +It's mostly a bunch of personal notes, probably incomplete. Feel free to query if you have any questions. + + - doc/test: add a proper documentation+regression testing system (#435) + - doc/test: checklist app to verify binding/integration of imgui (test inputs, rendering, callback, etc.). + - doc/tips: tips of the day: website? applet in imgui_club? + - project: folder or separate repository with maintained helpers (e.g. imgui_memory_editor.h, imgui_stl.h, maybe imgui_dock would be there?) + + - window: calling SetNextWindowSize() every frame with <= 0 doesn't do anything, may be useful to allow (particularly when used for a single axis). (#690) + - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. perhaps a lightweight explicit cleanup pass. + - window: auto-fit feedback loop when user relies on any dynamic layout (window width multiplier, column) appears weird to end-user. clarify. + - window: allow resizing of child windows (possibly given min/max for each axis?.) + - window: background options for child windows, border option (disable rounding). + - window: resizing from any sides? done. > need backends to honor mouse cursors properly. (#822) + - window: resize from borders: support some form of outer padding to make it easier to grab borders. (#822) + - window: begin with *p_open == false should return false. + - window: get size/pos helpers given names (see discussion in #249) + - window: a collapsed window can be stuck behind the main menu bar? + - window: when window is very small, prioritize resize button over close button. + - window: detect extra End() call that pop the "Debug" window out and assert at End() call site instead of at end of frame. + - window: increase minimum size of a window with menus or fix the menu rendering so that it doesn't look odd. + - window: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? + - window: expose contents size. (#1045) + - window: GetWindowSize() returns (0,0) when not calculated? (#1045) + - window: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate. +!- scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet. + - scrolling/clipping: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y). (2017-08-20: can't repro) + + - drawlist: end-user probably can't call Clear() directly because we expect a texture to be pushed in the stack. + - drawlist: maintaining bounding box per command would allow to merge draw command when clipping isn't relied on (typical non-scrolling window or non-overflowing column would merge with previous command). + - drawlist: primtiives/helpers to manipulate vertices post submission, so e.g. a quad/rect can be resized to fit later submitted content, _without_ using the ChannelSplit api + - drawlist: make it easier to toggle AA per primitive, so we can use e.g. non-AA fill + AA borders more naturally + - drawlist: non-AA strokes have gaps between points (#593, #288), especially RenderCheckmark(). + - drawlist: would be good to be able to deep copy a draw list (ImVector= op?). + - drawlist/opt: AddRect() axis aligned pixel aligned (no-aa) could use 8 triangles instead of 16 and no normal calculation. + + - main: considering adding an Init() function? some constructs are awkward in the implementation because of the lack of them. + - main: find a way to preserve relative orders of multiple reappearing windows (so an app toggling between "modes" e.g. fullscreen vs all tools) won't lose relative ordering. + - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes + - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? + - main: rename the main "Debug" window to avoid ID collision with user who may want to use "Debug" with specific flags. + + - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395) + - widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h. + - widgets: add visauls for Disabled/ReadOnly mode and expose publicly (#211) + - widgets: add always-allow-overlap mode. + - widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260 + - widgets: activate by identifier (trigger button, focus given id) + + - input text: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now and super fragile. + - input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541) + - input text: expose CursorPos in char filter event (#816) + - input text: access public fields via a non-callback API e.g. InputTextGetState("xxx") that may return NULL if not active. + - input text: flag to disable live update of the user buffer (also applies to float/int text input) (#701) + - input text: way to dynamically grow the buffer without forcing the user to initially allocate for worse case, e.g. more natural std::string (follow up on #200) + - input text: hover tooltip could show unclamped text + - input text: option to Tab after an Enter validation. + - input text: add ImGuiInputTextFlags_EnterToApply? (off #218) + - input text: easier ways to update buffer (from source char*) while owned. preserve some sort of cursor position for multi-line text. + - input text: add discard flag (e.g. ImGuiInputTextFlags_DiscardActiveBuffer) or make it easier to clear active focus for text replacement during edition (#725) + - input text: display bug when clicking a drag/slider after an input text in a different window has all-selected text (order dependant). actually a very old bug but no one appears to have noticed it. + - input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc). + - input text multi-line: line numbers? status bar? (follow up on #200) + - input text multi-line: behave better when user changes input buffer while editing is active (even though it is illegal behavior). namely, the change of buffer can create a scrollbar glitch (#725) + - input text multi-line: better horizontal scrolling support (#383, #1224) + - input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position. + - input number: optional range min/max for Input*() functions + - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) + - input number: use mouse wheel to step up/down + - input number: applying arithmetics ops (+,-,*,/) messes up with text edit undo stack. + + - layout: helper or a way to express ImGui::SameLine(ImGui::GetCursorStartPos().x + ImGui::CalcItemWidth() + ImGui::GetStyle().ItemInnerSpacing.x); in a simpler manner. + - layout: generalization of the above: a concept equivalent to word processor ruler tab stop ~ mini columns (position in X, no clipping implied) (vaguely relate to #267, #395, also what is used internally for menu items) + - layout: horizontal layout helper (#97) + - layout: horizontal flow until no space left (#404) + - layout: more generic alignment state (left/right/centered) for single items? + - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding. + - layout: BeginGroup() needs a border option. (~#1496) + - layout: vertical alignement of mixed height items (e.g. buttons) within a same line (#1284) + + - columns: sizing policy (e.g. for each column: fixed size, %, fill, distribute default size among fills) (#513, #125) + - columns: add a conditional parameter to SetColumnOffset() (#513, #125) + - columns: headers. reorderable. (#513, #125) + - columns: optional sorting modifiers (up/down), sort list so sorting can be done multi-critera. notify user when sort order changed. + - columns: option to alternate background colors on odd/even scanlines. + - columns: allow columns to recurse. + - columns: allow a same columns set to be interrupted by e.g. CollapsingHeader and resume with columns in sync when moving them. + - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125) + - columns: flag to add horizontal separator above/below? + - columns/layout: setup minimum line height (equivalent of automatically calling AlignFirstTextHeightToWidgets) + +!- color: the color conversion helpers/types are a mess and needs sorting out. + - color: (api breaking) ImGui::ColorConvertXXX functions should be loose ImColorConvertXX to match imgui_internals.h + - coloredit: it is still somehow awkward to copy colors around (unless going through Hex mode). + + - plot: full featured plot/graph api w/ scrolling, zooming etc. all bell & whistle. why not! + - plot: PlotLines() should use the polygon-stroke facilities, less verticles (currently issues with averaging normals) + - plot: make it easier for user to draw extra stuff into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots) + - plot: "smooth" automatic scale over time, user give an input 0.0(full user scale) 1.0(full derived from value) + - plot: option/feature: draw the zero line + - plot: option/feature: draw grid, vertical markers + - plot: option/feature: draw unit + - plot: add a helper e.g. Plot(char* label, float value, float time_span=2.0f) that stores values and Plot them for you - probably another function name. and/or automatically allow to plot ANY displayed value (more reliance on stable ID) + + - clipper: ability to force display 1 item in the list would be convenient (for patterns where we need to set active id etc.) + - clipper: ability to disable the clipping through a simple flag/bool. + - clipper: ability to run without knowing full count in advance. + + - splitter/separator: formalize the splitter idiom into an official api (we want to handle n-way split) (#319) + + - dock: docking extension + - dock: dock out from a collapsing header? would work nicely but need emitting window to keep submitting the code. + + - tabs: re-ordering, close buttons, context menu, persistent order (#261, #351) + + - ext: stl-ish friendly extension (imgui_stl.h) that has wrapped for std::string, std::vector etc. + + - button: provide a button that looks framed. + - image/image button: misalignment on padded/bordered button? + - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? + - image button: not taking an explicit id is odd. + - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() + - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). + - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate. + - slider: tint background based on value (e.g. v_min -> v_max, or use 0.0f either side of the sign) + - slider: precision dragging + - slider: step option (#1183) + - knob: rotating knob widget (#942) + - slider & drag: int data passing through a float + - drag float: up/down axis + - drag float: added leeway on edge (e.g. a few invisible steps past the clamp limits) + + - combo: use clipper: make it easier to disable clipper with a single flag. + - combo: option for BeginCombo to not return true when unchanged (#1182) + - combo/listbox: keyboard control. need InputText-like non-active focus + key handling. considering keyboard for custom listbox (pr #203) + - listbox: multiple selection. + - listbox: unselect option (#1208) + - listbox: make it easier/more natural to implement range-select (need some sort of info/ref about the last clicked/focused item that user can translate to an index?) (wip stash) + - listbox: user may want to initial scroll to focus on the one selected value? + - listbox: expose hovered item for a basic ListBox + - listbox: keyboard navigation. + - listbox: scrolling should track modified selection. + +!- popups/menus: clarify usage of popups id, how MenuItem/Selectable closing parent popups affects the ID, etc. this is quite fishy needs improvement! (#331, #402) + - popups: reopening context menu at new position should be the behavior by default? (equivalent to internal OpenPopupEx() with reopen_existing=true) (~#1497) + - popups: if the popup functions took explicit ImGuiID it would allow the user to manage the scope of those ID. (#331) + - popups: clicking outside (to close popup) and holding shouldn't drag window below. + - popups: add variant using global identifier similar to Begin/End (#402) + - popups: border options. richer api like BeginChild() perhaps? (#197) + - tooltip: tooltip that doesn't fit in entire screen seems to lose their "last preferred direction" and may teleport when moving mouse. + - tooltip: allow to set the width of a tooltip to allow TextWrapped() etc. while keeping the height automatic. + - tooltip: allow tooltips with timers? or general timer policy? (instaneous vs timed) + + - menus: calling BeginMenu() twice with a same name doesn't append as Begin() does for regular windows (#1207) + - statusbar: add a per-window status bar helper similar to what menubar does. + - shortcuts: local-style shortcut api, e.g. parse "&Save" + - shortcuts,menus: global-style shortcut api e.g. "Save (CTRL+S)" -> explicit flag for recursing into closed menu + - shortcuts: programmatically access shortcuts "Focus("&Save")) + - menus: menubars: main menu-bar could affect clamping of windows position (~ akin to modifying DisplayMin) + + - text: selectable text (for copy) as a generic feature (ItemFlags?) + - text: proper alignment options in imgui_internal.h + - text wrapped: figure out better way to use TextWrapped() in an always auto-resize context (tooltip, etc.) (#249) + - text: it's currently impossible to have a window title with "##". perhaps an official workaround would be nice. \ style inhibitor? non-visible ascii code to insert between #? + - text link/url button: underlined. should api expose an ID or use text contents as ID? which colors enum to use? + + - tree node / optimization: avoid formatting when clipped. + - tree node: tree-node/header right-most side doesn't take account of horizontal scrolling. + - tree node: add treenode/treepush int variants? not there because (void*) cast from int warns on some platforms/settings? + - tree node: try to apply scrolling at time of TreePop() if node was just opened and end of node is past scrolling limits? + - tree node / selectable render mismatch which is visible if you use them both next to each other (e.g. cf. property viewer) + - tree node: tweak color scheme to distinguish headers from selected tree node (#581) + +!- settings: expose enough to save/load .ini from RAM instead of fopen + - settings: write more decent code to allow saving/loading new fields: columns, selected tree nodes? + - settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file (#437) + - stb: add defines to disable stb implementations + +!- style: better default styles. (#707) + - style: border types: out-screen, in-screen, etc. (#447) + - style/optimization: store rounded corners in texture to use 1 quad per corner (filled and wireframe) to lower the cost of rounding. + - style: add window shadow (fading away from the window. Paint-style calculation of vertices alpha after drawlist would be easier) + - style: a concept of "compact style" that the end-user can easily rely on (e.g. PushStyleCompact()?) that maps to other settings? avoid implementing duplicate helpers such as SmallCheckbox(), etc. + - style: try to make PushStyleVar() more robust to incorrect parameters (to be more friendly to edit & continues situation). + - style: global scale setting. + - style: WindowPadding needs to be EVEN as the 0.5 multiplier used on this value probably have a subtle effect on clip rectangle + - style: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space? (#438, #707, #1223) + - style: gradients fill (#1223) ~ 2 bg colors for each fill? tricky with rounded shapes and using textures for corners. + - style editor: color child window height expressed in multiple of line height. + + - log: LogButtons() options for specifying depth and/or hiding depth slider + - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) + - log: be able to log anything (e.g. right-click on a window/tree-node, shows context menu? log into tty/file/clipboard) + - log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs. + + - filters: set a current filter that tree node can automatically query to hide themselves + - filters: handle wildcards (with implicit leading/trailing *), regexps + - filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb) + + - drag and drop: add demo. (#143, #479) + - drag and drop: test with reordering nodes (in a list, or a tree node). (#143) + - drag and drop: test integrating with os drag and drop. + - node/graph editor (#306) + - pie menus patterns (#434) + - markup: simple markup language for color change? (#902) + + - font: better vertical centering (based e.g on height of lowercase 'x'?). currently Roboto-Medium size 16 px isn't currently centered. + - font: free the Alpha buffer if user only requested RGBA. +!- font: better CalcTextSizeA() API, at least for simple use cases. current one is horrible (perhaps have simple vs extended versions). + - font: enforce monospace through ImFontConfig (for icons?) + create dual ImFont output from same input, reusing rasterized data but with different glyphs/AdvanceX + - font: finish CustomRectRegister() to allow mapping unicode codepoint to custom texture data + - font: PushFontSize API (#1018) + - font/atlas: incremental updates + - font/atlas: dynamic font atlas to avoid baking huge ranges into bitmap and make scaling easier. + - font/atlas: allow user to submit its own primitive to be rectpacked, and allow to map them on a Unicode point. + - font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite? + - font/text: vertical and/or rotated text renderer (#705) - vertical is easier clipping wise + - font: imgui_freetype.h alternative renderer (#618) + - font: optimization: for monospace font (like the default one) we can trim IndexXAdvance as long as trailing value is == FallbackXAdvance (need to make sure TAB is still correct). + - font: add support for kerning, probably optional. A) perhaps default to (32..128)^2 matrix ~ 9K entries = 36KB, then hash for non-ascii?. B) or sparse lookup into per-char list? + - font: add a simpler CalcTextSizeA() api? current one ok but not welcome if user needs to call it directly (without going through ImGui::CalcTextSize) + - font: fix AddRemapChar() to work before font has been built. + - font: (api breaking) removed "TTF" from symbol names. also because it now supports OTF. + +!- nav/keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing. + - nav: integrate navigation branch into master. (#787) + - nav: integrate/design keyboard controls. + - nav: once tab should go through most/all widgets (in submission order?) + - nav: currently cannot access menubar of a child window with Alt/menu key. + - nav: esc/enter default behavior for popups, e.g. be able to mark an "ok" or "cancel" button that would get triggered by those keys. + - focus: preserve ActiveId/focus stack state, e.g. when opening a menu and close it, previously selected InputText() focus gets restored (#622) + - focus: SetKeyboardFocusHere() on with >= 0 offset could be done on same frame (else latch and modulate on beginning of next frame) + - focus: unable to use SetKeyboardFocusHere() on clipped widgets. (#787) + - inputs: rework IO system to be able to pass actual ordered/timestamped events. use an event queue? (~#335, #71) + - inputs: allow to pass explicit double-clicks if that's the only thing the user's backend can get them. (e.g. for windows by the CS_DBLCLKS style). + - inputs: support track pad style scrolling & slider edit. + + - misc: idle refresh: expose cursor blink animation timer for backend to be able to lower framerate. + - misc: make the ImGuiCond values linear (non-power-of-two). internal storage for ImGuiWindow can use integers to combine into flags (Why?) + - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL) + - misc: fix for compilation settings where stdcall isn't the default (e.g. vectorcall) (#1230) + - remote: make a system like RemoteImGui first-class citizen/project (#75) + + - demo: add vertical separator demo + - demo: add virtual scrolling example? + - examples: directx9: save/restore device state more thoroughly. + - examples: window minimize, maximize (#583) + - examples: provide a zero-framerate/idle example. + - examples: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // the problem is that DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440) + - optimization: replace vsnprintf with stb_printf? or enable the defines/infrastructure to allow it (#1038) + - optimization: add clipping for multi-component widgets (SliderFloatX, ColorEditX, etc.). one problem is that nav branch can't easily clip parent group when there is a move request. + - optimization: add a flag to disable most of rendering, for the case where the user expect to skip it (#335) + - optimization: use another hash function than crc32, e.g. FNV1a + - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)? + - optimization: turn some the various stack vectors into statically-sized arrays diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/.gitignore b/lib/cimgui-1.53.1/imgui-1.53/examples/.gitignore new file mode 100644 index 0000000..9516dc7 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/.gitignore @@ -0,0 +1,49 @@ +## Visual Studio files +Debug/* +Release/* +ipch/* +x64/* +directx9_example/Debug/* +directx9_example/Release/* +directx9_example/ipch/* +directx9_example/x64/* +directx10_example/Debug/* +directx10_example/Release/* +directx10_example/ipch/* +directx10_example/x64/* +directx11_example/Debug/* +directx11_example/Release/* +directx11_example/ipch/* +directx11_example/x64/* +opengl2_example/Debug/* +opengl2_example/Release/* +opengl2_example/ipch/* +opengl2_example/x64/* +opengl2_example/opengl_example +opengl3_example/Debug/* +opengl3_example/Release/* +opengl3_example/ipch/* +opengl3_example/x64/* +opengl3_example/opengl3_example +sdl_opengl2_example/Debug/* +sdl_opengl2_example/Release/* +sdl_opengl2_example/ipch/* +sdl_opengl2_example/x64/* +sdl_opengl3_example/Debug/* +sdl_opengl3_example/Release/* +sdl_opengl3_example/ipch/* +sdl_opengl3_example/x64/* +*.opensdf +*.sdf +*.suo +*.vcxproj.user +*.o +*.obj +*.exe +*.pdb +*.ilk +*.VC.db +*.VC.VC.opendb + +## Ini files +imgui.ini diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/README.txt b/lib/cimgui-1.53.1/imgui-1.53/examples/README.txt new file mode 100644 index 0000000..1f00756 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/README.txt @@ -0,0 +1,102 @@ +Those are standalone ready-to-build applications to demonstrate ImGui. +Binaries of some of those demos: http://www.miracleworld.net/imgui/binaries + +Third party languages and frameworks bindings: https://github.com/ocornut/imgui/wiki/Links +(languages: C, .net, rust, D, Python, Lua..) +(frameworks: DX12, Vulkan, Cinder, OpenGLES, openFrameworks, Cocos2d-x, SFML, Flexium, NanoRT, Irrlicht..) +(extras: RemoteImGui, ImWindow, imgui_wm..) + +TL;DR; + - Newcomers, read 'PROGRAMMER GUIDE' in imgui.cpp for notes on how to setup ImGui in your codebase. + - If you are using of the backend provided here, so you can copy the imgui_impl_xxx.cpp/h files + to your project and use them unmodified. + - To LEARN how the library is setup, you may refer to 'opengl2_example' because is the simplest one to read. + However, do NOT USE the 'opengl2_example' if your code is using any modern GL3+ calls. + Mixing old fixed-pipeline OpenGL2 and modern OpenGL3+ is going to make everything more complicated. + Read comments below for details. If you are not sure, in doubt, use 'opengl3_example'. + - If you have your own engine, you probably want to read a few of the examples first then adapt it to + your engine. Please note that if your engine is based on OpenGL/DirectX you can perfectly use the + existing rendering backends, don't feel forced to rewrite them with your own engine API, or you can + do that later when you already got things to work. + +ImGui is highly portable and only requires a few things to run: + - Providing mouse/keyboard inputs + - Load the font atlas texture into graphics memory + - Providing a render function to render indexed textured triangles + - Optional: clipboard support, mouse cursor supports, Windows IME support, etc. +So this is essentially what those examples are doing + the obligatory cruft for portability. + +Unfortunately in 2016 it is still tedious to create and maintain portable build files using external +libraries (the kind we're using here to create a window and render 3D triangles) without relying on +third party software. For most examples here I choose to provide: + - Makefiles for Linux/OSX + - Batch files for Visual Studio 2008+ + - A .sln project file for Visual Studio 2010+ +Please let me know if they don't work with your setup! +You can probably just import the imgui_impl_xxx.cpp/.h files into your own codebase or compile those +directly with a command-line compiler. + +ImGui has zero frame of lag for most behaviors and one frame of lag for some behaviors. +At 60 FPS your experience should be pleasant. Consider that OS mouse cursors are typically drawn through +a specific hardware accelerated route and may feel smoother than other GPU rendered contents. You may +experiment with the io.MouseDrawCursor flag to request ImGui to draw a mouse cursor itself, to visualize +the lag between a hardware cursor and a software cursor. It might be beneficial to the user experience +to switch to a software rendered cursor when an interactive drag is in progress. +Also note that some setup or GPU drivers may be causing extra lag (possibly by enforcing triple buffering), +leaving you with no option but sadness/anger (Intel GPU drivers were reported as such). + +opengl2_example/ + **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** + **Prefer using the code in the opengl3_example/ folder** + GLFW + OpenGL example (legacy, fixed pipeline). + This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. + If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more + complicated, will require your code to reset every single OpenGL attributes to their initial state, and might + confuse your GPU driver. + +opengl3_example/ + GLFW + OpenGL example (programmable pipeline, binding modern functions with GL3W). + This uses more modern OpenGL calls and custom shaders. + Prefer using that if you are using modern OpenGL in your application (anything with shaders, vbo, vao, etc.). + +directx9_example/ + DirectX9 example, Windows only. + +directx10_example/ + DirectX10 example, Windows only. + This is quite long and tedious, because: DirectX10. + +directx11_example/ + DirectX11 example, Windows only. + This is quite long and tedious, because: DirectX11. + +apple_example/ + OSX & iOS example. + On iOS, Using Synergy to access keyboard/mouse data from server computer. + Synergy keyboard integration is rather hacky. + +sdl_opengl2_example/ + **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** + **Prefer using the code in the sdl_opengl3_example/ folder** + SDL2 + OpenGL example (legacy, fixed pipeline). + This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. + If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more + complicated, will require your code to reset every single OpenGL attributes to their initial state, and might + confuse your GPU driver. + +sdl_opengl3_example/ + SDL2 + OpenGL3 example. + This uses more modern OpenGL calls and custom shaders. + Prefer using that if you are using modern OpenGL in your application (anything with shaders, vbo, vao, etc.). + +allegro5_example/ + Allegro 5 example. + +marmalade_example/ + Marmalade example using IwGx + +vulkan_example/ + Vulkan example. + This is quite long and tedious, because: Vulkan. + +TODO: Apple, SDL GL/GL3, Allegro, Marmalade, Vulkan examples do not honor the io.WantMoveMouse flag. diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/README.md b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/README.md new file mode 100644 index 0000000..d891982 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/README.md @@ -0,0 +1,15 @@ + +# How to Build + +- On Ubuntu 14.04+ + +```bash +g++ -I ../imgui main.cpp imgui_impl_a5.cpp ../imgui/imgui*.cpp -lallegro -lallegro_primitives +``` + +- On Windows with Visual Studio's CLI + +``` +set ALLEGRODIR=path_to_your_allegro5_folder +cl /Zi /MD /I %ALLEGRODIR%\include /I ..\.. main.cpp imgui_impl_a5.cpp ..\..\imgui*.cpp /link /LIBPATH:%ALLEGRODIR%\lib allegro-5.0.10-monolith-md.lib user32.lib +``` diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.cpp new file mode 100644 index 0000000..0d38592 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.cpp @@ -0,0 +1,298 @@ +// ImGui Allegro 5 bindings +// In this binding, ImTextureID is used to store a 'ALLEGRO_BITMAP*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// TODO: +// - Clipboard is not supported. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui +// by @birthggd + +#include // uint64_t +#include // memcpy +#include +#include "imgui_impl_a5.h" +#include +#include + +#ifdef _WIN32 +#include +#endif + +// Data +static ALLEGRO_DISPLAY* g_Display = NULL; +static ALLEGRO_BITMAP* g_Texture = NULL; +static double g_Time = 0.0; +static ALLEGRO_MOUSE_CURSOR* g_MouseCursorInvisible = NULL; +static ALLEGRO_VERTEX_DECL* g_VertexDecl = NULL; + +#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) + +struct ImDrawVertAllegro +{ + ImVec2 pos; + ImVec2 uv; + ALLEGRO_COLOR col; +}; + +void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data) +{ + int op, src, dst; + al_get_blender(&op, &src, &dst); + al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); + + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + + // FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats + static ImVector vertices; + vertices.resize(cmd_list->VtxBuffer.Size); + for (int i = 0; i < cmd_list->VtxBuffer.Size; ++i) + { + const ImDrawVert &dv = cmd_list->VtxBuffer[i]; + ImDrawVertAllegro v; + v.pos = dv.pos; + v.uv = dv.uv; + unsigned char *c = (unsigned char*)&dv.col; + v.col = al_map_rgba(c[0], c[1], c[2], c[3]); + vertices[i] = v; + } + + // FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices + // You can also use '#define ImDrawIdx unsigned int' in imconfig.h and request ImGui to output 32-bit indices + static ImVector indices; + indices.resize(cmd_list->IdxBuffer.Size); + for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i) + indices[i] = (int)cmd_list->IdxBuffer.Data[i]; + + int idx_offset = 0; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId; + al_set_clipping_rectangle(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z-pcmd->ClipRect.x, pcmd->ClipRect.w-pcmd->ClipRect.y); + al_draw_indexed_prim(&vertices[0], g_VertexDecl, texture, &indices[idx_offset], pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST); + } + idx_offset += pcmd->ElemCount; + } + } + + // Restore modified state + al_set_blender(op, src, dst); + al_set_clipping_rectangle(0, 0, al_get_display_width(g_Display), al_get_display_height(g_Display)); +} + +bool Imgui_ImplA5_CreateDeviceObjects() +{ + // Build texture atlas + ImGuiIO &io = ImGui::GetIO(); + unsigned char *pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + // Create texture + int flags = al_get_new_bitmap_flags(); + int fmt = al_get_new_bitmap_format(); + al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP|ALLEGRO_MIN_LINEAR|ALLEGRO_MAG_LINEAR); + al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE); + ALLEGRO_BITMAP* img = al_create_bitmap(width, height); + al_set_new_bitmap_flags(flags); + al_set_new_bitmap_format(fmt); + if (!img) + return false; + + ALLEGRO_LOCKED_REGION *locked_img = al_lock_bitmap(img, al_get_bitmap_format(img), ALLEGRO_LOCK_WRITEONLY); + if (!locked_img) + { + al_destroy_bitmap(img); + return false; + } + memcpy(locked_img->data, pixels, sizeof(int)*width*height); + al_unlock_bitmap(img); + + // Convert software texture to hardware texture. + ALLEGRO_BITMAP* cloned_img = al_clone_bitmap(img); + al_destroy_bitmap(img); + if (!cloned_img) + return false; + + // Store our identifier + io.Fonts->TexID = (void*)cloned_img; + g_Texture = cloned_img; + + // Create an invisible mouse cursor + // Because al_hide_mouse_cursor() seems to mess up with the actual inputs.. + ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8,8); + g_MouseCursorInvisible = al_create_mouse_cursor(mouse_cursor, 0, 0); + al_destroy_bitmap(mouse_cursor); + + return true; +} + +void ImGui_ImplA5_InvalidateDeviceObjects() +{ + if (g_Texture) + { + al_destroy_bitmap(g_Texture); + ImGui::GetIO().Fonts->TexID = NULL; + g_Texture = NULL; + } + if (g_MouseCursorInvisible) + { + al_destroy_mouse_cursor(g_MouseCursorInvisible); + g_MouseCursorInvisible = NULL; + } +} + +bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display) +{ + g_Display = display; + + // Create custom vertex declaration. + // Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats. + // We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion. + ALLEGRO_VERTEX_ELEMENT elems[] = + { + { ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, pos) }, + { ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, uv) }, + { ALLEGRO_PRIM_COLOR_ATTR, 0, OFFSETOF(ImDrawVertAllegro, col) }, + { 0, 0, 0 } + }; + g_VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro)); + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = ALLEGRO_KEY_TAB; + io.KeyMap[ImGuiKey_LeftArrow] = ALLEGRO_KEY_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = ALLEGRO_KEY_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = ALLEGRO_KEY_UP; + io.KeyMap[ImGuiKey_DownArrow] = ALLEGRO_KEY_DOWN; + io.KeyMap[ImGuiKey_PageUp] = ALLEGRO_KEY_PGUP; + io.KeyMap[ImGuiKey_PageDown] = ALLEGRO_KEY_PGDN; + io.KeyMap[ImGuiKey_Home] = ALLEGRO_KEY_HOME; + io.KeyMap[ImGuiKey_End] = ALLEGRO_KEY_END; + io.KeyMap[ImGuiKey_Delete] = ALLEGRO_KEY_DELETE; + io.KeyMap[ImGuiKey_Backspace] = ALLEGRO_KEY_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = ALLEGRO_KEY_ENTER; + io.KeyMap[ImGuiKey_Escape] = ALLEGRO_KEY_ESCAPE; + io.KeyMap[ImGuiKey_A] = ALLEGRO_KEY_A; + io.KeyMap[ImGuiKey_C] = ALLEGRO_KEY_C; + io.KeyMap[ImGuiKey_V] = ALLEGRO_KEY_V; + io.KeyMap[ImGuiKey_X] = ALLEGRO_KEY_X; + io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y; + io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z; + + io.RenderDrawListsFn = ImGui_ImplA5_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. +#ifdef _WIN32 + io.ImeWindowHandle = al_get_win_window_handle(g_Display); +#endif + + return true; +} + +void ImGui_ImplA5_Shutdown() +{ + ImGui_ImplA5_InvalidateDeviceObjects(); + ImGui::Shutdown(); +} + +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +bool ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT *ev) +{ + ImGuiIO &io = ImGui::GetIO(); + + switch (ev->type) + { + case ALLEGRO_EVENT_MOUSE_AXES: + io.MouseWheel += ev->mouse.dz; + return true; + case ALLEGRO_EVENT_KEY_CHAR: + if (ev->keyboard.display == g_Display) + if (ev->keyboard.unichar > 0 && ev->keyboard.unichar < 0x10000) + io.AddInputCharacter((unsigned short)ev->keyboard.unichar); + return true; + case ALLEGRO_EVENT_KEY_DOWN: + case ALLEGRO_EVENT_KEY_UP: + if (ev->keyboard.display == g_Display) + io.KeysDown[ev->keyboard.keycode] = (ev->type == ALLEGRO_EVENT_KEY_DOWN); + return true; + } + return false; +} + +void ImGui_ImplA5_NewFrame() +{ + if (!g_Texture) + Imgui_ImplA5_CreateDeviceObjects(); + + ImGuiIO &io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + w = al_get_display_width(g_Display); + h = al_get_display_height(g_Display); + io.DisplaySize = ImVec2((float)w, (float)h); + + // Setup time step + double current_time = al_get_time(); + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); + g_Time = current_time; + + // Setup inputs + ALLEGRO_KEYBOARD_STATE keys; + al_get_keyboard_state(&keys); + io.KeyCtrl = al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL); + io.KeyShift = al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT); + io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR); + io.KeySuper = al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN); + + ALLEGRO_MOUSE_STATE mouse; + if (keys.display == g_Display) + { + al_get_mouse_state(&mouse); + io.MousePos = ImVec2((float)mouse.x, (float)mouse.y); + } + else + { + io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); + } + + al_get_mouse_state(&mouse); + io.MouseDown[0] = mouse.buttons & (1 << 0); + io.MouseDown[1] = mouse.buttons & (1 << 1); + io.MouseDown[2] = mouse.buttons & (1 << 2); + + // Hide OS mouse cursor if ImGui is drawing it + if (io.MouseDrawCursor) + { + al_set_mouse_cursor(g_Display, g_MouseCursorInvisible); + } + else + { + ALLEGRO_SYSTEM_MOUSE_CURSOR cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT; + switch (ImGui::GetMouseCursor()) + { + case ImGuiMouseCursor_TextInput: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_EDIT; break; + case ImGuiMouseCursor_Move: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_MOVE; break; + case ImGuiMouseCursor_ResizeNS: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N; break; + case ImGuiMouseCursor_ResizeEW: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E; break; + case ImGuiMouseCursor_ResizeNESW: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE; break; + case ImGuiMouseCursor_ResizeNWSE: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW; break; + } + al_set_system_mouse_cursor(g_Display, cursor_id); + } + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.h b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.h new file mode 100644 index 0000000..b7439fe --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/imgui_impl_a5.h @@ -0,0 +1,22 @@ +// ImGui Allegro 5 bindings +// In this binding, ImTextureID is used to store a 'ALLEGRO_BITMAP*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui +// by @birthggd + +#pragma once + +struct ALLEGRO_DISPLAY; +union ALLEGRO_EVENT; + +IMGUI_API bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display); +IMGUI_API void ImGui_ImplA5_Shutdown(); +IMGUI_API void ImGui_ImplA5_NewFrame(); +IMGUI_API bool ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT* event); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API bool Imgui_ImplA5_CreateDeviceObjects(); +IMGUI_API void ImGui_ImplA5_InvalidateDeviceObjects(); diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/main.cpp new file mode 100644 index 0000000..3c9c977 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/allegro5_example/main.cpp @@ -0,0 +1,116 @@ +// ImGui - standalone example application for Allegro 5 +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include +#include +#include +#include +#include "imgui_impl_a5.h" + +int main(int, char**) +{ + // Setup Allegro + al_init(); + al_install_keyboard(); + al_install_mouse(); + al_init_primitives_addon(); + al_set_new_display_flags(ALLEGRO_RESIZABLE); + ALLEGRO_DISPLAY* display = al_create_display(1280, 720); + al_set_window_title(display, "ImGui Allegro 5 example"); + ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue(); + al_register_event_source(queue, al_get_display_event_source(display)); + al_register_event_source(queue, al_get_keyboard_event_source()); + al_register_event_source(queue, al_get_mouse_event_source()); + + // Setup ImGui binding + ImGui_ImplA5_Init(display); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + bool running = true; + while (running) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + ALLEGRO_EVENT ev; + while (al_get_next_event(queue, &ev)) + { + ImGui_ImplA5_ProcessEvent(&ev); + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) + running = false; + if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) + { + ImGui_ImplA5_InvalidateDeviceObjects(); + al_acknowledge_resize(display); + Imgui_ImplA5_CreateDeviceObjects(); + } + } + ImGui_ImplA5_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); + ImGui::Render(); + al_flip_display(); + } + + // Cleanup + ImGui_ImplA5_Shutdown(); + al_destroy_event_queue(queue); + al_destroy_display(display); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/.gitignore b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/.gitignore new file mode 100644 index 0000000..8feda89 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +imguiex.xcodeproj/project.xcworkspace/ +imguiex.xcodeproj/xcuserdata/ \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/README.md b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/README.md new file mode 100644 index 0000000..339f6bf --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/README.md @@ -0,0 +1,41 @@ +# iOS / OSX example + +## Introduction + +This example is the default XCode "OpenGL" example code, modified to support ImGui and [Synergy](http://synergy-project.org/) to share mouse/keyboard on an iOS device. + +It is a rather complex and messy example because of all of the faff required to get an XCode/iOS application running. Refer to the regular OpenGL examples if you want to learn about integrating ImGui. **The opengl3_example/ should also work on OS X and is much simpler.** This is an integration for iOS with Synergy. + +Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use ImGui without it. Synergy includes a "uSynergy" library that allows embedding a synergy client, this is what is used here. ImGui supports "TouchPadding", and this is enabled when Synergy is not active. + +## How to Use on iOS + +* In Synergy, go to Preferences, and uncheck "Use SSL encryption" +* Run the example app. +* Tap the "servername" button in the corner +* Enter the name or the IP of your synergy host +* If you had previously connected to a server, you may need to kill and re-start the app. + +## How to Build on OSX + +* Make sure you have install `brew`, if not, please refer to [Homebrew Website](http://brew.sh) +* Run the command: `brew install glfw3` +* Double click `imguiex.xcodeproj` and select `imguiex-osx` scheme +* Click `Run` button + +## Notes and TODOs + +Things that would be nice but I didn't get around to doing: + +* iOS software keyboard not supported for text inputs +* iOS hardware (bluetooth) keyboards not supported +* Graceful disconnect/reconnect from uSynergy. +* Copy/Paste not well-supported + +## C++ on iOS / OSX + +ImGui is a c++ library. If you want to include it directly, rename your Obj-C file to have the ".mm" extension. + +Alternatively, you can wrap your debug code in a C interface, this is what I am demonstrating here with the "debug_hud.h" interface. Either approach works, use whatever you prefer. + +In my case, most of my game code is already in C++ so it's not really an issue and I can use ImGui directly. diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.h b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.h new file mode 100644 index 0000000..82f1542 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.h @@ -0,0 +1,13 @@ +// +// AppDelegate.h +// imguiex + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.m b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.m new file mode 100644 index 0000000..ab83101 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/AppDelegate.m @@ -0,0 +1,41 @@ +// +// AppDelegate.m +// imguiex + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/LaunchScreen.xib b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..5717c00 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/LaunchScreen.xib @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/Main.storyboard b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/Main.storyboard new file mode 100644 index 0000000..90dfb2e --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Base.lproj/Main.storyboard @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.h b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.h new file mode 100644 index 0000000..3323cfd --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.h @@ -0,0 +1,12 @@ +// +// GameViewController.h +// imguiex + +// This is the OpenGL Example template from XCode, modified to support ImGui + +#import +#import + +@interface GameViewController : GLKViewController + +@end diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.m b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.m new file mode 100644 index 0000000..e902f7a --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/GameViewController.m @@ -0,0 +1,481 @@ +// +// GameViewController.m +// imguiex +// +#import "GameViewController.h" +#import + +#import "imgui_impl_ios.h" +#import "debug_hud.h" + +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) + +#define SERVERNAME_KEY @"ServerName" + +#define SERVERNAME_ALERT_TAG (10) + +// Uniform index. +enum +{ + UNIFORM_MODELVIEWPROJECTION_MATRIX, + UNIFORM_NORMAL_MATRIX, + UNIFORM_DIFFUSE_COLOR, + + NUM_UNIFORMS +}; +GLint uniforms[NUM_UNIFORMS]; + +// Attribute index. +enum +{ + ATTRIB_VERTEX, + ATTRIB_NORMAL, + NUM_ATTRIBUTES +}; + +GLfloat gCubeVertexData[216] = +{ + // Data layout for each line below is: + // positionX, positionY, positionZ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-0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + + 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f +}; + +@interface GameViewController () +{ + GLuint _program; + + GLKMatrix4 _modelViewProjectionMatrix; + GLKMatrix3 _normalMatrix; + float _rotation; + + GLuint _vertexArray; + GLuint _vertexBuffer; + + DebugHUD _hud; +} +@property (strong, nonatomic) EAGLContext *context; +@property (strong, nonatomic) GLKBaseEffect *effect; +@property (strong, nonatomic) ImGuiHelper *imgui; +@property (weak, nonatomic) IBOutlet UIButton *btnServername; + +@property (strong, nonatomic) NSString *serverName; + +- (IBAction)onServernameTapped:(id)sender; + +- (void)setupGL; +- (void)tearDownGL; + +- (BOOL)loadShaders; +- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file; +- (BOOL)linkProgram:(GLuint)prog; +- (BOOL)validateProgram:(GLuint)prog; +@end + +@implementation GameViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + + if (!self.context) { + NSLog(@"Failed to create ES context"); + } + + GLKView *view = (GLKView *)self.view; + view.context = self.context; + view.drawableDepthFormat = GLKViewDrawableDepthFormat24; + + [self.btnServername setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + + [self setupGL]; + + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + self.serverName = [userDefaults objectForKey: SERVERNAME_KEY ]; + self.imgui = [[ImGuiHelper alloc] initWithView:self.view ]; + if (self.serverName) + { + [self.btnServername setTitle:self.serverName forState:UIControlStateNormal]; + [self.imgui connectServer: self.serverName ]; + } + + DebugHUD_InitDefaults( &_hud ); +} + +- (void)dealloc +{ + [self tearDownGL]; + + if ([EAGLContext currentContext] == self.context) { + [EAGLContext setCurrentContext:nil]; + } +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + + if ([self isViewLoaded] && ([[self view] window] == nil)) { + self.view = nil; + + [self tearDownGL]; + + if ([EAGLContext currentContext] == self.context) { + [EAGLContext setCurrentContext:nil]; + } + self.context = nil; + } + + // Dispose of any resources that can be recreated. +} + + +- (BOOL)prefersStatusBarHidden { + return YES; +} + +- (IBAction)onServernameTapped:(id)sender +{ + UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Set Server" message:@"Enter server name or IP for uSynergy" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil ]; + alert.alertViewStyle = UIAlertViewStylePlainTextInput; + alert.tag = SERVERNAME_ALERT_TAG; // cheezy way to tell which alert view we're responding to + [alert show]; +} + +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex +{ + if ((buttonIndex==0)&&(alertView.tag==SERVERNAME_ALERT_TAG)) + { + // This is really janky. I usually just hardcode the servername since I'm building it anyway. + // If you want to properly handle updating the server, you'll want to tear down and recreate + // the usynergy stuff in connectServer + BOOL serverNameWasSet = self.serverName.length > 0; + NSString *serverName = [[alertView textFieldAtIndex:0] text]; + + if ([serverName length] > 0) { + self.serverName = serverName; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setObject:serverName forKey:SERVERNAME_KEY ]; + [userDefaults synchronize]; + + [self.btnServername setTitle:self.serverName forState:UIControlStateNormal]; + + // If we hadn't previously connected, try now + if (!serverNameWasSet) { + [self.imgui connectServer:self.serverName]; + } + else + { + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Servername Updated" + message:@"Restart the app to connect the server" + delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [alert show]; + } + } + } +} + +- (void)setupGL +{ + [EAGLContext setCurrentContext:self.context]; + + [self loadShaders]; + + self.effect = [[GLKBaseEffect alloc] init]; + self.effect.light0.enabled = GL_TRUE; + self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 1.0f); + + glEnable(GL_DEPTH_TEST); + + glGenVertexArraysOES(1, &_vertexArray); + glBindVertexArrayOES(_vertexArray); + + glGenBuffers(1, &_vertexBuffer); + glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); + + glEnableVertexAttribArray(GLKVertexAttribPosition); + glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); + glEnableVertexAttribArray(GLKVertexAttribNormal); + glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); + + glBindVertexArrayOES(0); + + +} + +- (void)tearDownGL +{ + [EAGLContext setCurrentContext:self.context]; + + glDeleteBuffers(1, &_vertexBuffer); + glDeleteVertexArraysOES(1, &_vertexArray); + + self.effect = nil; + + if (_program) { + glDeleteProgram(_program); + _program = 0; + } +} + +#pragma mark - GLKView and GLKViewController delegate methods + +- (void)update +{ + float aspect = fabs(self.view.bounds.size.width / self.view.bounds.size.height); + GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f); + + self.effect.transform.projectionMatrix = projectionMatrix; + + GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -4.0f); + baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f); + + // Compute the model view matrix for the object rendered with GLKit + GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.5f); + modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f); + modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix); + + self.effect.transform.modelviewMatrix = modelViewMatrix; + + // Compute the model view matrix for the object rendered with ES2 + modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 1.5f); + modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f); + modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix); + + _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL); + + _modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); + + _rotation += self.timeSinceLastUpdate * (_hud.rotation_speed * (M_PI / 180.0)); +} + + +- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect +{ + glClearColor(0.65f, 0.65f, 0.65f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glBindVertexArrayOES(_vertexArray); + + // Render the object with GLKit + [self.effect prepareToDraw]; + + glDrawArrays(GL_TRIANGLES, 0, 36); + + // Render the object again with ES2 + glUseProgram(_program); + + glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m); + glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m); + glUniform3f(uniforms[UNIFORM_DIFFUSE_COLOR], _hud.cubeColor1[0], _hud.cubeColor1[1], _hud.cubeColor1[2] ); + + glDrawArrays(GL_TRIANGLES, 0, 36); + + [self.imgui newFrame]; + + // Now do our ImGUI UI + DebugHUD_DoInterface( &_hud ); + + self.effect.light0.diffuseColor = GLKVector4Make( _hud.cubeColor2[0], _hud.cubeColor2[1], _hud.cubeColor2[2], 1.0f); + + // Now render Imgui + [self.imgui render]; + +} + +#pragma mark - OpenGL ES 2 shader compilation + +- (BOOL)loadShaders +{ + GLuint vertShader, fragShader; + NSString *vertShaderPathname, *fragShaderPathname; + + // Create shader program. + _program = glCreateProgram(); + + // Create and compile vertex shader. + vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"]; + if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname]) { + NSLog(@"Failed to compile vertex shader"); + return NO; + } + + // Create and compile fragment shader. + fragShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"]; + if (![self compileShader:&fragShader type:GL_FRAGMENT_SHADER file:fragShaderPathname]) { + NSLog(@"Failed to compile fragment shader"); + return NO; + } + + // Attach vertex shader to program. + glAttachShader(_program, vertShader); + + // Attach fragment shader to program. + glAttachShader(_program, fragShader); + + // Bind attribute locations. + // This needs to be done prior to linking. + glBindAttribLocation(_program, GLKVertexAttribPosition, "position"); + glBindAttribLocation(_program, GLKVertexAttribNormal, "normal"); + + // Link program. + if (![self linkProgram:_program]) { + NSLog(@"Failed to link program: %d", _program); + + if (vertShader) { + glDeleteShader(vertShader); + vertShader = 0; + } + if (fragShader) { + glDeleteShader(fragShader); + fragShader = 0; + } + if (_program) { + glDeleteProgram(_program); + _program = 0; + } + + return NO; + } + + // Get uniform locations. + uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX] = glGetUniformLocation(_program, "modelViewProjectionMatrix"); + uniforms[UNIFORM_NORMAL_MATRIX] = glGetUniformLocation(_program, "normalMatrix"); + uniforms[UNIFORM_DIFFUSE_COLOR] = glGetUniformLocation(_program, "diffuseColor"); + + // Release vertex and fragment shaders. + if (vertShader) { + glDetachShader(_program, vertShader); + glDeleteShader(vertShader); + } + if (fragShader) { + glDetachShader(_program, fragShader); + glDeleteShader(fragShader); + } + + return YES; +} + +- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file +{ + GLint status; + const GLchar *source; + + source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String]; + if (!source) { + NSLog(@"Failed to load vertex shader"); + return NO; + } + + *shader = glCreateShader(type); + glShaderSource(*shader, 1, &source, NULL); + glCompileShader(*shader); + +#if defined(DEBUG) + GLint logLength; + glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetShaderInfoLog(*shader, logLength, &logLength, log); + NSLog(@"Shader compile log:\n%s", log); + free(log); + } +#endif + + glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + if (status == 0) { + glDeleteShader(*shader); + return NO; + } + + return YES; +} + +- (BOOL)linkProgram:(GLuint)prog +{ + GLint status; + glLinkProgram(prog); + +#if defined(DEBUG) + GLint logLength; + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(prog, logLength, &logLength, log); + NSLog(@"Program link log:\n%s", log); + free(log); + } +#endif + + glGetProgramiv(prog, GL_LINK_STATUS, &status); + if (status == 0) { + return NO; + } + + return YES; +} + +- (BOOL)validateProgram:(GLuint)prog +{ + GLint logLength, status; + + glValidateProgram(prog); + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(prog, logLength, &logLength, log); + NSLog(@"Program validate log:\n%s", log); + free(log); + } + + glGetProgramiv(prog, GL_VALIDATE_STATUS, &status); + if (status == 0) { + return NO; + } + + return YES; +} + +@end diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/Contents.json b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..06b60d8 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,77 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "icon_imgui_60@2x~iphone.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "icon_imgui_60@3x~iphone.png", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "icon_imgui_76~ipad.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "icon_imgui_76@2x~ipad.png", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_60@2x~iphone.png b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_60@2x~iphone.png new file mode 100644 index 0000000000000000000000000000000000000000..d728bc3fe627b885d0c9df2ce95ddd9bc89ee419 GIT binary patch literal 3974 zcmV;14|(v3P)#-701_q?R~1MyQ{|Q3 zR_|`S{MvVD1O@;i9o!OW@p=q=>Dd55Nkn3y8I)7p0L$8;{h8Cx*Xs*WG7xAKs_LAJG2Fa;xu15%T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QCh^44w6NknnQoiEC#ZyH`QQTgc zJ$t3MH#iCe$YHa`Q}aYAFnD8gGZGHe0aIR-ItXpCIqU__^Fg>hy}cmQ@fHAgG_*}E zx6hVW6ciSr^01gJl6nxtegZm>Lq|RZ+=qCqs# gAev~RK{V000Rc@npWJ{1ApigX07*qoM6N<$g2?NtdjJ3c literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_60@3x~iphone.png b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_60@3x~iphone.png new file mode 100644 index 0000000000000000000000000000000000000000..f48b799dba2cf05b31924886eb4fc9d803ea4a83 GIT binary patch literal 5953 zcmY+IbyO5U*Z&s~mXK~(kX*V!I+q0mrE_VJP`W#$L0CGL7U`7k5Trv8SxP}*k?!u- z=Q;0r&+qrg+_`7YoSE;P`#Dpwn(E5IX1b9acHVLf|;1`5Ce<3HOTNdq-6m0#X-tG_jZ zCXx1+H@A5Eh_t1$Snf`Sa#+jbR*MW=oQ%ePzPMemdpGE{`ukxHC@`MH8o^yN@$!hL zxIJpKDO#U^f%ElC`W*Yf{FvD$rs<9?i9vKf5?Kltb0IMJ6l)WBbSq1}KgvHK?SA}G zCpGaSQw4Pz{hoXnwv{9I;?~GooqZjXGY51~nLrgIS3oJs_@*^zwb7edUegYg?Qd1& z_ASfz&isotGH+^k;vPB^7Zb;=5?ekS8*)ByL?7_i&4EtHDN8XAdH>NoU*_WWCONsI zxn+wii}(fAor!gzoh|lTM<$W6uN7<*6tWCIiqw+bsjOEJkH-Og(q%1uOR%lgBhxzl zp!por(8eC~oNTe(+(kES1}GEq!wf_)(g^QRuq>F2DZ1I)x9xIhwXQ4RaKkP?4DIALW)Wy!;({s>d?>FPImuiN zzFeS8v$EYaj_}W)cUBIO@TxVdJFgNCo$KHvFY$;XJ6ICZse&W-fMFIKc=Ur4`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zKtQ}5CQ5^_(9#mPpl`Tk(t#u1o?3iFIj{%h0Fib@Zh9f` zHM8T0+Vdz*>`$W831QS_k%v&LxKkMu+%PG0Qj$~T4%)$UbNcYgx~A2~UaQ#=W!W{! z=pMgKQj_<_=2p_HVtE;Dtt1fai}f#-z}pn<3jR+;w%$^CLCBGe66{p|9k_C2p%r-n z*OBrxH)o05gU|$cFe}pRpmjfFU4eMQv6xQVmG1N@R7?)UKtKeH!T5%@4sZkf*Z%*F aW)oPOXB1N~w0~dYfLBm;#aac6u>S!7Vo}-v literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_76@2x~ipad.png b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_76@2x~ipad.png new file mode 100644 index 0000000000000000000000000000000000000000..67b08b84c6c5ceb4982bd6f278c46138b73c20b8 GIT binary patch literal 4959 zcmV-l6QJygP)0ssI2m!P+H000vvNklF8rH#l-*!w1?iM_u>P^Q!ES+sYphofOF0RP$kt6!bdMMSV<4FNCP4nz}3m) z`A4N(^S%Tyk>(b=X{*)R-feECX^Yttfri!@rA8Vep;kR{;`phF$`lbuRf|u6h>$~s zEbDC7S2wqof@BOwqz539nd#$E5vB1%Rp(|td;HiVcXRn)f7C;jh`|ik?(D9tUCUR; zUP(tPQbb#=4iWlR2V%y=L}?5)F3dkQJvA3XN_(Kca_3wKVR7YZtF=>XvpNcqAPS<@ z$?`MLd`9n|HZ4@P+TF`nZUGppx;Q^~I?rMj(tVywm6YLf>mM#%PSZBPaSuB^LyUGO z{qA?3fArK0_2rkp{>O#4u1!x*h9F~NajG_Z?4grkpB4*15DDIwAD(@Darx@#POaYY z)^_tJKmEfGU-)(i;eU&zsuEGBo4s`AT$1>)DU<4)pE>@hs?sL}K#(*)+}5hI_1!h* zgh-={3_+%9mA{;O=e-*%Pn=#5QD)rx4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*8z!=-}U6==H}*~!ziq2{H9Q6(hf5v5#pc)0AOFN z%q;0o-GAZu^*-G&C5SWoq`uCmnoEZ|G9IAIRh=$>D)XB1_o-u)^Zf@ zS5)FseEU+Ul^(IHsYwSzLt&7q++twK@tSo>A;qeWqGJ8UdNK9A>T;Bf$hpx}=oyq^ z-=llCNls3Q>yu=RY(%0KGd$L~a;;FH)|XYaG6$ej6b9n|YwwP65QL!s41;PZhBJ7gPj@#Y~FOC2J002ovPDHLkV1i~^jllo_ literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_76~ipad.png b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Images.xcassets/AppIcon.appiconset/icon_imgui_76~ipad.png new file mode 100644 index 0000000000000000000000000000000000000000..ae88e04d9c50882bb5636c6514ef03ba7214e3d4 GIT binary patch literal 2576 zcmV+r3h(uaP)5w)ZN`N+nG%XDQ%wY`F2R5=~-FkYv{p;I0kiXvavdK5I0q zojtzae&2rIYW2*G9`{N{iU^m%5lSePDOEml9M22!>I~X3fY{NX5RAZt#z&)Zxowa# zk#stv$=D6=l#*yP7z{NL661ML&|857O*kTPty+tMDDt<36I71uUUqw~DCnUTTk%LV zSbx1T5NPa}^TzH9LY+?hO0FYeIDo;d9#6pS@ryzyb8;|OPPg6;doLIhYz&9v@Dfm{ zsXOcQH!w~OkPulW8`qT;$kLU6SNfNs1@ zVwbP}BNmgGo^6G{VXYwWp>TB9J4cue0gS@&6BkbYv#K)*6QLp7dPkh+#zrQhV6a+p zD3!SkEs&tfvY3t>JA1aGId`Rn1aRI9rt!mQsP zLIg4xbhqiSgCrpaLtZ3(WI~o06;!IIC(5#1TYnB|rUMpLXIE@|0>axWgvePIr_+9y zUT=cyvKqiQxT_+Oz)ep)%QI3$WFiZ^U@(|WbQONBMIcK#Q4uV-{DCE{I;EIhRY;4Vgq)LdhC~Wc z1IcVoMN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Zo_7KwoOt-W02+h4 z!I$i|Y|Mpn;;c?6!Cr07!@81Q`OK^#(m5 zHyDJ*F?j@Gug?#SR6#OM3`g5JENT!6Bej1|t!Dg0zm6aFq?A`g+b_)`Tq3397N2)b mUu3D2G-Mhw4Vi{aL;f4Eji$yBE*?7o0000`q-%e literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Info.plist b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Info.plist new file mode 100644 index 0000000..bc6f548 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Info.plist @@ -0,0 +1,49 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + org.imgui.example.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.fsh b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.fsh new file mode 100644 index 0000000..4000524 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.fsh @@ -0,0 +1,10 @@ +// +// Shader.fsh +// imguiex + +varying lowp vec4 colorVarying; + +void main() +{ + gl_FragColor = colorVarying; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.vsh b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.vsh new file mode 100644 index 0000000..313c3d7 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/Shaders/Shader.vsh @@ -0,0 +1,25 @@ +// +// Shader.vsh +// imguiex + +attribute vec4 position; +attribute vec3 normal; + +varying lowp vec4 colorVarying; + +uniform vec3 diffuseColor; +uniform mat4 modelViewProjectionMatrix; +uniform mat3 normalMatrix; + +void main() +{ + vec3 eyeNormal = normalize(normalMatrix * normal); + vec3 lightPosition = vec3(0.0, 0.0, 1.0); + + float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition))); + + vec3 colorLit = diffuseColor * nDotVP; + colorVarying = vec4( colorLit.x, colorLit.y, colorLit.z, 1.0 ); + + gl_Position = modelViewProjectionMatrix * position; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.cpp new file mode 100644 index 0000000..c81f273 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.cpp @@ -0,0 +1,44 @@ +// +// debug_hud.cpp +// imguiex + +#include + +#include "debug_hud.h" +#include "imgui.h" + +void DebugHUD_InitDefaults( DebugHUD *hud ) +{ + hud->show_demo_window = true; + hud->show_example_window = true; + hud->rotation_speed = 15.0f; + + hud->cubeColor1[0] = 0.4f; + hud->cubeColor1[1] = 0.4f; + hud->cubeColor1[2] = 1.0f; + hud->cubeColor1[3] = 1.0f; + + hud->cubeColor2[0] = 1.0f; + hud->cubeColor2[1] = 0.4f; + hud->cubeColor2[2] = 0.4f; + hud->cubeColor2[3] = 1.0f; +} + +void DebugHUD_DoInterface(DebugHUD *hud) +{ + if (hud->show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&hud->show_demo_window ); + } + + if (hud->show_example_window) + { + ImGui::Begin("Another Window", &hud->show_example_window); + ImGui::Text("Hello from another window!"); + ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1); + ImGui::ColorEdit3("Cube 2 Color", hud->cubeColor2); + ImGui::SliderFloat("Rotation Speed", &hud->rotation_speed, 0.0f, 200.0f); + ImGui::End(); + } +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.h b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.h new file mode 100644 index 0000000..601376c --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/debug_hud.h @@ -0,0 +1,25 @@ +// +// debug_hud.h +// imguiex + +#pragma once + +typedef struct DebugHUD +{ + bool show_demo_window; + bool show_example_window; + float rotation_speed; + float cubeColor1[4]; + float cubeColor2[4]; +} DebugHUD; + +#if __cplusplus +extern "C" { +#endif + +void DebugHUD_InitDefaults( DebugHUD *hud ); +void DebugHUD_DoInterface( DebugHUD *hud ); + +#if __cplusplus +} +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_ex_icon.png b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_ex_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..820e4d73e3bdb406ce26f87d09a0a38018e3bbf4 GIT binary patch literal 12653 zcmch7bx>SS*XA7<+zEl;B)Ge~dw>LjGe8JIf)1{O6P(~K!94^>aCdiihu{``=lAaZ zu~qwiTi@1OwYTb4ceUI;_vzDpo<4oPs=t-TLMK57002u-LFOF*Ai%Q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4>pe4THBa%A_ri3#J2&C*u? zzz>-a{{Ry=BBGTt8(@s~=VBlhZa*cRdy4jQp$|KP4QQ25Mw(0|g$@DXb;Ti{9jFDr zj!d`vCS-fK`^V38?Sms}ll-V*b^TOOOsW1XTdsP>I6s2jLEq3%JM2L@EG_DjPHrYGonDgI}c|J}eUiHfZqL)+hS*$}_~7 zhny^Qv3=^(OF@~Pp&EAFQH?H8ZJkxiCW7y@m%NQ7vP48rh5B2qkKt^=hP}TtseE}< zQYHiEZAM!jXCO)AWXw*0jNKTD>cx4_X()yrC|rU`V5Yb&Iq%zrSaJ0E04n*KGJ!Vamhyca0i=eD%l-FmVm$O3 zv*xJK_-aL@5y}@L#B40DS{y_0(uldu)sH2xe>)t`>~V?1LrH+BYxw1~d;~?K$>5Cj ztld!R;XRx~YznuYth5R{oD;m)GSQ(~D!32^ElUi#1QufKWReBZUj<+DJ4n6XdzY;F zJy)j{Ign45fBn#RvC%g%*pCC&X<6!1g8djMJ2t_#u{9xuhq1w8wnt;3Lf*~x)Y+c< z3gzl(Yb{S*I&OFV9O)Rv^~UI%6&Fes$+oSx&g1j5iooFK!AL3}%+RjAeG-)+zBC7@ zt04E)V_fz9kx}JBsW_q12U5eCjmLG=sbMdl)Pf8bVX-Wt@Z*u=<<5^_mUd!5{kF8U z^UUPTs4Lc)?4XMh`=I&`1CVHn5fBt3{&V!%-IlV}2m}}yl2fWq>|eT;ijM#W1OZke zW;LIdw1KBW>_07A@g#WzPFzSY?T0~H8q`|pQc{U`BR@Q|_pu=^ +#include + +@interface ImGuiHelper : NSObject + +- (id) initWithView: (UIView *)view; + +- (void)connectServer: (NSString*)serverName; + +- (void)render; +- (void)newFrame; + +@end diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_impl_ios.mm b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_impl_ios.mm new file mode 100644 index 0000000..bfcae7c --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/imgui_impl_ios.mm @@ -0,0 +1,807 @@ +// ImGui iOS+OpenGL+Synergy binding +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// Providing a standalone iOS application with Synergy integration makes this sample more verbose than others. It also hasn't been tested as much. +// Refer to other examples to get an easier understanding of how to integrate ImGui into your existing application. + +// TODO: +// - Clipboard is not supported. + +#import +#import + +#include +#include +#include +#include + +#include "imgui_impl_ios.h" +#include "imgui.h" + +#include "uSynergy.h" + +// From Carbon HIToolbox/Events.h +// FIXME: Keyboard mapping is hacked in because Synergy doesn't give us character but only keycode which aren't really portable if you consider keyboard locale. See https://github.com/ocornut/imgui/pull/247 +enum { + kVK_ANSI_A = 0x00, + kVK_ANSI_S = 0x01, + kVK_ANSI_D = 0x02, + kVK_ANSI_F = 0x03, + kVK_ANSI_H = 0x04, + kVK_ANSI_G = 0x05, + kVK_ANSI_Z = 0x06, + kVK_ANSI_X = 0x07, + kVK_ANSI_C = 0x08, + kVK_ANSI_V = 0x09, + kVK_ANSI_B = 0x0B, + kVK_ANSI_Q = 0x0C, + kVK_ANSI_W = 0x0D, + kVK_ANSI_E = 0x0E, + kVK_ANSI_R = 0x0F, + kVK_ANSI_Y = 0x10, + kVK_ANSI_T = 0x11, + kVK_ANSI_1 = 0x12, + kVK_ANSI_2 = 0x13, + kVK_ANSI_3 = 0x14, + kVK_ANSI_4 = 0x15, + kVK_ANSI_6 = 0x16, + kVK_ANSI_5 = 0x17, + kVK_ANSI_Equal = 0x18, + kVK_ANSI_9 = 0x19, + kVK_ANSI_7 = 0x1A, + kVK_ANSI_Minus = 0x1B, + kVK_ANSI_8 = 0x1C, + kVK_ANSI_0 = 0x1D, + kVK_ANSI_RightBracket = 0x1E, + kVK_ANSI_O = 0x1F, + kVK_ANSI_U = 0x20, + kVK_ANSI_LeftBracket = 0x21, + kVK_ANSI_I = 0x22, + kVK_ANSI_P = 0x23, + kVK_ANSI_L = 0x25, + kVK_ANSI_J = 0x26, + kVK_ANSI_Quote = 0x27, + kVK_ANSI_K = 0x28, + kVK_ANSI_Semicolon = 0x29, + kVK_ANSI_Backslash = 0x2A, + kVK_ANSI_Comma = 0x2B, + kVK_ANSI_Slash = 0x2C, + kVK_ANSI_N = 0x2D, + kVK_ANSI_M = 0x2E, + kVK_ANSI_Period = 0x2F, + kVK_ANSI_Grave = 0x32, + kVK_ANSI_KeypadDecimal = 0x41, + kVK_ANSI_KeypadMultiply = 0x43, + kVK_ANSI_KeypadPlus = 0x45, + kVK_ANSI_KeypadClear = 0x47, + kVK_ANSI_KeypadDivide = 0x4B, + kVK_ANSI_KeypadEnter = 0x4C, + kVK_ANSI_KeypadMinus = 0x4E, + kVK_ANSI_KeypadEquals = 0x51, + kVK_ANSI_Keypad0 = 0x52, + kVK_ANSI_Keypad1 = 0x53, + kVK_ANSI_Keypad2 = 0x54, + kVK_ANSI_Keypad3 = 0x55, + kVK_ANSI_Keypad4 = 0x56, + kVK_ANSI_Keypad5 = 0x57, + kVK_ANSI_Keypad6 = 0x58, + kVK_ANSI_Keypad7 = 0x59, + kVK_ANSI_Keypad8 = 0x5B, + kVK_ANSI_Keypad9 = 0x5C +}; + +/* keycodes for keys that are independent of keyboard layout*/ +enum { + kVK_Return = 0x24, + kVK_Tab = 0x30, + kVK_Space = 0x31, + kVK_Delete = 0x33, + kVK_Escape = 0x35, + kVK_Command = 0x37, + kVK_Shift = 0x38, + kVK_CapsLock = 0x39, + kVK_Option = 0x3A, + kVK_Control = 0x3B, + kVK_RightShift = 0x3C, + kVK_RightOption = 0x3D, + kVK_RightControl = 0x3E, + kVK_Function = 0x3F, + kVK_F17 = 0x40, + kVK_VolumeUp = 0x48, + kVK_VolumeDown = 0x49, + kVK_Mute = 0x4A, + kVK_F18 = 0x4F, + kVK_F19 = 0x50, + kVK_F20 = 0x5A, + kVK_F5 = 0x60, + kVK_F6 = 0x61, + kVK_F7 = 0x62, + kVK_F3 = 0x63, + kVK_F8 = 0x64, + kVK_F9 = 0x65, + kVK_F11 = 0x67, + kVK_F13 = 0x69, + kVK_F16 = 0x6A, + kVK_F14 = 0x6B, + kVK_F10 = 0x6D, + kVK_F12 = 0x6F, + kVK_F15 = 0x71, + kVK_Help = 0x72, + kVK_Home = 0x73, + kVK_PageUp = 0x74, + kVK_ForwardDelete = 0x75, + kVK_F4 = 0x76, + kVK_End = 0x77, + kVK_F2 = 0x78, + kVK_PageDown = 0x79, + kVK_F1 = 0x7A, + kVK_LeftArrow = 0x7B, + kVK_RightArrow = 0x7C, + kVK_DownArrow = 0x7D, + kVK_UpArrow = 0x7E +}; + +static char g_keycodeCharUnshifted[256] = {}; +static char g_keycodeCharShifted[256] = {}; + +//static double g_Time = 0.0f; +static bool g_MousePressed[3] = { false, false, false }; +static float g_mouseWheelX = 0.0f; +static float g_mouseWheelY = 0.0f; + +static GLuint g_FontTexture = 0; +static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; +static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; +static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0; +static size_t g_VboSize = 0; +static unsigned int g_VboHandle = 0, g_VaoHandle = 0; +static float g_displayScale; + +static int usynergy_sockfd; +static bool g_synergyPtrActive = false; +static uint16_t g_mousePosX = 0; +static uint16_t g_mousePosY = 0; + +static void ImGui_ImplIOS_RenderDrawLists (ImDrawData *draw_data); +bool ImGui_ImplIOS_CreateDeviceObjects(); + +static NSString *g_serverName; + +uSynergyBool ImGui_ConnectFunc(uSynergyCookie cookie) +{ + // NOTE: You need to turn off "Use SSL Encryption" in Synergy preferences, since + // uSynergy does not support SSL. + + NSLog( @"Connect Func!"); + struct addrinfo hints, *res; + + // first, load up address structs with getaddrinfo(): + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever + hints.ai_socktype = SOCK_STREAM; + + // get server address + getaddrinfo([g_serverName UTF8String], "24800", &hints, &res); + + if (!res) + { + NSLog( @"Could not find server: %@", g_serverName ); + return USYNERGY_FALSE; + } + + // make a socket: + usynergy_sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + + // connect it to the address and port we passed in to getaddrinfo(): + int ret = connect(usynergy_sockfd, res->ai_addr, res->ai_addrlen); + if (!ret) { + NSLog( @"Connect succeeded..."); + } else { + NSLog( @"Connect failed, %d", ret ); + } + + + return USYNERGY_TRUE; +} + +uSynergyBool ImGui_SendFunc(uSynergyCookie cookie, const uint8_t *buffer, int length) +{ +// NSLog( @"Send Func" ); + send( usynergy_sockfd, buffer, length, 0 ); + + return USYNERGY_TRUE; +} + +uSynergyBool ImGui_RecvFunc(uSynergyCookie cookie, uint8_t *buffer, int maxLength, int* outLength) +{ + *outLength = (int)recv( usynergy_sockfd, buffer, maxLength, 0 ); + + return USYNERGY_TRUE; +} + +void ImGui_SleepFunc(uSynergyCookie cookie, int timeMs) +{ + usleep( timeMs * 1000 ); +} + +uint32_t ImGui_GetTimeFunc() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + + return (int32_t)((tv.tv_sec) * 1000 + (tv.tv_usec) / 1000); +} + +void ImGui_TraceFunc(uSynergyCookie cookie, const char *text) +{ + puts(text); +} + +void ImGui_ScreenActiveCallback(uSynergyCookie cookie, uSynergyBool active) +{ + g_synergyPtrActive = active; +// printf( "Synergy: screen activate %s\n", active?"YES":"NO" ); +} + +void ImGui_MouseCallback(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_t wheelX, int16_t wheelY, + uSynergyBool buttonLeft, uSynergyBool buttonRight, uSynergyBool buttonMiddle) +{ +// printf("Synergy: mouse callback %d %d -- wheel %d %d\n", x, y, wheelX, wheelY ); + uSynergyContext *ctx = (uSynergyContext*)cookie; + g_mousePosX = x; + g_mousePosY = y; + g_mouseWheelX = wheelX; + g_mouseWheelY = wheelY; + g_MousePressed[0] = buttonLeft; + g_MousePressed[1] = buttonMiddle; + g_MousePressed[2] = buttonRight; + + ctx->m_mouseWheelX = 0; + ctx->m_mouseWheelY = 0; +} + +void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key, + uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) +{ + int scanCode = key-1; +// printf("Synergy: keyboard callback: 0x%02X (%s)", scanCode, down?"true":"false"); + ImGuiIO& io = ImGui::GetIO(); + io.KeysDown[key] = down; + io.KeyShift = (modifiers & USYNERGY_MODIFIER_SHIFT); + io.KeyCtrl = (modifiers & USYNERGY_MODIFIER_CTRL); + io.KeyAlt = (modifiers & USYNERGY_MODIFIER_ALT); + io.KeySuper = (modifiers & USYNERGY_MODIFIER_WIN); + + // Add this as keyboard input + if ((down) && (key) && (scanCode<256) && !(modifiers & USYNERGY_MODIFIER_CTRL)) + { + // If this key maps to a character input, apply it + int charForKeycode = (modifiers & USYNERGY_MODIFIER_SHIFT) ? g_keycodeCharShifted[scanCode] : g_keycodeCharUnshifted[scanCode]; + io.AddInputCharacter((unsigned short)charForKeycode); + } + +} + +void ImGui_JoystickCallback(uSynergyCookie cookie, uint8_t joyNum, uint16_t buttons, int8_t leftStickX, int8_t leftStickY, int8_t rightStickX, int8_t rightStickY) +{ + printf("Synergy: joystick callback TODO\n"); +} + +void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat format, const uint8_t *data, uint32_t size) +{ + printf("Synergy: clipboard callback TODO\n" ); +} + +@interface ImGuiHelper () +{ + BOOL _mouseDown; + BOOL _mouseTapped; + CGPoint _touchPos; + + uSynergyContext _synergyCtx; + dispatch_queue_t _synergyQueue; +} +@property (nonatomic, weak) UIView *view; +@property (nonatomic, strong) NSString *serverName; + +@end + +@implementation ImGuiHelper + +- (id) initWithView: (UIView *)view +{ + self = [super init]; + if (self) + { + self.view = view; + + [self setupImGuiHooks]; + } + return self; +} + +- (void)setupKeymaps +{ + // The keyboard mapping is a big headache. I tried for a while to find a better way to do this, + // but this was the best I could come up with. There are some device independent API's available + // to convert scan codes to unicode characters, but these are only available on mac and not + // on iOS as far as I can tell (it's part of Carbon). I didn't see any better way to do + // this or any way to get the character codes out of usynergy. + g_keycodeCharUnshifted[ kVK_ANSI_A ]='a'; + g_keycodeCharUnshifted[ kVK_ANSI_S ]='s'; + g_keycodeCharUnshifted[ kVK_ANSI_D ]='d'; + g_keycodeCharUnshifted[ kVK_ANSI_F ]='f'; + g_keycodeCharUnshifted[ kVK_ANSI_H ]='h'; + g_keycodeCharUnshifted[ kVK_ANSI_G ]='g'; + g_keycodeCharUnshifted[ kVK_ANSI_Z ]='z'; + g_keycodeCharUnshifted[ kVK_ANSI_X ]='x'; + g_keycodeCharUnshifted[ kVK_ANSI_C ]='c'; + g_keycodeCharUnshifted[ kVK_ANSI_V ]='v'; + g_keycodeCharUnshifted[ kVK_ANSI_B ]='b'; + g_keycodeCharUnshifted[ kVK_ANSI_Q ]='q'; + g_keycodeCharUnshifted[ kVK_ANSI_W ]='w'; + g_keycodeCharUnshifted[ kVK_ANSI_E ]='e'; + g_keycodeCharUnshifted[ kVK_ANSI_R ]='r'; + g_keycodeCharUnshifted[ kVK_ANSI_Y ]='y'; + g_keycodeCharUnshifted[ kVK_ANSI_T ]='t'; + g_keycodeCharUnshifted[ kVK_ANSI_1 ]='1'; + g_keycodeCharUnshifted[ kVK_ANSI_2 ]='2'; + g_keycodeCharUnshifted[ kVK_ANSI_3 ]='3'; + g_keycodeCharUnshifted[ kVK_ANSI_4 ]='4'; + g_keycodeCharUnshifted[ kVK_ANSI_6 ]='6'; + g_keycodeCharUnshifted[ kVK_ANSI_5 ]='5'; + g_keycodeCharUnshifted[ kVK_ANSI_Equal ]='='; + g_keycodeCharUnshifted[ kVK_ANSI_9 ]='9'; + g_keycodeCharUnshifted[ kVK_ANSI_7 ]='7'; + g_keycodeCharUnshifted[ kVK_ANSI_Minus ]='-'; + g_keycodeCharUnshifted[ kVK_ANSI_8 ]='8'; + g_keycodeCharUnshifted[ kVK_ANSI_0 ]='0'; + g_keycodeCharUnshifted[ kVK_ANSI_RightBracket ]=']'; + g_keycodeCharUnshifted[ kVK_ANSI_O ]='o'; + g_keycodeCharUnshifted[ kVK_ANSI_U ]='u'; + g_keycodeCharUnshifted[ kVK_ANSI_LeftBracket ]='['; + g_keycodeCharUnshifted[ kVK_ANSI_I ]='i'; + g_keycodeCharUnshifted[ kVK_ANSI_P ]='p'; + g_keycodeCharUnshifted[ kVK_ANSI_L ]='l'; + g_keycodeCharUnshifted[ kVK_ANSI_J ]='j'; + g_keycodeCharUnshifted[ kVK_ANSI_Quote ]='\''; + g_keycodeCharUnshifted[ kVK_ANSI_K ]='k'; + g_keycodeCharUnshifted[ kVK_ANSI_Semicolon ]=';'; + g_keycodeCharUnshifted[ kVK_ANSI_Backslash ]='\\'; + g_keycodeCharUnshifted[ kVK_ANSI_Comma ]=','; + g_keycodeCharUnshifted[ kVK_ANSI_Slash ]='/'; + g_keycodeCharUnshifted[ kVK_ANSI_N ]='n'; + g_keycodeCharUnshifted[ kVK_ANSI_M ]='m'; + g_keycodeCharUnshifted[ kVK_ANSI_Period ]='.'; + g_keycodeCharUnshifted[ kVK_ANSI_Grave ]='`'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadDecimal ]='.'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadMultiply ]='*'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadPlus ]='+'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadDivide ]='/'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadEnter ]='\n'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadMinus ]='-'; + g_keycodeCharUnshifted[ kVK_ANSI_KeypadEquals ]='='; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad0 ]='0'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad1 ]='1'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad2 ]='2'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad3 ]='3'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad4 ]='4'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad5 ]='5'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad6 ]='6'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad7 ]='7'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad8 ]='8'; + g_keycodeCharUnshifted[ kVK_ANSI_Keypad9 ]='9'; + g_keycodeCharUnshifted[ kVK_Space ]=' '; + + g_keycodeCharShifted[ kVK_ANSI_A ]='A'; + g_keycodeCharShifted[ kVK_ANSI_S ]='S'; + g_keycodeCharShifted[ kVK_ANSI_D ]='D'; + g_keycodeCharShifted[ kVK_ANSI_F ]='F'; + g_keycodeCharShifted[ kVK_ANSI_H ]='H'; + g_keycodeCharShifted[ kVK_ANSI_G ]='G'; + g_keycodeCharShifted[ kVK_ANSI_Z ]='Z'; + g_keycodeCharShifted[ kVK_ANSI_X ]='X'; + g_keycodeCharShifted[ kVK_ANSI_C ]='C'; + g_keycodeCharShifted[ kVK_ANSI_V ]='V'; + g_keycodeCharShifted[ kVK_ANSI_B ]='B'; + g_keycodeCharShifted[ kVK_ANSI_Q ]='Q'; + g_keycodeCharShifted[ kVK_ANSI_W ]='W'; + g_keycodeCharShifted[ kVK_ANSI_E ]='E'; + g_keycodeCharShifted[ kVK_ANSI_R ]='R'; + g_keycodeCharShifted[ kVK_ANSI_Y ]='Y'; + g_keycodeCharShifted[ kVK_ANSI_T ]='T'; + g_keycodeCharShifted[ kVK_ANSI_1 ]='!'; + g_keycodeCharShifted[ kVK_ANSI_2 ]='@'; + g_keycodeCharShifted[ kVK_ANSI_3 ]='#'; + g_keycodeCharShifted[ kVK_ANSI_4 ]='$'; + g_keycodeCharShifted[ kVK_ANSI_6 ]='^'; + g_keycodeCharShifted[ kVK_ANSI_5 ]='%'; + g_keycodeCharShifted[ kVK_ANSI_Equal ]='+'; + g_keycodeCharShifted[ kVK_ANSI_9 ]='('; + g_keycodeCharShifted[ kVK_ANSI_7 ]='&'; + g_keycodeCharShifted[ kVK_ANSI_Minus ]='_'; + g_keycodeCharShifted[ kVK_ANSI_8 ]='*'; + g_keycodeCharShifted[ kVK_ANSI_0 ]=')'; + g_keycodeCharShifted[ kVK_ANSI_RightBracket ]='}'; + g_keycodeCharShifted[ kVK_ANSI_O ]='O'; + g_keycodeCharShifted[ kVK_ANSI_U ]='U'; + g_keycodeCharShifted[ kVK_ANSI_LeftBracket ]='{'; + g_keycodeCharShifted[ kVK_ANSI_I ]='I'; + g_keycodeCharShifted[ kVK_ANSI_P ]='P'; + g_keycodeCharShifted[ kVK_ANSI_L ]='L'; + g_keycodeCharShifted[ kVK_ANSI_J ]='J'; + g_keycodeCharShifted[ kVK_ANSI_Quote ]='\"'; + g_keycodeCharShifted[ kVK_ANSI_K ]='K'; + g_keycodeCharShifted[ kVK_ANSI_Semicolon ]=':'; + g_keycodeCharShifted[ kVK_ANSI_Backslash ]='|'; + g_keycodeCharShifted[ kVK_ANSI_Comma ]='<'; + g_keycodeCharShifted[ kVK_ANSI_Slash ]='?'; + g_keycodeCharShifted[ kVK_ANSI_N ]='N'; + g_keycodeCharShifted[ kVK_ANSI_M ]='M'; + g_keycodeCharShifted[ kVK_ANSI_Period ]='>'; + g_keycodeCharShifted[ kVK_ANSI_Grave ]='~'; + g_keycodeCharShifted[ kVK_ANSI_KeypadDecimal ]='.'; + g_keycodeCharShifted[ kVK_ANSI_KeypadMultiply ]='*'; + g_keycodeCharShifted[ kVK_ANSI_KeypadPlus ]='+'; + g_keycodeCharShifted[ kVK_ANSI_KeypadDivide ]='/'; + g_keycodeCharShifted[ kVK_ANSI_KeypadEnter ]='\n'; + g_keycodeCharShifted[ kVK_ANSI_KeypadMinus ]='-'; + g_keycodeCharShifted[ kVK_ANSI_KeypadEquals ]='='; + g_keycodeCharShifted[ kVK_ANSI_Keypad0 ]='0'; + g_keycodeCharShifted[ kVK_ANSI_Keypad1 ]='1'; + g_keycodeCharShifted[ kVK_ANSI_Keypad2 ]='2'; + g_keycodeCharShifted[ kVK_ANSI_Keypad3 ]='3'; + g_keycodeCharShifted[ kVK_ANSI_Keypad4 ]='4'; + g_keycodeCharShifted[ kVK_ANSI_Keypad5 ]='5'; + g_keycodeCharShifted[ kVK_ANSI_Keypad6 ]='6'; + g_keycodeCharShifted[ kVK_ANSI_Keypad7 ]='7'; + g_keycodeCharShifted[ kVK_ANSI_Keypad8 ]='8'; + g_keycodeCharShifted[ kVK_ANSI_Keypad9 ]='9'; + g_keycodeCharShifted[ kVK_Space ]=' '; +} + +- (void)setupImGuiHooks +{ + ImGuiIO &io = ImGui::GetIO(); + + [self setupKeymaps]; + + // Account for retina display for glScissor + g_displayScale = [[UIScreen mainScreen] scale]; + + ImGuiStyle &style = ImGui::GetStyle(); + style.TouchExtraPadding = ImVec2( 4.0, 4.0 ); + + io.RenderDrawListsFn = ImGui_ImplIOS_RenderDrawLists; + + UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(viewDidPan:) ]; + [self.view addGestureRecognizer:panRecognizer]; + + UITapGestureRecognizer *tapRecoginzer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector( viewDidTap:)]; + [self.view addGestureRecognizer:tapRecoginzer]; + + // Fill out the Synergy key map + // (for some reason synergy scan codes are off by 1) + io.KeyMap[ImGuiKey_Tab] = kVK_Tab+1; + io.KeyMap[ImGuiKey_LeftArrow] = kVK_LeftArrow+1; + io.KeyMap[ImGuiKey_RightArrow] = kVK_RightArrow+1; + io.KeyMap[ImGuiKey_UpArrow] = kVK_UpArrow+1; + io.KeyMap[ImGuiKey_DownArrow] = kVK_DownArrow+1; + io.KeyMap[ImGuiKey_Home] = kVK_Home+1; + io.KeyMap[ImGuiKey_End] = kVK_End+1; + io.KeyMap[ImGuiKey_Delete] = kVK_ForwardDelete+1; + io.KeyMap[ImGuiKey_Backspace] = kVK_Delete+1; + io.KeyMap[ImGuiKey_Enter] = kVK_Return+1; + io.KeyMap[ImGuiKey_Escape] = kVK_Escape+1; + io.KeyMap[ImGuiKey_A] = kVK_ANSI_A+1; + io.KeyMap[ImGuiKey_C] = kVK_ANSI_C+1; + io.KeyMap[ImGuiKey_V] = kVK_ANSI_V+1; + io.KeyMap[ImGuiKey_X] = kVK_ANSI_X+1; + io.KeyMap[ImGuiKey_Y] = kVK_ANSI_Y+1; + io.KeyMap[ImGuiKey_Z] = kVK_ANSI_Z+1; +} + +- (void)connectServer: (NSString*)serverName +{ + self.serverName = serverName; + g_serverName = serverName; + + // Init synergy + NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey]; + + uSynergyInit( &_synergyCtx ); + _synergyCtx.m_clientName = strdup( [bundleName UTF8String] ); + _synergyCtx.m_clientWidth = self.view.bounds.size.width; + _synergyCtx.m_clientHeight = self.view.bounds.size.height; + + _synergyCtx.m_connectFunc = ImGui_ConnectFunc; + _synergyCtx.m_sendFunc = ImGui_SendFunc; + _synergyCtx.m_receiveFunc = ImGui_RecvFunc; + _synergyCtx.m_sleepFunc = ImGui_SleepFunc; + _synergyCtx.m_traceFunc = ImGui_TraceFunc; + _synergyCtx.m_getTimeFunc = ImGui_GetTimeFunc; + + _synergyCtx.m_traceFunc = ImGui_TraceFunc; + _synergyCtx.m_screenActiveCallback = ImGui_ScreenActiveCallback; + _synergyCtx.m_mouseCallback = ImGui_MouseCallback; + _synergyCtx.m_keyboardCallback = ImGui_KeyboardCallback; + + _synergyCtx.m_cookie = (uSynergyCookie)&_synergyCtx; + + // Create a background thread for synergy + _synergyQueue = dispatch_queue_create( "imgui-usynergy", NULL ); + dispatch_async( _synergyQueue, ^{ + while (1) { + uSynergyUpdate( &_synergyCtx ); + } + }); +} + + +- (void)viewDidPan: (UIPanGestureRecognizer *)recognizer +{ + + if ((recognizer.state == UIGestureRecognizerStateBegan) || + (recognizer.state == UIGestureRecognizerStateChanged)) + { + _mouseDown = YES; + _touchPos = [recognizer locationInView:self.view]; + } + else + { + _mouseDown = NO; + _touchPos = CGPointMake( -1, -1 ); + } +} + +- (void)viewDidTap: (UITapGestureRecognizer*)recognizer +{ + _touchPos = [recognizer locationInView:self.view]; + _mouseTapped = YES; +} + +- (void)render +{ + ImGui::Render(); +} + +- (void)newFrame +{ + ImGuiIO& io = ImGui::GetIO(); + ImGuiStyle &style = ImGui::GetStyle(); + + if (!g_FontTexture) + { + ImGui_ImplIOS_CreateDeviceObjects(); + } + + io.DisplaySize = ImVec2( _view.bounds.size.width, _view.bounds.size.height ); + + io.MouseDrawCursor = g_synergyPtrActive; + if (g_synergyPtrActive) + { + style.TouchExtraPadding = ImVec2( 0.0, 0.0 ); + io.MousePos = ImVec2( g_mousePosX, g_mousePosY ); + for (int i=0; i < 3; i++) + { + io.MouseDown[i] = g_MousePressed[i]; + } + + // This is an arbitrary scaling factor that works for me. Not sure what units these + // mousewheel values from synergy are supposed to be in + io.MouseWheel = g_mouseWheelY / 500.0; + } + else + { + // Synergy not active, use touch events + style.TouchExtraPadding = ImVec2( 4.0, 4.0 ); + io.MousePos = ImVec2(_touchPos.x, _touchPos.y ); + if ((_mouseDown) || (_mouseTapped)) + { + io.MouseDown[0] = true; + _mouseTapped = NO; + } + else + { + io.MouseDown[0] = false; + } + } + + ImGui::NewFrame(); +} +@end + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +// NOTE: this is copied pretty much entirely from the opengl3_example, with only minor changes for ES +static void ImGui_ImplIOS_RenderDrawLists (ImDrawData *draw_data) +{ + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled + // FIXME: Backport changes from imgui_impl_glfw_gl3.cpp + GLint last_program, last_texture; + glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glActiveTexture(GL_TEXTURE0); + + // Setup orthographic projection matrix + const float width = ImGui::GetIO().DisplaySize.x; + const float height = ImGui::GetIO().DisplaySize.y; + const float ortho_projection[4][4] = + { + { 2.0f/width, 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/-height, 0.0f, 0.0f }, + { 0.0f, 0.0f, -1.0f, 0.0f }, + { -1.0f, 1.0f, 0.0f, 1.0f }, + }; + glUseProgram(g_ShaderHandle); + glUniform1i(g_AttribLocationTex, 0); + glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); + glBindVertexArray(g_VaoHandle); + + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + ImDrawList* cmd_list = draw_data->CmdLists[n]; + ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front(); + + glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); + const int needed_vtx_size = cmd_list->VtxBuffer.Size * sizeof(ImDrawVert); + if (g_VboSize < needed_vtx_size) + { + // Grow our buffer if needed + g_VboSize = needed_vtx_size + 2000 * sizeof(ImDrawVert); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)g_VboSize, NULL, GL_STREAM_DRAW); + } + + unsigned char* vtx_data = (unsigned char*)glMapBufferRange(GL_ARRAY_BUFFER, 0, needed_vtx_size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); + if (!vtx_data) + continue; + memcpy(vtx_data, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + glScissor((int)(pcmd->ClipRect.x * g_displayScale), + (int)((height - pcmd->ClipRect.w) * g_displayScale), + (int)((pcmd->ClipRect.z - pcmd->ClipRect.x) * g_displayScale), + (int)((pcmd->ClipRect.w - pcmd->ClipRect.y) * g_displayScale)); + glDrawElements( GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer ); + } + idx_buffer += pcmd->ElemCount; + } + } + + // Restore modified state + glBindVertexArray(0); + glBindBuffer( GL_ARRAY_BUFFER, 0); + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + glUseProgram(last_program); + glDisable(GL_SCISSOR_TEST); + glBindTexture(GL_TEXTURE_2D, last_texture); +} + +void ImGui_ImplIOS_CreateFontsTexture() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader. + + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGenTextures(1, &g_FontTexture); + glBindTexture(GL_TEXTURE_2D, g_FontTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + // Store our identifier + io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); +} + +bool ImGui_ImplIOS_CreateDeviceObjects() +{ + const GLchar *vertex_shader = + "uniform mat4 ProjMtx;\n" + "attribute highp vec2 Position;\n" + "attribute highp vec2 UV;\n" + "attribute highp vec4 Color;\n" + "varying vec2 Frag_UV;\n" + "varying vec4 Frag_Color;\n" + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Color = Color;\n" + " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" + "}\n"; + + const GLchar* fragment_shader = + "uniform sampler2D Texture;\n" + "varying highp vec2 Frag_UV;\n" + "varying highp vec4 Frag_Color;\n" + "void main()\n" + "{\n" + " gl_FragColor = Frag_Color * texture2D( Texture, Frag_UV.st);\n" + "}\n"; + + g_ShaderHandle = glCreateProgram(); + g_VertHandle = glCreateShader(GL_VERTEX_SHADER); + g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(g_VertHandle, 1, &vertex_shader, 0); + glShaderSource(g_FragHandle, 1, &fragment_shader, 0); + glCompileShader(g_VertHandle); + +#if defined(DEBUG) + GLint logLength; + glGetShaderiv( g_VertHandle, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetShaderInfoLog(g_VertHandle, logLength, &logLength, log); + NSLog(@"VERTEX Shader compile log:\n%s", log); + free(log); + } +#endif + + glCompileShader(g_FragHandle); + +#if defined(DEBUG) + glGetShaderiv( g_FragHandle, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetShaderInfoLog(g_FragHandle, logLength, &logLength, log); + NSLog(@"FRAGMENT Shader compile log:\n%s", log); + free(log); + } +#endif + + glAttachShader(g_ShaderHandle, g_VertHandle); + glAttachShader(g_ShaderHandle, g_FragHandle); + glLinkProgram(g_ShaderHandle); + + g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture"); + g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx"); + g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position"); + g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV"); + g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color"); + + glGenBuffers(1, &g_VboHandle); + + glGenVertexArrays(1, &g_VaoHandle); + glBindVertexArray(g_VaoHandle); + glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); + glEnableVertexAttribArray(g_AttribLocationPosition); + glEnableVertexAttribArray(g_AttribLocationUV); + glEnableVertexAttribArray(g_AttribLocationColor); + +#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) + glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); +#undef OFFSETOF + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + ImGui_ImplIOS_CreateFontsTexture(); + + return true; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/main.m b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/main.m new file mode 100644 index 0000000..faba099 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-ios/main.m @@ -0,0 +1,13 @@ +// +// main.m +// imguiex +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.h b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.h new file mode 100644 index 0000000..33d199b --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.h @@ -0,0 +1,15 @@ +// +// AppDelegate.h +// imguiex-osx +// +// Created by James Chen on 4/5/16. +// Copyright © 2016 Joel Davis. All rights reserved. +// + +#import + +@interface AppDelegate : NSObject + + +@end + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.m b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.m new file mode 100644 index 0000000..59e877b --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/AppDelegate.m @@ -0,0 +1,26 @@ +// +// AppDelegate.m +// imguiex-osx +// +// Created by James Chen on 4/5/16. +// Copyright © 2016 Joel Davis. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@property (weak) IBOutlet NSWindow *window; +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + // Insert code here to tear down your application +} + +@end diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/Contents.json b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..b13908f --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,64 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "icon_imgui_180x180.png", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/icon_imgui_180x180.png b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/AppIcon.appiconset/icon_imgui_180x180.png new file mode 100644 index 0000000000000000000000000000000000000000..f48b799dba2cf05b31924886eb4fc9d803ea4a83 GIT binary patch literal 5953 zcmY+IbyO5U*Z&s~mXK~(kX*V!I+q0mrE_VJP`W#$L0CGL7U`7k5Trv8SxP}*k?!u- z=Q;0r&+qrg+_`7YoSE;P`#Dpwn(E5IX1b9acHVLf|;1`5Ce<3HOTNdq-6m0#X-tG_jZ zCXx1+H@A5Eh_t1$Snf`Sa#+jbR*MW=oQ%ePzPMemdpGE{`ukxHC@`MH8o^yN@$!hL zxIJpKDO#U^f%ElC`W*Yf{FvD$rs<9?i9vKf5?Kltb0IMJ6l)WBbSq1}KgvHK?SA}G zCpGaSQw4Pz{hoXnwv{9I;?~GooqZjXGY51~nLrgIS3oJs_@*^zwb7edUegYg?Qd1& z_ASfz&isotGH+^k;vPB^7Zb;=5?ekS8*)ByL?7_i&4EtHDN8XAdH>NoU*_WWCONsI zxn+wii}(fAor!gzoh|lTM<$W6uN7<*6tWCIiqw+bsjOEJkH-Og(q%1uOR%lgBhxzl zp!por(8eC~oNTe(+(kES1}GEq!wf_)(g^QRuq>F2DZ1I)x9xIhwXQ4RaKkP?4DIALW)Wy!;({s>d?>FPImuiN zzFeS8v$EYaj_}W)cUBIO@TxVdJFgNCo$KHvFY$;XJ6ICZse&W-fM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Mdj>4yAr!4zKtQ}5CQ5^_(9#mPpl`Tk(t#u1o?3iFIj{%h0Fib@Zh9f` zHM8T0+Vdz*>`$W831QS_k%v&LxKkMu+%PG0Qj$~T4%)$UbNcYgx~A2~UaQ#=W!W{! z=pMgKQj_<_=2p_HVtE;Dtt1fai}f#-z}pn<3jR+;w%$^CLCBGe66{p|9k_C2p%r-n z*OBrxH)o05gU|$cFe}pRpmjfFU4eMQv6xQVmG1N@R7?)UKtKeH!T5%@4sZkf*Z%*F aW)oPOXB1N~w0~dYfLBm;#aac6u>S!7Vo}-v literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/Contents.json b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Info.plist b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Info.plist new file mode 100644 index 0000000..ba1c2bb --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2016 Joel Davis. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/main.m b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/main.m new file mode 100644 index 0000000..20b0731 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex-osx/main.m @@ -0,0 +1,13 @@ +// +// main.m +// imguiex-osx +// +// Created by James Chen on 4/5/16. +// Copyright © 2016 Joel Davis. All rights reserved. +// + +#import + +int main(int argc, const char * argv[]) { + return NSApplicationMain(argc, argv); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex.xcodeproj/project.pbxproj b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex.xcodeproj/project.pbxproj new file mode 100644 index 0000000..be43fb6 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/apple_example/imguiex.xcodeproj/project.pbxproj @@ -0,0 +1,539 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 197E1E871B8943FE00E3FE6A /* imgui_draw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */; }; + 197E1E891B89443600E3FE6A /* imgui_demo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 197E1E881B89443600E3FE6A /* imgui_demo.cpp */; }; + 1A1A0F231CB39FB50090F036 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A1A0F221CB39FB50090F036 /* AppDelegate.m */; }; + 1A1A0F281CB39FB50090F036 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A1A0F271CB39FB50090F036 /* Assets.xcassets */; }; + 1A1A0F301CB3A0DA0090F036 /* imgui_draw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */; }; + 1A1A0F311CB3A0DA0090F036 /* imgui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5861B2E64AB00C130BA /* imgui.cpp */; }; + 1A1A0F321CB3A0DE0090F036 /* uSynergy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D1E39151B35EEF10017B40F /* uSynergy.c */; }; + 1A1A0F331CB3A0E10090F036 /* imgui_demo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 197E1E881B89443600E3FE6A /* imgui_demo.cpp */; }; + 1A1A0F341CB3A0EC0090F036 /* debug_hud.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5891B2E6A5500C130BA /* debug_hud.cpp */; }; + 1A1A0F481CB3A2E50090F036 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1A0F391CB3A1B20090F036 /* main.cpp */; }; + 1A1A0F4A1CB3A5070090F036 /* imgui_impl_glfw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1A0F371CB3A1B20090F036 /* imgui_impl_glfw.cpp */; }; + 1A1A0F4E1CB3C54D0090F036 /* libglfw3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A1A0F4D1CB3C54D0090F036 /* libglfw3.dylib */; }; + 6D1E39171B35EEF10017B40F /* uSynergy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D1E39151B35EEF10017B40F /* uSynergy.c */; }; + 6D2FC55A1B2E632000C130BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5591B2E632000C130BA /* main.m */; }; + 6D2FC55D1B2E632000C130BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC55C1B2E632000C130BA /* AppDelegate.m */; }; + 6D2FC55F1B2E632000C130BA /* Shader.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 6D2FC55E1B2E632000C130BA /* Shader.fsh */; }; + 6D2FC5611B2E632000C130BA /* Shader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = 6D2FC5601B2E632000C130BA /* Shader.vsh */; }; + 6D2FC5641B2E632000C130BA /* GameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5631B2E632000C130BA /* GameViewController.m */; }; + 6D2FC5671B2E632000C130BA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6D2FC5651B2E632000C130BA /* Main.storyboard */; }; + 6D2FC5691B2E632000C130BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6D2FC5681B2E632000C130BA /* Images.xcassets */; }; + 6D2FC56C1B2E632000C130BA /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6D2FC56A1B2E632000C130BA /* LaunchScreen.xib */; }; + 6D2FC5831B2E63A100C130BA /* imgui_impl_ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5811B2E63A100C130BA /* imgui_impl_ios.mm */; }; + 6D2FC5881B2E64AB00C130BA /* imgui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5861B2E64AB00C130BA /* imgui.cpp */; }; + 6D2FC58B1B2E6A5500C130BA /* debug_hud.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5891B2E6A5500C130BA /* debug_hud.cpp */; }; + 6D2FC5911B30773F00C130BA /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D2FC5901B30773F00C130BA /* CFNetwork.framework */; }; + 6D2FC5931B30774900C130BA /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D2FC5921B30774900C130BA /* SystemConfiguration.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui_draw.cpp; path = ../../imgui_draw.cpp; sourceTree = ""; }; + 197E1E881B89443600E3FE6A /* imgui_demo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui_demo.cpp; path = ../../../imgui_demo.cpp; sourceTree = ""; }; + 1A1A0F1F1CB39FB50090F036 /* imguiex-osx.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "imguiex-osx.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 1A1A0F211CB39FB50090F036 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 1A1A0F221CB39FB50090F036 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 1A1A0F271CB39FB50090F036 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 1A1A0F2C1CB39FB50090F036 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 1A1A0F371CB3A1B20090F036 /* imgui_impl_glfw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = imgui_impl_glfw.cpp; sourceTree = ""; }; + 1A1A0F381CB3A1B20090F036 /* imgui_impl_glfw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = imgui_impl_glfw.h; sourceTree = ""; }; + 1A1A0F391CB3A1B20090F036 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 1A1A0F4D1CB3C54D0090F036 /* libglfw3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libglfw3.dylib; path = /usr/local/lib/libglfw3.dylib; sourceTree = ""; }; + 6D1E39151B35EEF10017B40F /* uSynergy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uSynergy.c; sourceTree = ""; }; + 6D1E39161B35EEF10017B40F /* uSynergy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uSynergy.h; sourceTree = ""; }; + 6D2FC5541B2E632000C130BA /* imguiex-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "imguiex-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6D2FC5581B2E632000C130BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6D2FC5591B2E632000C130BA /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 6D2FC55B1B2E632000C130BA /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 6D2FC55C1B2E632000C130BA /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 6D2FC55E1B2E632000C130BA /* Shader.fsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = Shader.fsh; path = Shaders/Shader.fsh; sourceTree = ""; }; + 6D2FC5601B2E632000C130BA /* Shader.vsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = Shader.vsh; path = Shaders/Shader.vsh; sourceTree = ""; }; + 6D2FC5621B2E632000C130BA /* GameViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GameViewController.h; sourceTree = ""; }; + 6D2FC5631B2E632000C130BA /* GameViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GameViewController.m; sourceTree = ""; }; + 6D2FC5661B2E632000C130BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 6D2FC5681B2E632000C130BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 6D2FC56B1B2E632000C130BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + 6D2FC5811B2E63A100C130BA /* imgui_impl_ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = imgui_impl_ios.mm; sourceTree = ""; }; + 6D2FC5821B2E63A100C130BA /* imgui_impl_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = imgui_impl_ios.h; sourceTree = ""; }; + 6D2FC5851B2E64AB00C130BA /* imconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imconfig.h; path = ../../imconfig.h; sourceTree = ""; }; + 6D2FC5861B2E64AB00C130BA /* imgui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui.cpp; path = ../../imgui.cpp; sourceTree = ""; }; + 6D2FC5871B2E64AB00C130BA /* imgui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imgui.h; path = ../../imgui.h; sourceTree = ""; }; + 6D2FC5891B2E6A5500C130BA /* debug_hud.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = debug_hud.cpp; sourceTree = ""; }; + 6D2FC58A1B2E6A5500C130BA /* debug_hud.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = debug_hud.h; sourceTree = ""; }; + 6D2FC5901B30773F00C130BA /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; + 6D2FC5921B30774900C130BA /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A1A0F1C1CB39FB50090F036 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1A0F4E1CB3C54D0090F036 /* libglfw3.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6D2FC5511B2E632000C130BA /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6D2FC5931B30774900C130BA /* SystemConfiguration.framework in Frameworks */, + 6D2FC5911B30773F00C130BA /* CFNetwork.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1A1A0F201CB39FB50090F036 /* imguiex-osx */ = { + isa = PBXGroup; + children = ( + 1A1A0F4D1CB3C54D0090F036 /* libglfw3.dylib */, + 1A1A0F351CB3A1B20090F036 /* opengl2_example */, + 1A1A0F211CB39FB50090F036 /* AppDelegate.h */, + 1A1A0F221CB39FB50090F036 /* AppDelegate.m */, + 1A1A0F271CB39FB50090F036 /* Assets.xcassets */, + 1A1A0F2C1CB39FB50090F036 /* Info.plist */, + 1A1A0F241CB39FB50090F036 /* Supporting Files */, + ); + path = "imguiex-osx"; + sourceTree = ""; + }; + 1A1A0F241CB39FB50090F036 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 1A1A0F351CB3A1B20090F036 /* opengl2_example */ = { + isa = PBXGroup; + children = ( + 1A1A0F371CB3A1B20090F036 /* imgui_impl_glfw.cpp */, + 1A1A0F381CB3A1B20090F036 /* imgui_impl_glfw.h */, + 1A1A0F391CB3A1B20090F036 /* main.cpp */, + ); + name = opengl2_example; + path = ../../opengl2_example; + sourceTree = ""; + }; + 6D1E39141B35EEF10017B40F /* usynergy */ = { + isa = PBXGroup; + children = ( + 6D1E39151B35EEF10017B40F /* uSynergy.c */, + 6D1E39161B35EEF10017B40F /* uSynergy.h */, + ); + name = usynergy; + path = ../libs/usynergy; + sourceTree = ""; + }; + 6D2FC54B1B2E632000C130BA = { + isa = PBXGroup; + children = ( + 6D1E39141B35EEF10017B40F /* usynergy */, + 6D2FC5841B2E648D00C130BA /* imgui */, + 6D2FC5561B2E632000C130BA /* imguiex-ios */, + 1A1A0F201CB39FB50090F036 /* imguiex-osx */, + 6D2FC5551B2E632000C130BA /* Products */, + ); + sourceTree = ""; + }; + 6D2FC5551B2E632000C130BA /* Products */ = { + isa = PBXGroup; + children = ( + 6D2FC5541B2E632000C130BA /* imguiex-ios.app */, + 1A1A0F1F1CB39FB50090F036 /* imguiex-osx.app */, + ); + name = Products; + sourceTree = ""; + }; + 6D2FC5561B2E632000C130BA /* imguiex-ios */ = { + isa = PBXGroup; + children = ( + 6D2FC5811B2E63A100C130BA /* imgui_impl_ios.mm */, + 6D2FC5821B2E63A100C130BA /* imgui_impl_ios.h */, + 197E1E881B89443600E3FE6A /* imgui_demo.cpp */, + 6D2FC5891B2E6A5500C130BA /* debug_hud.cpp */, + 6D2FC58A1B2E6A5500C130BA /* debug_hud.h */, + 6D2FC55B1B2E632000C130BA /* AppDelegate.h */, + 6D2FC55C1B2E632000C130BA /* AppDelegate.m */, + 6D2FC55E1B2E632000C130BA /* Shader.fsh */, + 6D2FC5601B2E632000C130BA /* Shader.vsh */, + 6D2FC5621B2E632000C130BA /* GameViewController.h */, + 6D2FC5631B2E632000C130BA /* GameViewController.m */, + 6D2FC5651B2E632000C130BA /* Main.storyboard */, + 6D2FC5681B2E632000C130BA /* Images.xcassets */, + 6D2FC56A1B2E632000C130BA /* LaunchScreen.xib */, + 6D2FC5571B2E632000C130BA /* Supporting Files */, + ); + path = "imguiex-ios"; + sourceTree = ""; + }; + 6D2FC5571B2E632000C130BA /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 6D2FC5921B30774900C130BA /* SystemConfiguration.framework */, + 6D2FC5901B30773F00C130BA /* CFNetwork.framework */, + 6D2FC5581B2E632000C130BA /* Info.plist */, + 6D2FC5591B2E632000C130BA /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 6D2FC5841B2E648D00C130BA /* imgui */ = { + isa = PBXGroup; + children = ( + 6D2FC5851B2E64AB00C130BA /* imconfig.h */, + 197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */, + 6D2FC5861B2E64AB00C130BA /* imgui.cpp */, + 6D2FC5871B2E64AB00C130BA /* imgui.h */, + ); + name = imgui; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 1A1A0F1E1CB39FB50090F036 /* imguiex-osx */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A1A0F2F1CB39FB50090F036 /* Build configuration list for PBXNativeTarget "imguiex-osx" */; + buildPhases = ( + 1A1A0F1B1CB39FB50090F036 /* Sources */, + 1A1A0F1C1CB39FB50090F036 /* Frameworks */, + 1A1A0F1D1CB39FB50090F036 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "imguiex-osx"; + productName = "imguiex-osx"; + productReference = 1A1A0F1F1CB39FB50090F036 /* imguiex-osx.app */; + productType = "com.apple.product-type.application"; + }; + 6D2FC5531B2E632000C130BA /* imguiex-ios */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6D2FC57B1B2E632000C130BA /* Build configuration list for PBXNativeTarget "imguiex-ios" */; + buildPhases = ( + 6D2FC5501B2E632000C130BA /* Sources */, + 6D2FC5511B2E632000C130BA /* Frameworks */, + 6D2FC5521B2E632000C130BA /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "imguiex-ios"; + productName = imguiex; + productReference = 6D2FC5541B2E632000C130BA /* imguiex-ios.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 6D2FC54C1B2E632000C130BA /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0630; + ORGANIZATIONNAME = "Joel Davis"; + TargetAttributes = { + 1A1A0F1E1CB39FB50090F036 = { + CreatedOnToolsVersion = 7.3; + }; + 6D2FC5531B2E632000C130BA = { + CreatedOnToolsVersion = 6.3.2; + }; + }; + }; + buildConfigurationList = 6D2FC54F1B2E632000C130BA /* Build configuration list for PBXProject "imguiex" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 6D2FC54B1B2E632000C130BA; + productRefGroup = 6D2FC5551B2E632000C130BA /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6D2FC5531B2E632000C130BA /* imguiex-ios */, + 1A1A0F1E1CB39FB50090F036 /* imguiex-osx */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 1A1A0F1D1CB39FB50090F036 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1A0F281CB39FB50090F036 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6D2FC5521B2E632000C130BA /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6D2FC56C1B2E632000C130BA /* LaunchScreen.xib in Resources */, + 6D2FC5671B2E632000C130BA /* Main.storyboard in Resources */, + 6D2FC5691B2E632000C130BA /* Images.xcassets in Resources */, + 6D2FC5611B2E632000C130BA /* Shader.vsh in Resources */, + 6D2FC55F1B2E632000C130BA /* Shader.fsh in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 1A1A0F1B1CB39FB50090F036 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1A0F301CB3A0DA0090F036 /* imgui_draw.cpp in Sources */, + 1A1A0F311CB3A0DA0090F036 /* imgui.cpp in Sources */, + 1A1A0F331CB3A0E10090F036 /* imgui_demo.cpp in Sources */, + 1A1A0F341CB3A0EC0090F036 /* debug_hud.cpp in Sources */, + 1A1A0F481CB3A2E50090F036 /* main.cpp in Sources */, + 1A1A0F321CB3A0DE0090F036 /* uSynergy.c in Sources */, + 1A1A0F231CB39FB50090F036 /* AppDelegate.m in Sources */, + 1A1A0F4A1CB3A5070090F036 /* imgui_impl_glfw.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6D2FC5501B2E632000C130BA /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6D2FC55D1B2E632000C130BA /* AppDelegate.m in Sources */, + 6D2FC5831B2E63A100C130BA /* imgui_impl_ios.mm in Sources */, + 6D1E39171B35EEF10017B40F /* uSynergy.c in Sources */, + 6D2FC5641B2E632000C130BA /* GameViewController.m in Sources */, + 6D2FC55A1B2E632000C130BA /* main.m in Sources */, + 6D2FC5881B2E64AB00C130BA /* imgui.cpp in Sources */, + 6D2FC58B1B2E6A5500C130BA /* debug_hud.cpp in Sources */, + 197E1E871B8943FE00E3FE6A /* imgui_draw.cpp in Sources */, + 197E1E891B89443600E3FE6A /* imgui_demo.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 6D2FC5651B2E632000C130BA /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 6D2FC5661B2E632000C130BA /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 6D2FC56A1B2E632000C130BA /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + 6D2FC56B1B2E632000C130BA /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 1A1A0F2D1CB39FB50090F036 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_TESTABILITY = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "$(SRCROOT)/../../", + /usr/local/include, + ); + INFOPLIST_FILE = "imguiex-osx/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_BUNDLE_IDENTIFIER = "org.imgui.example.imguiex.imguiex-osx"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + USER_HEADER_SEARCH_PATHS = ""; + }; + name = Debug; + }; + 1A1A0F2E1CB39FB50090F036 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "$(SRCROOT)/../../", + /usr/local/include, + ); + INFOPLIST_FILE = "imguiex-osx/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_BUNDLE_IDENTIFIER = "org.imgui.example.imguiex.imguiex-osx"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + USER_HEADER_SEARCH_PATHS = ""; + }; + name = Release; + }; + 6D2FC5791B2E632000C130BA /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../../"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = ""; + }; + name = Debug; + }; + 6D2FC57A1B2E632000C130BA /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../../"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = ""; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 6D2FC57C1B2E632000C130BA /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = "imguiex-ios/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 6D2FC57D1B2E632000C130BA /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = "imguiex-ios/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1A1A0F2F1CB39FB50090F036 /* Build configuration list for PBXNativeTarget "imguiex-osx" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A1A0F2D1CB39FB50090F036 /* Debug */, + 1A1A0F2E1CB39FB50090F036 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6D2FC54F1B2E632000C130BA /* Build configuration list for PBXProject "imguiex" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6D2FC5791B2E632000C130BA /* Debug */, + 6D2FC57A1B2E632000C130BA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6D2FC57B1B2E632000C130BA /* Build configuration list for PBXNativeTarget "imguiex-ios" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6D2FC57C1B2E632000C130BA /* Debug */, + 6D2FC57D1B2E632000C130BA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 6D2FC54C1B2E632000C130BA /* Project object */; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/build_win32.bat new file mode 100644 index 0000000..2b30786 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/build_win32.bat @@ -0,0 +1,4 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include" /D UNICODE /D _UNICODE *.cpp ..\..\*.cpp /FeDebug/directx10_example.exe /FoDebug/ /link /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d10.lib d3dcompiler.lib + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj new file mode 100644 index 0000000..c4f15c5 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {345A953E-A004-4648-B442-DC5F9F11068C} + directx10_example + + + + Application + true + Unicode + + + Application + true + Unicode + + + Application + false + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level4 + Disabled + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + d3d10.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + Disabled + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + d3d10.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + true + true + d3d10.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + true + true + d3d10.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + Console + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj.filters b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj.filters new file mode 100644 index 0000000..15e924c --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/directx10_example.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} + + + {08e36723-ce4f-4cff-9662-c40801cf1acf} + + + + + imgui + + + imgui + + + sources + + + imgui + + + + + imgui + + + sources + + + sources + + + imgui + + + imgui + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.cpp new file mode 100644 index 0000000..5915267 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.cpp @@ -0,0 +1,614 @@ +// ImGui Win32 + DirectX10 binding +// In this binding, ImTextureID is used to store a 'ID3D10ShaderResourceView*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include "imgui.h" +#include "imgui_impl_dx10.h" + +// DirectX +#include +#include +#include +#define DIRECTINPUT_VERSION 0x0800 +#include + +// Data +static INT64 g_Time = 0; +static INT64 g_TicksPerSecond = 0; + +static HWND g_hWnd = 0; +static ID3D10Device* g_pd3dDevice = NULL; +static ID3D10Buffer* g_pVB = NULL; +static ID3D10Buffer* g_pIB = NULL; +static ID3D10Blob * g_pVertexShaderBlob = NULL; +static ID3D10VertexShader* g_pVertexShader = NULL; +static ID3D10InputLayout* g_pInputLayout = NULL; +static ID3D10Buffer* g_pVertexConstantBuffer = NULL; +static ID3D10Blob * g_pPixelShaderBlob = NULL; +static ID3D10PixelShader* g_pPixelShader = NULL; +static ID3D10SamplerState* g_pFontSampler = NULL; +static ID3D10ShaderResourceView*g_pFontTextureView = NULL; +static ID3D10RasterizerState* g_pRasterizerState = NULL; +static ID3D10BlendState* g_pBlendState = NULL; +static ID3D10DepthStencilState* g_pDepthStencilState = NULL; +static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000; + +struct VERTEX_CONSTANT_BUFFER +{ + float mvp[4][4]; +}; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data) +{ + ID3D10Device* ctx = g_pd3dDevice; + + // Create and grow vertex/index buffers if needed + if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount) + { + if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } + g_VertexBufferSize = draw_data->TotalVtxCount + 5000; + D3D10_BUFFER_DESC desc; + memset(&desc, 0, sizeof(D3D10_BUFFER_DESC)); + desc.Usage = D3D10_USAGE_DYNAMIC; + desc.ByteWidth = g_VertexBufferSize * sizeof(ImDrawVert); + desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; + desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + if (ctx->CreateBuffer(&desc, NULL, &g_pVB) < 0) + return; + } + + if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount) + { + if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } + g_IndexBufferSize = draw_data->TotalIdxCount + 10000; + D3D10_BUFFER_DESC desc; + memset(&desc, 0, sizeof(D3D10_BUFFER_DESC)); + desc.Usage = D3D10_USAGE_DYNAMIC; + desc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx); + desc.BindFlags = D3D10_BIND_INDEX_BUFFER; + desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; + if (ctx->CreateBuffer(&desc, NULL, &g_pIB) < 0) + return; + } + + // Copy and convert all vertices into a single contiguous buffer + ImDrawVert* vtx_dst = NULL; + ImDrawIdx* idx_dst = NULL; + g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst); + g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst); + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); + memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); + vtx_dst += cmd_list->VtxBuffer.Size; + idx_dst += cmd_list->IdxBuffer.Size; + } + g_pVB->Unmap(); + g_pIB->Unmap(); + + // Setup orthographic projection matrix into our constant buffer + { + void* mapped_resource; + if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) + return; + VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource; + const float L = 0.0f; + const float R = ImGui::GetIO().DisplaySize.x; + const float B = ImGui::GetIO().DisplaySize.y; + const float T = 0.0f; + const float mvp[4][4] = + { + { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.5f, 0.0f }, + { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, + }; + memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); + g_pVertexConstantBuffer->Unmap(); + } + + // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) + struct BACKUP_DX10_STATE + { + UINT ScissorRectsCount, ViewportsCount; + D3D10_RECT ScissorRects[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + D3D10_VIEWPORT Viewports[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + ID3D10RasterizerState* RS; + ID3D10BlendState* BlendState; + FLOAT BlendFactor[4]; + UINT SampleMask; + UINT StencilRef; + ID3D10DepthStencilState* DepthStencilState; + ID3D10ShaderResourceView* PSShaderResource; + ID3D10SamplerState* PSSampler; + ID3D10PixelShader* PS; + ID3D10VertexShader* VS; + D3D10_PRIMITIVE_TOPOLOGY PrimitiveTopology; + ID3D10Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; + UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; + DXGI_FORMAT IndexBufferFormat; + ID3D10InputLayout* InputLayout; + }; + BACKUP_DX10_STATE old; + old.ScissorRectsCount = old.ViewportsCount = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; + ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); + ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); + ctx->RSGetState(&old.RS); + ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); + ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); + ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); + ctx->PSGetSamplers(0, 1, &old.PSSampler); + ctx->PSGetShader(&old.PS); + ctx->VSGetShader(&old.VS); + ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); + ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); + ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); + ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); + ctx->IAGetInputLayout(&old.InputLayout); + + // Setup viewport + D3D10_VIEWPORT vp; + memset(&vp, 0, sizeof(D3D10_VIEWPORT)); + vp.Width = (UINT)ImGui::GetIO().DisplaySize.x; + vp.Height = (UINT)ImGui::GetIO().DisplaySize.y; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + vp.TopLeftX = vp.TopLeftY = 0; + ctx->RSSetViewports(1, &vp); + + // Bind shader and vertex buffers + unsigned int stride = sizeof(ImDrawVert); + unsigned int offset = 0; + ctx->IASetInputLayout(g_pInputLayout); + ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); + ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); + ctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->VSSetShader(g_pVertexShader); + ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); + ctx->PSSetShader(g_pPixelShader); + ctx->PSSetSamplers(0, 1, &g_pFontSampler); + + // Setup render state + const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; + ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff); + ctx->OMSetDepthStencilState(g_pDepthStencilState, 0); + ctx->RSSetState(g_pRasterizerState); + + // Render command lists + int vtx_offset = 0; + int idx_offset = 0; + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + const D3D10_RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w }; + ctx->PSSetShaderResources(0, 1, (ID3D10ShaderResourceView**)&pcmd->TextureId); + ctx->RSSetScissorRects(1, &r); + ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset); + } + idx_offset += pcmd->ElemCount; + } + vtx_offset += cmd_list->VtxBuffer.Size; + } + + // Restore modified DX state + ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); + ctx->RSSetViewports(old.ViewportsCount, old.Viewports); + ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); + ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); + ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); + ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); + ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); + ctx->PSSetShader(old.PS); if (old.PS) old.PS->Release(); + ctx->VSSetShader(old.VS); if (old.VS) old.VS->Release(); + ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); + ctx->IASetPrimitiveTopology(old.PrimitiveTopology); + ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); + ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); + ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); +} + +static bool IsAnyMouseButtonDown() +{ + ImGuiIO& io = ImGui::GetIO(); + for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++) + if (io.MouseDown[n]) + return true; + return false; +} + +// Process Win32 mouse/keyboard inputs. +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + ImGuiIO& io = ImGui::GetIO(); + switch (msg) + { + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + { + int button = 0; + if (msg == WM_LBUTTONDOWN) button = 0; + if (msg == WM_RBUTTONDOWN) button = 1; + if (msg == WM_MBUTTONDOWN) button = 2; + if (!IsAnyMouseButtonDown() && GetCapture() == NULL) + SetCapture(hwnd); + io.MouseDown[button] = true; + return 0; + } + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + { + int button = 0; + if (msg == WM_LBUTTONUP) button = 0; + if (msg == WM_RBUTTONUP) button = 1; + if (msg == WM_MBUTTONUP) button = 2; + io.MouseDown[button] = false; + if (!IsAnyMouseButtonDown() && GetCapture() == hwnd) + ReleaseCapture(); + return 0; + } + case WM_MOUSEWHEEL: + io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + return 0; + case WM_MOUSEMOVE: + io.MousePos.x = (signed short)(lParam); + io.MousePos.y = (signed short)(lParam >> 16); + return 0; + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + if (wParam < 256) + io.KeysDown[wParam] = 1; + return 0; + case WM_KEYUP: + case WM_SYSKEYUP: + if (wParam < 256) + io.KeysDown[wParam] = 0; + return 0; + case WM_CHAR: + // You can also use ToAscii()+GetKeyboardState() to retrieve characters. + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacter((unsigned short)wParam); + return 0; + } + return 0; +} + +static void ImGui_ImplDX10_CreateFontsTexture() +{ + ImGuiIO& io = ImGui::GetIO(); + + // Build + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + // Create DX10 texture + { + D3D10_TEXTURE2D_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Width = width; + desc.Height = height; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.SampleDesc.Count = 1; + desc.Usage = D3D10_USAGE_DEFAULT; + desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + + ID3D10Texture2D *pTexture = NULL; + D3D10_SUBRESOURCE_DATA subResource; + subResource.pSysMem = pixels; + subResource.SysMemPitch = desc.Width * 4; + subResource.SysMemSlicePitch = 0; + g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); + + // Create texture view + D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc; + ZeroMemory(&srv_desc, sizeof(srv_desc)); + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MipLevels = desc.MipLevels; + srv_desc.Texture2D.MostDetailedMip = 0; + g_pd3dDevice->CreateShaderResourceView(pTexture, &srv_desc, &g_pFontTextureView); + pTexture->Release(); + } + + // Store our identifier + io.Fonts->TexID = (void *)g_pFontTextureView; + + // Create texture sampler + { + D3D10_SAMPLER_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR; + desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP; + desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP; + desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP; + desc.MipLODBias = 0.f; + desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS; + desc.MinLOD = 0.f; + desc.MaxLOD = 0.f; + g_pd3dDevice->CreateSamplerState(&desc, &g_pFontSampler); + } + + // Cleanup (don't clear the input data if you want to append new fonts later) + io.Fonts->ClearInputData(); + io.Fonts->ClearTexData(); +} + +bool ImGui_ImplDX10_CreateDeviceObjects() +{ + if (!g_pd3dDevice) + return false; + if (g_pFontSampler) + ImGui_ImplDX10_InvalidateDeviceObjects(); + + // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) + // If you would like to use this DX11 sample code but remove this dependency you can: + // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] + // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. + // See https://github.com/ocornut/imgui/pull/638 for sources and details. + + // Create the vertex shader + { + static const char* vertexShader = + "cbuffer vertexBuffer : register(b0) \ + {\ + float4x4 ProjectionMatrix; \ + };\ + struct VS_INPUT\ + {\ + float2 pos : POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + \ + struct PS_INPUT\ + {\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + \ + PS_INPUT main(VS_INPUT input)\ + {\ + PS_INPUT output;\ + output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ + output.col = input.col;\ + output.uv = input.uv;\ + return output;\ + }"; + + D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL); + if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! + return false; + if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pVertexShader) != S_OK) + return false; + + // Create the input layout + D3D10_INPUT_ELEMENT_DESC local_layout[] = + { + { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D10_INPUT_PER_VERTEX_DATA, 0 }, + }; + if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK) + return false; + + // Create the constant buffer + { + D3D10_BUFFER_DESC desc; + desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); + desc.Usage = D3D10_USAGE_DYNAMIC; + desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER; + desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVertexConstantBuffer); + } + } + + // Create the pixel shader + { + static const char* pixelShader = + "struct PS_INPUT\ + {\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + sampler sampler0;\ + Texture2D texture0;\ + \ + float4 main(PS_INPUT input) : SV_Target\ + {\ + float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ + return out_col; \ + }"; + + D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL); + if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! + return false; + if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), &g_pPixelShader) != S_OK) + return false; + } + + // Create the blending setup + { + D3D10_BLEND_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.AlphaToCoverageEnable = false; + desc.BlendEnable[0] = true; + desc.SrcBlend = D3D10_BLEND_SRC_ALPHA; + desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; + desc.BlendOp = D3D10_BLEND_OP_ADD; + desc.SrcBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA; + desc.DestBlendAlpha = D3D10_BLEND_ZERO; + desc.BlendOpAlpha = D3D10_BLEND_OP_ADD; + desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; + g_pd3dDevice->CreateBlendState(&desc, &g_pBlendState); + } + + // Create the rasterizer state + { + D3D10_RASTERIZER_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.FillMode = D3D10_FILL_SOLID; + desc.CullMode = D3D10_CULL_NONE; + desc.ScissorEnable = true; + desc.DepthClipEnable = true; + g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState); + } + + // Create depth-stencil State + { + D3D10_DEPTH_STENCIL_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.DepthEnable = false; + desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL; + desc.DepthFunc = D3D10_COMPARISON_ALWAYS; + desc.StencilEnable = false; + desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP; + desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS; + desc.BackFace = desc.FrontFace; + g_pd3dDevice->CreateDepthStencilState(&desc, &g_pDepthStencilState); + } + + ImGui_ImplDX10_CreateFontsTexture(); + + return true; +} + +void ImGui_ImplDX10_InvalidateDeviceObjects() +{ + if (!g_pd3dDevice) + return; + + if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; } + if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. + if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } + if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } + + if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; } + if (g_pDepthStencilState) { g_pDepthStencilState->Release(); g_pDepthStencilState = NULL; } + if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = NULL; } + if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; } + if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; } + if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; } + if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; } + if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; } + if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; } +} + +bool ImGui_ImplDX10_Init(void* hwnd, ID3D10Device* device) +{ + g_hWnd = (HWND)hwnd; + g_pd3dDevice = device; + + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond)) + return false; + if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time)) + return false; + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = VK_UP; + io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; + io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; + io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; + io.KeyMap[ImGuiKey_Home] = VK_HOME; + io.KeyMap[ImGuiKey_End] = VK_END; + io.KeyMap[ImGuiKey_Delete] = VK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = VK_BACK; + io.KeyMap[ImGuiKey_Enter] = VK_RETURN; + io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; + + io.RenderDrawListsFn = ImGui_ImplDX10_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.ImeWindowHandle = g_hWnd; + + return true; +} + +void ImGui_ImplDX10_Shutdown() +{ + ImGui_ImplDX10_InvalidateDeviceObjects(); + ImGui::Shutdown(); + g_pd3dDevice = NULL; + g_hWnd = (HWND)0; +} + +void ImGui_ImplDX10_NewFrame() +{ + if (!g_pFontSampler) + ImGui_ImplDX10_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + RECT rect; + GetClientRect(g_hWnd, &rect); + io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); + + // Setup time step + INT64 current_time; + QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); + io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond; + g_Time = current_time; + + // Read keyboard modifiers inputs + io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0; + io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0; + io.KeyAlt = (GetKeyState(VK_MENU) & 0x8000) != 0; + io.KeySuper = false; + // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events + // io.MousePos : filled by WM_MOUSEMOVE events + // io.MouseDown : filled by WM_*BUTTON* events + // io.MouseWheel : filled by WM_MOUSEWHEEL events + + // Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation) + if (io.WantMoveMouse) + { + POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; + ClientToScreen(g_hWnd, &pos); + SetCursorPos(pos.x, pos.y); + } + + // Hide OS mouse cursor if ImGui is drawing it + if (io.MouseDrawCursor) + SetCursor(NULL); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.h b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.h new file mode 100644 index 0000000..38a03a2 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/imgui_impl_dx10.h @@ -0,0 +1,24 @@ +// ImGui Win32 + DirectX10 binding +// In this binding, ImTextureID is used to store a 'ID3D10ShaderResourceView*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct ID3D10Device; + +IMGUI_API bool ImGui_ImplDX10_Init(void* hwnd, ID3D10Device* device); +IMGUI_API void ImGui_ImplDX10_Shutdown(); +IMGUI_API void ImGui_ImplDX10_NewFrame(); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplDX10_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplDX10_CreateDeviceObjects(); + +// Handler for Win32 messages, update mouse/keyboard data. +// You may or not need this for your implementation, but it can serve as reference for handling inputs. +// Commented out to avoid dragging dependencies on types. You can copy the extern declaration in your code. +/* +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +*/ diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/main.cpp new file mode 100644 index 0000000..38f4054 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx10_example/main.cpp @@ -0,0 +1,211 @@ +// ImGui - standalone example application for DirectX 10 +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include +#include "imgui_impl_dx10.h" +#include +#include +#define DIRECTINPUT_VERSION 0x0800 +#include +#include + +// Data +static ID3D10Device* g_pd3dDevice = NULL; +static IDXGISwapChain* g_pSwapChain = NULL; +static ID3D10RenderTargetView* g_mainRenderTargetView = NULL; + +void CreateRenderTarget() +{ + DXGI_SWAP_CHAIN_DESC sd; + g_pSwapChain->GetDesc(&sd); + + // Create the render target + ID3D10Texture2D* pBackBuffer; + D3D10_RENDER_TARGET_VIEW_DESC render_target_view_desc; + ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); + render_target_view_desc.Format = sd.BufferDesc.Format; + render_target_view_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; + g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer); + g_pd3dDevice->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); + pBackBuffer->Release(); +} + +void CleanupRenderTarget() +{ + if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; } +} + +HRESULT CreateDeviceD3D(HWND hWnd) +{ + // Setup swap chain + DXGI_SWAP_CHAIN_DESC sd; + { + ZeroMemory(&sd, sizeof(sd)); + sd.BufferCount = 2; + sd.BufferDesc.Width = 0; + sd.BufferDesc.Height = 0; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = hWnd; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + } + + UINT createDeviceFlags = 0; + //createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; + if (D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice) != S_OK) + return E_FAIL; + + CreateRenderTarget(); + + return S_OK; +} + +void CleanupDeviceD3D() +{ + CleanupRenderTarget(); + if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; } + if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } +} + +extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) + return true; + + switch (msg) + { + case WM_SIZE: + if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED) + { + ImGui_ImplDX10_InvalidateDeviceObjects(); + CleanupRenderTarget(); + g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0); + CreateRenderTarget(); + ImGui_ImplDX10_CreateDeviceObjects(); + } + return 0; + case WM_SYSCOMMAND: + if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu + return 0; + break; + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +int main(int, char**) +{ + // Create application window + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL }; + RegisterClassEx(&wc); + HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX10 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); + + // Initialize Direct3D + if (CreateDeviceD3D(hwnd) < 0) + { + CleanupDeviceD3D(); + UnregisterClass(_T("ImGui Example"), wc.hInstance); + return 1; + } + + // Show the window + ShowWindow(hwnd, SW_SHOWDEFAULT); + UpdateWindow(hwnd); + + // Setup ImGui binding + ImGui_ImplDX10_Init(hwnd, g_pd3dDevice); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + MSG msg; + ZeroMemory(&msg, sizeof(msg)); + while (msg.message != WM_QUIT) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + continue; + } + ImGui_ImplDX10_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + g_pd3dDevice->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); + g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); + ImGui::Render(); + + g_pSwapChain->Present(1, 0); // Present with vsync + //g_pSwapChain->Present(0, 0); // Present without vsync + } + + ImGui_ImplDX10_Shutdown(); + CleanupDeviceD3D(); + UnregisterClass(_T("ImGui Example"), wc.hInstance); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/build_win32.bat new file mode 100644 index 0000000..2d1c40f --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/build_win32.bat @@ -0,0 +1,4 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include" /D UNICODE /D _UNICODE *.cpp ..\..\*.cpp /FeDebug/directx11_example.exe /FoDebug/ /link /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj new file mode 100644 index 0000000..944c8e8 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {9F316E83-5AE5-4939-A723-305A94F48005} + directx11_example + + + + Application + true + Unicode + + + Application + true + Unicode + + + Application + false + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level4 + Disabled + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + Disabled + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + true + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + true + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + Console + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj.filters b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj.filters new file mode 100644 index 0000000..5cd0ca4 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/directx11_example.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} + + + {08e36723-ce4f-4cff-9662-c40801cf1acf} + + + + + imgui + + + imgui + + + sources + + + imgui + + + + + imgui + + + sources + + + sources + + + imgui + + + imgui + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.cpp new file mode 100644 index 0000000..af6e54f --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.cpp @@ -0,0 +1,617 @@ +// ImGui Win32 + DirectX11 binding +// In this binding, ImTextureID is used to store a 'ID3D11ShaderResourceView*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include +#include "imgui_impl_dx11.h" + +// DirectX +#include +#include +#define DIRECTINPUT_VERSION 0x0800 +#include + +// Data +static INT64 g_Time = 0; +static INT64 g_TicksPerSecond = 0; + +static HWND g_hWnd = 0; +static ID3D11Device* g_pd3dDevice = NULL; +static ID3D11DeviceContext* g_pd3dDeviceContext = NULL; +static ID3D11Buffer* g_pVB = NULL; +static ID3D11Buffer* g_pIB = NULL; +static ID3D10Blob * g_pVertexShaderBlob = NULL; +static ID3D11VertexShader* g_pVertexShader = NULL; +static ID3D11InputLayout* g_pInputLayout = NULL; +static ID3D11Buffer* g_pVertexConstantBuffer = NULL; +static ID3D10Blob * g_pPixelShaderBlob = NULL; +static ID3D11PixelShader* g_pPixelShader = NULL; +static ID3D11SamplerState* g_pFontSampler = NULL; +static ID3D11ShaderResourceView*g_pFontTextureView = NULL; +static ID3D11RasterizerState* g_pRasterizerState = NULL; +static ID3D11BlendState* g_pBlendState = NULL; +static ID3D11DepthStencilState* g_pDepthStencilState = NULL; +static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000; + +struct VERTEX_CONSTANT_BUFFER +{ + float mvp[4][4]; +}; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) +{ + ID3D11DeviceContext* ctx = g_pd3dDeviceContext; + + // Create and grow vertex/index buffers if needed + if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount) + { + if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } + g_VertexBufferSize = draw_data->TotalVtxCount + 5000; + D3D11_BUFFER_DESC desc; + memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.ByteWidth = g_VertexBufferSize * sizeof(ImDrawVert); + desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0) + return; + } + if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount) + { + if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } + g_IndexBufferSize = draw_data->TotalIdxCount + 10000; + D3D11_BUFFER_DESC desc; + memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx); + desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pIB) < 0) + return; + } + + // Copy and convert all vertices into a single contiguous buffer + D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource; + if (ctx->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK) + return; + if (ctx->Map(g_pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK) + return; + ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData; + ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData; + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); + memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); + vtx_dst += cmd_list->VtxBuffer.Size; + idx_dst += cmd_list->IdxBuffer.Size; + } + ctx->Unmap(g_pVB, 0); + ctx->Unmap(g_pIB, 0); + + // Setup orthographic projection matrix into our constant buffer + { + D3D11_MAPPED_SUBRESOURCE mapped_resource; + if (ctx->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) + return; + VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource.pData; + float L = 0.0f; + float R = ImGui::GetIO().DisplaySize.x; + float B = ImGui::GetIO().DisplaySize.y; + float T = 0.0f; + float mvp[4][4] = + { + { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.5f, 0.0f }, + { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, + }; + memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); + ctx->Unmap(g_pVertexConstantBuffer, 0); + } + + // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) + struct BACKUP_DX11_STATE + { + UINT ScissorRectsCount, ViewportsCount; + D3D11_RECT ScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + D3D11_VIEWPORT Viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + ID3D11RasterizerState* RS; + ID3D11BlendState* BlendState; + FLOAT BlendFactor[4]; + UINT SampleMask; + UINT StencilRef; + ID3D11DepthStencilState* DepthStencilState; + ID3D11ShaderResourceView* PSShaderResource; + ID3D11SamplerState* PSSampler; + ID3D11PixelShader* PS; + ID3D11VertexShader* VS; + UINT PSInstancesCount, VSInstancesCount; + ID3D11ClassInstance* PSInstances[256], *VSInstances[256]; // 256 is max according to PSSetShader documentation + D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology; + ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; + UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; + DXGI_FORMAT IndexBufferFormat; + ID3D11InputLayout* InputLayout; + }; + BACKUP_DX11_STATE old; + old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; + ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); + ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); + ctx->RSGetState(&old.RS); + ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); + ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); + ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); + ctx->PSGetSamplers(0, 1, &old.PSSampler); + old.PSInstancesCount = old.VSInstancesCount = 256; + ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount); + ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount); + ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); + ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); + ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); + ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); + ctx->IAGetInputLayout(&old.InputLayout); + + // Setup viewport + D3D11_VIEWPORT vp; + memset(&vp, 0, sizeof(D3D11_VIEWPORT)); + vp.Width = ImGui::GetIO().DisplaySize.x; + vp.Height = ImGui::GetIO().DisplaySize.y; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + vp.TopLeftX = vp.TopLeftY = 0.0f; + ctx->RSSetViewports(1, &vp); + + // Bind shader and vertex buffers + unsigned int stride = sizeof(ImDrawVert); + unsigned int offset = 0; + ctx->IASetInputLayout(g_pInputLayout); + ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); + ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->VSSetShader(g_pVertexShader, NULL, 0); + ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); + ctx->PSSetShader(g_pPixelShader, NULL, 0); + ctx->PSSetSamplers(0, 1, &g_pFontSampler); + + // Setup render state + const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; + ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff); + ctx->OMSetDepthStencilState(g_pDepthStencilState, 0); + ctx->RSSetState(g_pRasterizerState); + + // Render command lists + int vtx_offset = 0; + int idx_offset = 0; + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + const D3D11_RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w }; + ctx->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->TextureId); + ctx->RSSetScissorRects(1, &r); + ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset); + } + idx_offset += pcmd->ElemCount; + } + vtx_offset += cmd_list->VtxBuffer.Size; + } + + // Restore modified DX state + ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); + ctx->RSSetViewports(old.ViewportsCount, old.Viewports); + ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); + ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); + ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); + ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); + ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); + ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release(); + for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release(); + ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release(); + ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); + for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release(); + ctx->IASetPrimitiveTopology(old.PrimitiveTopology); + ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); + ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); + ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); +} + +static bool IsAnyMouseButtonDown() +{ + ImGuiIO& io = ImGui::GetIO(); + for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++) + if (io.MouseDown[n]) + return true; + return false; +} + +// Process Win32 mouse/keyboard inputs. +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + ImGuiIO& io = ImGui::GetIO(); + switch (msg) + { + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + { + int button = 0; + if (msg == WM_LBUTTONDOWN) button = 0; + if (msg == WM_RBUTTONDOWN) button = 1; + if (msg == WM_MBUTTONDOWN) button = 2; + if (!IsAnyMouseButtonDown() && GetCapture() == NULL) + SetCapture(hwnd); + io.MouseDown[button] = true; + return 0; + } + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + { + int button = 0; + if (msg == WM_LBUTTONUP) button = 0; + if (msg == WM_RBUTTONUP) button = 1; + if (msg == WM_MBUTTONUP) button = 2; + io.MouseDown[button] = false; + if (!IsAnyMouseButtonDown() && GetCapture() == hwnd) + ReleaseCapture(); + return 0; + } + case WM_MOUSEWHEEL: + io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + return 0; + case WM_MOUSEMOVE: + io.MousePos.x = (signed short)(lParam); + io.MousePos.y = (signed short)(lParam >> 16); + return 0; + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + if (wParam < 256) + io.KeysDown[wParam] = 1; + return 0; + case WM_KEYUP: + case WM_SYSKEYUP: + if (wParam < 256) + io.KeysDown[wParam] = 0; + return 0; + case WM_CHAR: + // You can also use ToAscii()+GetKeyboardState() to retrieve characters. + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacter((unsigned short)wParam); + return 0; + } + return 0; +} + +static void ImGui_ImplDX11_CreateFontsTexture() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + // Upload texture to graphics system + { + D3D11_TEXTURE2D_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Width = width; + desc.Height = height; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.SampleDesc.Count = 1; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + + ID3D11Texture2D *pTexture = NULL; + D3D11_SUBRESOURCE_DATA subResource; + subResource.pSysMem = pixels; + subResource.SysMemPitch = desc.Width * 4; + subResource.SysMemSlicePitch = 0; + g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); + + // Create texture view + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + ZeroMemory(&srvDesc, sizeof(srvDesc)); + srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MipLevels = desc.MipLevels; + srvDesc.Texture2D.MostDetailedMip = 0; + g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView); + pTexture->Release(); + } + + // Store our identifier + io.Fonts->TexID = (void *)g_pFontTextureView; + + // Create texture sampler + { + D3D11_SAMPLER_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + desc.MipLODBias = 0.f; + desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; + desc.MinLOD = 0.f; + desc.MaxLOD = 0.f; + g_pd3dDevice->CreateSamplerState(&desc, &g_pFontSampler); + } +} + +bool ImGui_ImplDX11_CreateDeviceObjects() +{ + if (!g_pd3dDevice) + return false; + if (g_pFontSampler) + ImGui_ImplDX11_InvalidateDeviceObjects(); + + // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) + // If you would like to use this DX11 sample code but remove this dependency you can: + // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] + // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. + // See https://github.com/ocornut/imgui/pull/638 for sources and details. + + // Create the vertex shader + { + static const char* vertexShader = + "cbuffer vertexBuffer : register(b0) \ + {\ + float4x4 ProjectionMatrix; \ + };\ + struct VS_INPUT\ + {\ + float2 pos : POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + \ + struct PS_INPUT\ + {\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + \ + PS_INPUT main(VS_INPUT input)\ + {\ + PS_INPUT output;\ + output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ + output.col = input.col;\ + output.uv = input.uv;\ + return output;\ + }"; + + D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL); + if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! + return false; + if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) + return false; + + // Create the input layout + D3D11_INPUT_ELEMENT_DESC local_layout[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; + if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK) + return false; + + // Create the constant buffer + { + D3D11_BUFFER_DESC desc; + desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVertexConstantBuffer); + } + } + + // Create the pixel shader + { + static const char* pixelShader = + "struct PS_INPUT\ + {\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + sampler sampler0;\ + Texture2D texture0;\ + \ + float4 main(PS_INPUT input) : SV_Target\ + {\ + float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ + return out_col; \ + }"; + + D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL); + if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! + return false; + if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) + return false; + } + + // Create the blending setup + { + D3D11_BLEND_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.AlphaToCoverageEnable = false; + desc.RenderTarget[0].BlendEnable = true; + desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; + desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; + desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + g_pd3dDevice->CreateBlendState(&desc, &g_pBlendState); + } + + // Create the rasterizer state + { + D3D11_RASTERIZER_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.FillMode = D3D11_FILL_SOLID; + desc.CullMode = D3D11_CULL_NONE; + desc.ScissorEnable = true; + desc.DepthClipEnable = true; + g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState); + } + + // Create depth-stencil State + { + D3D11_DEPTH_STENCIL_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.DepthEnable = false; + desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; + desc.DepthFunc = D3D11_COMPARISON_ALWAYS; + desc.StencilEnable = false; + desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + desc.BackFace = desc.FrontFace; + g_pd3dDevice->CreateDepthStencilState(&desc, &g_pDepthStencilState); + } + + ImGui_ImplDX11_CreateFontsTexture(); + + return true; +} + +void ImGui_ImplDX11_InvalidateDeviceObjects() +{ + if (!g_pd3dDevice) + return; + + if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; } + if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. + if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } + if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } + + if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; } + if (g_pDepthStencilState) { g_pDepthStencilState->Release(); g_pDepthStencilState = NULL; } + if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = NULL; } + if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; } + if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; } + if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; } + if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; } + if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; } + if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; } +} + +bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context) +{ + g_hWnd = (HWND)hwnd; + g_pd3dDevice = device; + g_pd3dDeviceContext = device_context; + + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond)) + return false; + if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time)) + return false; + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = VK_UP; + io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; + io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; + io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; + io.KeyMap[ImGuiKey_Home] = VK_HOME; + io.KeyMap[ImGuiKey_End] = VK_END; + io.KeyMap[ImGuiKey_Delete] = VK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = VK_BACK; + io.KeyMap[ImGuiKey_Enter] = VK_RETURN; + io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; + + io.RenderDrawListsFn = ImGui_ImplDX11_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.ImeWindowHandle = g_hWnd; + + return true; +} + +void ImGui_ImplDX11_Shutdown() +{ + ImGui_ImplDX11_InvalidateDeviceObjects(); + ImGui::Shutdown(); + g_pd3dDevice = NULL; + g_pd3dDeviceContext = NULL; + g_hWnd = (HWND)0; +} + +void ImGui_ImplDX11_NewFrame() +{ + if (!g_pFontSampler) + ImGui_ImplDX11_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + RECT rect; + GetClientRect(g_hWnd, &rect); + io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); + + // Setup time step + INT64 current_time; + QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); + io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond; + g_Time = current_time; + + // Read keyboard modifiers inputs + io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0; + io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0; + io.KeyAlt = (GetKeyState(VK_MENU) & 0x8000) != 0; + io.KeySuper = false; + // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events + // io.MousePos : filled by WM_MOUSEMOVE events + // io.MouseDown : filled by WM_*BUTTON* events + // io.MouseWheel : filled by WM_MOUSEWHEEL events + + // Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation) + if (io.WantMoveMouse) + { + POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; + ClientToScreen(g_hWnd, &pos); + SetCursorPos(pos.x, pos.y); + } + + // Hide OS mouse cursor if ImGui is drawing it + if (io.MouseDrawCursor) + SetCursor(NULL); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.h b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.h new file mode 100644 index 0000000..3606674 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/imgui_impl_dx11.h @@ -0,0 +1,25 @@ +// ImGui Win32 + DirectX11 binding +// In this binding, ImTextureID is used to store a 'ID3D11ShaderResourceView*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct ID3D11Device; +struct ID3D11DeviceContext; + +IMGUI_API bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context); +IMGUI_API void ImGui_ImplDX11_Shutdown(); +IMGUI_API void ImGui_ImplDX11_NewFrame(); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplDX11_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplDX11_CreateDeviceObjects(); + +// Handler for Win32 messages, update mouse/keyboard data. +// You may or not need this for your implementation, but it can serve as reference for handling inputs. +// Commented out to avoid dragging dependencies on types. You can copy the extern declaration in your code. +/* +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +*/ diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/main.cpp new file mode 100644 index 0000000..79e7bb1 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx11_example/main.cpp @@ -0,0 +1,214 @@ +// ImGui - standalone example application for DirectX 11 +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include +#include "imgui_impl_dx11.h" +#include +#define DIRECTINPUT_VERSION 0x0800 +#include +#include + +// Data +static ID3D11Device* g_pd3dDevice = NULL; +static ID3D11DeviceContext* g_pd3dDeviceContext = NULL; +static IDXGISwapChain* g_pSwapChain = NULL; +static ID3D11RenderTargetView* g_mainRenderTargetView = NULL; + +void CreateRenderTarget() +{ + DXGI_SWAP_CHAIN_DESC sd; + g_pSwapChain->GetDesc(&sd); + + // Create the render target + ID3D11Texture2D* pBackBuffer; + D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; + ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); + render_target_view_desc.Format = sd.BufferDesc.Format; + render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); + g_pd3dDevice->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); + pBackBuffer->Release(); +} + +void CleanupRenderTarget() +{ + if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; } +} + +HRESULT CreateDeviceD3D(HWND hWnd) +{ + // Setup swap chain + DXGI_SWAP_CHAIN_DESC sd; + { + ZeroMemory(&sd, sizeof(sd)); + sd.BufferCount = 2; + sd.BufferDesc.Width = 0; + sd.BufferDesc.Height = 0; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = hWnd; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + } + + UINT createDeviceFlags = 0; + //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; + D3D_FEATURE_LEVEL featureLevel; + const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, }; + if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK) + return E_FAIL; + + CreateRenderTarget(); + + return S_OK; +} + +void CleanupDeviceD3D() +{ + CleanupRenderTarget(); + if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; } + if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; } + if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } +} + +extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) + return true; + + switch (msg) + { + case WM_SIZE: + if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED) + { + ImGui_ImplDX11_InvalidateDeviceObjects(); + CleanupRenderTarget(); + g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0); + CreateRenderTarget(); + ImGui_ImplDX11_CreateDeviceObjects(); + } + return 0; + case WM_SYSCOMMAND: + if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu + return 0; + break; + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +int main(int, char**) +{ + // Create application window + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL }; + RegisterClassEx(&wc); + HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX11 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); + + // Initialize Direct3D + if (CreateDeviceD3D(hwnd) < 0) + { + CleanupDeviceD3D(); + UnregisterClass(_T("ImGui Example"), wc.hInstance); + return 1; + } + + // Show the window + ShowWindow(hwnd, SW_SHOWDEFAULT); + UpdateWindow(hwnd); + + // Setup ImGui binding + ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + MSG msg; + ZeroMemory(&msg, sizeof(msg)); + while (msg.message != WM_QUIT) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + continue; + } + ImGui_ImplDX11_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); + g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); + ImGui::Render(); + + g_pSwapChain->Present(1, 0); // Present with vsync + //g_pSwapChain->Present(0, 0); // Present without vsync + } + + ImGui_ImplDX11_Shutdown(); + CleanupDeviceD3D(); + UnregisterClass(_T("ImGui Example"), wc.hInstance); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/build_win32.bat new file mode 100644 index 0000000..c3647d4 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I "%DXSDK_DIR%/Include" /D UNICODE /D _UNICODE *.cpp ..\..\*.cpp /FeDebug/directx9_example.exe /FoDebug/ /link /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d9.lib diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj new file mode 100644 index 0000000..c10731d --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {4165A294-21F2-44CA-9B38-E3F935ABADF5} + directx9_example + + + + Application + true + Unicode + + + Application + true + Unicode + + + Application + false + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level4 + Disabled + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) + d3d9.lib;%(AdditionalDependencies) + Console + + + + + Level4 + Disabled + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + $(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories) + d3d9.lib;%(AdditionalDependencies) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + true + true + $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) + d3d9.lib;%(AdditionalDependencies) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + + + true + true + true + $(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories) + d3d9.lib;%(AdditionalDependencies) + Console + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj.filters b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj.filters new file mode 100644 index 0000000..5cf0283 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/directx9_example.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {a82cba23-9de0-45c2-b1e3-2eb1666702de} + + + + + sources + + + imgui + + + sources + + + imgui + + + imgui + + + + + imgui + + + imgui + + + sources + + + imgui + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.cpp new file mode 100644 index 0000000..484e84c --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.cpp @@ -0,0 +1,391 @@ +// ImGui Win32 + DirectX9 binding +// In this binding, ImTextureID is used to store a 'LPDIRECT3DTEXTURE9' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include +#include "imgui_impl_dx9.h" + +// DirectX +#include +#define DIRECTINPUT_VERSION 0x0800 +#include + +// Data +static HWND g_hWnd = 0; +static INT64 g_Time = 0; +static INT64 g_TicksPerSecond = 0; +static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; +static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; +static LPDIRECT3DINDEXBUFFER9 g_pIB = NULL; +static LPDIRECT3DTEXTURE9 g_FontTexture = NULL; +static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000; + +struct CUSTOMVERTEX +{ + float pos[3]; + D3DCOLOR col; + float uv[2]; +}; +#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data) +{ + // Avoid rendering when minimized + ImGuiIO& io = ImGui::GetIO(); + if (io.DisplaySize.x <= 0.0f || io.DisplaySize.y <= 0.0f) + return; + + // Create and grow buffers if needed + if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount) + { + if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } + g_VertexBufferSize = draw_data->TotalVtxCount + 5000; + if (g_pd3dDevice->CreateVertexBuffer(g_VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0) + return; + } + if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount) + { + if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } + g_IndexBufferSize = draw_data->TotalIdxCount + 10000; + if (g_pd3dDevice->CreateIndexBuffer(g_IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &g_pIB, NULL) < 0) + return; + } + + // Backup the DX9 state + IDirect3DStateBlock9* d3d9_state_block = NULL; + if (g_pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0) + return; + + // Copy and convert all vertices into a single contiguous buffer + CUSTOMVERTEX* vtx_dst; + ImDrawIdx* idx_dst; + if (g_pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0) + return; + if (g_pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0) + return; + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + const ImDrawVert* vtx_src = cmd_list->VtxBuffer.Data; + for (int i = 0; i < cmd_list->VtxBuffer.Size; i++) + { + vtx_dst->pos[0] = vtx_src->pos.x; + vtx_dst->pos[1] = vtx_src->pos.y; + vtx_dst->pos[2] = 0.0f; + vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 + vtx_dst->uv[0] = vtx_src->uv.x; + vtx_dst->uv[1] = vtx_src->uv.y; + vtx_dst++; + vtx_src++; + } + memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); + idx_dst += cmd_list->IdxBuffer.Size; + } + g_pVB->Unlock(); + g_pIB->Unlock(); + g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); + g_pd3dDevice->SetIndices(g_pIB); + g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); + + // Setup viewport + D3DVIEWPORT9 vp; + vp.X = vp.Y = 0; + vp.Width = (DWORD)io.DisplaySize.x; + vp.Height = (DWORD)io.DisplaySize.y; + vp.MinZ = 0.0f; + vp.MaxZ = 1.0f; + g_pd3dDevice->SetViewport(&vp); + + // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing + g_pd3dDevice->SetPixelShader(NULL); + g_pd3dDevice->SetVertexShader(NULL); + g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false); + g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); + g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); + g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); + g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); + g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true); + g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); + g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); + g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); + g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + + // Setup orthographic projection matrix + // Being agnostic of whether or can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH() + { + const float L = 0.5f, R = io.DisplaySize.x+0.5f, T = 0.5f, B = io.DisplaySize.y+0.5f; + D3DMATRIX mat_identity = { { 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 } }; + D3DMATRIX mat_projection = + { + 2.0f/(R-L), 0.0f, 0.0f, 0.0f, + 0.0f, 2.0f/(T-B), 0.0f, 0.0f, + 0.0f, 0.0f, 0.5f, 0.0f, + (L+R)/(L-R), (T+B)/(B-T), 0.5f, 1.0f, + }; + g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat_identity); + g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat_identity); + g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection); + } + + // Render command lists + int vtx_offset = 0; + int idx_offset = 0; + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + const RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w }; + g_pd3dDevice->SetTexture(0, (LPDIRECT3DTEXTURE9)pcmd->TextureId); + g_pd3dDevice->SetScissorRect(&r); + g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, idx_offset, pcmd->ElemCount/3); + } + idx_offset += pcmd->ElemCount; + } + vtx_offset += cmd_list->VtxBuffer.Size; + } + + // Restore the DX9 state + d3d9_state_block->Apply(); + d3d9_state_block->Release(); +} + +static bool IsAnyMouseButtonDown() +{ + ImGuiIO& io = ImGui::GetIO(); + for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++) + if (io.MouseDown[n]) + return true; + return false; +} + +// Process Win32 mouse/keyboard inputs. +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + ImGuiIO& io = ImGui::GetIO(); + switch (msg) + { + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + { + int button = 0; + if (msg == WM_LBUTTONDOWN) button = 0; + if (msg == WM_RBUTTONDOWN) button = 1; + if (msg == WM_MBUTTONDOWN) button = 2; + if (!IsAnyMouseButtonDown() && GetCapture() == NULL) + SetCapture(hwnd); + io.MouseDown[button] = true; + return 0; + } + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + { + int button = 0; + if (msg == WM_LBUTTONUP) button = 0; + if (msg == WM_RBUTTONUP) button = 1; + if (msg == WM_MBUTTONUP) button = 2; + io.MouseDown[button] = false; + if (!IsAnyMouseButtonDown() && GetCapture() == hwnd) + ReleaseCapture(); + return 0; + } + case WM_MOUSEWHEEL: + io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + return 0; + case WM_MOUSEMOVE: + io.MousePos.x = (signed short)(lParam); + io.MousePos.y = (signed short)(lParam >> 16); + return 0; + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + if (wParam < 256) + io.KeysDown[wParam] = 1; + return 0; + case WM_KEYUP: + case WM_SYSKEYUP: + if (wParam < 256) + io.KeysDown[wParam] = 0; + return 0; + case WM_CHAR: + // You can also use ToAscii()+GetKeyboardState() to retrieve characters. + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacter((unsigned short)wParam); + return 0; + } + return 0; +} + +bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device) +{ + g_hWnd = (HWND)hwnd; + g_pd3dDevice = device; + + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond)) + return false; + if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time)) + return false; + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = VK_UP; + io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; + io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; + io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; + io.KeyMap[ImGuiKey_Home] = VK_HOME; + io.KeyMap[ImGuiKey_End] = VK_END; + io.KeyMap[ImGuiKey_Delete] = VK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = VK_BACK; + io.KeyMap[ImGuiKey_Enter] = VK_RETURN; + io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; + + io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.ImeWindowHandle = g_hWnd; + + return true; +} + +void ImGui_ImplDX9_Shutdown() +{ + ImGui_ImplDX9_InvalidateDeviceObjects(); + ImGui::Shutdown(); + g_pd3dDevice = NULL; + g_hWnd = 0; +} + +static bool ImGui_ImplDX9_CreateFontsTexture() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height, bytes_per_pixel; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_per_pixel); + + // Upload texture to graphics system + g_FontTexture = NULL; + if (g_pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_FontTexture, NULL) < 0) + return false; + D3DLOCKED_RECT tex_locked_rect; + if (g_FontTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK) + return false; + for (int y = 0; y < height; y++) + memcpy((unsigned char *)tex_locked_rect.pBits + tex_locked_rect.Pitch * y, pixels + (width * bytes_per_pixel) * y, (width * bytes_per_pixel)); + g_FontTexture->UnlockRect(0); + + // Store our identifier + io.Fonts->TexID = (void *)g_FontTexture; + + return true; +} + +bool ImGui_ImplDX9_CreateDeviceObjects() +{ + if (!g_pd3dDevice) + return false; + if (!ImGui_ImplDX9_CreateFontsTexture()) + return false; + return true; +} + +void ImGui_ImplDX9_InvalidateDeviceObjects() +{ + if (!g_pd3dDevice) + return; + if (g_pVB) + { + g_pVB->Release(); + g_pVB = NULL; + } + if (g_pIB) + { + g_pIB->Release(); + g_pIB = NULL; + } + + // At this point note that we set ImGui::GetIO().Fonts->TexID to be == g_FontTexture, so clear both. + ImGuiIO& io = ImGui::GetIO(); + IM_ASSERT(g_FontTexture == io.Fonts->TexID); + if (g_FontTexture) + g_FontTexture->Release(); + g_FontTexture = NULL; + io.Fonts->TexID = NULL; +} + +void ImGui_ImplDX9_NewFrame() +{ + if (!g_FontTexture) + ImGui_ImplDX9_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + RECT rect; + GetClientRect(g_hWnd, &rect); + io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); + + // Setup time step + INT64 current_time; + QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); + io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond; + g_Time = current_time; + + // Read keyboard modifiers inputs + io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0; + io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0; + io.KeyAlt = (GetKeyState(VK_MENU) & 0x8000) != 0; + io.KeySuper = false; + // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events + // io.MousePos : filled by WM_MOUSEMOVE events + // io.MouseDown : filled by WM_*BUTTON* events + // io.MouseWheel : filled by WM_MOUSEWHEEL events + + // Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation) + if (io.WantMoveMouse) + { + POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; + ClientToScreen(g_hWnd, &pos); + SetCursorPos(pos.x, pos.y); + } + + // Hide OS mouse cursor if ImGui is drawing it + if (io.MouseDrawCursor) + SetCursor(NULL); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.h b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.h new file mode 100644 index 0000000..acaed53 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/imgui_impl_dx9.h @@ -0,0 +1,24 @@ +// ImGui Win32 + DirectX9 binding +// In this binding, ImTextureID is used to store a 'LPDIRECT3DTEXTURE9' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct IDirect3DDevice9; + +IMGUI_API bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device); +IMGUI_API void ImGui_ImplDX9_Shutdown(); +IMGUI_API void ImGui_ImplDX9_NewFrame(); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplDX9_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplDX9_CreateDeviceObjects(); + +// Handler for Win32 messages, update mouse/keyboard data. +// You may or not need this for your implementation, but it can serve as reference for handling inputs. +// Commented out to avoid dragging dependencies on types. You can copy the extern declaration in your code. +/* +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +*/ diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/main.cpp new file mode 100644 index 0000000..09a109d --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/directx9_example/main.cpp @@ -0,0 +1,181 @@ +// ImGui - standalone example application for DirectX 9 +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include +#include "imgui_impl_dx9.h" +#include +#define DIRECTINPUT_VERSION 0x0800 +#include +#include + +// Data +static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; +static D3DPRESENT_PARAMETERS g_d3dpp; + +extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) + return true; + + switch (msg) + { + case WM_SIZE: + if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED) + { + ImGui_ImplDX9_InvalidateDeviceObjects(); + g_d3dpp.BackBufferWidth = LOWORD(lParam); + g_d3dpp.BackBufferHeight = HIWORD(lParam); + HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp); + if (hr == D3DERR_INVALIDCALL) + IM_ASSERT(0); + ImGui_ImplDX9_CreateDeviceObjects(); + } + return 0; + case WM_SYSCOMMAND: + if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu + return 0; + break; + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +int main(int, char**) +{ + // Create application window + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL }; + RegisterClassEx(&wc); + HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX9 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); + + // Initialize Direct3D + LPDIRECT3D9 pD3D; + if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) + { + UnregisterClass(_T("ImGui Example"), wc.hInstance); + return 0; + } + ZeroMemory(&g_d3dpp, sizeof(g_d3dpp)); + g_d3dpp.Windowed = TRUE; + g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; + g_d3dpp.EnableAutoDepthStencil = TRUE; + g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16; + g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync + //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate + + // Create the D3DDevice + if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0) + { + pD3D->Release(); + UnregisterClass(_T("ImGui Example"), wc.hInstance); + return 0; + } + + // Setup ImGui binding + ImGui_ImplDX9_Init(hwnd, g_pd3dDevice); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + MSG msg; + ZeroMemory(&msg, sizeof(msg)); + ShowWindow(hwnd, SW_SHOWDEFAULT); + UpdateWindow(hwnd); + while (msg.message != WM_QUIT) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + continue; + } + ImGui_ImplDX9_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + ImGui::EndFrame(); + g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false); + D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f)); + g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0); + if (g_pd3dDevice->BeginScene() >= 0) + { + ImGui::Render(); + g_pd3dDevice->EndScene(); + } + HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL); + + // Handle loss of D3D9 device + if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) + { + ImGui_ImplDX9_InvalidateDeviceObjects(); + g_pd3dDevice->Reset(&g_d3dpp); + ImGui_ImplDX9_CreateDeviceObjects(); + } + } + + ImGui_ImplDX9_Shutdown(); + if (g_pd3dDevice) g_pd3dDevice->Release(); + if (pD3D) pD3D->Release(); + UnregisterClass(_T("ImGui Example"), wc.hInstance); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/imgui_examples_msvc2010.sln b/lib/cimgui-1.53.1/imgui-1.53/examples/imgui_examples_msvc2010.sln new file mode 100644 index 0000000..8c1cd2a --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/imgui_examples_msvc2010.sln @@ -0,0 +1,66 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl2_example", "opengl2_example\opengl2_example.vcxproj", "{9CDA7840-B7A5-496D-A527-E95571496D18}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx9_example", "directx9_example\directx9_example.vcxproj", "{4165A294-21F2-44CA-9B38-E3F935ABADF5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx11_example", "directx11_example\directx11_example.vcxproj", "{9F316E83-5AE5-4939-A723-305A94F48005}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl3_example", "opengl3_example\opengl3_example.vcxproj", "{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx10_example", "directx10_example\directx10_example.vcxproj", "{345A953E-A004-4648-B442-DC5F9F11068C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.ActiveCfg = Debug|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.Build.0 = Debug|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|x64.ActiveCfg = Debug|x64 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|x64.Build.0 = Debug|x64 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.ActiveCfg = Release|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.Build.0 = Release|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|x64.ActiveCfg = Release|x64 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|x64.Build.0 = Release|x64 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.ActiveCfg = Debug|Win32 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.Build.0 = Debug|Win32 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|x64.ActiveCfg = Debug|x64 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|x64.Build.0 = Debug|x64 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.ActiveCfg = Release|Win32 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.Build.0 = Release|Win32 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|x64.ActiveCfg = Release|x64 + {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|x64.Build.0 = Release|x64 + {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.ActiveCfg = Debug|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.Build.0 = Debug|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|x64.ActiveCfg = Debug|x64 + {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|x64.Build.0 = Debug|x64 + {9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.ActiveCfg = Release|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.Build.0 = Release|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Release|x64.ActiveCfg = Release|x64 + {9F316E83-5AE5-4939-A723-305A94F48005}.Release|x64.Build.0 = Release|x64 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.ActiveCfg = Debug|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.Build.0 = Debug|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|x64.ActiveCfg = Debug|x64 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|x64.Build.0 = Debug|x64 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.ActiveCfg = Release|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.Build.0 = Release|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.ActiveCfg = Release|x64 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.Build.0 = Release|x64 + {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.ActiveCfg = Debug|Win32 + {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.Build.0 = Debug|Win32 + {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.ActiveCfg = Debug|x64 + {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.Build.0 = Debug|x64 + {345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.ActiveCfg = Release|Win32 + {345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.Build.0 = Release|Win32 + {345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.ActiveCfg = Release|x64 + {345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.c b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.c new file mode 100644 index 0000000..464e017 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.c @@ -0,0 +1,1344 @@ +#include + +#ifdef _MSC_VER +#pragma warning (disable: 4055) // warning C4055: 'type cast' : from data pointer 'void *' to function pointer +#pragma warning (disable: 4152) // warning C4152: nonstandard extension, function/data pointer conversion in expression +#endif + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include + +static HMODULE libgl; + +static void open_libgl(void) +{ + libgl = LoadLibraryA("opengl32.dll"); +} + +static void close_libgl(void) +{ + FreeLibrary(libgl); +} + +static void *get_proc(const char *proc) +{ + void *res; + + res = wglGetProcAddress(proc); + if (!res) + res = GetProcAddress(libgl, proc); + return res; +} +#elif defined(__APPLE__) || defined(__APPLE_CC__) +#include + +CFBundleRef bundle; +CFURLRef bundleURL; + +static void open_libgl(void) +{ + bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, + CFSTR("/System/Library/Frameworks/OpenGL.framework"), + kCFURLPOSIXPathStyle, true); + + bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL); + assert(bundle != NULL); +} + +static void close_libgl(void) +{ + CFRelease(bundle); + CFRelease(bundleURL); +} + +static void *get_proc(const char *proc) +{ + void *res; + + CFStringRef procname = CFStringCreateWithCString(kCFAllocatorDefault, proc, + kCFStringEncodingASCII); + res = CFBundleGetFunctionPointerForName(bundle, procname); + CFRelease(procname); + return res; +} +#else +#include +#include + +static void *libgl; + +static void open_libgl(void) +{ + libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); +} + +static void close_libgl(void) +{ + dlclose(libgl); +} + +static void *get_proc(const char *proc) +{ + void *res; + + res = (void*)glXGetProcAddress((const GLubyte *) proc); + if (!res) + res = dlsym(libgl, proc); + return res; +} +#endif + +static struct { + int major, minor; +} version; + +static int parse_version(void) +{ + if (!glGetIntegerv) + return -1; + + glGetIntegerv(GL_MAJOR_VERSION, &version.major); + glGetIntegerv(GL_MINOR_VERSION, &version.minor); + + if (version.major < 3) + return -1; + return 0; +} + +static void load_procs(void); + +int gl3wInit(void) +{ + open_libgl(); + load_procs(); + close_libgl(); + return parse_version(); +} + +int gl3wIsSupported(int major, int minor) +{ + if (major < 3) + return 0; + if (version.major == major) + return version.minor >= minor; + return version.major >= major; +} + +void *gl3wGetProcAddress(const char *proc) +{ + return get_proc(proc); +} + +PFNGLCULLFACEPROC gl3wCullFace; +PFNGLFRONTFACEPROC gl3wFrontFace; +PFNGLHINTPROC gl3wHint; +PFNGLLINEWIDTHPROC gl3wLineWidth; +PFNGLPOINTSIZEPROC gl3wPointSize; +PFNGLPOLYGONMODEPROC gl3wPolygonMode; +PFNGLSCISSORPROC gl3wScissor; +PFNGLTEXPARAMETERFPROC gl3wTexParameterf; +PFNGLTEXPARAMETERFVPROC gl3wTexParameterfv; +PFNGLTEXPARAMETERIPROC gl3wTexParameteri; +PFNGLTEXPARAMETERIVPROC gl3wTexParameteriv; +PFNGLTEXIMAGE1DPROC gl3wTexImage1D; +PFNGLTEXIMAGE2DPROC gl3wTexImage2D; +PFNGLDRAWBUFFERPROC gl3wDrawBuffer; +PFNGLCLEARPROC gl3wClear; +PFNGLCLEARCOLORPROC gl3wClearColor; +PFNGLCLEARSTENCILPROC gl3wClearStencil; +PFNGLCLEARDEPTHPROC gl3wClearDepth; +PFNGLSTENCILMASKPROC gl3wStencilMask; +PFNGLCOLORMASKPROC gl3wColorMask; +PFNGLDEPTHMASKPROC gl3wDepthMask; +PFNGLDISABLEPROC gl3wDisable; +PFNGLENABLEPROC gl3wEnable; +PFNGLFINISHPROC gl3wFinish; +PFNGLFLUSHPROC gl3wFlush; +PFNGLBLENDFUNCPROC gl3wBlendFunc; +PFNGLLOGICOPPROC gl3wLogicOp; +PFNGLSTENCILFUNCPROC gl3wStencilFunc; +PFNGLSTENCILOPPROC gl3wStencilOp; +PFNGLDEPTHFUNCPROC gl3wDepthFunc; +PFNGLPIXELSTOREFPROC gl3wPixelStoref; +PFNGLPIXELSTOREIPROC gl3wPixelStorei; +PFNGLREADBUFFERPROC gl3wReadBuffer; +PFNGLREADPIXELSPROC gl3wReadPixels; +PFNGLGETBOOLEANVPROC gl3wGetBooleanv; +PFNGLGETDOUBLEVPROC gl3wGetDoublev; +PFNGLGETERRORPROC gl3wGetError; +PFNGLGETFLOATVPROC gl3wGetFloatv; +PFNGLGETINTEGERVPROC gl3wGetIntegerv; +PFNGLGETSTRINGPROC gl3wGetString; +PFNGLGETTEXIMAGEPROC gl3wGetTexImage; +PFNGLGETTEXPARAMETERFVPROC gl3wGetTexParameterfv; +PFNGLGETTEXPARAMETERIVPROC gl3wGetTexParameteriv; +PFNGLGETTEXLEVELPARAMETERFVPROC gl3wGetTexLevelParameterfv; +PFNGLGETTEXLEVELPARAMETERIVPROC gl3wGetTexLevelParameteriv; +PFNGLISENABLEDPROC gl3wIsEnabled; +PFNGLDEPTHRANGEPROC gl3wDepthRange; +PFNGLVIEWPORTPROC gl3wViewport; +PFNGLDRAWARRAYSPROC gl3wDrawArrays; +PFNGLDRAWELEMENTSPROC gl3wDrawElements; +PFNGLGETPOINTERVPROC gl3wGetPointerv; +PFNGLPOLYGONOFFSETPROC gl3wPolygonOffset; +PFNGLCOPYTEXIMAGE1DPROC gl3wCopyTexImage1D; +PFNGLCOPYTEXIMAGE2DPROC gl3wCopyTexImage2D; +PFNGLCOPYTEXSUBIMAGE1DPROC gl3wCopyTexSubImage1D; +PFNGLCOPYTEXSUBIMAGE2DPROC gl3wCopyTexSubImage2D; +PFNGLTEXSUBIMAGE1DPROC gl3wTexSubImage1D; +PFNGLTEXSUBIMAGE2DPROC gl3wTexSubImage2D; +PFNGLBINDTEXTUREPROC gl3wBindTexture; +PFNGLDELETETEXTURESPROC gl3wDeleteTextures; +PFNGLGENTEXTURESPROC gl3wGenTextures; +PFNGLISTEXTUREPROC gl3wIsTexture; +PFNGLBLENDCOLORPROC gl3wBlendColor; +PFNGLBLENDEQUATIONPROC gl3wBlendEquation; +PFNGLDRAWRANGEELEMENTSPROC gl3wDrawRangeElements; +PFNGLTEXIMAGE3DPROC gl3wTexImage3D; +PFNGLTEXSUBIMAGE3DPROC gl3wTexSubImage3D; +PFNGLCOPYTEXSUBIMAGE3DPROC gl3wCopyTexSubImage3D; +PFNGLACTIVETEXTUREPROC gl3wActiveTexture; +PFNGLSAMPLECOVERAGEPROC gl3wSampleCoverage; +PFNGLCOMPRESSEDTEXIMAGE3DPROC gl3wCompressedTexImage3D; +PFNGLCOMPRESSEDTEXIMAGE2DPROC gl3wCompressedTexImage2D; +PFNGLCOMPRESSEDTEXIMAGE1DPROC gl3wCompressedTexImage1D; +PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC gl3wCompressedTexSubImage3D; +PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC gl3wCompressedTexSubImage2D; +PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC gl3wCompressedTexSubImage1D; +PFNGLGETCOMPRESSEDTEXIMAGEPROC gl3wGetCompressedTexImage; +PFNGLBLENDFUNCSEPARATEPROC gl3wBlendFuncSeparate; +PFNGLMULTIDRAWARRAYSPROC gl3wMultiDrawArrays; +PFNGLMULTIDRAWELEMENTSPROC gl3wMultiDrawElements; +PFNGLPOINTPARAMETERFPROC gl3wPointParameterf; +PFNGLPOINTPARAMETERFVPROC gl3wPointParameterfv; +PFNGLPOINTPARAMETERIPROC gl3wPointParameteri; +PFNGLPOINTPARAMETERIVPROC gl3wPointParameteriv; +PFNGLGENQUERIESPROC gl3wGenQueries; +PFNGLDELETEQUERIESPROC gl3wDeleteQueries; +PFNGLISQUERYPROC gl3wIsQuery; +PFNGLBEGINQUERYPROC gl3wBeginQuery; +PFNGLENDQUERYPROC gl3wEndQuery; +PFNGLGETQUERYIVPROC gl3wGetQueryiv; +PFNGLGETQUERYOBJECTIVPROC gl3wGetQueryObjectiv; +PFNGLGETQUERYOBJECTUIVPROC gl3wGetQueryObjectuiv; +PFNGLBINDBUFFERPROC gl3wBindBuffer; +PFNGLDELETEBUFFERSPROC gl3wDeleteBuffers; +PFNGLGENBUFFERSPROC gl3wGenBuffers; +PFNGLISBUFFERPROC gl3wIsBuffer; +PFNGLBUFFERDATAPROC gl3wBufferData; +PFNGLBUFFERSUBDATAPROC gl3wBufferSubData; +PFNGLGETBUFFERSUBDATAPROC gl3wGetBufferSubData; +PFNGLMAPBUFFERPROC gl3wMapBuffer; +PFNGLUNMAPBUFFERPROC gl3wUnmapBuffer; +PFNGLGETBUFFERPARAMETERIVPROC gl3wGetBufferParameteriv; +PFNGLGETBUFFERPOINTERVPROC gl3wGetBufferPointerv; +PFNGLBLENDEQUATIONSEPARATEPROC gl3wBlendEquationSeparate; +PFNGLDRAWBUFFERSPROC gl3wDrawBuffers; +PFNGLSTENCILOPSEPARATEPROC gl3wStencilOpSeparate; +PFNGLSTENCILFUNCSEPARATEPROC gl3wStencilFuncSeparate; +PFNGLSTENCILMASKSEPARATEPROC gl3wStencilMaskSeparate; +PFNGLATTACHSHADERPROC gl3wAttachShader; +PFNGLBINDATTRIBLOCATIONPROC gl3wBindAttribLocation; +PFNGLCOMPILESHADERPROC gl3wCompileShader; +PFNGLCREATEPROGRAMPROC gl3wCreateProgram; +PFNGLCREATESHADERPROC gl3wCreateShader; +PFNGLDELETEPROGRAMPROC gl3wDeleteProgram; +PFNGLDELETESHADERPROC gl3wDeleteShader; +PFNGLDETACHSHADERPROC gl3wDetachShader; +PFNGLDISABLEVERTEXATTRIBARRAYPROC gl3wDisableVertexAttribArray; +PFNGLENABLEVERTEXATTRIBARRAYPROC gl3wEnableVertexAttribArray; +PFNGLGETACTIVEATTRIBPROC gl3wGetActiveAttrib; +PFNGLGETACTIVEUNIFORMPROC gl3wGetActiveUniform; +PFNGLGETATTACHEDSHADERSPROC gl3wGetAttachedShaders; +PFNGLGETATTRIBLOCATIONPROC gl3wGetAttribLocation; +PFNGLGETPROGRAMIVPROC gl3wGetProgramiv; +PFNGLGETPROGRAMINFOLOGPROC gl3wGetProgramInfoLog; +PFNGLGETSHADERIVPROC gl3wGetShaderiv; +PFNGLGETSHADERINFOLOGPROC gl3wGetShaderInfoLog; +PFNGLGETSHADERSOURCEPROC gl3wGetShaderSource; +PFNGLGETUNIFORMLOCATIONPROC gl3wGetUniformLocation; +PFNGLGETUNIFORMFVPROC gl3wGetUniformfv; +PFNGLGETUNIFORMIVPROC gl3wGetUniformiv; +PFNGLGETVERTEXATTRIBDVPROC gl3wGetVertexAttribdv; +PFNGLGETVERTEXATTRIBFVPROC gl3wGetVertexAttribfv; +PFNGLGETVERTEXATTRIBIVPROC gl3wGetVertexAttribiv; +PFNGLGETVERTEXATTRIBPOINTERVPROC gl3wGetVertexAttribPointerv; +PFNGLISPROGRAMPROC gl3wIsProgram; +PFNGLISSHADERPROC gl3wIsShader; +PFNGLLINKPROGRAMPROC gl3wLinkProgram; +PFNGLSHADERSOURCEPROC gl3wShaderSource; +PFNGLUSEPROGRAMPROC gl3wUseProgram; +PFNGLUNIFORM1FPROC gl3wUniform1f; +PFNGLUNIFORM2FPROC gl3wUniform2f; +PFNGLUNIFORM3FPROC gl3wUniform3f; +PFNGLUNIFORM4FPROC gl3wUniform4f; +PFNGLUNIFORM1IPROC gl3wUniform1i; +PFNGLUNIFORM2IPROC gl3wUniform2i; +PFNGLUNIFORM3IPROC gl3wUniform3i; +PFNGLUNIFORM4IPROC gl3wUniform4i; +PFNGLUNIFORM1FVPROC gl3wUniform1fv; +PFNGLUNIFORM2FVPROC gl3wUniform2fv; +PFNGLUNIFORM3FVPROC gl3wUniform3fv; +PFNGLUNIFORM4FVPROC gl3wUniform4fv; +PFNGLUNIFORM1IVPROC gl3wUniform1iv; +PFNGLUNIFORM2IVPROC gl3wUniform2iv; +PFNGLUNIFORM3IVPROC gl3wUniform3iv; +PFNGLUNIFORM4IVPROC gl3wUniform4iv; +PFNGLUNIFORMMATRIX2FVPROC gl3wUniformMatrix2fv; +PFNGLUNIFORMMATRIX3FVPROC gl3wUniformMatrix3fv; +PFNGLUNIFORMMATRIX4FVPROC gl3wUniformMatrix4fv; +PFNGLVALIDATEPROGRAMPROC gl3wValidateProgram; +PFNGLVERTEXATTRIB1DPROC gl3wVertexAttrib1d; +PFNGLVERTEXATTRIB1DVPROC gl3wVertexAttrib1dv; +PFNGLVERTEXATTRIB1FPROC gl3wVertexAttrib1f; +PFNGLVERTEXATTRIB1FVPROC gl3wVertexAttrib1fv; +PFNGLVERTEXATTRIB1SPROC gl3wVertexAttrib1s; +PFNGLVERTEXATTRIB1SVPROC gl3wVertexAttrib1sv; +PFNGLVERTEXATTRIB2DPROC gl3wVertexAttrib2d; +PFNGLVERTEXATTRIB2DVPROC gl3wVertexAttrib2dv; +PFNGLVERTEXATTRIB2FPROC gl3wVertexAttrib2f; +PFNGLVERTEXATTRIB2FVPROC gl3wVertexAttrib2fv; +PFNGLVERTEXATTRIB2SPROC gl3wVertexAttrib2s; +PFNGLVERTEXATTRIB2SVPROC gl3wVertexAttrib2sv; +PFNGLVERTEXATTRIB3DPROC gl3wVertexAttrib3d; +PFNGLVERTEXATTRIB3DVPROC gl3wVertexAttrib3dv; +PFNGLVERTEXATTRIB3FPROC gl3wVertexAttrib3f; +PFNGLVERTEXATTRIB3FVPROC gl3wVertexAttrib3fv; +PFNGLVERTEXATTRIB3SPROC gl3wVertexAttrib3s; +PFNGLVERTEXATTRIB3SVPROC gl3wVertexAttrib3sv; +PFNGLVERTEXATTRIB4NBVPROC gl3wVertexAttrib4Nbv; +PFNGLVERTEXATTRIB4NIVPROC gl3wVertexAttrib4Niv; +PFNGLVERTEXATTRIB4NSVPROC gl3wVertexAttrib4Nsv; +PFNGLVERTEXATTRIB4NUBPROC gl3wVertexAttrib4Nub; +PFNGLVERTEXATTRIB4NUBVPROC gl3wVertexAttrib4Nubv; +PFNGLVERTEXATTRIB4NUIVPROC gl3wVertexAttrib4Nuiv; +PFNGLVERTEXATTRIB4NUSVPROC gl3wVertexAttrib4Nusv; +PFNGLVERTEXATTRIB4BVPROC gl3wVertexAttrib4bv; +PFNGLVERTEXATTRIB4DPROC gl3wVertexAttrib4d; +PFNGLVERTEXATTRIB4DVPROC gl3wVertexAttrib4dv; +PFNGLVERTEXATTRIB4FPROC gl3wVertexAttrib4f; +PFNGLVERTEXATTRIB4FVPROC gl3wVertexAttrib4fv; +PFNGLVERTEXATTRIB4IVPROC gl3wVertexAttrib4iv; +PFNGLVERTEXATTRIB4SPROC gl3wVertexAttrib4s; +PFNGLVERTEXATTRIB4SVPROC gl3wVertexAttrib4sv; +PFNGLVERTEXATTRIB4UBVPROC gl3wVertexAttrib4ubv; +PFNGLVERTEXATTRIB4UIVPROC gl3wVertexAttrib4uiv; +PFNGLVERTEXATTRIB4USVPROC gl3wVertexAttrib4usv; +PFNGLVERTEXATTRIBPOINTERPROC gl3wVertexAttribPointer; +PFNGLUNIFORMMATRIX2X3FVPROC gl3wUniformMatrix2x3fv; +PFNGLUNIFORMMATRIX3X2FVPROC gl3wUniformMatrix3x2fv; +PFNGLUNIFORMMATRIX2X4FVPROC gl3wUniformMatrix2x4fv; +PFNGLUNIFORMMATRIX4X2FVPROC gl3wUniformMatrix4x2fv; +PFNGLUNIFORMMATRIX3X4FVPROC gl3wUniformMatrix3x4fv; +PFNGLUNIFORMMATRIX4X3FVPROC gl3wUniformMatrix4x3fv; +PFNGLCOLORMASKIPROC gl3wColorMaski; +PFNGLGETBOOLEANI_VPROC gl3wGetBooleani_v; +PFNGLGETINTEGERI_VPROC gl3wGetIntegeri_v; +PFNGLENABLEIPROC gl3wEnablei; +PFNGLDISABLEIPROC gl3wDisablei; +PFNGLISENABLEDIPROC gl3wIsEnabledi; +PFNGLBEGINTRANSFORMFEEDBACKPROC gl3wBeginTransformFeedback; +PFNGLENDTRANSFORMFEEDBACKPROC gl3wEndTransformFeedback; +PFNGLBINDBUFFERRANGEPROC gl3wBindBufferRange; +PFNGLBINDBUFFERBASEPROC gl3wBindBufferBase; +PFNGLTRANSFORMFEEDBACKVARYINGSPROC gl3wTransformFeedbackVaryings; +PFNGLGETTRANSFORMFEEDBACKVARYINGPROC gl3wGetTransformFeedbackVarying; +PFNGLCLAMPCOLORPROC gl3wClampColor; +PFNGLBEGINCONDITIONALRENDERPROC gl3wBeginConditionalRender; +PFNGLENDCONDITIONALRENDERPROC gl3wEndConditionalRender; +PFNGLVERTEXATTRIBIPOINTERPROC gl3wVertexAttribIPointer; +PFNGLGETVERTEXATTRIBIIVPROC gl3wGetVertexAttribIiv; +PFNGLGETVERTEXATTRIBIUIVPROC gl3wGetVertexAttribIuiv; +PFNGLVERTEXATTRIBI1IPROC gl3wVertexAttribI1i; +PFNGLVERTEXATTRIBI2IPROC gl3wVertexAttribI2i; +PFNGLVERTEXATTRIBI3IPROC gl3wVertexAttribI3i; +PFNGLVERTEXATTRIBI4IPROC gl3wVertexAttribI4i; +PFNGLVERTEXATTRIBI1UIPROC gl3wVertexAttribI1ui; +PFNGLVERTEXATTRIBI2UIPROC gl3wVertexAttribI2ui; +PFNGLVERTEXATTRIBI3UIPROC gl3wVertexAttribI3ui; +PFNGLVERTEXATTRIBI4UIPROC gl3wVertexAttribI4ui; +PFNGLVERTEXATTRIBI1IVPROC gl3wVertexAttribI1iv; +PFNGLVERTEXATTRIBI2IVPROC gl3wVertexAttribI2iv; +PFNGLVERTEXATTRIBI3IVPROC gl3wVertexAttribI3iv; +PFNGLVERTEXATTRIBI4IVPROC gl3wVertexAttribI4iv; +PFNGLVERTEXATTRIBI1UIVPROC gl3wVertexAttribI1uiv; +PFNGLVERTEXATTRIBI2UIVPROC gl3wVertexAttribI2uiv; +PFNGLVERTEXATTRIBI3UIVPROC gl3wVertexAttribI3uiv; +PFNGLVERTEXATTRIBI4UIVPROC gl3wVertexAttribI4uiv; +PFNGLVERTEXATTRIBI4BVPROC gl3wVertexAttribI4bv; +PFNGLVERTEXATTRIBI4SVPROC gl3wVertexAttribI4sv; +PFNGLVERTEXATTRIBI4UBVPROC gl3wVertexAttribI4ubv; +PFNGLVERTEXATTRIBI4USVPROC gl3wVertexAttribI4usv; +PFNGLGETUNIFORMUIVPROC gl3wGetUniformuiv; +PFNGLBINDFRAGDATALOCATIONPROC gl3wBindFragDataLocation; +PFNGLGETFRAGDATALOCATIONPROC gl3wGetFragDataLocation; +PFNGLUNIFORM1UIPROC gl3wUniform1ui; +PFNGLUNIFORM2UIPROC gl3wUniform2ui; +PFNGLUNIFORM3UIPROC gl3wUniform3ui; +PFNGLUNIFORM4UIPROC gl3wUniform4ui; +PFNGLUNIFORM1UIVPROC gl3wUniform1uiv; +PFNGLUNIFORM2UIVPROC gl3wUniform2uiv; +PFNGLUNIFORM3UIVPROC gl3wUniform3uiv; +PFNGLUNIFORM4UIVPROC gl3wUniform4uiv; +PFNGLTEXPARAMETERIIVPROC gl3wTexParameterIiv; +PFNGLTEXPARAMETERIUIVPROC gl3wTexParameterIuiv; +PFNGLGETTEXPARAMETERIIVPROC gl3wGetTexParameterIiv; +PFNGLGETTEXPARAMETERIUIVPROC gl3wGetTexParameterIuiv; +PFNGLCLEARBUFFERIVPROC gl3wClearBufferiv; +PFNGLCLEARBUFFERUIVPROC gl3wClearBufferuiv; +PFNGLCLEARBUFFERFVPROC gl3wClearBufferfv; +PFNGLCLEARBUFFERFIPROC gl3wClearBufferfi; +PFNGLGETSTRINGIPROC gl3wGetStringi; +PFNGLDRAWARRAYSINSTANCEDPROC gl3wDrawArraysInstanced; +PFNGLDRAWELEMENTSINSTANCEDPROC gl3wDrawElementsInstanced; +PFNGLTEXBUFFERPROC gl3wTexBuffer; +PFNGLPRIMITIVERESTARTINDEXPROC gl3wPrimitiveRestartIndex; +PFNGLGETINTEGER64I_VPROC gl3wGetInteger64i_v; +PFNGLGETBUFFERPARAMETERI64VPROC gl3wGetBufferParameteri64v; +PFNGLFRAMEBUFFERTEXTUREPROC gl3wFramebufferTexture; +PFNGLVERTEXATTRIBDIVISORPROC gl3wVertexAttribDivisor; +PFNGLMINSAMPLESHADINGPROC gl3wMinSampleShading; +PFNGLBLENDEQUATIONIPROC gl3wBlendEquationi; +PFNGLBLENDEQUATIONSEPARATEIPROC gl3wBlendEquationSeparatei; +PFNGLBLENDFUNCIPROC gl3wBlendFunci; +PFNGLBLENDFUNCSEPARATEIPROC gl3wBlendFuncSeparatei; +PFNGLISRENDERBUFFERPROC gl3wIsRenderbuffer; +PFNGLBINDRENDERBUFFERPROC gl3wBindRenderbuffer; +PFNGLDELETERENDERBUFFERSPROC gl3wDeleteRenderbuffers; +PFNGLGENRENDERBUFFERSPROC gl3wGenRenderbuffers; +PFNGLRENDERBUFFERSTORAGEPROC gl3wRenderbufferStorage; +PFNGLGETRENDERBUFFERPARAMETERIVPROC gl3wGetRenderbufferParameteriv; +PFNGLISFRAMEBUFFERPROC gl3wIsFramebuffer; +PFNGLBINDFRAMEBUFFERPROC gl3wBindFramebuffer; +PFNGLDELETEFRAMEBUFFERSPROC gl3wDeleteFramebuffers; +PFNGLGENFRAMEBUFFERSPROC gl3wGenFramebuffers; +PFNGLCHECKFRAMEBUFFERSTATUSPROC gl3wCheckFramebufferStatus; +PFNGLFRAMEBUFFERTEXTURE1DPROC gl3wFramebufferTexture1D; +PFNGLFRAMEBUFFERTEXTURE2DPROC gl3wFramebufferTexture2D; +PFNGLFRAMEBUFFERTEXTURE3DPROC gl3wFramebufferTexture3D; +PFNGLFRAMEBUFFERRENDERBUFFERPROC gl3wFramebufferRenderbuffer; +PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC gl3wGetFramebufferAttachmentParameteriv; +PFNGLGENERATEMIPMAPPROC gl3wGenerateMipmap; +PFNGLBLITFRAMEBUFFERPROC gl3wBlitFramebuffer; +PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC gl3wRenderbufferStorageMultisample; +PFNGLFRAMEBUFFERTEXTURELAYERPROC gl3wFramebufferTextureLayer; +PFNGLMAPBUFFERRANGEPROC gl3wMapBufferRange; +PFNGLFLUSHMAPPEDBUFFERRANGEPROC gl3wFlushMappedBufferRange; +PFNGLBINDVERTEXARRAYPROC gl3wBindVertexArray; +PFNGLDELETEVERTEXARRAYSPROC gl3wDeleteVertexArrays; +PFNGLGENVERTEXARRAYSPROC gl3wGenVertexArrays; +PFNGLISVERTEXARRAYPROC gl3wIsVertexArray; +PFNGLGETUNIFORMINDICESPROC gl3wGetUniformIndices; +PFNGLGETACTIVEUNIFORMSIVPROC gl3wGetActiveUniformsiv; +PFNGLGETACTIVEUNIFORMNAMEPROC gl3wGetActiveUniformName; +PFNGLGETUNIFORMBLOCKINDEXPROC gl3wGetUniformBlockIndex; +PFNGLGETACTIVEUNIFORMBLOCKIVPROC gl3wGetActiveUniformBlockiv; +PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC gl3wGetActiveUniformBlockName; +PFNGLUNIFORMBLOCKBINDINGPROC gl3wUniformBlockBinding; +PFNGLCOPYBUFFERSUBDATAPROC gl3wCopyBufferSubData; +PFNGLDRAWELEMENTSBASEVERTEXPROC gl3wDrawElementsBaseVertex; +PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC gl3wDrawRangeElementsBaseVertex; +PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC gl3wDrawElementsInstancedBaseVertex; +PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC gl3wMultiDrawElementsBaseVertex; +PFNGLPROVOKINGVERTEXPROC gl3wProvokingVertex; +PFNGLFENCESYNCPROC gl3wFenceSync; +PFNGLISSYNCPROC gl3wIsSync; +PFNGLDELETESYNCPROC gl3wDeleteSync; +PFNGLCLIENTWAITSYNCPROC gl3wClientWaitSync; +PFNGLWAITSYNCPROC gl3wWaitSync; +PFNGLGETINTEGER64VPROC gl3wGetInteger64v; +PFNGLGETSYNCIVPROC gl3wGetSynciv; +PFNGLTEXIMAGE2DMULTISAMPLEPROC gl3wTexImage2DMultisample; +PFNGLTEXIMAGE3DMULTISAMPLEPROC gl3wTexImage3DMultisample; +PFNGLGETMULTISAMPLEFVPROC gl3wGetMultisamplefv; +PFNGLSAMPLEMASKIPROC gl3wSampleMaski; +PFNGLBLENDEQUATIONIARBPROC gl3wBlendEquationiARB; +PFNGLBLENDEQUATIONSEPARATEIARBPROC gl3wBlendEquationSeparateiARB; +PFNGLBLENDFUNCIARBPROC gl3wBlendFunciARB; +PFNGLBLENDFUNCSEPARATEIARBPROC gl3wBlendFuncSeparateiARB; +PFNGLMINSAMPLESHADINGARBPROC gl3wMinSampleShadingARB; +PFNGLNAMEDSTRINGARBPROC gl3wNamedStringARB; +PFNGLDELETENAMEDSTRINGARBPROC gl3wDeleteNamedStringARB; +PFNGLCOMPILESHADERINCLUDEARBPROC gl3wCompileShaderIncludeARB; +PFNGLISNAMEDSTRINGARBPROC gl3wIsNamedStringARB; +PFNGLGETNAMEDSTRINGARBPROC gl3wGetNamedStringARB; +PFNGLGETNAMEDSTRINGIVARBPROC gl3wGetNamedStringivARB; +PFNGLBINDFRAGDATALOCATIONINDEXEDPROC gl3wBindFragDataLocationIndexed; +PFNGLGETFRAGDATAINDEXPROC gl3wGetFragDataIndex; +PFNGLGENSAMPLERSPROC gl3wGenSamplers; +PFNGLDELETESAMPLERSPROC gl3wDeleteSamplers; +PFNGLISSAMPLERPROC gl3wIsSampler; +PFNGLBINDSAMPLERPROC gl3wBindSampler; +PFNGLSAMPLERPARAMETERIPROC gl3wSamplerParameteri; +PFNGLSAMPLERPARAMETERIVPROC gl3wSamplerParameteriv; +PFNGLSAMPLERPARAMETERFPROC gl3wSamplerParameterf; +PFNGLSAMPLERPARAMETERFVPROC gl3wSamplerParameterfv; +PFNGLSAMPLERPARAMETERIIVPROC gl3wSamplerParameterIiv; +PFNGLSAMPLERPARAMETERIUIVPROC gl3wSamplerParameterIuiv; +PFNGLGETSAMPLERPARAMETERIVPROC gl3wGetSamplerParameteriv; +PFNGLGETSAMPLERPARAMETERIIVPROC gl3wGetSamplerParameterIiv; +PFNGLGETSAMPLERPARAMETERFVPROC gl3wGetSamplerParameterfv; +PFNGLGETSAMPLERPARAMETERIUIVPROC gl3wGetSamplerParameterIuiv; +PFNGLQUERYCOUNTERPROC gl3wQueryCounter; +PFNGLGETQUERYOBJECTI64VPROC gl3wGetQueryObjecti64v; +PFNGLGETQUERYOBJECTUI64VPROC gl3wGetQueryObjectui64v; +PFNGLVERTEXP2UIPROC gl3wVertexP2ui; +PFNGLVERTEXP2UIVPROC gl3wVertexP2uiv; +PFNGLVERTEXP3UIPROC gl3wVertexP3ui; +PFNGLVERTEXP3UIVPROC gl3wVertexP3uiv; +PFNGLVERTEXP4UIPROC gl3wVertexP4ui; +PFNGLVERTEXP4UIVPROC gl3wVertexP4uiv; +PFNGLTEXCOORDP1UIPROC gl3wTexCoordP1ui; +PFNGLTEXCOORDP1UIVPROC gl3wTexCoordP1uiv; +PFNGLTEXCOORDP2UIPROC gl3wTexCoordP2ui; +PFNGLTEXCOORDP2UIVPROC gl3wTexCoordP2uiv; +PFNGLTEXCOORDP3UIPROC gl3wTexCoordP3ui; +PFNGLTEXCOORDP3UIVPROC gl3wTexCoordP3uiv; +PFNGLTEXCOORDP4UIPROC gl3wTexCoordP4ui; +PFNGLTEXCOORDP4UIVPROC gl3wTexCoordP4uiv; +PFNGLMULTITEXCOORDP1UIPROC gl3wMultiTexCoordP1ui; +PFNGLMULTITEXCOORDP1UIVPROC gl3wMultiTexCoordP1uiv; +PFNGLMULTITEXCOORDP2UIPROC gl3wMultiTexCoordP2ui; +PFNGLMULTITEXCOORDP2UIVPROC gl3wMultiTexCoordP2uiv; +PFNGLMULTITEXCOORDP3UIPROC gl3wMultiTexCoordP3ui; +PFNGLMULTITEXCOORDP3UIVPROC gl3wMultiTexCoordP3uiv; +PFNGLMULTITEXCOORDP4UIPROC gl3wMultiTexCoordP4ui; +PFNGLMULTITEXCOORDP4UIVPROC gl3wMultiTexCoordP4uiv; +PFNGLNORMALP3UIPROC gl3wNormalP3ui; +PFNGLNORMALP3UIVPROC gl3wNormalP3uiv; +PFNGLCOLORP3UIPROC gl3wColorP3ui; +PFNGLCOLORP3UIVPROC gl3wColorP3uiv; +PFNGLCOLORP4UIPROC gl3wColorP4ui; +PFNGLCOLORP4UIVPROC gl3wColorP4uiv; +PFNGLSECONDARYCOLORP3UIPROC gl3wSecondaryColorP3ui; +PFNGLSECONDARYCOLORP3UIVPROC gl3wSecondaryColorP3uiv; +PFNGLVERTEXATTRIBP1UIPROC gl3wVertexAttribP1ui; +PFNGLVERTEXATTRIBP1UIVPROC gl3wVertexAttribP1uiv; +PFNGLVERTEXATTRIBP2UIPROC gl3wVertexAttribP2ui; +PFNGLVERTEXATTRIBP2UIVPROC gl3wVertexAttribP2uiv; +PFNGLVERTEXATTRIBP3UIPROC gl3wVertexAttribP3ui; +PFNGLVERTEXATTRIBP3UIVPROC gl3wVertexAttribP3uiv; +PFNGLVERTEXATTRIBP4UIPROC gl3wVertexAttribP4ui; +PFNGLVERTEXATTRIBP4UIVPROC gl3wVertexAttribP4uiv; +PFNGLDRAWARRAYSINDIRECTPROC gl3wDrawArraysIndirect; +PFNGLDRAWELEMENTSINDIRECTPROC gl3wDrawElementsIndirect; +PFNGLUNIFORM1DPROC gl3wUniform1d; +PFNGLUNIFORM2DPROC gl3wUniform2d; +PFNGLUNIFORM3DPROC gl3wUniform3d; +PFNGLUNIFORM4DPROC gl3wUniform4d; +PFNGLUNIFORM1DVPROC gl3wUniform1dv; +PFNGLUNIFORM2DVPROC gl3wUniform2dv; +PFNGLUNIFORM3DVPROC gl3wUniform3dv; +PFNGLUNIFORM4DVPROC gl3wUniform4dv; +PFNGLUNIFORMMATRIX2DVPROC gl3wUniformMatrix2dv; +PFNGLUNIFORMMATRIX3DVPROC gl3wUniformMatrix3dv; +PFNGLUNIFORMMATRIX4DVPROC gl3wUniformMatrix4dv; +PFNGLUNIFORMMATRIX2X3DVPROC gl3wUniformMatrix2x3dv; +PFNGLUNIFORMMATRIX2X4DVPROC gl3wUniformMatrix2x4dv; +PFNGLUNIFORMMATRIX3X2DVPROC gl3wUniformMatrix3x2dv; +PFNGLUNIFORMMATRIX3X4DVPROC gl3wUniformMatrix3x4dv; +PFNGLUNIFORMMATRIX4X2DVPROC gl3wUniformMatrix4x2dv; +PFNGLUNIFORMMATRIX4X3DVPROC gl3wUniformMatrix4x3dv; +PFNGLGETUNIFORMDVPROC gl3wGetUniformdv; +PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC gl3wGetSubroutineUniformLocation; +PFNGLGETSUBROUTINEINDEXPROC gl3wGetSubroutineIndex; +PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC gl3wGetActiveSubroutineUniformiv; +PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC gl3wGetActiveSubroutineUniformName; +PFNGLGETACTIVESUBROUTINENAMEPROC gl3wGetActiveSubroutineName; +PFNGLUNIFORMSUBROUTINESUIVPROC gl3wUniformSubroutinesuiv; +PFNGLGETUNIFORMSUBROUTINEUIVPROC gl3wGetUniformSubroutineuiv; +PFNGLGETPROGRAMSTAGEIVPROC gl3wGetProgramStageiv; +PFNGLPATCHPARAMETERIPROC gl3wPatchParameteri; +PFNGLPATCHPARAMETERFVPROC gl3wPatchParameterfv; +PFNGLBINDTRANSFORMFEEDBACKPROC gl3wBindTransformFeedback; +PFNGLDELETETRANSFORMFEEDBACKSPROC gl3wDeleteTransformFeedbacks; +PFNGLGENTRANSFORMFEEDBACKSPROC gl3wGenTransformFeedbacks; +PFNGLISTRANSFORMFEEDBACKPROC gl3wIsTransformFeedback; +PFNGLPAUSETRANSFORMFEEDBACKPROC gl3wPauseTransformFeedback; +PFNGLRESUMETRANSFORMFEEDBACKPROC gl3wResumeTransformFeedback; +PFNGLDRAWTRANSFORMFEEDBACKPROC gl3wDrawTransformFeedback; +PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC gl3wDrawTransformFeedbackStream; +PFNGLBEGINQUERYINDEXEDPROC gl3wBeginQueryIndexed; +PFNGLENDQUERYINDEXEDPROC gl3wEndQueryIndexed; +PFNGLGETQUERYINDEXEDIVPROC gl3wGetQueryIndexediv; +PFNGLRELEASESHADERCOMPILERPROC gl3wReleaseShaderCompiler; +PFNGLSHADERBINARYPROC gl3wShaderBinary; +PFNGLGETSHADERPRECISIONFORMATPROC gl3wGetShaderPrecisionFormat; +PFNGLDEPTHRANGEFPROC gl3wDepthRangef; +PFNGLCLEARDEPTHFPROC gl3wClearDepthf; +PFNGLGETPROGRAMBINARYPROC gl3wGetProgramBinary; +PFNGLPROGRAMBINARYPROC gl3wProgramBinary; +PFNGLPROGRAMPARAMETERIPROC gl3wProgramParameteri; +PFNGLUSEPROGRAMSTAGESPROC gl3wUseProgramStages; +PFNGLACTIVESHADERPROGRAMPROC gl3wActiveShaderProgram; +PFNGLCREATESHADERPROGRAMVPROC gl3wCreateShaderProgramv; +PFNGLBINDPROGRAMPIPELINEPROC gl3wBindProgramPipeline; +PFNGLDELETEPROGRAMPIPELINESPROC gl3wDeleteProgramPipelines; +PFNGLGENPROGRAMPIPELINESPROC gl3wGenProgramPipelines; +PFNGLISPROGRAMPIPELINEPROC gl3wIsProgramPipeline; +PFNGLGETPROGRAMPIPELINEIVPROC gl3wGetProgramPipelineiv; +PFNGLPROGRAMUNIFORM1IPROC gl3wProgramUniform1i; +PFNGLPROGRAMUNIFORM1IVPROC gl3wProgramUniform1iv; +PFNGLPROGRAMUNIFORM1FPROC gl3wProgramUniform1f; +PFNGLPROGRAMUNIFORM1FVPROC gl3wProgramUniform1fv; +PFNGLPROGRAMUNIFORM1DPROC gl3wProgramUniform1d; +PFNGLPROGRAMUNIFORM1DVPROC gl3wProgramUniform1dv; +PFNGLPROGRAMUNIFORM1UIPROC gl3wProgramUniform1ui; +PFNGLPROGRAMUNIFORM1UIVPROC gl3wProgramUniform1uiv; +PFNGLPROGRAMUNIFORM2IPROC gl3wProgramUniform2i; +PFNGLPROGRAMUNIFORM2IVPROC gl3wProgramUniform2iv; +PFNGLPROGRAMUNIFORM2FPROC gl3wProgramUniform2f; +PFNGLPROGRAMUNIFORM2FVPROC gl3wProgramUniform2fv; +PFNGLPROGRAMUNIFORM2DPROC gl3wProgramUniform2d; +PFNGLPROGRAMUNIFORM2DVPROC gl3wProgramUniform2dv; +PFNGLPROGRAMUNIFORM2UIPROC gl3wProgramUniform2ui; +PFNGLPROGRAMUNIFORM2UIVPROC gl3wProgramUniform2uiv; +PFNGLPROGRAMUNIFORM3IPROC gl3wProgramUniform3i; +PFNGLPROGRAMUNIFORM3IVPROC gl3wProgramUniform3iv; +PFNGLPROGRAMUNIFORM3FPROC gl3wProgramUniform3f; +PFNGLPROGRAMUNIFORM3FVPROC gl3wProgramUniform3fv; +PFNGLPROGRAMUNIFORM3DPROC gl3wProgramUniform3d; +PFNGLPROGRAMUNIFORM3DVPROC gl3wProgramUniform3dv; +PFNGLPROGRAMUNIFORM3UIPROC gl3wProgramUniform3ui; +PFNGLPROGRAMUNIFORM3UIVPROC gl3wProgramUniform3uiv; +PFNGLPROGRAMUNIFORM4IPROC gl3wProgramUniform4i; +PFNGLPROGRAMUNIFORM4IVPROC gl3wProgramUniform4iv; +PFNGLPROGRAMUNIFORM4FPROC gl3wProgramUniform4f; +PFNGLPROGRAMUNIFORM4FVPROC gl3wProgramUniform4fv; +PFNGLPROGRAMUNIFORM4DPROC gl3wProgramUniform4d; +PFNGLPROGRAMUNIFORM4DVPROC gl3wProgramUniform4dv; +PFNGLPROGRAMUNIFORM4UIPROC gl3wProgramUniform4ui; +PFNGLPROGRAMUNIFORM4UIVPROC gl3wProgramUniform4uiv; +PFNGLPROGRAMUNIFORMMATRIX2FVPROC gl3wProgramUniformMatrix2fv; +PFNGLPROGRAMUNIFORMMATRIX3FVPROC gl3wProgramUniformMatrix3fv; +PFNGLPROGRAMUNIFORMMATRIX4FVPROC gl3wProgramUniformMatrix4fv; +PFNGLPROGRAMUNIFORMMATRIX2DVPROC gl3wProgramUniformMatrix2dv; +PFNGLPROGRAMUNIFORMMATRIX3DVPROC gl3wProgramUniformMatrix3dv; +PFNGLPROGRAMUNIFORMMATRIX4DVPROC gl3wProgramUniformMatrix4dv; +PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC gl3wProgramUniformMatrix2x3fv; +PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC gl3wProgramUniformMatrix3x2fv; +PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC gl3wProgramUniformMatrix2x4fv; +PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC gl3wProgramUniformMatrix4x2fv; +PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC gl3wProgramUniformMatrix3x4fv; +PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC gl3wProgramUniformMatrix4x3fv; +PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC gl3wProgramUniformMatrix2x3dv; +PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC gl3wProgramUniformMatrix3x2dv; +PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC gl3wProgramUniformMatrix2x4dv; +PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC gl3wProgramUniformMatrix4x2dv; +PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC gl3wProgramUniformMatrix3x4dv; +PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC gl3wProgramUniformMatrix4x3dv; +PFNGLVALIDATEPROGRAMPIPELINEPROC gl3wValidateProgramPipeline; +PFNGLGETPROGRAMPIPELINEINFOLOGPROC gl3wGetProgramPipelineInfoLog; +PFNGLVERTEXATTRIBL1DPROC gl3wVertexAttribL1d; +PFNGLVERTEXATTRIBL2DPROC gl3wVertexAttribL2d; +PFNGLVERTEXATTRIBL3DPROC gl3wVertexAttribL3d; +PFNGLVERTEXATTRIBL4DPROC gl3wVertexAttribL4d; +PFNGLVERTEXATTRIBL1DVPROC gl3wVertexAttribL1dv; +PFNGLVERTEXATTRIBL2DVPROC gl3wVertexAttribL2dv; +PFNGLVERTEXATTRIBL3DVPROC gl3wVertexAttribL3dv; +PFNGLVERTEXATTRIBL4DVPROC gl3wVertexAttribL4dv; +PFNGLVERTEXATTRIBLPOINTERPROC gl3wVertexAttribLPointer; +PFNGLGETVERTEXATTRIBLDVPROC gl3wGetVertexAttribLdv; +PFNGLVIEWPORTARRAYVPROC gl3wViewportArrayv; +PFNGLVIEWPORTINDEXEDFPROC gl3wViewportIndexedf; +PFNGLVIEWPORTINDEXEDFVPROC gl3wViewportIndexedfv; +PFNGLSCISSORARRAYVPROC gl3wScissorArrayv; +PFNGLSCISSORINDEXEDPROC gl3wScissorIndexed; +PFNGLSCISSORINDEXEDVPROC gl3wScissorIndexedv; +PFNGLDEPTHRANGEARRAYVPROC gl3wDepthRangeArrayv; +PFNGLDEPTHRANGEINDEXEDPROC gl3wDepthRangeIndexed; +PFNGLGETFLOATI_VPROC gl3wGetFloati_v; +PFNGLGETDOUBLEI_VPROC gl3wGetDoublei_v; +PFNGLCREATESYNCFROMCLEVENTARBPROC gl3wCreateSyncFromCLeventARB; +PFNGLDEBUGMESSAGECONTROLARBPROC gl3wDebugMessageControlARB; +PFNGLDEBUGMESSAGEINSERTARBPROC gl3wDebugMessageInsertARB; +PFNGLDEBUGMESSAGECALLBACKARBPROC gl3wDebugMessageCallbackARB; +PFNGLGETDEBUGMESSAGELOGARBPROC gl3wGetDebugMessageLogARB; +PFNGLGETGRAPHICSRESETSTATUSARBPROC gl3wGetGraphicsResetStatusARB; +PFNGLGETNTEXIMAGEARBPROC gl3wGetnTexImageARB; +PFNGLREADNPIXELSARBPROC gl3wReadnPixelsARB; +PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC gl3wGetnCompressedTexImageARB; +PFNGLGETNUNIFORMFVARBPROC gl3wGetnUniformfvARB; +PFNGLGETNUNIFORMIVARBPROC gl3wGetnUniformivARB; +PFNGLGETNUNIFORMUIVARBPROC gl3wGetnUniformuivARB; +PFNGLGETNUNIFORMDVARBPROC gl3wGetnUniformdvARB; +PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC gl3wDrawArraysInstancedBaseInstance; +PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC gl3wDrawElementsInstancedBaseInstance; +PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC gl3wDrawElementsInstancedBaseVertexBaseInstance; +PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC gl3wDrawTransformFeedbackInstanced; +PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC gl3wDrawTransformFeedbackStreamInstanced; +PFNGLGETINTERNALFORMATIVPROC gl3wGetInternalformativ; +PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC gl3wGetActiveAtomicCounterBufferiv; +PFNGLBINDIMAGETEXTUREPROC gl3wBindImageTexture; +PFNGLMEMORYBARRIERPROC gl3wMemoryBarrier; +PFNGLTEXSTORAGE1DPROC gl3wTexStorage1D; +PFNGLTEXSTORAGE2DPROC gl3wTexStorage2D; +PFNGLTEXSTORAGE3DPROC gl3wTexStorage3D; +PFNGLTEXTURESTORAGE1DEXTPROC gl3wTextureStorage1DEXT; +PFNGLTEXTURESTORAGE2DEXTPROC gl3wTextureStorage2DEXT; +PFNGLTEXTURESTORAGE3DEXTPROC gl3wTextureStorage3DEXT; +PFNGLDEBUGMESSAGECONTROLPROC gl3wDebugMessageControl; +PFNGLDEBUGMESSAGEINSERTPROC gl3wDebugMessageInsert; +PFNGLDEBUGMESSAGECALLBACKPROC gl3wDebugMessageCallback; +PFNGLGETDEBUGMESSAGELOGPROC gl3wGetDebugMessageLog; +PFNGLPUSHDEBUGGROUPPROC gl3wPushDebugGroup; +PFNGLPOPDEBUGGROUPPROC gl3wPopDebugGroup; +PFNGLOBJECTLABELPROC gl3wObjectLabel; +PFNGLGETOBJECTLABELPROC gl3wGetObjectLabel; +PFNGLOBJECTPTRLABELPROC gl3wObjectPtrLabel; +PFNGLGETOBJECTPTRLABELPROC gl3wGetObjectPtrLabel; +PFNGLCLEARBUFFERDATAPROC gl3wClearBufferData; +PFNGLCLEARBUFFERSUBDATAPROC gl3wClearBufferSubData; +PFNGLCLEARNAMEDBUFFERDATAEXTPROC gl3wClearNamedBufferDataEXT; +PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC gl3wClearNamedBufferSubDataEXT; +PFNGLDISPATCHCOMPUTEPROC gl3wDispatchCompute; +PFNGLDISPATCHCOMPUTEINDIRECTPROC gl3wDispatchComputeIndirect; +PFNGLCOPYIMAGESUBDATAPROC gl3wCopyImageSubData; +PFNGLTEXTUREVIEWPROC gl3wTextureView; +PFNGLBINDVERTEXBUFFERPROC gl3wBindVertexBuffer; +PFNGLVERTEXATTRIBFORMATPROC gl3wVertexAttribFormat; +PFNGLVERTEXATTRIBIFORMATPROC gl3wVertexAttribIFormat; +PFNGLVERTEXATTRIBLFORMATPROC gl3wVertexAttribLFormat; +PFNGLVERTEXATTRIBBINDINGPROC gl3wVertexAttribBinding; +PFNGLVERTEXBINDINGDIVISORPROC gl3wVertexBindingDivisor; +PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC gl3wVertexArrayBindVertexBufferEXT; +PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC gl3wVertexArrayVertexAttribFormatEXT; +PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC gl3wVertexArrayVertexAttribIFormatEXT; +PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC gl3wVertexArrayVertexAttribLFormatEXT; +PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC gl3wVertexArrayVertexAttribBindingEXT; +PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC gl3wVertexArrayVertexBindingDivisorEXT; +PFNGLFRAMEBUFFERPARAMETERIPROC gl3wFramebufferParameteri; +PFNGLGETFRAMEBUFFERPARAMETERIVPROC gl3wGetFramebufferParameteriv; +PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC gl3wNamedFramebufferParameteriEXT; +PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC gl3wGetNamedFramebufferParameterivEXT; +PFNGLGETINTERNALFORMATI64VPROC gl3wGetInternalformati64v; +PFNGLINVALIDATETEXSUBIMAGEPROC gl3wInvalidateTexSubImage; +PFNGLINVALIDATETEXIMAGEPROC gl3wInvalidateTexImage; +PFNGLINVALIDATEBUFFERSUBDATAPROC gl3wInvalidateBufferSubData; +PFNGLINVALIDATEBUFFERDATAPROC gl3wInvalidateBufferData; +PFNGLINVALIDATEFRAMEBUFFERPROC gl3wInvalidateFramebuffer; +PFNGLINVALIDATESUBFRAMEBUFFERPROC gl3wInvalidateSubFramebuffer; +PFNGLMULTIDRAWARRAYSINDIRECTPROC gl3wMultiDrawArraysIndirect; +PFNGLMULTIDRAWELEMENTSINDIRECTPROC gl3wMultiDrawElementsIndirect; +PFNGLGETPROGRAMINTERFACEIVPROC gl3wGetProgramInterfaceiv; +PFNGLGETPROGRAMRESOURCEINDEXPROC gl3wGetProgramResourceIndex; +PFNGLGETPROGRAMRESOURCENAMEPROC gl3wGetProgramResourceName; +PFNGLGETPROGRAMRESOURCEIVPROC gl3wGetProgramResourceiv; +PFNGLGETPROGRAMRESOURCELOCATIONPROC gl3wGetProgramResourceLocation; +PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC gl3wGetProgramResourceLocationIndex; +PFNGLSHADERSTORAGEBLOCKBINDINGPROC gl3wShaderStorageBlockBinding; +PFNGLTEXBUFFERRANGEPROC gl3wTexBufferRange; +PFNGLTEXTUREBUFFERRANGEEXTPROC gl3wTextureBufferRangeEXT; +PFNGLTEXSTORAGE2DMULTISAMPLEPROC gl3wTexStorage2DMultisample; +PFNGLTEXSTORAGE3DMULTISAMPLEPROC gl3wTexStorage3DMultisample; +PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC gl3wTextureStorage2DMultisampleEXT; +PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC gl3wTextureStorage3DMultisampleEXT; + +static void load_procs(void) +{ + gl3wCullFace = (PFNGLCULLFACEPROC) get_proc("glCullFace"); + gl3wFrontFace = (PFNGLFRONTFACEPROC) get_proc("glFrontFace"); + gl3wHint = (PFNGLHINTPROC) get_proc("glHint"); + gl3wLineWidth = (PFNGLLINEWIDTHPROC) get_proc("glLineWidth"); + gl3wPointSize = (PFNGLPOINTSIZEPROC) get_proc("glPointSize"); + gl3wPolygonMode = (PFNGLPOLYGONMODEPROC) get_proc("glPolygonMode"); + gl3wScissor = (PFNGLSCISSORPROC) get_proc("glScissor"); + gl3wTexParameterf = (PFNGLTEXPARAMETERFPROC) get_proc("glTexParameterf"); + gl3wTexParameterfv = (PFNGLTEXPARAMETERFVPROC) get_proc("glTexParameterfv"); + gl3wTexParameteri = (PFNGLTEXPARAMETERIPROC) get_proc("glTexParameteri"); + gl3wTexParameteriv = (PFNGLTEXPARAMETERIVPROC) get_proc("glTexParameteriv"); + gl3wTexImage1D = (PFNGLTEXIMAGE1DPROC) get_proc("glTexImage1D"); + gl3wTexImage2D = (PFNGLTEXIMAGE2DPROC) get_proc("glTexImage2D"); + gl3wDrawBuffer = (PFNGLDRAWBUFFERPROC) get_proc("glDrawBuffer"); + gl3wClear = (PFNGLCLEARPROC) get_proc("glClear"); + gl3wClearColor = (PFNGLCLEARCOLORPROC) get_proc("glClearColor"); + gl3wClearStencil = (PFNGLCLEARSTENCILPROC) get_proc("glClearStencil"); + gl3wClearDepth = (PFNGLCLEARDEPTHPROC) get_proc("glClearDepth"); + gl3wStencilMask = (PFNGLSTENCILMASKPROC) get_proc("glStencilMask"); + gl3wColorMask = (PFNGLCOLORMASKPROC) get_proc("glColorMask"); + gl3wDepthMask = (PFNGLDEPTHMASKPROC) get_proc("glDepthMask"); + gl3wDisable = (PFNGLDISABLEPROC) get_proc("glDisable"); + gl3wEnable = (PFNGLENABLEPROC) get_proc("glEnable"); + gl3wFinish = (PFNGLFINISHPROC) get_proc("glFinish"); + gl3wFlush = (PFNGLFLUSHPROC) get_proc("glFlush"); + gl3wBlendFunc = (PFNGLBLENDFUNCPROC) get_proc("glBlendFunc"); + gl3wLogicOp = (PFNGLLOGICOPPROC) get_proc("glLogicOp"); + gl3wStencilFunc = (PFNGLSTENCILFUNCPROC) get_proc("glStencilFunc"); + gl3wStencilOp = (PFNGLSTENCILOPPROC) get_proc("glStencilOp"); + gl3wDepthFunc = (PFNGLDEPTHFUNCPROC) get_proc("glDepthFunc"); + gl3wPixelStoref = (PFNGLPIXELSTOREFPROC) get_proc("glPixelStoref"); + gl3wPixelStorei = (PFNGLPIXELSTOREIPROC) get_proc("glPixelStorei"); + gl3wReadBuffer = (PFNGLREADBUFFERPROC) get_proc("glReadBuffer"); + gl3wReadPixels = (PFNGLREADPIXELSPROC) get_proc("glReadPixels"); + gl3wGetBooleanv = (PFNGLGETBOOLEANVPROC) get_proc("glGetBooleanv"); + gl3wGetDoublev = (PFNGLGETDOUBLEVPROC) get_proc("glGetDoublev"); + gl3wGetError = (PFNGLGETERRORPROC) get_proc("glGetError"); + gl3wGetFloatv = (PFNGLGETFLOATVPROC) get_proc("glGetFloatv"); + gl3wGetIntegerv = (PFNGLGETINTEGERVPROC) get_proc("glGetIntegerv"); + gl3wGetString = (PFNGLGETSTRINGPROC) get_proc("glGetString"); + gl3wGetTexImage = (PFNGLGETTEXIMAGEPROC) get_proc("glGetTexImage"); + gl3wGetTexParameterfv = (PFNGLGETTEXPARAMETERFVPROC) get_proc("glGetTexParameterfv"); + gl3wGetTexParameteriv = (PFNGLGETTEXPARAMETERIVPROC) get_proc("glGetTexParameteriv"); + gl3wGetTexLevelParameterfv = (PFNGLGETTEXLEVELPARAMETERFVPROC) get_proc("glGetTexLevelParameterfv"); + gl3wGetTexLevelParameteriv = (PFNGLGETTEXLEVELPARAMETERIVPROC) get_proc("glGetTexLevelParameteriv"); + gl3wIsEnabled = (PFNGLISENABLEDPROC) get_proc("glIsEnabled"); + gl3wDepthRange = (PFNGLDEPTHRANGEPROC) get_proc("glDepthRange"); + gl3wViewport = (PFNGLVIEWPORTPROC) get_proc("glViewport"); + gl3wDrawArrays = (PFNGLDRAWARRAYSPROC) get_proc("glDrawArrays"); + gl3wDrawElements = (PFNGLDRAWELEMENTSPROC) get_proc("glDrawElements"); + gl3wGetPointerv = (PFNGLGETPOINTERVPROC) get_proc("glGetPointerv"); + gl3wPolygonOffset = (PFNGLPOLYGONOFFSETPROC) get_proc("glPolygonOffset"); + gl3wCopyTexImage1D = (PFNGLCOPYTEXIMAGE1DPROC) get_proc("glCopyTexImage1D"); + gl3wCopyTexImage2D = (PFNGLCOPYTEXIMAGE2DPROC) get_proc("glCopyTexImage2D"); + gl3wCopyTexSubImage1D = (PFNGLCOPYTEXSUBIMAGE1DPROC) get_proc("glCopyTexSubImage1D"); + gl3wCopyTexSubImage2D = (PFNGLCOPYTEXSUBIMAGE2DPROC) get_proc("glCopyTexSubImage2D"); + gl3wTexSubImage1D = (PFNGLTEXSUBIMAGE1DPROC) get_proc("glTexSubImage1D"); + gl3wTexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC) get_proc("glTexSubImage2D"); + gl3wBindTexture = (PFNGLBINDTEXTUREPROC) get_proc("glBindTexture"); + gl3wDeleteTextures = (PFNGLDELETETEXTURESPROC) get_proc("glDeleteTextures"); + gl3wGenTextures = (PFNGLGENTEXTURESPROC) get_proc("glGenTextures"); + gl3wIsTexture = (PFNGLISTEXTUREPROC) get_proc("glIsTexture"); + gl3wBlendColor = (PFNGLBLENDCOLORPROC) get_proc("glBlendColor"); + gl3wBlendEquation = (PFNGLBLENDEQUATIONPROC) get_proc("glBlendEquation"); + gl3wDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) get_proc("glDrawRangeElements"); + gl3wTexImage3D = (PFNGLTEXIMAGE3DPROC) get_proc("glTexImage3D"); + gl3wTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) get_proc("glTexSubImage3D"); + gl3wCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC) get_proc("glCopyTexSubImage3D"); + gl3wActiveTexture = (PFNGLACTIVETEXTUREPROC) get_proc("glActiveTexture"); + gl3wSampleCoverage = (PFNGLSAMPLECOVERAGEPROC) get_proc("glSampleCoverage"); + gl3wCompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC) get_proc("glCompressedTexImage3D"); + gl3wCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) get_proc("glCompressedTexImage2D"); + gl3wCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC) get_proc("glCompressedTexImage1D"); + gl3wCompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) get_proc("glCompressedTexSubImage3D"); + gl3wCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) get_proc("glCompressedTexSubImage2D"); + gl3wCompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) get_proc("glCompressedTexSubImage1D"); + gl3wGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC) get_proc("glGetCompressedTexImage"); + gl3wBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC) get_proc("glBlendFuncSeparate"); + gl3wMultiDrawArrays = (PFNGLMULTIDRAWARRAYSPROC) get_proc("glMultiDrawArrays"); + gl3wMultiDrawElements = (PFNGLMULTIDRAWELEMENTSPROC) get_proc("glMultiDrawElements"); + gl3wPointParameterf = (PFNGLPOINTPARAMETERFPROC) get_proc("glPointParameterf"); + gl3wPointParameterfv = (PFNGLPOINTPARAMETERFVPROC) get_proc("glPointParameterfv"); + gl3wPointParameteri = (PFNGLPOINTPARAMETERIPROC) get_proc("glPointParameteri"); + gl3wPointParameteriv = (PFNGLPOINTPARAMETERIVPROC) get_proc("glPointParameteriv"); + gl3wGenQueries = (PFNGLGENQUERIESPROC) get_proc("glGenQueries"); + gl3wDeleteQueries = (PFNGLDELETEQUERIESPROC) get_proc("glDeleteQueries"); + gl3wIsQuery = (PFNGLISQUERYPROC) get_proc("glIsQuery"); + gl3wBeginQuery = (PFNGLBEGINQUERYPROC) get_proc("glBeginQuery"); + gl3wEndQuery = (PFNGLENDQUERYPROC) get_proc("glEndQuery"); + gl3wGetQueryiv = (PFNGLGETQUERYIVPROC) get_proc("glGetQueryiv"); + gl3wGetQueryObjectiv = (PFNGLGETQUERYOBJECTIVPROC) get_proc("glGetQueryObjectiv"); + gl3wGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC) get_proc("glGetQueryObjectuiv"); + gl3wBindBuffer = (PFNGLBINDBUFFERPROC) get_proc("glBindBuffer"); + gl3wDeleteBuffers = (PFNGLDELETEBUFFERSPROC) get_proc("glDeleteBuffers"); + gl3wGenBuffers = (PFNGLGENBUFFERSPROC) get_proc("glGenBuffers"); + gl3wIsBuffer = (PFNGLISBUFFERPROC) get_proc("glIsBuffer"); + gl3wBufferData = (PFNGLBUFFERDATAPROC) get_proc("glBufferData"); + gl3wBufferSubData = (PFNGLBUFFERSUBDATAPROC) get_proc("glBufferSubData"); + gl3wGetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC) get_proc("glGetBufferSubData"); + gl3wMapBuffer = (PFNGLMAPBUFFERPROC) get_proc("glMapBuffer"); + gl3wUnmapBuffer = (PFNGLUNMAPBUFFERPROC) get_proc("glUnmapBuffer"); + gl3wGetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVPROC) get_proc("glGetBufferParameteriv"); + gl3wGetBufferPointerv = (PFNGLGETBUFFERPOINTERVPROC) get_proc("glGetBufferPointerv"); + gl3wBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC) get_proc("glBlendEquationSeparate"); + gl3wDrawBuffers = (PFNGLDRAWBUFFERSPROC) get_proc("glDrawBuffers"); + gl3wStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC) get_proc("glStencilOpSeparate"); + gl3wStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC) get_proc("glStencilFuncSeparate"); + gl3wStencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC) get_proc("glStencilMaskSeparate"); + gl3wAttachShader = (PFNGLATTACHSHADERPROC) get_proc("glAttachShader"); + gl3wBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) get_proc("glBindAttribLocation"); + gl3wCompileShader = (PFNGLCOMPILESHADERPROC) get_proc("glCompileShader"); + gl3wCreateProgram = (PFNGLCREATEPROGRAMPROC) get_proc("glCreateProgram"); + gl3wCreateShader = (PFNGLCREATESHADERPROC) get_proc("glCreateShader"); + gl3wDeleteProgram = (PFNGLDELETEPROGRAMPROC) get_proc("glDeleteProgram"); + gl3wDeleteShader = (PFNGLDELETESHADERPROC) get_proc("glDeleteShader"); + gl3wDetachShader = (PFNGLDETACHSHADERPROC) get_proc("glDetachShader"); + gl3wDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) get_proc("glDisableVertexAttribArray"); + gl3wEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) get_proc("glEnableVertexAttribArray"); + gl3wGetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC) get_proc("glGetActiveAttrib"); + gl3wGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC) get_proc("glGetActiveUniform"); + gl3wGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC) get_proc("glGetAttachedShaders"); + gl3wGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC) get_proc("glGetAttribLocation"); + gl3wGetProgramiv = (PFNGLGETPROGRAMIVPROC) get_proc("glGetProgramiv"); + gl3wGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) get_proc("glGetProgramInfoLog"); + gl3wGetShaderiv = (PFNGLGETSHADERIVPROC) get_proc("glGetShaderiv"); + gl3wGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) get_proc("glGetShaderInfoLog"); + gl3wGetShaderSource = (PFNGLGETSHADERSOURCEPROC) get_proc("glGetShaderSource"); + gl3wGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) get_proc("glGetUniformLocation"); + gl3wGetUniformfv = (PFNGLGETUNIFORMFVPROC) get_proc("glGetUniformfv"); + gl3wGetUniformiv = (PFNGLGETUNIFORMIVPROC) get_proc("glGetUniformiv"); + gl3wGetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC) get_proc("glGetVertexAttribdv"); + gl3wGetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC) get_proc("glGetVertexAttribfv"); + gl3wGetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC) get_proc("glGetVertexAttribiv"); + gl3wGetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC) get_proc("glGetVertexAttribPointerv"); + gl3wIsProgram = (PFNGLISPROGRAMPROC) get_proc("glIsProgram"); + gl3wIsShader = (PFNGLISSHADERPROC) get_proc("glIsShader"); + gl3wLinkProgram = (PFNGLLINKPROGRAMPROC) get_proc("glLinkProgram"); + gl3wShaderSource = (PFNGLSHADERSOURCEPROC) get_proc("glShaderSource"); + gl3wUseProgram = (PFNGLUSEPROGRAMPROC) get_proc("glUseProgram"); + gl3wUniform1f = (PFNGLUNIFORM1FPROC) get_proc("glUniform1f"); + gl3wUniform2f = (PFNGLUNIFORM2FPROC) get_proc("glUniform2f"); + gl3wUniform3f = (PFNGLUNIFORM3FPROC) get_proc("glUniform3f"); + gl3wUniform4f = (PFNGLUNIFORM4FPROC) get_proc("glUniform4f"); + gl3wUniform1i = (PFNGLUNIFORM1IPROC) get_proc("glUniform1i"); + gl3wUniform2i = (PFNGLUNIFORM2IPROC) get_proc("glUniform2i"); + gl3wUniform3i = (PFNGLUNIFORM3IPROC) get_proc("glUniform3i"); + gl3wUniform4i = (PFNGLUNIFORM4IPROC) get_proc("glUniform4i"); + gl3wUniform1fv = (PFNGLUNIFORM1FVPROC) get_proc("glUniform1fv"); + gl3wUniform2fv = (PFNGLUNIFORM2FVPROC) get_proc("glUniform2fv"); + gl3wUniform3fv = (PFNGLUNIFORM3FVPROC) get_proc("glUniform3fv"); + gl3wUniform4fv = (PFNGLUNIFORM4FVPROC) get_proc("glUniform4fv"); + gl3wUniform1iv = (PFNGLUNIFORM1IVPROC) get_proc("glUniform1iv"); + gl3wUniform2iv = (PFNGLUNIFORM2IVPROC) get_proc("glUniform2iv"); + gl3wUniform3iv = (PFNGLUNIFORM3IVPROC) get_proc("glUniform3iv"); + gl3wUniform4iv = (PFNGLUNIFORM4IVPROC) get_proc("glUniform4iv"); + gl3wUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC) get_proc("glUniformMatrix2fv"); + gl3wUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC) get_proc("glUniformMatrix3fv"); + gl3wUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) get_proc("glUniformMatrix4fv"); + gl3wValidateProgram = (PFNGLVALIDATEPROGRAMPROC) get_proc("glValidateProgram"); + gl3wVertexAttrib1d = (PFNGLVERTEXATTRIB1DPROC) get_proc("glVertexAttrib1d"); + gl3wVertexAttrib1dv = (PFNGLVERTEXATTRIB1DVPROC) get_proc("glVertexAttrib1dv"); + gl3wVertexAttrib1f = (PFNGLVERTEXATTRIB1FPROC) get_proc("glVertexAttrib1f"); + gl3wVertexAttrib1fv = (PFNGLVERTEXATTRIB1FVPROC) get_proc("glVertexAttrib1fv"); + gl3wVertexAttrib1s = (PFNGLVERTEXATTRIB1SPROC) get_proc("glVertexAttrib1s"); + gl3wVertexAttrib1sv = (PFNGLVERTEXATTRIB1SVPROC) get_proc("glVertexAttrib1sv"); + gl3wVertexAttrib2d = (PFNGLVERTEXATTRIB2DPROC) get_proc("glVertexAttrib2d"); + gl3wVertexAttrib2dv = (PFNGLVERTEXATTRIB2DVPROC) get_proc("glVertexAttrib2dv"); + gl3wVertexAttrib2f = (PFNGLVERTEXATTRIB2FPROC) get_proc("glVertexAttrib2f"); + gl3wVertexAttrib2fv = (PFNGLVERTEXATTRIB2FVPROC) get_proc("glVertexAttrib2fv"); + gl3wVertexAttrib2s = (PFNGLVERTEXATTRIB2SPROC) get_proc("glVertexAttrib2s"); + gl3wVertexAttrib2sv = (PFNGLVERTEXATTRIB2SVPROC) get_proc("glVertexAttrib2sv"); + gl3wVertexAttrib3d = (PFNGLVERTEXATTRIB3DPROC) get_proc("glVertexAttrib3d"); + gl3wVertexAttrib3dv = (PFNGLVERTEXATTRIB3DVPROC) get_proc("glVertexAttrib3dv"); + gl3wVertexAttrib3f = (PFNGLVERTEXATTRIB3FPROC) get_proc("glVertexAttrib3f"); + gl3wVertexAttrib3fv = (PFNGLVERTEXATTRIB3FVPROC) get_proc("glVertexAttrib3fv"); + gl3wVertexAttrib3s = (PFNGLVERTEXATTRIB3SPROC) get_proc("glVertexAttrib3s"); + gl3wVertexAttrib3sv = (PFNGLVERTEXATTRIB3SVPROC) get_proc("glVertexAttrib3sv"); + gl3wVertexAttrib4Nbv = (PFNGLVERTEXATTRIB4NBVPROC) get_proc("glVertexAttrib4Nbv"); + gl3wVertexAttrib4Niv = (PFNGLVERTEXATTRIB4NIVPROC) get_proc("glVertexAttrib4Niv"); + gl3wVertexAttrib4Nsv = (PFNGLVERTEXATTRIB4NSVPROC) get_proc("glVertexAttrib4Nsv"); + gl3wVertexAttrib4Nub = (PFNGLVERTEXATTRIB4NUBPROC) get_proc("glVertexAttrib4Nub"); + gl3wVertexAttrib4Nubv = (PFNGLVERTEXATTRIB4NUBVPROC) get_proc("glVertexAttrib4Nubv"); + gl3wVertexAttrib4Nuiv = (PFNGLVERTEXATTRIB4NUIVPROC) get_proc("glVertexAttrib4Nuiv"); + gl3wVertexAttrib4Nusv = (PFNGLVERTEXATTRIB4NUSVPROC) get_proc("glVertexAttrib4Nusv"); + gl3wVertexAttrib4bv = (PFNGLVERTEXATTRIB4BVPROC) get_proc("glVertexAttrib4bv"); + gl3wVertexAttrib4d = (PFNGLVERTEXATTRIB4DPROC) get_proc("glVertexAttrib4d"); + gl3wVertexAttrib4dv = (PFNGLVERTEXATTRIB4DVPROC) get_proc("glVertexAttrib4dv"); + gl3wVertexAttrib4f = (PFNGLVERTEXATTRIB4FPROC) get_proc("glVertexAttrib4f"); + gl3wVertexAttrib4fv = (PFNGLVERTEXATTRIB4FVPROC) get_proc("glVertexAttrib4fv"); + gl3wVertexAttrib4iv = (PFNGLVERTEXATTRIB4IVPROC) get_proc("glVertexAttrib4iv"); + gl3wVertexAttrib4s = (PFNGLVERTEXATTRIB4SPROC) get_proc("glVertexAttrib4s"); + gl3wVertexAttrib4sv = (PFNGLVERTEXATTRIB4SVPROC) get_proc("glVertexAttrib4sv"); + gl3wVertexAttrib4ubv = (PFNGLVERTEXATTRIB4UBVPROC) get_proc("glVertexAttrib4ubv"); + gl3wVertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC) get_proc("glVertexAttrib4uiv"); + gl3wVertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC) get_proc("glVertexAttrib4usv"); + gl3wVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) get_proc("glVertexAttribPointer"); + gl3wUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC) get_proc("glUniformMatrix2x3fv"); + gl3wUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC) get_proc("glUniformMatrix3x2fv"); + gl3wUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC) get_proc("glUniformMatrix2x4fv"); + gl3wUniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC) get_proc("glUniformMatrix4x2fv"); + gl3wUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC) get_proc("glUniformMatrix3x4fv"); + gl3wUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC) get_proc("glUniformMatrix4x3fv"); + gl3wColorMaski = (PFNGLCOLORMASKIPROC) get_proc("glColorMaski"); + gl3wGetBooleani_v = (PFNGLGETBOOLEANI_VPROC) get_proc("glGetBooleani_v"); + gl3wGetIntegeri_v = (PFNGLGETINTEGERI_VPROC) get_proc("glGetIntegeri_v"); + gl3wEnablei = (PFNGLENABLEIPROC) get_proc("glEnablei"); + gl3wDisablei = (PFNGLDISABLEIPROC) get_proc("glDisablei"); + gl3wIsEnabledi = (PFNGLISENABLEDIPROC) get_proc("glIsEnabledi"); + gl3wBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) get_proc("glBeginTransformFeedback"); + gl3wEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC) get_proc("glEndTransformFeedback"); + gl3wBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) get_proc("glBindBufferRange"); + gl3wBindBufferBase = (PFNGLBINDBUFFERBASEPROC) get_proc("glBindBufferBase"); + gl3wTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC) get_proc("glTransformFeedbackVaryings"); + gl3wGetTransformFeedbackVarying = (PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) get_proc("glGetTransformFeedbackVarying"); + gl3wClampColor = (PFNGLCLAMPCOLORPROC) get_proc("glClampColor"); + gl3wBeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC) get_proc("glBeginConditionalRender"); + gl3wEndConditionalRender = (PFNGLENDCONDITIONALRENDERPROC) get_proc("glEndConditionalRender"); + gl3wVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC) get_proc("glVertexAttribIPointer"); + gl3wGetVertexAttribIiv = (PFNGLGETVERTEXATTRIBIIVPROC) get_proc("glGetVertexAttribIiv"); + gl3wGetVertexAttribIuiv = (PFNGLGETVERTEXATTRIBIUIVPROC) get_proc("glGetVertexAttribIuiv"); + gl3wVertexAttribI1i = (PFNGLVERTEXATTRIBI1IPROC) get_proc("glVertexAttribI1i"); + gl3wVertexAttribI2i = (PFNGLVERTEXATTRIBI2IPROC) get_proc("glVertexAttribI2i"); + gl3wVertexAttribI3i = (PFNGLVERTEXATTRIBI3IPROC) get_proc("glVertexAttribI3i"); + gl3wVertexAttribI4i = (PFNGLVERTEXATTRIBI4IPROC) get_proc("glVertexAttribI4i"); + gl3wVertexAttribI1ui = (PFNGLVERTEXATTRIBI1UIPROC) get_proc("glVertexAttribI1ui"); + gl3wVertexAttribI2ui = (PFNGLVERTEXATTRIBI2UIPROC) get_proc("glVertexAttribI2ui"); + gl3wVertexAttribI3ui = (PFNGLVERTEXATTRIBI3UIPROC) get_proc("glVertexAttribI3ui"); + gl3wVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC) get_proc("glVertexAttribI4ui"); + gl3wVertexAttribI1iv = (PFNGLVERTEXATTRIBI1IVPROC) get_proc("glVertexAttribI1iv"); + gl3wVertexAttribI2iv = (PFNGLVERTEXATTRIBI2IVPROC) get_proc("glVertexAttribI2iv"); + gl3wVertexAttribI3iv = (PFNGLVERTEXATTRIBI3IVPROC) get_proc("glVertexAttribI3iv"); + gl3wVertexAttribI4iv = (PFNGLVERTEXATTRIBI4IVPROC) get_proc("glVertexAttribI4iv"); + gl3wVertexAttribI1uiv = (PFNGLVERTEXATTRIBI1UIVPROC) get_proc("glVertexAttribI1uiv"); + gl3wVertexAttribI2uiv = (PFNGLVERTEXATTRIBI2UIVPROC) get_proc("glVertexAttribI2uiv"); + gl3wVertexAttribI3uiv = (PFNGLVERTEXATTRIBI3UIVPROC) get_proc("glVertexAttribI3uiv"); + gl3wVertexAttribI4uiv = (PFNGLVERTEXATTRIBI4UIVPROC) get_proc("glVertexAttribI4uiv"); + gl3wVertexAttribI4bv = (PFNGLVERTEXATTRIBI4BVPROC) get_proc("glVertexAttribI4bv"); + gl3wVertexAttribI4sv = (PFNGLVERTEXATTRIBI4SVPROC) get_proc("glVertexAttribI4sv"); + gl3wVertexAttribI4ubv = (PFNGLVERTEXATTRIBI4UBVPROC) get_proc("glVertexAttribI4ubv"); + gl3wVertexAttribI4usv = (PFNGLVERTEXATTRIBI4USVPROC) get_proc("glVertexAttribI4usv"); + gl3wGetUniformuiv = (PFNGLGETUNIFORMUIVPROC) get_proc("glGetUniformuiv"); + gl3wBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC) get_proc("glBindFragDataLocation"); + gl3wGetFragDataLocation = (PFNGLGETFRAGDATALOCATIONPROC) get_proc("glGetFragDataLocation"); + gl3wUniform1ui = (PFNGLUNIFORM1UIPROC) get_proc("glUniform1ui"); + gl3wUniform2ui = (PFNGLUNIFORM2UIPROC) get_proc("glUniform2ui"); + gl3wUniform3ui = (PFNGLUNIFORM3UIPROC) get_proc("glUniform3ui"); + gl3wUniform4ui = (PFNGLUNIFORM4UIPROC) get_proc("glUniform4ui"); + gl3wUniform1uiv = (PFNGLUNIFORM1UIVPROC) get_proc("glUniform1uiv"); + gl3wUniform2uiv = (PFNGLUNIFORM2UIVPROC) get_proc("glUniform2uiv"); + gl3wUniform3uiv = (PFNGLUNIFORM3UIVPROC) get_proc("glUniform3uiv"); + gl3wUniform4uiv = (PFNGLUNIFORM4UIVPROC) get_proc("glUniform4uiv"); + gl3wTexParameterIiv = (PFNGLTEXPARAMETERIIVPROC) get_proc("glTexParameterIiv"); + gl3wTexParameterIuiv = (PFNGLTEXPARAMETERIUIVPROC) get_proc("glTexParameterIuiv"); + gl3wGetTexParameterIiv = (PFNGLGETTEXPARAMETERIIVPROC) get_proc("glGetTexParameterIiv"); + gl3wGetTexParameterIuiv = (PFNGLGETTEXPARAMETERIUIVPROC) get_proc("glGetTexParameterIuiv"); + gl3wClearBufferiv = (PFNGLCLEARBUFFERIVPROC) get_proc("glClearBufferiv"); + gl3wClearBufferuiv = (PFNGLCLEARBUFFERUIVPROC) get_proc("glClearBufferuiv"); + gl3wClearBufferfv = (PFNGLCLEARBUFFERFVPROC) get_proc("glClearBufferfv"); + gl3wClearBufferfi = (PFNGLCLEARBUFFERFIPROC) get_proc("glClearBufferfi"); + gl3wGetStringi = (PFNGLGETSTRINGIPROC) get_proc("glGetStringi"); + gl3wDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) get_proc("glDrawArraysInstanced"); + gl3wDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) get_proc("glDrawElementsInstanced"); + gl3wTexBuffer = (PFNGLTEXBUFFERPROC) get_proc("glTexBuffer"); + gl3wPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC) get_proc("glPrimitiveRestartIndex"); + gl3wGetInteger64i_v = (PFNGLGETINTEGER64I_VPROC) get_proc("glGetInteger64i_v"); + gl3wGetBufferParameteri64v = (PFNGLGETBUFFERPARAMETERI64VPROC) get_proc("glGetBufferParameteri64v"); + gl3wFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC) get_proc("glFramebufferTexture"); + gl3wVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) get_proc("glVertexAttribDivisor"); + gl3wMinSampleShading = (PFNGLMINSAMPLESHADINGPROC) get_proc("glMinSampleShading"); + gl3wBlendEquationi = (PFNGLBLENDEQUATIONIPROC) get_proc("glBlendEquationi"); + gl3wBlendEquationSeparatei = (PFNGLBLENDEQUATIONSEPARATEIPROC) get_proc("glBlendEquationSeparatei"); + gl3wBlendFunci = (PFNGLBLENDFUNCIPROC) get_proc("glBlendFunci"); + gl3wBlendFuncSeparatei = (PFNGLBLENDFUNCSEPARATEIPROC) get_proc("glBlendFuncSeparatei"); + gl3wIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) get_proc("glIsRenderbuffer"); + gl3wBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) get_proc("glBindRenderbuffer"); + gl3wDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) get_proc("glDeleteRenderbuffers"); + gl3wGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) get_proc("glGenRenderbuffers"); + gl3wRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) get_proc("glRenderbufferStorage"); + gl3wGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) get_proc("glGetRenderbufferParameteriv"); + gl3wIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) get_proc("glIsFramebuffer"); + gl3wBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) get_proc("glBindFramebuffer"); + gl3wDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) get_proc("glDeleteFramebuffers"); + gl3wGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) get_proc("glGenFramebuffers"); + gl3wCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) get_proc("glCheckFramebufferStatus"); + gl3wFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) get_proc("glFramebufferTexture1D"); + gl3wFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) get_proc("glFramebufferTexture2D"); + gl3wFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) get_proc("glFramebufferTexture3D"); + gl3wFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) get_proc("glFramebufferRenderbuffer"); + gl3wGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) get_proc("glGetFramebufferAttachmentParameteriv"); + gl3wGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) get_proc("glGenerateMipmap"); + gl3wBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC) get_proc("glBlitFramebuffer"); + gl3wRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) get_proc("glRenderbufferStorageMultisample"); + gl3wFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC) get_proc("glFramebufferTextureLayer"); + gl3wMapBufferRange = (PFNGLMAPBUFFERRANGEPROC) get_proc("glMapBufferRange"); + gl3wFlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC) get_proc("glFlushMappedBufferRange"); + gl3wBindVertexArray = (PFNGLBINDVERTEXARRAYPROC) get_proc("glBindVertexArray"); + gl3wDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) get_proc("glDeleteVertexArrays"); + gl3wGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) get_proc("glGenVertexArrays"); + gl3wIsVertexArray = (PFNGLISVERTEXARRAYPROC) get_proc("glIsVertexArray"); + gl3wGetUniformIndices = (PFNGLGETUNIFORMINDICESPROC) get_proc("glGetUniformIndices"); + gl3wGetActiveUniformsiv = (PFNGLGETACTIVEUNIFORMSIVPROC) get_proc("glGetActiveUniformsiv"); + gl3wGetActiveUniformName = (PFNGLGETACTIVEUNIFORMNAMEPROC) get_proc("glGetActiveUniformName"); + gl3wGetUniformBlockIndex = (PFNGLGETUNIFORMBLOCKINDEXPROC) get_proc("glGetUniformBlockIndex"); + gl3wGetActiveUniformBlockiv = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC) get_proc("glGetActiveUniformBlockiv"); + gl3wGetActiveUniformBlockName = (PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) get_proc("glGetActiveUniformBlockName"); + gl3wUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC) get_proc("glUniformBlockBinding"); + gl3wCopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC) get_proc("glCopyBufferSubData"); + gl3wDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC) get_proc("glDrawElementsBaseVertex"); + gl3wDrawRangeElementsBaseVertex = (PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) get_proc("glDrawRangeElementsBaseVertex"); + gl3wDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) get_proc("glDrawElementsInstancedBaseVertex"); + gl3wMultiDrawElementsBaseVertex = (PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) get_proc("glMultiDrawElementsBaseVertex"); + gl3wProvokingVertex = (PFNGLPROVOKINGVERTEXPROC) get_proc("glProvokingVertex"); + gl3wFenceSync = (PFNGLFENCESYNCPROC) get_proc("glFenceSync"); + gl3wIsSync = (PFNGLISSYNCPROC) get_proc("glIsSync"); + gl3wDeleteSync = (PFNGLDELETESYNCPROC) get_proc("glDeleteSync"); + gl3wClientWaitSync = (PFNGLCLIENTWAITSYNCPROC) get_proc("glClientWaitSync"); + gl3wWaitSync = (PFNGLWAITSYNCPROC) get_proc("glWaitSync"); + gl3wGetInteger64v = (PFNGLGETINTEGER64VPROC) get_proc("glGetInteger64v"); + gl3wGetSynciv = (PFNGLGETSYNCIVPROC) get_proc("glGetSynciv"); + gl3wTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC) get_proc("glTexImage2DMultisample"); + gl3wTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC) get_proc("glTexImage3DMultisample"); + gl3wGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC) get_proc("glGetMultisamplefv"); + gl3wSampleMaski = (PFNGLSAMPLEMASKIPROC) get_proc("glSampleMaski"); + gl3wBlendEquationiARB = (PFNGLBLENDEQUATIONIARBPROC) get_proc("glBlendEquationiARB"); + gl3wBlendEquationSeparateiARB = (PFNGLBLENDEQUATIONSEPARATEIARBPROC) get_proc("glBlendEquationSeparateiARB"); + gl3wBlendFunciARB = (PFNGLBLENDFUNCIARBPROC) get_proc("glBlendFunciARB"); + gl3wBlendFuncSeparateiARB = (PFNGLBLENDFUNCSEPARATEIARBPROC) get_proc("glBlendFuncSeparateiARB"); + gl3wMinSampleShadingARB = (PFNGLMINSAMPLESHADINGARBPROC) get_proc("glMinSampleShadingARB"); + gl3wNamedStringARB = (PFNGLNAMEDSTRINGARBPROC) get_proc("glNamedStringARB"); + gl3wDeleteNamedStringARB = (PFNGLDELETENAMEDSTRINGARBPROC) get_proc("glDeleteNamedStringARB"); + gl3wCompileShaderIncludeARB = (PFNGLCOMPILESHADERINCLUDEARBPROC) get_proc("glCompileShaderIncludeARB"); + gl3wIsNamedStringARB = (PFNGLISNAMEDSTRINGARBPROC) get_proc("glIsNamedStringARB"); + gl3wGetNamedStringARB = (PFNGLGETNAMEDSTRINGARBPROC) get_proc("glGetNamedStringARB"); + gl3wGetNamedStringivARB = (PFNGLGETNAMEDSTRINGIVARBPROC) get_proc("glGetNamedStringivARB"); + gl3wBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) get_proc("glBindFragDataLocationIndexed"); + gl3wGetFragDataIndex = (PFNGLGETFRAGDATAINDEXPROC) get_proc("glGetFragDataIndex"); + gl3wGenSamplers = (PFNGLGENSAMPLERSPROC) get_proc("glGenSamplers"); + gl3wDeleteSamplers = (PFNGLDELETESAMPLERSPROC) get_proc("glDeleteSamplers"); + gl3wIsSampler = (PFNGLISSAMPLERPROC) get_proc("glIsSampler"); + gl3wBindSampler = (PFNGLBINDSAMPLERPROC) get_proc("glBindSampler"); + gl3wSamplerParameteri = (PFNGLSAMPLERPARAMETERIPROC) get_proc("glSamplerParameteri"); + gl3wSamplerParameteriv = (PFNGLSAMPLERPARAMETERIVPROC) get_proc("glSamplerParameteriv"); + gl3wSamplerParameterf = (PFNGLSAMPLERPARAMETERFPROC) get_proc("glSamplerParameterf"); + gl3wSamplerParameterfv = (PFNGLSAMPLERPARAMETERFVPROC) get_proc("glSamplerParameterfv"); + gl3wSamplerParameterIiv = (PFNGLSAMPLERPARAMETERIIVPROC) get_proc("glSamplerParameterIiv"); + gl3wSamplerParameterIuiv = (PFNGLSAMPLERPARAMETERIUIVPROC) get_proc("glSamplerParameterIuiv"); + gl3wGetSamplerParameteriv = (PFNGLGETSAMPLERPARAMETERIVPROC) get_proc("glGetSamplerParameteriv"); + gl3wGetSamplerParameterIiv = (PFNGLGETSAMPLERPARAMETERIIVPROC) get_proc("glGetSamplerParameterIiv"); + gl3wGetSamplerParameterfv = (PFNGLGETSAMPLERPARAMETERFVPROC) get_proc("glGetSamplerParameterfv"); + gl3wGetSamplerParameterIuiv = (PFNGLGETSAMPLERPARAMETERIUIVPROC) get_proc("glGetSamplerParameterIuiv"); + gl3wQueryCounter = (PFNGLQUERYCOUNTERPROC) get_proc("glQueryCounter"); + gl3wGetQueryObjecti64v = (PFNGLGETQUERYOBJECTI64VPROC) get_proc("glGetQueryObjecti64v"); + gl3wGetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC) get_proc("glGetQueryObjectui64v"); + gl3wVertexP2ui = (PFNGLVERTEXP2UIPROC) get_proc("glVertexP2ui"); + gl3wVertexP2uiv = (PFNGLVERTEXP2UIVPROC) get_proc("glVertexP2uiv"); + gl3wVertexP3ui = (PFNGLVERTEXP3UIPROC) get_proc("glVertexP3ui"); + gl3wVertexP3uiv = (PFNGLVERTEXP3UIVPROC) get_proc("glVertexP3uiv"); + gl3wVertexP4ui = (PFNGLVERTEXP4UIPROC) get_proc("glVertexP4ui"); + gl3wVertexP4uiv = (PFNGLVERTEXP4UIVPROC) get_proc("glVertexP4uiv"); + gl3wTexCoordP1ui = (PFNGLTEXCOORDP1UIPROC) get_proc("glTexCoordP1ui"); + gl3wTexCoordP1uiv = (PFNGLTEXCOORDP1UIVPROC) get_proc("glTexCoordP1uiv"); + gl3wTexCoordP2ui = (PFNGLTEXCOORDP2UIPROC) get_proc("glTexCoordP2ui"); + gl3wTexCoordP2uiv = (PFNGLTEXCOORDP2UIVPROC) get_proc("glTexCoordP2uiv"); + gl3wTexCoordP3ui = (PFNGLTEXCOORDP3UIPROC) get_proc("glTexCoordP3ui"); + gl3wTexCoordP3uiv = (PFNGLTEXCOORDP3UIVPROC) get_proc("glTexCoordP3uiv"); + gl3wTexCoordP4ui = (PFNGLTEXCOORDP4UIPROC) get_proc("glTexCoordP4ui"); + gl3wTexCoordP4uiv = (PFNGLTEXCOORDP4UIVPROC) get_proc("glTexCoordP4uiv"); + gl3wMultiTexCoordP1ui = (PFNGLMULTITEXCOORDP1UIPROC) get_proc("glMultiTexCoordP1ui"); + gl3wMultiTexCoordP1uiv = (PFNGLMULTITEXCOORDP1UIVPROC) get_proc("glMultiTexCoordP1uiv"); + gl3wMultiTexCoordP2ui = (PFNGLMULTITEXCOORDP2UIPROC) get_proc("glMultiTexCoordP2ui"); + gl3wMultiTexCoordP2uiv = (PFNGLMULTITEXCOORDP2UIVPROC) get_proc("glMultiTexCoordP2uiv"); + gl3wMultiTexCoordP3ui = (PFNGLMULTITEXCOORDP3UIPROC) get_proc("glMultiTexCoordP3ui"); + gl3wMultiTexCoordP3uiv = (PFNGLMULTITEXCOORDP3UIVPROC) get_proc("glMultiTexCoordP3uiv"); + gl3wMultiTexCoordP4ui = (PFNGLMULTITEXCOORDP4UIPROC) get_proc("glMultiTexCoordP4ui"); + gl3wMultiTexCoordP4uiv = (PFNGLMULTITEXCOORDP4UIVPROC) get_proc("glMultiTexCoordP4uiv"); + gl3wNormalP3ui = (PFNGLNORMALP3UIPROC) get_proc("glNormalP3ui"); + gl3wNormalP3uiv = (PFNGLNORMALP3UIVPROC) get_proc("glNormalP3uiv"); + gl3wColorP3ui = (PFNGLCOLORP3UIPROC) get_proc("glColorP3ui"); + gl3wColorP3uiv = (PFNGLCOLORP3UIVPROC) get_proc("glColorP3uiv"); + gl3wColorP4ui = (PFNGLCOLORP4UIPROC) get_proc("glColorP4ui"); + gl3wColorP4uiv = (PFNGLCOLORP4UIVPROC) get_proc("glColorP4uiv"); + gl3wSecondaryColorP3ui = (PFNGLSECONDARYCOLORP3UIPROC) get_proc("glSecondaryColorP3ui"); + gl3wSecondaryColorP3uiv = (PFNGLSECONDARYCOLORP3UIVPROC) get_proc("glSecondaryColorP3uiv"); + gl3wVertexAttribP1ui = (PFNGLVERTEXATTRIBP1UIPROC) get_proc("glVertexAttribP1ui"); + gl3wVertexAttribP1uiv = (PFNGLVERTEXATTRIBP1UIVPROC) get_proc("glVertexAttribP1uiv"); + gl3wVertexAttribP2ui = (PFNGLVERTEXATTRIBP2UIPROC) get_proc("glVertexAttribP2ui"); + gl3wVertexAttribP2uiv = (PFNGLVERTEXATTRIBP2UIVPROC) get_proc("glVertexAttribP2uiv"); + gl3wVertexAttribP3ui = (PFNGLVERTEXATTRIBP3UIPROC) get_proc("glVertexAttribP3ui"); + gl3wVertexAttribP3uiv = (PFNGLVERTEXATTRIBP3UIVPROC) get_proc("glVertexAttribP3uiv"); + gl3wVertexAttribP4ui = (PFNGLVERTEXATTRIBP4UIPROC) get_proc("glVertexAttribP4ui"); + gl3wVertexAttribP4uiv = (PFNGLVERTEXATTRIBP4UIVPROC) get_proc("glVertexAttribP4uiv"); + gl3wDrawArraysIndirect = (PFNGLDRAWARRAYSINDIRECTPROC) get_proc("glDrawArraysIndirect"); + gl3wDrawElementsIndirect = (PFNGLDRAWELEMENTSINDIRECTPROC) get_proc("glDrawElementsIndirect"); + gl3wUniform1d = (PFNGLUNIFORM1DPROC) get_proc("glUniform1d"); + gl3wUniform2d = (PFNGLUNIFORM2DPROC) get_proc("glUniform2d"); + gl3wUniform3d = (PFNGLUNIFORM3DPROC) get_proc("glUniform3d"); + gl3wUniform4d = (PFNGLUNIFORM4DPROC) get_proc("glUniform4d"); + gl3wUniform1dv = (PFNGLUNIFORM1DVPROC) get_proc("glUniform1dv"); + gl3wUniform2dv = (PFNGLUNIFORM2DVPROC) get_proc("glUniform2dv"); + gl3wUniform3dv = (PFNGLUNIFORM3DVPROC) get_proc("glUniform3dv"); + gl3wUniform4dv = (PFNGLUNIFORM4DVPROC) get_proc("glUniform4dv"); + gl3wUniformMatrix2dv = (PFNGLUNIFORMMATRIX2DVPROC) get_proc("glUniformMatrix2dv"); + gl3wUniformMatrix3dv = (PFNGLUNIFORMMATRIX3DVPROC) get_proc("glUniformMatrix3dv"); + gl3wUniformMatrix4dv = (PFNGLUNIFORMMATRIX4DVPROC) get_proc("glUniformMatrix4dv"); + gl3wUniformMatrix2x3dv = (PFNGLUNIFORMMATRIX2X3DVPROC) get_proc("glUniformMatrix2x3dv"); + gl3wUniformMatrix2x4dv = (PFNGLUNIFORMMATRIX2X4DVPROC) get_proc("glUniformMatrix2x4dv"); + gl3wUniformMatrix3x2dv = (PFNGLUNIFORMMATRIX3X2DVPROC) get_proc("glUniformMatrix3x2dv"); + gl3wUniformMatrix3x4dv = (PFNGLUNIFORMMATRIX3X4DVPROC) get_proc("glUniformMatrix3x4dv"); + gl3wUniformMatrix4x2dv = (PFNGLUNIFORMMATRIX4X2DVPROC) get_proc("glUniformMatrix4x2dv"); + gl3wUniformMatrix4x3dv = (PFNGLUNIFORMMATRIX4X3DVPROC) get_proc("glUniformMatrix4x3dv"); + gl3wGetUniformdv = (PFNGLGETUNIFORMDVPROC) get_proc("glGetUniformdv"); + gl3wGetSubroutineUniformLocation = (PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) get_proc("glGetSubroutineUniformLocation"); + gl3wGetSubroutineIndex = (PFNGLGETSUBROUTINEINDEXPROC) get_proc("glGetSubroutineIndex"); + gl3wGetActiveSubroutineUniformiv = (PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) get_proc("glGetActiveSubroutineUniformiv"); + gl3wGetActiveSubroutineUniformName = (PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) get_proc("glGetActiveSubroutineUniformName"); + gl3wGetActiveSubroutineName = (PFNGLGETACTIVESUBROUTINENAMEPROC) get_proc("glGetActiveSubroutineName"); + gl3wUniformSubroutinesuiv = (PFNGLUNIFORMSUBROUTINESUIVPROC) get_proc("glUniformSubroutinesuiv"); + gl3wGetUniformSubroutineuiv = (PFNGLGETUNIFORMSUBROUTINEUIVPROC) get_proc("glGetUniformSubroutineuiv"); + gl3wGetProgramStageiv = (PFNGLGETPROGRAMSTAGEIVPROC) get_proc("glGetProgramStageiv"); + gl3wPatchParameteri = (PFNGLPATCHPARAMETERIPROC) get_proc("glPatchParameteri"); + gl3wPatchParameterfv = (PFNGLPATCHPARAMETERFVPROC) get_proc("glPatchParameterfv"); + gl3wBindTransformFeedback = (PFNGLBINDTRANSFORMFEEDBACKPROC) get_proc("glBindTransformFeedback"); + gl3wDeleteTransformFeedbacks = (PFNGLDELETETRANSFORMFEEDBACKSPROC) get_proc("glDeleteTransformFeedbacks"); + gl3wGenTransformFeedbacks = (PFNGLGENTRANSFORMFEEDBACKSPROC) get_proc("glGenTransformFeedbacks"); + gl3wIsTransformFeedback = (PFNGLISTRANSFORMFEEDBACKPROC) get_proc("glIsTransformFeedback"); + gl3wPauseTransformFeedback = (PFNGLPAUSETRANSFORMFEEDBACKPROC) get_proc("glPauseTransformFeedback"); + gl3wResumeTransformFeedback = (PFNGLRESUMETRANSFORMFEEDBACKPROC) get_proc("glResumeTransformFeedback"); + gl3wDrawTransformFeedback = (PFNGLDRAWTRANSFORMFEEDBACKPROC) get_proc("glDrawTransformFeedback"); + gl3wDrawTransformFeedbackStream = (PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) get_proc("glDrawTransformFeedbackStream"); + gl3wBeginQueryIndexed = (PFNGLBEGINQUERYINDEXEDPROC) get_proc("glBeginQueryIndexed"); + gl3wEndQueryIndexed = (PFNGLENDQUERYINDEXEDPROC) get_proc("glEndQueryIndexed"); + gl3wGetQueryIndexediv = (PFNGLGETQUERYINDEXEDIVPROC) get_proc("glGetQueryIndexediv"); + gl3wReleaseShaderCompiler = (PFNGLRELEASESHADERCOMPILERPROC) get_proc("glReleaseShaderCompiler"); + gl3wShaderBinary = (PFNGLSHADERBINARYPROC) get_proc("glShaderBinary"); + gl3wGetShaderPrecisionFormat = (PFNGLGETSHADERPRECISIONFORMATPROC) get_proc("glGetShaderPrecisionFormat"); + gl3wDepthRangef = (PFNGLDEPTHRANGEFPROC) get_proc("glDepthRangef"); + gl3wClearDepthf = (PFNGLCLEARDEPTHFPROC) get_proc("glClearDepthf"); + gl3wGetProgramBinary = (PFNGLGETPROGRAMBINARYPROC) get_proc("glGetProgramBinary"); + gl3wProgramBinary = (PFNGLPROGRAMBINARYPROC) get_proc("glProgramBinary"); + gl3wProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC) get_proc("glProgramParameteri"); + gl3wUseProgramStages = (PFNGLUSEPROGRAMSTAGESPROC) get_proc("glUseProgramStages"); + gl3wActiveShaderProgram = (PFNGLACTIVESHADERPROGRAMPROC) get_proc("glActiveShaderProgram"); + gl3wCreateShaderProgramv = (PFNGLCREATESHADERPROGRAMVPROC) get_proc("glCreateShaderProgramv"); + gl3wBindProgramPipeline = (PFNGLBINDPROGRAMPIPELINEPROC) get_proc("glBindProgramPipeline"); + gl3wDeleteProgramPipelines = (PFNGLDELETEPROGRAMPIPELINESPROC) get_proc("glDeleteProgramPipelines"); + gl3wGenProgramPipelines = (PFNGLGENPROGRAMPIPELINESPROC) get_proc("glGenProgramPipelines"); + gl3wIsProgramPipeline = (PFNGLISPROGRAMPIPELINEPROC) get_proc("glIsProgramPipeline"); + gl3wGetProgramPipelineiv = (PFNGLGETPROGRAMPIPELINEIVPROC) get_proc("glGetProgramPipelineiv"); + gl3wProgramUniform1i = (PFNGLPROGRAMUNIFORM1IPROC) get_proc("glProgramUniform1i"); + gl3wProgramUniform1iv = (PFNGLPROGRAMUNIFORM1IVPROC) get_proc("glProgramUniform1iv"); + gl3wProgramUniform1f = (PFNGLPROGRAMUNIFORM1FPROC) get_proc("glProgramUniform1f"); + gl3wProgramUniform1fv = (PFNGLPROGRAMUNIFORM1FVPROC) get_proc("glProgramUniform1fv"); + gl3wProgramUniform1d = (PFNGLPROGRAMUNIFORM1DPROC) get_proc("glProgramUniform1d"); + gl3wProgramUniform1dv = (PFNGLPROGRAMUNIFORM1DVPROC) get_proc("glProgramUniform1dv"); + gl3wProgramUniform1ui = (PFNGLPROGRAMUNIFORM1UIPROC) get_proc("glProgramUniform1ui"); + gl3wProgramUniform1uiv = (PFNGLPROGRAMUNIFORM1UIVPROC) get_proc("glProgramUniform1uiv"); + gl3wProgramUniform2i = (PFNGLPROGRAMUNIFORM2IPROC) get_proc("glProgramUniform2i"); + gl3wProgramUniform2iv = (PFNGLPROGRAMUNIFORM2IVPROC) get_proc("glProgramUniform2iv"); + gl3wProgramUniform2f = (PFNGLPROGRAMUNIFORM2FPROC) get_proc("glProgramUniform2f"); + gl3wProgramUniform2fv = (PFNGLPROGRAMUNIFORM2FVPROC) get_proc("glProgramUniform2fv"); + gl3wProgramUniform2d = (PFNGLPROGRAMUNIFORM2DPROC) get_proc("glProgramUniform2d"); + gl3wProgramUniform2dv = (PFNGLPROGRAMUNIFORM2DVPROC) get_proc("glProgramUniform2dv"); + gl3wProgramUniform2ui = (PFNGLPROGRAMUNIFORM2UIPROC) get_proc("glProgramUniform2ui"); + gl3wProgramUniform2uiv = (PFNGLPROGRAMUNIFORM2UIVPROC) get_proc("glProgramUniform2uiv"); + gl3wProgramUniform3i = (PFNGLPROGRAMUNIFORM3IPROC) get_proc("glProgramUniform3i"); + gl3wProgramUniform3iv = (PFNGLPROGRAMUNIFORM3IVPROC) get_proc("glProgramUniform3iv"); + gl3wProgramUniform3f = (PFNGLPROGRAMUNIFORM3FPROC) get_proc("glProgramUniform3f"); + gl3wProgramUniform3fv = (PFNGLPROGRAMUNIFORM3FVPROC) get_proc("glProgramUniform3fv"); + gl3wProgramUniform3d = (PFNGLPROGRAMUNIFORM3DPROC) get_proc("glProgramUniform3d"); + gl3wProgramUniform3dv = (PFNGLPROGRAMUNIFORM3DVPROC) get_proc("glProgramUniform3dv"); + gl3wProgramUniform3ui = (PFNGLPROGRAMUNIFORM3UIPROC) get_proc("glProgramUniform3ui"); + gl3wProgramUniform3uiv = (PFNGLPROGRAMUNIFORM3UIVPROC) get_proc("glProgramUniform3uiv"); + gl3wProgramUniform4i = (PFNGLPROGRAMUNIFORM4IPROC) get_proc("glProgramUniform4i"); + gl3wProgramUniform4iv = (PFNGLPROGRAMUNIFORM4IVPROC) get_proc("glProgramUniform4iv"); + gl3wProgramUniform4f = (PFNGLPROGRAMUNIFORM4FPROC) get_proc("glProgramUniform4f"); + gl3wProgramUniform4fv = (PFNGLPROGRAMUNIFORM4FVPROC) get_proc("glProgramUniform4fv"); + gl3wProgramUniform4d = (PFNGLPROGRAMUNIFORM4DPROC) get_proc("glProgramUniform4d"); + gl3wProgramUniform4dv = (PFNGLPROGRAMUNIFORM4DVPROC) get_proc("glProgramUniform4dv"); + gl3wProgramUniform4ui = (PFNGLPROGRAMUNIFORM4UIPROC) get_proc("glProgramUniform4ui"); + gl3wProgramUniform4uiv = (PFNGLPROGRAMUNIFORM4UIVPROC) get_proc("glProgramUniform4uiv"); + gl3wProgramUniformMatrix2fv = (PFNGLPROGRAMUNIFORMMATRIX2FVPROC) get_proc("glProgramUniformMatrix2fv"); + gl3wProgramUniformMatrix3fv = (PFNGLPROGRAMUNIFORMMATRIX3FVPROC) get_proc("glProgramUniformMatrix3fv"); + gl3wProgramUniformMatrix4fv = (PFNGLPROGRAMUNIFORMMATRIX4FVPROC) get_proc("glProgramUniformMatrix4fv"); + gl3wProgramUniformMatrix2dv = (PFNGLPROGRAMUNIFORMMATRIX2DVPROC) get_proc("glProgramUniformMatrix2dv"); + gl3wProgramUniformMatrix3dv = (PFNGLPROGRAMUNIFORMMATRIX3DVPROC) get_proc("glProgramUniformMatrix3dv"); + gl3wProgramUniformMatrix4dv = (PFNGLPROGRAMUNIFORMMATRIX4DVPROC) get_proc("glProgramUniformMatrix4dv"); + gl3wProgramUniformMatrix2x3fv = (PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) get_proc("glProgramUniformMatrix2x3fv"); + gl3wProgramUniformMatrix3x2fv = (PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) get_proc("glProgramUniformMatrix3x2fv"); + gl3wProgramUniformMatrix2x4fv = (PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) get_proc("glProgramUniformMatrix2x4fv"); + gl3wProgramUniformMatrix4x2fv = (PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) get_proc("glProgramUniformMatrix4x2fv"); + gl3wProgramUniformMatrix3x4fv = (PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) get_proc("glProgramUniformMatrix3x4fv"); + gl3wProgramUniformMatrix4x3fv = (PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) get_proc("glProgramUniformMatrix4x3fv"); + gl3wProgramUniformMatrix2x3dv = (PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) get_proc("glProgramUniformMatrix2x3dv"); + gl3wProgramUniformMatrix3x2dv = (PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) get_proc("glProgramUniformMatrix3x2dv"); + gl3wProgramUniformMatrix2x4dv = (PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) get_proc("glProgramUniformMatrix2x4dv"); + gl3wProgramUniformMatrix4x2dv = (PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) get_proc("glProgramUniformMatrix4x2dv"); + gl3wProgramUniformMatrix3x4dv = (PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) get_proc("glProgramUniformMatrix3x4dv"); + gl3wProgramUniformMatrix4x3dv = (PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) get_proc("glProgramUniformMatrix4x3dv"); + gl3wValidateProgramPipeline = (PFNGLVALIDATEPROGRAMPIPELINEPROC) get_proc("glValidateProgramPipeline"); + gl3wGetProgramPipelineInfoLog = (PFNGLGETPROGRAMPIPELINEINFOLOGPROC) get_proc("glGetProgramPipelineInfoLog"); + gl3wVertexAttribL1d = (PFNGLVERTEXATTRIBL1DPROC) get_proc("glVertexAttribL1d"); + gl3wVertexAttribL2d = (PFNGLVERTEXATTRIBL2DPROC) get_proc("glVertexAttribL2d"); + gl3wVertexAttribL3d = (PFNGLVERTEXATTRIBL3DPROC) get_proc("glVertexAttribL3d"); + gl3wVertexAttribL4d = (PFNGLVERTEXATTRIBL4DPROC) get_proc("glVertexAttribL4d"); + gl3wVertexAttribL1dv = (PFNGLVERTEXATTRIBL1DVPROC) get_proc("glVertexAttribL1dv"); + gl3wVertexAttribL2dv = (PFNGLVERTEXATTRIBL2DVPROC) get_proc("glVertexAttribL2dv"); + gl3wVertexAttribL3dv = (PFNGLVERTEXATTRIBL3DVPROC) get_proc("glVertexAttribL3dv"); + gl3wVertexAttribL4dv = (PFNGLVERTEXATTRIBL4DVPROC) get_proc("glVertexAttribL4dv"); + gl3wVertexAttribLPointer = (PFNGLVERTEXATTRIBLPOINTERPROC) get_proc("glVertexAttribLPointer"); + gl3wGetVertexAttribLdv = (PFNGLGETVERTEXATTRIBLDVPROC) get_proc("glGetVertexAttribLdv"); + gl3wViewportArrayv = (PFNGLVIEWPORTARRAYVPROC) get_proc("glViewportArrayv"); + gl3wViewportIndexedf = (PFNGLVIEWPORTINDEXEDFPROC) get_proc("glViewportIndexedf"); + gl3wViewportIndexedfv = (PFNGLVIEWPORTINDEXEDFVPROC) get_proc("glViewportIndexedfv"); + gl3wScissorArrayv = (PFNGLSCISSORARRAYVPROC) get_proc("glScissorArrayv"); + gl3wScissorIndexed = (PFNGLSCISSORINDEXEDPROC) get_proc("glScissorIndexed"); + gl3wScissorIndexedv = (PFNGLSCISSORINDEXEDVPROC) get_proc("glScissorIndexedv"); + gl3wDepthRangeArrayv = (PFNGLDEPTHRANGEARRAYVPROC) get_proc("glDepthRangeArrayv"); + gl3wDepthRangeIndexed = (PFNGLDEPTHRANGEINDEXEDPROC) get_proc("glDepthRangeIndexed"); + gl3wGetFloati_v = (PFNGLGETFLOATI_VPROC) get_proc("glGetFloati_v"); + gl3wGetDoublei_v = (PFNGLGETDOUBLEI_VPROC) get_proc("glGetDoublei_v"); + gl3wCreateSyncFromCLeventARB = (PFNGLCREATESYNCFROMCLEVENTARBPROC) get_proc("glCreateSyncFromCLeventARB"); + gl3wDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC) get_proc("glDebugMessageControlARB"); + gl3wDebugMessageInsertARB = (PFNGLDEBUGMESSAGEINSERTARBPROC) get_proc("glDebugMessageInsertARB"); + gl3wDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC) get_proc("glDebugMessageCallbackARB"); + gl3wGetDebugMessageLogARB = (PFNGLGETDEBUGMESSAGELOGARBPROC) get_proc("glGetDebugMessageLogARB"); + gl3wGetGraphicsResetStatusARB = (PFNGLGETGRAPHICSRESETSTATUSARBPROC) get_proc("glGetGraphicsResetStatusARB"); + gl3wGetnTexImageARB = (PFNGLGETNTEXIMAGEARBPROC) get_proc("glGetnTexImageARB"); + gl3wReadnPixelsARB = (PFNGLREADNPIXELSARBPROC) get_proc("glReadnPixelsARB"); + gl3wGetnCompressedTexImageARB = (PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) get_proc("glGetnCompressedTexImageARB"); + gl3wGetnUniformfvARB = (PFNGLGETNUNIFORMFVARBPROC) get_proc("glGetnUniformfvARB"); + gl3wGetnUniformivARB = (PFNGLGETNUNIFORMIVARBPROC) get_proc("glGetnUniformivARB"); + gl3wGetnUniformuivARB = (PFNGLGETNUNIFORMUIVARBPROC) get_proc("glGetnUniformuivARB"); + gl3wGetnUniformdvARB = (PFNGLGETNUNIFORMDVARBPROC) get_proc("glGetnUniformdvARB"); + gl3wDrawArraysInstancedBaseInstance = (PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) get_proc("glDrawArraysInstancedBaseInstance"); + gl3wDrawElementsInstancedBaseInstance = (PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) get_proc("glDrawElementsInstancedBaseInstance"); + gl3wDrawElementsInstancedBaseVertexBaseInstance = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) get_proc("glDrawElementsInstancedBaseVertexBaseInstance"); + gl3wDrawTransformFeedbackInstanced = (PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) get_proc("glDrawTransformFeedbackInstanced"); + gl3wDrawTransformFeedbackStreamInstanced = (PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) get_proc("glDrawTransformFeedbackStreamInstanced"); + gl3wGetInternalformativ = (PFNGLGETINTERNALFORMATIVPROC) get_proc("glGetInternalformativ"); + gl3wGetActiveAtomicCounterBufferiv = (PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) get_proc("glGetActiveAtomicCounterBufferiv"); + gl3wBindImageTexture = (PFNGLBINDIMAGETEXTUREPROC) get_proc("glBindImageTexture"); + gl3wMemoryBarrier = (PFNGLMEMORYBARRIERPROC) get_proc("glMemoryBarrier"); + gl3wTexStorage1D = (PFNGLTEXSTORAGE1DPROC) get_proc("glTexStorage1D"); + gl3wTexStorage2D = (PFNGLTEXSTORAGE2DPROC) get_proc("glTexStorage2D"); + gl3wTexStorage3D = (PFNGLTEXSTORAGE3DPROC) get_proc("glTexStorage3D"); + gl3wTextureStorage1DEXT = (PFNGLTEXTURESTORAGE1DEXTPROC) get_proc("glTextureStorage1DEXT"); + gl3wTextureStorage2DEXT = (PFNGLTEXTURESTORAGE2DEXTPROC) get_proc("glTextureStorage2DEXT"); + gl3wTextureStorage3DEXT = (PFNGLTEXTURESTORAGE3DEXTPROC) get_proc("glTextureStorage3DEXT"); + gl3wDebugMessageControl = (PFNGLDEBUGMESSAGECONTROLPROC) get_proc("glDebugMessageControl"); + gl3wDebugMessageInsert = (PFNGLDEBUGMESSAGEINSERTPROC) get_proc("glDebugMessageInsert"); + gl3wDebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKPROC) get_proc("glDebugMessageCallback"); + gl3wGetDebugMessageLog = (PFNGLGETDEBUGMESSAGELOGPROC) get_proc("glGetDebugMessageLog"); + gl3wPushDebugGroup = (PFNGLPUSHDEBUGGROUPPROC) get_proc("glPushDebugGroup"); + gl3wPopDebugGroup = (PFNGLPOPDEBUGGROUPPROC) get_proc("glPopDebugGroup"); + gl3wObjectLabel = (PFNGLOBJECTLABELPROC) get_proc("glObjectLabel"); + gl3wGetObjectLabel = (PFNGLGETOBJECTLABELPROC) get_proc("glGetObjectLabel"); + gl3wObjectPtrLabel = (PFNGLOBJECTPTRLABELPROC) get_proc("glObjectPtrLabel"); + gl3wGetObjectPtrLabel = (PFNGLGETOBJECTPTRLABELPROC) get_proc("glGetObjectPtrLabel"); + gl3wClearBufferData = (PFNGLCLEARBUFFERDATAPROC) get_proc("glClearBufferData"); + gl3wClearBufferSubData = (PFNGLCLEARBUFFERSUBDATAPROC) get_proc("glClearBufferSubData"); + gl3wClearNamedBufferDataEXT = (PFNGLCLEARNAMEDBUFFERDATAEXTPROC) get_proc("glClearNamedBufferDataEXT"); + gl3wClearNamedBufferSubDataEXT = (PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) get_proc("glClearNamedBufferSubDataEXT"); + gl3wDispatchCompute = (PFNGLDISPATCHCOMPUTEPROC) get_proc("glDispatchCompute"); + gl3wDispatchComputeIndirect = (PFNGLDISPATCHCOMPUTEINDIRECTPROC) get_proc("glDispatchComputeIndirect"); + gl3wCopyImageSubData = (PFNGLCOPYIMAGESUBDATAPROC) get_proc("glCopyImageSubData"); + gl3wTextureView = (PFNGLTEXTUREVIEWPROC) get_proc("glTextureView"); + gl3wBindVertexBuffer = (PFNGLBINDVERTEXBUFFERPROC) get_proc("glBindVertexBuffer"); + gl3wVertexAttribFormat = (PFNGLVERTEXATTRIBFORMATPROC) get_proc("glVertexAttribFormat"); + gl3wVertexAttribIFormat = (PFNGLVERTEXATTRIBIFORMATPROC) get_proc("glVertexAttribIFormat"); + gl3wVertexAttribLFormat = (PFNGLVERTEXATTRIBLFORMATPROC) get_proc("glVertexAttribLFormat"); + gl3wVertexAttribBinding = (PFNGLVERTEXATTRIBBINDINGPROC) get_proc("glVertexAttribBinding"); + gl3wVertexBindingDivisor = (PFNGLVERTEXBINDINGDIVISORPROC) get_proc("glVertexBindingDivisor"); + gl3wVertexArrayBindVertexBufferEXT = (PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) get_proc("glVertexArrayBindVertexBufferEXT"); + gl3wVertexArrayVertexAttribFormatEXT = (PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) get_proc("glVertexArrayVertexAttribFormatEXT"); + gl3wVertexArrayVertexAttribIFormatEXT = (PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) get_proc("glVertexArrayVertexAttribIFormatEXT"); + gl3wVertexArrayVertexAttribLFormatEXT = (PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) get_proc("glVertexArrayVertexAttribLFormatEXT"); + gl3wVertexArrayVertexAttribBindingEXT = (PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) get_proc("glVertexArrayVertexAttribBindingEXT"); + gl3wVertexArrayVertexBindingDivisorEXT = (PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) get_proc("glVertexArrayVertexBindingDivisorEXT"); + gl3wFramebufferParameteri = (PFNGLFRAMEBUFFERPARAMETERIPROC) get_proc("glFramebufferParameteri"); + gl3wGetFramebufferParameteriv = (PFNGLGETFRAMEBUFFERPARAMETERIVPROC) get_proc("glGetFramebufferParameteriv"); + gl3wNamedFramebufferParameteriEXT = (PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) get_proc("glNamedFramebufferParameteriEXT"); + gl3wGetNamedFramebufferParameterivEXT = (PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) get_proc("glGetNamedFramebufferParameterivEXT"); + gl3wGetInternalformati64v = (PFNGLGETINTERNALFORMATI64VPROC) get_proc("glGetInternalformati64v"); + gl3wInvalidateTexSubImage = (PFNGLINVALIDATETEXSUBIMAGEPROC) get_proc("glInvalidateTexSubImage"); + gl3wInvalidateTexImage = (PFNGLINVALIDATETEXIMAGEPROC) get_proc("glInvalidateTexImage"); + gl3wInvalidateBufferSubData = (PFNGLINVALIDATEBUFFERSUBDATAPROC) get_proc("glInvalidateBufferSubData"); + gl3wInvalidateBufferData = (PFNGLINVALIDATEBUFFERDATAPROC) get_proc("glInvalidateBufferData"); + gl3wInvalidateFramebuffer = (PFNGLINVALIDATEFRAMEBUFFERPROC) get_proc("glInvalidateFramebuffer"); + gl3wInvalidateSubFramebuffer = (PFNGLINVALIDATESUBFRAMEBUFFERPROC) get_proc("glInvalidateSubFramebuffer"); + gl3wMultiDrawArraysIndirect = (PFNGLMULTIDRAWARRAYSINDIRECTPROC) get_proc("glMultiDrawArraysIndirect"); + gl3wMultiDrawElementsIndirect = (PFNGLMULTIDRAWELEMENTSINDIRECTPROC) get_proc("glMultiDrawElementsIndirect"); + gl3wGetProgramInterfaceiv = (PFNGLGETPROGRAMINTERFACEIVPROC) get_proc("glGetProgramInterfaceiv"); + gl3wGetProgramResourceIndex = (PFNGLGETPROGRAMRESOURCEINDEXPROC) get_proc("glGetProgramResourceIndex"); + gl3wGetProgramResourceName = (PFNGLGETPROGRAMRESOURCENAMEPROC) get_proc("glGetProgramResourceName"); + gl3wGetProgramResourceiv = (PFNGLGETPROGRAMRESOURCEIVPROC) get_proc("glGetProgramResourceiv"); + gl3wGetProgramResourceLocation = (PFNGLGETPROGRAMRESOURCELOCATIONPROC) get_proc("glGetProgramResourceLocation"); + gl3wGetProgramResourceLocationIndex = (PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) get_proc("glGetProgramResourceLocationIndex"); + gl3wShaderStorageBlockBinding = (PFNGLSHADERSTORAGEBLOCKBINDINGPROC) get_proc("glShaderStorageBlockBinding"); + gl3wTexBufferRange = (PFNGLTEXBUFFERRANGEPROC) get_proc("glTexBufferRange"); + gl3wTextureBufferRangeEXT = (PFNGLTEXTUREBUFFERRANGEEXTPROC) get_proc("glTextureBufferRangeEXT"); + gl3wTexStorage2DMultisample = (PFNGLTEXSTORAGE2DMULTISAMPLEPROC) get_proc("glTexStorage2DMultisample"); + gl3wTexStorage3DMultisample = (PFNGLTEXSTORAGE3DMULTISAMPLEPROC) get_proc("glTexStorage3DMultisample"); + gl3wTextureStorage2DMultisampleEXT = (PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) get_proc("glTextureStorage2DMultisampleEXT"); + gl3wTextureStorage3DMultisampleEXT = (PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) get_proc("glTextureStorage3DMultisampleEXT"); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.h b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.h new file mode 100644 index 0000000..ee563f8 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/gl3w.h @@ -0,0 +1,1234 @@ +#ifndef __gl3w_h_ +#define __gl3w_h_ + +#include + +#ifndef __gl_h_ +#define __gl_h_ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* gl3w api */ +int gl3wInit(void); +int gl3wIsSupported(int major, int minor); +void *gl3wGetProcAddress(const char *proc); + +/* OpenGL functions */ +extern PFNGLCULLFACEPROC gl3wCullFace; +extern PFNGLFRONTFACEPROC gl3wFrontFace; +extern PFNGLHINTPROC gl3wHint; +extern PFNGLLINEWIDTHPROC gl3wLineWidth; +extern PFNGLPOINTSIZEPROC gl3wPointSize; +extern PFNGLPOLYGONMODEPROC gl3wPolygonMode; +extern PFNGLSCISSORPROC gl3wScissor; +extern PFNGLTEXPARAMETERFPROC gl3wTexParameterf; +extern PFNGLTEXPARAMETERFVPROC gl3wTexParameterfv; +extern PFNGLTEXPARAMETERIPROC gl3wTexParameteri; +extern PFNGLTEXPARAMETERIVPROC gl3wTexParameteriv; +extern PFNGLTEXIMAGE1DPROC gl3wTexImage1D; +extern PFNGLTEXIMAGE2DPROC gl3wTexImage2D; +extern PFNGLDRAWBUFFERPROC gl3wDrawBuffer; +extern PFNGLCLEARPROC gl3wClear; +extern PFNGLCLEARCOLORPROC gl3wClearColor; +extern PFNGLCLEARSTENCILPROC gl3wClearStencil; +extern PFNGLCLEARDEPTHPROC gl3wClearDepth; +extern PFNGLSTENCILMASKPROC gl3wStencilMask; +extern PFNGLCOLORMASKPROC gl3wColorMask; +extern PFNGLDEPTHMASKPROC gl3wDepthMask; +extern PFNGLDISABLEPROC gl3wDisable; +extern PFNGLENABLEPROC gl3wEnable; +extern PFNGLFINISHPROC gl3wFinish; +extern PFNGLFLUSHPROC gl3wFlush; +extern PFNGLBLENDFUNCPROC gl3wBlendFunc; +extern PFNGLLOGICOPPROC gl3wLogicOp; +extern PFNGLSTENCILFUNCPROC gl3wStencilFunc; +extern PFNGLSTENCILOPPROC gl3wStencilOp; +extern PFNGLDEPTHFUNCPROC gl3wDepthFunc; +extern PFNGLPIXELSTOREFPROC gl3wPixelStoref; +extern PFNGLPIXELSTOREIPROC gl3wPixelStorei; +extern PFNGLREADBUFFERPROC gl3wReadBuffer; +extern PFNGLREADPIXELSPROC gl3wReadPixels; +extern PFNGLGETBOOLEANVPROC gl3wGetBooleanv; +extern PFNGLGETDOUBLEVPROC gl3wGetDoublev; +extern PFNGLGETERRORPROC gl3wGetError; +extern PFNGLGETFLOATVPROC gl3wGetFloatv; +extern PFNGLGETINTEGERVPROC gl3wGetIntegerv; +extern PFNGLGETSTRINGPROC gl3wGetString; +extern PFNGLGETTEXIMAGEPROC gl3wGetTexImage; +extern PFNGLGETTEXPARAMETERFVPROC gl3wGetTexParameterfv; +extern PFNGLGETTEXPARAMETERIVPROC gl3wGetTexParameteriv; +extern PFNGLGETTEXLEVELPARAMETERFVPROC gl3wGetTexLevelParameterfv; +extern PFNGLGETTEXLEVELPARAMETERIVPROC gl3wGetTexLevelParameteriv; +extern PFNGLISENABLEDPROC gl3wIsEnabled; +extern PFNGLDEPTHRANGEPROC gl3wDepthRange; +extern PFNGLVIEWPORTPROC gl3wViewport; +extern PFNGLDRAWARRAYSPROC gl3wDrawArrays; +extern PFNGLDRAWELEMENTSPROC gl3wDrawElements; +extern PFNGLGETPOINTERVPROC gl3wGetPointerv; +extern PFNGLPOLYGONOFFSETPROC gl3wPolygonOffset; +extern PFNGLCOPYTEXIMAGE1DPROC gl3wCopyTexImage1D; +extern PFNGLCOPYTEXIMAGE2DPROC gl3wCopyTexImage2D; +extern PFNGLCOPYTEXSUBIMAGE1DPROC gl3wCopyTexSubImage1D; +extern PFNGLCOPYTEXSUBIMAGE2DPROC gl3wCopyTexSubImage2D; +extern PFNGLTEXSUBIMAGE1DPROC gl3wTexSubImage1D; +extern PFNGLTEXSUBIMAGE2DPROC gl3wTexSubImage2D; +extern PFNGLBINDTEXTUREPROC gl3wBindTexture; +extern PFNGLDELETETEXTURESPROC gl3wDeleteTextures; +extern PFNGLGENTEXTURESPROC gl3wGenTextures; +extern PFNGLISTEXTUREPROC gl3wIsTexture; +extern PFNGLBLENDCOLORPROC gl3wBlendColor; +extern PFNGLBLENDEQUATIONPROC gl3wBlendEquation; +extern PFNGLDRAWRANGEELEMENTSPROC gl3wDrawRangeElements; +extern PFNGLTEXIMAGE3DPROC gl3wTexImage3D; +extern PFNGLTEXSUBIMAGE3DPROC gl3wTexSubImage3D; +extern PFNGLCOPYTEXSUBIMAGE3DPROC gl3wCopyTexSubImage3D; +extern PFNGLACTIVETEXTUREPROC gl3wActiveTexture; +extern PFNGLSAMPLECOVERAGEPROC gl3wSampleCoverage; +extern PFNGLCOMPRESSEDTEXIMAGE3DPROC gl3wCompressedTexImage3D; +extern PFNGLCOMPRESSEDTEXIMAGE2DPROC gl3wCompressedTexImage2D; +extern PFNGLCOMPRESSEDTEXIMAGE1DPROC gl3wCompressedTexImage1D; +extern PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC gl3wCompressedTexSubImage3D; +extern PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC gl3wCompressedTexSubImage2D; +extern PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC gl3wCompressedTexSubImage1D; +extern PFNGLGETCOMPRESSEDTEXIMAGEPROC gl3wGetCompressedTexImage; +extern PFNGLBLENDFUNCSEPARATEPROC gl3wBlendFuncSeparate; +extern PFNGLMULTIDRAWARRAYSPROC gl3wMultiDrawArrays; +extern PFNGLMULTIDRAWELEMENTSPROC gl3wMultiDrawElements; +extern PFNGLPOINTPARAMETERFPROC gl3wPointParameterf; +extern PFNGLPOINTPARAMETERFVPROC gl3wPointParameterfv; +extern PFNGLPOINTPARAMETERIPROC gl3wPointParameteri; +extern PFNGLPOINTPARAMETERIVPROC gl3wPointParameteriv; +extern PFNGLGENQUERIESPROC gl3wGenQueries; +extern PFNGLDELETEQUERIESPROC gl3wDeleteQueries; +extern PFNGLISQUERYPROC gl3wIsQuery; +extern PFNGLBEGINQUERYPROC gl3wBeginQuery; +extern PFNGLENDQUERYPROC gl3wEndQuery; +extern PFNGLGETQUERYIVPROC gl3wGetQueryiv; +extern PFNGLGETQUERYOBJECTIVPROC gl3wGetQueryObjectiv; +extern PFNGLGETQUERYOBJECTUIVPROC gl3wGetQueryObjectuiv; +extern PFNGLBINDBUFFERPROC gl3wBindBuffer; +extern PFNGLDELETEBUFFERSPROC gl3wDeleteBuffers; +extern PFNGLGENBUFFERSPROC gl3wGenBuffers; +extern PFNGLISBUFFERPROC gl3wIsBuffer; +extern PFNGLBUFFERDATAPROC gl3wBufferData; +extern PFNGLBUFFERSUBDATAPROC gl3wBufferSubData; +extern PFNGLGETBUFFERSUBDATAPROC gl3wGetBufferSubData; +extern PFNGLMAPBUFFERPROC gl3wMapBuffer; +extern PFNGLUNMAPBUFFERPROC gl3wUnmapBuffer; +extern PFNGLGETBUFFERPARAMETERIVPROC gl3wGetBufferParameteriv; +extern PFNGLGETBUFFERPOINTERVPROC gl3wGetBufferPointerv; +extern PFNGLBLENDEQUATIONSEPARATEPROC gl3wBlendEquationSeparate; +extern PFNGLDRAWBUFFERSPROC gl3wDrawBuffers; +extern PFNGLSTENCILOPSEPARATEPROC gl3wStencilOpSeparate; +extern PFNGLSTENCILFUNCSEPARATEPROC gl3wStencilFuncSeparate; +extern PFNGLSTENCILMASKSEPARATEPROC gl3wStencilMaskSeparate; +extern PFNGLATTACHSHADERPROC gl3wAttachShader; +extern PFNGLBINDATTRIBLOCATIONPROC gl3wBindAttribLocation; +extern PFNGLCOMPILESHADERPROC gl3wCompileShader; +extern PFNGLCREATEPROGRAMPROC gl3wCreateProgram; +extern PFNGLCREATESHADERPROC gl3wCreateShader; +extern PFNGLDELETEPROGRAMPROC gl3wDeleteProgram; +extern PFNGLDELETESHADERPROC gl3wDeleteShader; +extern PFNGLDETACHSHADERPROC gl3wDetachShader; +extern PFNGLDISABLEVERTEXATTRIBARRAYPROC gl3wDisableVertexAttribArray; +extern PFNGLENABLEVERTEXATTRIBARRAYPROC gl3wEnableVertexAttribArray; +extern PFNGLGETACTIVEATTRIBPROC gl3wGetActiveAttrib; +extern PFNGLGETACTIVEUNIFORMPROC gl3wGetActiveUniform; +extern PFNGLGETATTACHEDSHADERSPROC gl3wGetAttachedShaders; +extern PFNGLGETATTRIBLOCATIONPROC gl3wGetAttribLocation; +extern PFNGLGETPROGRAMIVPROC gl3wGetProgramiv; +extern PFNGLGETPROGRAMINFOLOGPROC gl3wGetProgramInfoLog; +extern PFNGLGETSHADERIVPROC gl3wGetShaderiv; +extern PFNGLGETSHADERINFOLOGPROC gl3wGetShaderInfoLog; +extern PFNGLGETSHADERSOURCEPROC gl3wGetShaderSource; +extern PFNGLGETUNIFORMLOCATIONPROC gl3wGetUniformLocation; +extern PFNGLGETUNIFORMFVPROC gl3wGetUniformfv; +extern PFNGLGETUNIFORMIVPROC gl3wGetUniformiv; +extern PFNGLGETVERTEXATTRIBDVPROC gl3wGetVertexAttribdv; +extern PFNGLGETVERTEXATTRIBFVPROC gl3wGetVertexAttribfv; +extern PFNGLGETVERTEXATTRIBIVPROC gl3wGetVertexAttribiv; +extern PFNGLGETVERTEXATTRIBPOINTERVPROC gl3wGetVertexAttribPointerv; +extern PFNGLISPROGRAMPROC gl3wIsProgram; +extern PFNGLISSHADERPROC gl3wIsShader; +extern PFNGLLINKPROGRAMPROC gl3wLinkProgram; +extern PFNGLSHADERSOURCEPROC gl3wShaderSource; +extern PFNGLUSEPROGRAMPROC gl3wUseProgram; +extern PFNGLUNIFORM1FPROC gl3wUniform1f; +extern PFNGLUNIFORM2FPROC gl3wUniform2f; +extern PFNGLUNIFORM3FPROC gl3wUniform3f; +extern PFNGLUNIFORM4FPROC gl3wUniform4f; +extern PFNGLUNIFORM1IPROC gl3wUniform1i; +extern PFNGLUNIFORM2IPROC gl3wUniform2i; +extern PFNGLUNIFORM3IPROC gl3wUniform3i; +extern PFNGLUNIFORM4IPROC gl3wUniform4i; +extern PFNGLUNIFORM1FVPROC gl3wUniform1fv; +extern PFNGLUNIFORM2FVPROC gl3wUniform2fv; +extern PFNGLUNIFORM3FVPROC gl3wUniform3fv; +extern PFNGLUNIFORM4FVPROC gl3wUniform4fv; +extern PFNGLUNIFORM1IVPROC gl3wUniform1iv; +extern PFNGLUNIFORM2IVPROC gl3wUniform2iv; +extern PFNGLUNIFORM3IVPROC gl3wUniform3iv; +extern PFNGLUNIFORM4IVPROC gl3wUniform4iv; +extern PFNGLUNIFORMMATRIX2FVPROC gl3wUniformMatrix2fv; +extern PFNGLUNIFORMMATRIX3FVPROC gl3wUniformMatrix3fv; +extern PFNGLUNIFORMMATRIX4FVPROC gl3wUniformMatrix4fv; +extern PFNGLVALIDATEPROGRAMPROC gl3wValidateProgram; +extern PFNGLVERTEXATTRIB1DPROC gl3wVertexAttrib1d; +extern PFNGLVERTEXATTRIB1DVPROC gl3wVertexAttrib1dv; +extern PFNGLVERTEXATTRIB1FPROC gl3wVertexAttrib1f; +extern PFNGLVERTEXATTRIB1FVPROC gl3wVertexAttrib1fv; +extern PFNGLVERTEXATTRIB1SPROC gl3wVertexAttrib1s; +extern PFNGLVERTEXATTRIB1SVPROC gl3wVertexAttrib1sv; +extern PFNGLVERTEXATTRIB2DPROC gl3wVertexAttrib2d; +extern PFNGLVERTEXATTRIB2DVPROC gl3wVertexAttrib2dv; +extern PFNGLVERTEXATTRIB2FPROC gl3wVertexAttrib2f; +extern PFNGLVERTEXATTRIB2FVPROC gl3wVertexAttrib2fv; +extern PFNGLVERTEXATTRIB2SPROC gl3wVertexAttrib2s; +extern PFNGLVERTEXATTRIB2SVPROC gl3wVertexAttrib2sv; +extern PFNGLVERTEXATTRIB3DPROC gl3wVertexAttrib3d; +extern PFNGLVERTEXATTRIB3DVPROC gl3wVertexAttrib3dv; +extern PFNGLVERTEXATTRIB3FPROC gl3wVertexAttrib3f; +extern PFNGLVERTEXATTRIB3FVPROC gl3wVertexAttrib3fv; +extern PFNGLVERTEXATTRIB3SPROC gl3wVertexAttrib3s; +extern PFNGLVERTEXATTRIB3SVPROC gl3wVertexAttrib3sv; +extern PFNGLVERTEXATTRIB4NBVPROC gl3wVertexAttrib4Nbv; +extern PFNGLVERTEXATTRIB4NIVPROC gl3wVertexAttrib4Niv; +extern PFNGLVERTEXATTRIB4NSVPROC gl3wVertexAttrib4Nsv; +extern PFNGLVERTEXATTRIB4NUBPROC gl3wVertexAttrib4Nub; +extern PFNGLVERTEXATTRIB4NUBVPROC gl3wVertexAttrib4Nubv; +extern PFNGLVERTEXATTRIB4NUIVPROC gl3wVertexAttrib4Nuiv; +extern PFNGLVERTEXATTRIB4NUSVPROC gl3wVertexAttrib4Nusv; +extern PFNGLVERTEXATTRIB4BVPROC gl3wVertexAttrib4bv; +extern PFNGLVERTEXATTRIB4DPROC gl3wVertexAttrib4d; +extern PFNGLVERTEXATTRIB4DVPROC gl3wVertexAttrib4dv; +extern PFNGLVERTEXATTRIB4FPROC gl3wVertexAttrib4f; +extern PFNGLVERTEXATTRIB4FVPROC gl3wVertexAttrib4fv; +extern PFNGLVERTEXATTRIB4IVPROC gl3wVertexAttrib4iv; +extern PFNGLVERTEXATTRIB4SPROC gl3wVertexAttrib4s; +extern PFNGLVERTEXATTRIB4SVPROC gl3wVertexAttrib4sv; +extern PFNGLVERTEXATTRIB4UBVPROC gl3wVertexAttrib4ubv; +extern PFNGLVERTEXATTRIB4UIVPROC gl3wVertexAttrib4uiv; +extern PFNGLVERTEXATTRIB4USVPROC gl3wVertexAttrib4usv; +extern PFNGLVERTEXATTRIBPOINTERPROC gl3wVertexAttribPointer; +extern PFNGLUNIFORMMATRIX2X3FVPROC gl3wUniformMatrix2x3fv; +extern PFNGLUNIFORMMATRIX3X2FVPROC gl3wUniformMatrix3x2fv; +extern PFNGLUNIFORMMATRIX2X4FVPROC gl3wUniformMatrix2x4fv; +extern PFNGLUNIFORMMATRIX4X2FVPROC gl3wUniformMatrix4x2fv; +extern PFNGLUNIFORMMATRIX3X4FVPROC gl3wUniformMatrix3x4fv; +extern PFNGLUNIFORMMATRIX4X3FVPROC gl3wUniformMatrix4x3fv; +extern PFNGLCOLORMASKIPROC gl3wColorMaski; +extern PFNGLGETBOOLEANI_VPROC gl3wGetBooleani_v; +extern PFNGLGETINTEGERI_VPROC gl3wGetIntegeri_v; +extern PFNGLENABLEIPROC gl3wEnablei; +extern PFNGLDISABLEIPROC gl3wDisablei; +extern PFNGLISENABLEDIPROC gl3wIsEnabledi; +extern PFNGLBEGINTRANSFORMFEEDBACKPROC gl3wBeginTransformFeedback; +extern PFNGLENDTRANSFORMFEEDBACKPROC gl3wEndTransformFeedback; +extern PFNGLBINDBUFFERRANGEPROC gl3wBindBufferRange; +extern PFNGLBINDBUFFERBASEPROC gl3wBindBufferBase; +extern PFNGLTRANSFORMFEEDBACKVARYINGSPROC gl3wTransformFeedbackVaryings; +extern PFNGLGETTRANSFORMFEEDBACKVARYINGPROC gl3wGetTransformFeedbackVarying; +extern PFNGLCLAMPCOLORPROC gl3wClampColor; +extern PFNGLBEGINCONDITIONALRENDERPROC gl3wBeginConditionalRender; +extern PFNGLENDCONDITIONALRENDERPROC gl3wEndConditionalRender; +extern PFNGLVERTEXATTRIBIPOINTERPROC gl3wVertexAttribIPointer; +extern PFNGLGETVERTEXATTRIBIIVPROC gl3wGetVertexAttribIiv; +extern PFNGLGETVERTEXATTRIBIUIVPROC gl3wGetVertexAttribIuiv; +extern PFNGLVERTEXATTRIBI1IPROC gl3wVertexAttribI1i; +extern PFNGLVERTEXATTRIBI2IPROC gl3wVertexAttribI2i; +extern PFNGLVERTEXATTRIBI3IPROC gl3wVertexAttribI3i; +extern PFNGLVERTEXATTRIBI4IPROC gl3wVertexAttribI4i; +extern PFNGLVERTEXATTRIBI1UIPROC gl3wVertexAttribI1ui; +extern PFNGLVERTEXATTRIBI2UIPROC gl3wVertexAttribI2ui; +extern PFNGLVERTEXATTRIBI3UIPROC gl3wVertexAttribI3ui; +extern PFNGLVERTEXATTRIBI4UIPROC gl3wVertexAttribI4ui; +extern PFNGLVERTEXATTRIBI1IVPROC gl3wVertexAttribI1iv; +extern PFNGLVERTEXATTRIBI2IVPROC gl3wVertexAttribI2iv; +extern PFNGLVERTEXATTRIBI3IVPROC gl3wVertexAttribI3iv; +extern PFNGLVERTEXATTRIBI4IVPROC gl3wVertexAttribI4iv; +extern PFNGLVERTEXATTRIBI1UIVPROC gl3wVertexAttribI1uiv; +extern PFNGLVERTEXATTRIBI2UIVPROC gl3wVertexAttribI2uiv; +extern PFNGLVERTEXATTRIBI3UIVPROC gl3wVertexAttribI3uiv; +extern PFNGLVERTEXATTRIBI4UIVPROC gl3wVertexAttribI4uiv; +extern PFNGLVERTEXATTRIBI4BVPROC gl3wVertexAttribI4bv; +extern PFNGLVERTEXATTRIBI4SVPROC gl3wVertexAttribI4sv; +extern PFNGLVERTEXATTRIBI4UBVPROC gl3wVertexAttribI4ubv; +extern PFNGLVERTEXATTRIBI4USVPROC gl3wVertexAttribI4usv; +extern PFNGLGETUNIFORMUIVPROC gl3wGetUniformuiv; +extern PFNGLBINDFRAGDATALOCATIONPROC gl3wBindFragDataLocation; +extern PFNGLGETFRAGDATALOCATIONPROC gl3wGetFragDataLocation; +extern PFNGLUNIFORM1UIPROC gl3wUniform1ui; +extern PFNGLUNIFORM2UIPROC gl3wUniform2ui; +extern PFNGLUNIFORM3UIPROC gl3wUniform3ui; +extern PFNGLUNIFORM4UIPROC gl3wUniform4ui; +extern PFNGLUNIFORM1UIVPROC gl3wUniform1uiv; +extern PFNGLUNIFORM2UIVPROC gl3wUniform2uiv; +extern PFNGLUNIFORM3UIVPROC gl3wUniform3uiv; +extern PFNGLUNIFORM4UIVPROC gl3wUniform4uiv; +extern PFNGLTEXPARAMETERIIVPROC gl3wTexParameterIiv; +extern PFNGLTEXPARAMETERIUIVPROC gl3wTexParameterIuiv; +extern PFNGLGETTEXPARAMETERIIVPROC gl3wGetTexParameterIiv; +extern PFNGLGETTEXPARAMETERIUIVPROC gl3wGetTexParameterIuiv; +extern PFNGLCLEARBUFFERIVPROC gl3wClearBufferiv; +extern PFNGLCLEARBUFFERUIVPROC gl3wClearBufferuiv; +extern PFNGLCLEARBUFFERFVPROC gl3wClearBufferfv; +extern PFNGLCLEARBUFFERFIPROC gl3wClearBufferfi; +extern PFNGLGETSTRINGIPROC gl3wGetStringi; +extern PFNGLDRAWARRAYSINSTANCEDPROC gl3wDrawArraysInstanced; +extern PFNGLDRAWELEMENTSINSTANCEDPROC gl3wDrawElementsInstanced; +extern PFNGLTEXBUFFERPROC gl3wTexBuffer; +extern PFNGLPRIMITIVERESTARTINDEXPROC gl3wPrimitiveRestartIndex; +extern PFNGLGETINTEGER64I_VPROC gl3wGetInteger64i_v; +extern PFNGLGETBUFFERPARAMETERI64VPROC gl3wGetBufferParameteri64v; +extern PFNGLFRAMEBUFFERTEXTUREPROC gl3wFramebufferTexture; +extern PFNGLVERTEXATTRIBDIVISORPROC gl3wVertexAttribDivisor; +extern PFNGLMINSAMPLESHADINGPROC gl3wMinSampleShading; +extern PFNGLBLENDEQUATIONIPROC gl3wBlendEquationi; +extern PFNGLBLENDEQUATIONSEPARATEIPROC gl3wBlendEquationSeparatei; +extern PFNGLBLENDFUNCIPROC gl3wBlendFunci; +extern PFNGLBLENDFUNCSEPARATEIPROC gl3wBlendFuncSeparatei; +extern PFNGLISRENDERBUFFERPROC gl3wIsRenderbuffer; +extern PFNGLBINDRENDERBUFFERPROC gl3wBindRenderbuffer; +extern PFNGLDELETERENDERBUFFERSPROC gl3wDeleteRenderbuffers; +extern PFNGLGENRENDERBUFFERSPROC gl3wGenRenderbuffers; +extern PFNGLRENDERBUFFERSTORAGEPROC gl3wRenderbufferStorage; +extern PFNGLGETRENDERBUFFERPARAMETERIVPROC gl3wGetRenderbufferParameteriv; +extern PFNGLISFRAMEBUFFERPROC gl3wIsFramebuffer; +extern PFNGLBINDFRAMEBUFFERPROC gl3wBindFramebuffer; +extern PFNGLDELETEFRAMEBUFFERSPROC gl3wDeleteFramebuffers; +extern PFNGLGENFRAMEBUFFERSPROC gl3wGenFramebuffers; +extern PFNGLCHECKFRAMEBUFFERSTATUSPROC gl3wCheckFramebufferStatus; +extern PFNGLFRAMEBUFFERTEXTURE1DPROC gl3wFramebufferTexture1D; +extern PFNGLFRAMEBUFFERTEXTURE2DPROC gl3wFramebufferTexture2D; +extern PFNGLFRAMEBUFFERTEXTURE3DPROC gl3wFramebufferTexture3D; +extern PFNGLFRAMEBUFFERRENDERBUFFERPROC gl3wFramebufferRenderbuffer; +extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC gl3wGetFramebufferAttachmentParameteriv; +extern PFNGLGENERATEMIPMAPPROC gl3wGenerateMipmap; +extern PFNGLBLITFRAMEBUFFERPROC gl3wBlitFramebuffer; +extern PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC gl3wRenderbufferStorageMultisample; +extern PFNGLFRAMEBUFFERTEXTURELAYERPROC gl3wFramebufferTextureLayer; +extern PFNGLMAPBUFFERRANGEPROC gl3wMapBufferRange; +extern PFNGLFLUSHMAPPEDBUFFERRANGEPROC gl3wFlushMappedBufferRange; +extern PFNGLBINDVERTEXARRAYPROC gl3wBindVertexArray; +extern PFNGLDELETEVERTEXARRAYSPROC gl3wDeleteVertexArrays; +extern PFNGLGENVERTEXARRAYSPROC gl3wGenVertexArrays; +extern PFNGLISVERTEXARRAYPROC gl3wIsVertexArray; +extern PFNGLGETUNIFORMINDICESPROC gl3wGetUniformIndices; +extern PFNGLGETACTIVEUNIFORMSIVPROC gl3wGetActiveUniformsiv; +extern PFNGLGETACTIVEUNIFORMNAMEPROC gl3wGetActiveUniformName; +extern PFNGLGETUNIFORMBLOCKINDEXPROC gl3wGetUniformBlockIndex; +extern PFNGLGETACTIVEUNIFORMBLOCKIVPROC gl3wGetActiveUniformBlockiv; +extern PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC gl3wGetActiveUniformBlockName; +extern PFNGLUNIFORMBLOCKBINDINGPROC gl3wUniformBlockBinding; +extern PFNGLCOPYBUFFERSUBDATAPROC gl3wCopyBufferSubData; +extern PFNGLDRAWELEMENTSBASEVERTEXPROC gl3wDrawElementsBaseVertex; +extern PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC gl3wDrawRangeElementsBaseVertex; +extern PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC gl3wDrawElementsInstancedBaseVertex; +extern PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC gl3wMultiDrawElementsBaseVertex; +extern PFNGLPROVOKINGVERTEXPROC gl3wProvokingVertex; +extern PFNGLFENCESYNCPROC gl3wFenceSync; +extern PFNGLISSYNCPROC gl3wIsSync; +extern PFNGLDELETESYNCPROC gl3wDeleteSync; +extern PFNGLCLIENTWAITSYNCPROC gl3wClientWaitSync; +extern PFNGLWAITSYNCPROC gl3wWaitSync; +extern PFNGLGETINTEGER64VPROC gl3wGetInteger64v; +extern PFNGLGETSYNCIVPROC gl3wGetSynciv; +extern PFNGLTEXIMAGE2DMULTISAMPLEPROC gl3wTexImage2DMultisample; +extern PFNGLTEXIMAGE3DMULTISAMPLEPROC gl3wTexImage3DMultisample; +extern PFNGLGETMULTISAMPLEFVPROC gl3wGetMultisamplefv; +extern PFNGLSAMPLEMASKIPROC gl3wSampleMaski; +extern PFNGLBLENDEQUATIONIARBPROC gl3wBlendEquationiARB; +extern PFNGLBLENDEQUATIONSEPARATEIARBPROC gl3wBlendEquationSeparateiARB; +extern PFNGLBLENDFUNCIARBPROC gl3wBlendFunciARB; +extern PFNGLBLENDFUNCSEPARATEIARBPROC gl3wBlendFuncSeparateiARB; +extern PFNGLMINSAMPLESHADINGARBPROC gl3wMinSampleShadingARB; +extern PFNGLNAMEDSTRINGARBPROC gl3wNamedStringARB; +extern PFNGLDELETENAMEDSTRINGARBPROC gl3wDeleteNamedStringARB; +extern PFNGLCOMPILESHADERINCLUDEARBPROC gl3wCompileShaderIncludeARB; +extern PFNGLISNAMEDSTRINGARBPROC gl3wIsNamedStringARB; +extern PFNGLGETNAMEDSTRINGARBPROC gl3wGetNamedStringARB; +extern PFNGLGETNAMEDSTRINGIVARBPROC gl3wGetNamedStringivARB; +extern PFNGLBINDFRAGDATALOCATIONINDEXEDPROC gl3wBindFragDataLocationIndexed; +extern PFNGLGETFRAGDATAINDEXPROC gl3wGetFragDataIndex; +extern PFNGLGENSAMPLERSPROC gl3wGenSamplers; +extern PFNGLDELETESAMPLERSPROC gl3wDeleteSamplers; +extern PFNGLISSAMPLERPROC gl3wIsSampler; +extern PFNGLBINDSAMPLERPROC gl3wBindSampler; +extern PFNGLSAMPLERPARAMETERIPROC gl3wSamplerParameteri; +extern PFNGLSAMPLERPARAMETERIVPROC gl3wSamplerParameteriv; +extern PFNGLSAMPLERPARAMETERFPROC gl3wSamplerParameterf; +extern PFNGLSAMPLERPARAMETERFVPROC gl3wSamplerParameterfv; +extern PFNGLSAMPLERPARAMETERIIVPROC gl3wSamplerParameterIiv; +extern PFNGLSAMPLERPARAMETERIUIVPROC gl3wSamplerParameterIuiv; +extern PFNGLGETSAMPLERPARAMETERIVPROC gl3wGetSamplerParameteriv; +extern PFNGLGETSAMPLERPARAMETERIIVPROC gl3wGetSamplerParameterIiv; +extern PFNGLGETSAMPLERPARAMETERFVPROC gl3wGetSamplerParameterfv; +extern PFNGLGETSAMPLERPARAMETERIUIVPROC gl3wGetSamplerParameterIuiv; +extern PFNGLQUERYCOUNTERPROC gl3wQueryCounter; +extern PFNGLGETQUERYOBJECTI64VPROC gl3wGetQueryObjecti64v; +extern PFNGLGETQUERYOBJECTUI64VPROC gl3wGetQueryObjectui64v; +extern PFNGLVERTEXP2UIPROC gl3wVertexP2ui; +extern PFNGLVERTEXP2UIVPROC gl3wVertexP2uiv; +extern PFNGLVERTEXP3UIPROC gl3wVertexP3ui; +extern PFNGLVERTEXP3UIVPROC gl3wVertexP3uiv; +extern PFNGLVERTEXP4UIPROC gl3wVertexP4ui; +extern PFNGLVERTEXP4UIVPROC gl3wVertexP4uiv; +extern PFNGLTEXCOORDP1UIPROC gl3wTexCoordP1ui; +extern PFNGLTEXCOORDP1UIVPROC gl3wTexCoordP1uiv; +extern PFNGLTEXCOORDP2UIPROC gl3wTexCoordP2ui; +extern PFNGLTEXCOORDP2UIVPROC gl3wTexCoordP2uiv; +extern PFNGLTEXCOORDP3UIPROC gl3wTexCoordP3ui; +extern PFNGLTEXCOORDP3UIVPROC gl3wTexCoordP3uiv; +extern PFNGLTEXCOORDP4UIPROC gl3wTexCoordP4ui; +extern PFNGLTEXCOORDP4UIVPROC gl3wTexCoordP4uiv; +extern PFNGLMULTITEXCOORDP1UIPROC gl3wMultiTexCoordP1ui; +extern PFNGLMULTITEXCOORDP1UIVPROC gl3wMultiTexCoordP1uiv; +extern PFNGLMULTITEXCOORDP2UIPROC gl3wMultiTexCoordP2ui; +extern PFNGLMULTITEXCOORDP2UIVPROC gl3wMultiTexCoordP2uiv; +extern PFNGLMULTITEXCOORDP3UIPROC gl3wMultiTexCoordP3ui; +extern PFNGLMULTITEXCOORDP3UIVPROC gl3wMultiTexCoordP3uiv; +extern PFNGLMULTITEXCOORDP4UIPROC gl3wMultiTexCoordP4ui; +extern PFNGLMULTITEXCOORDP4UIVPROC gl3wMultiTexCoordP4uiv; +extern PFNGLNORMALP3UIPROC gl3wNormalP3ui; +extern PFNGLNORMALP3UIVPROC gl3wNormalP3uiv; +extern PFNGLCOLORP3UIPROC gl3wColorP3ui; +extern PFNGLCOLORP3UIVPROC gl3wColorP3uiv; +extern PFNGLCOLORP4UIPROC gl3wColorP4ui; +extern PFNGLCOLORP4UIVPROC gl3wColorP4uiv; +extern PFNGLSECONDARYCOLORP3UIPROC gl3wSecondaryColorP3ui; +extern PFNGLSECONDARYCOLORP3UIVPROC gl3wSecondaryColorP3uiv; +extern PFNGLVERTEXATTRIBP1UIPROC gl3wVertexAttribP1ui; +extern PFNGLVERTEXATTRIBP1UIVPROC gl3wVertexAttribP1uiv; +extern PFNGLVERTEXATTRIBP2UIPROC gl3wVertexAttribP2ui; +extern PFNGLVERTEXATTRIBP2UIVPROC gl3wVertexAttribP2uiv; +extern PFNGLVERTEXATTRIBP3UIPROC gl3wVertexAttribP3ui; +extern PFNGLVERTEXATTRIBP3UIVPROC gl3wVertexAttribP3uiv; +extern PFNGLVERTEXATTRIBP4UIPROC gl3wVertexAttribP4ui; +extern PFNGLVERTEXATTRIBP4UIVPROC gl3wVertexAttribP4uiv; +extern PFNGLDRAWARRAYSINDIRECTPROC gl3wDrawArraysIndirect; +extern PFNGLDRAWELEMENTSINDIRECTPROC gl3wDrawElementsIndirect; +extern PFNGLUNIFORM1DPROC gl3wUniform1d; +extern PFNGLUNIFORM2DPROC gl3wUniform2d; +extern PFNGLUNIFORM3DPROC gl3wUniform3d; +extern PFNGLUNIFORM4DPROC gl3wUniform4d; +extern PFNGLUNIFORM1DVPROC gl3wUniform1dv; +extern PFNGLUNIFORM2DVPROC gl3wUniform2dv; +extern PFNGLUNIFORM3DVPROC gl3wUniform3dv; +extern PFNGLUNIFORM4DVPROC gl3wUniform4dv; +extern PFNGLUNIFORMMATRIX2DVPROC gl3wUniformMatrix2dv; +extern PFNGLUNIFORMMATRIX3DVPROC gl3wUniformMatrix3dv; +extern PFNGLUNIFORMMATRIX4DVPROC gl3wUniformMatrix4dv; +extern PFNGLUNIFORMMATRIX2X3DVPROC gl3wUniformMatrix2x3dv; +extern PFNGLUNIFORMMATRIX2X4DVPROC gl3wUniformMatrix2x4dv; +extern PFNGLUNIFORMMATRIX3X2DVPROC gl3wUniformMatrix3x2dv; +extern PFNGLUNIFORMMATRIX3X4DVPROC gl3wUniformMatrix3x4dv; +extern PFNGLUNIFORMMATRIX4X2DVPROC gl3wUniformMatrix4x2dv; +extern PFNGLUNIFORMMATRIX4X3DVPROC gl3wUniformMatrix4x3dv; +extern PFNGLGETUNIFORMDVPROC gl3wGetUniformdv; +extern PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC gl3wGetSubroutineUniformLocation; +extern PFNGLGETSUBROUTINEINDEXPROC gl3wGetSubroutineIndex; +extern PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC gl3wGetActiveSubroutineUniformiv; +extern PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC gl3wGetActiveSubroutineUniformName; +extern PFNGLGETACTIVESUBROUTINENAMEPROC gl3wGetActiveSubroutineName; +extern PFNGLUNIFORMSUBROUTINESUIVPROC gl3wUniformSubroutinesuiv; +extern PFNGLGETUNIFORMSUBROUTINEUIVPROC gl3wGetUniformSubroutineuiv; +extern PFNGLGETPROGRAMSTAGEIVPROC gl3wGetProgramStageiv; +extern PFNGLPATCHPARAMETERIPROC gl3wPatchParameteri; +extern PFNGLPATCHPARAMETERFVPROC gl3wPatchParameterfv; +extern PFNGLBINDTRANSFORMFEEDBACKPROC gl3wBindTransformFeedback; +extern PFNGLDELETETRANSFORMFEEDBACKSPROC gl3wDeleteTransformFeedbacks; +extern PFNGLGENTRANSFORMFEEDBACKSPROC gl3wGenTransformFeedbacks; +extern PFNGLISTRANSFORMFEEDBACKPROC gl3wIsTransformFeedback; +extern PFNGLPAUSETRANSFORMFEEDBACKPROC gl3wPauseTransformFeedback; +extern PFNGLRESUMETRANSFORMFEEDBACKPROC gl3wResumeTransformFeedback; +extern PFNGLDRAWTRANSFORMFEEDBACKPROC gl3wDrawTransformFeedback; +extern PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC gl3wDrawTransformFeedbackStream; +extern PFNGLBEGINQUERYINDEXEDPROC gl3wBeginQueryIndexed; +extern PFNGLENDQUERYINDEXEDPROC gl3wEndQueryIndexed; +extern PFNGLGETQUERYINDEXEDIVPROC gl3wGetQueryIndexediv; +extern PFNGLRELEASESHADERCOMPILERPROC gl3wReleaseShaderCompiler; +extern PFNGLSHADERBINARYPROC gl3wShaderBinary; +extern PFNGLGETSHADERPRECISIONFORMATPROC gl3wGetShaderPrecisionFormat; +extern PFNGLDEPTHRANGEFPROC gl3wDepthRangef; +extern PFNGLCLEARDEPTHFPROC gl3wClearDepthf; +extern PFNGLGETPROGRAMBINARYPROC gl3wGetProgramBinary; +extern PFNGLPROGRAMBINARYPROC gl3wProgramBinary; +extern PFNGLPROGRAMPARAMETERIPROC gl3wProgramParameteri; +extern PFNGLUSEPROGRAMSTAGESPROC gl3wUseProgramStages; +extern PFNGLACTIVESHADERPROGRAMPROC gl3wActiveShaderProgram; +extern PFNGLCREATESHADERPROGRAMVPROC gl3wCreateShaderProgramv; +extern PFNGLBINDPROGRAMPIPELINEPROC gl3wBindProgramPipeline; +extern PFNGLDELETEPROGRAMPIPELINESPROC gl3wDeleteProgramPipelines; +extern PFNGLGENPROGRAMPIPELINESPROC gl3wGenProgramPipelines; +extern PFNGLISPROGRAMPIPELINEPROC gl3wIsProgramPipeline; +extern PFNGLGETPROGRAMPIPELINEIVPROC gl3wGetProgramPipelineiv; +extern PFNGLPROGRAMUNIFORM1IPROC gl3wProgramUniform1i; +extern PFNGLPROGRAMUNIFORM1IVPROC gl3wProgramUniform1iv; +extern PFNGLPROGRAMUNIFORM1FPROC gl3wProgramUniform1f; +extern PFNGLPROGRAMUNIFORM1FVPROC gl3wProgramUniform1fv; +extern PFNGLPROGRAMUNIFORM1DPROC gl3wProgramUniform1d; +extern PFNGLPROGRAMUNIFORM1DVPROC gl3wProgramUniform1dv; +extern PFNGLPROGRAMUNIFORM1UIPROC gl3wProgramUniform1ui; +extern PFNGLPROGRAMUNIFORM1UIVPROC gl3wProgramUniform1uiv; +extern PFNGLPROGRAMUNIFORM2IPROC gl3wProgramUniform2i; +extern PFNGLPROGRAMUNIFORM2IVPROC gl3wProgramUniform2iv; +extern PFNGLPROGRAMUNIFORM2FPROC gl3wProgramUniform2f; +extern PFNGLPROGRAMUNIFORM2FVPROC gl3wProgramUniform2fv; +extern PFNGLPROGRAMUNIFORM2DPROC gl3wProgramUniform2d; +extern PFNGLPROGRAMUNIFORM2DVPROC gl3wProgramUniform2dv; +extern PFNGLPROGRAMUNIFORM2UIPROC gl3wProgramUniform2ui; +extern PFNGLPROGRAMUNIFORM2UIVPROC gl3wProgramUniform2uiv; +extern PFNGLPROGRAMUNIFORM3IPROC gl3wProgramUniform3i; +extern PFNGLPROGRAMUNIFORM3IVPROC gl3wProgramUniform3iv; +extern PFNGLPROGRAMUNIFORM3FPROC gl3wProgramUniform3f; +extern PFNGLPROGRAMUNIFORM3FVPROC gl3wProgramUniform3fv; +extern PFNGLPROGRAMUNIFORM3DPROC gl3wProgramUniform3d; +extern PFNGLPROGRAMUNIFORM3DVPROC gl3wProgramUniform3dv; +extern PFNGLPROGRAMUNIFORM3UIPROC gl3wProgramUniform3ui; +extern PFNGLPROGRAMUNIFORM3UIVPROC gl3wProgramUniform3uiv; +extern PFNGLPROGRAMUNIFORM4IPROC gl3wProgramUniform4i; +extern PFNGLPROGRAMUNIFORM4IVPROC gl3wProgramUniform4iv; +extern PFNGLPROGRAMUNIFORM4FPROC gl3wProgramUniform4f; +extern PFNGLPROGRAMUNIFORM4FVPROC gl3wProgramUniform4fv; +extern PFNGLPROGRAMUNIFORM4DPROC gl3wProgramUniform4d; +extern PFNGLPROGRAMUNIFORM4DVPROC gl3wProgramUniform4dv; +extern PFNGLPROGRAMUNIFORM4UIPROC gl3wProgramUniform4ui; +extern PFNGLPROGRAMUNIFORM4UIVPROC gl3wProgramUniform4uiv; +extern PFNGLPROGRAMUNIFORMMATRIX2FVPROC gl3wProgramUniformMatrix2fv; +extern PFNGLPROGRAMUNIFORMMATRIX3FVPROC gl3wProgramUniformMatrix3fv; +extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC gl3wProgramUniformMatrix4fv; +extern PFNGLPROGRAMUNIFORMMATRIX2DVPROC gl3wProgramUniformMatrix2dv; +extern PFNGLPROGRAMUNIFORMMATRIX3DVPROC gl3wProgramUniformMatrix3dv; +extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC gl3wProgramUniformMatrix4dv; +extern PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC gl3wProgramUniformMatrix2x3fv; +extern PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC gl3wProgramUniformMatrix3x2fv; +extern PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC gl3wProgramUniformMatrix2x4fv; +extern PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC gl3wProgramUniformMatrix4x2fv; +extern PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC gl3wProgramUniformMatrix3x4fv; +extern PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC gl3wProgramUniformMatrix4x3fv; +extern PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC gl3wProgramUniformMatrix2x3dv; +extern PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC gl3wProgramUniformMatrix3x2dv; +extern PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC gl3wProgramUniformMatrix2x4dv; +extern PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC gl3wProgramUniformMatrix4x2dv; +extern PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC gl3wProgramUniformMatrix3x4dv; +extern PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC gl3wProgramUniformMatrix4x3dv; +extern PFNGLVALIDATEPROGRAMPIPELINEPROC gl3wValidateProgramPipeline; +extern PFNGLGETPROGRAMPIPELINEINFOLOGPROC gl3wGetProgramPipelineInfoLog; +extern PFNGLVERTEXATTRIBL1DPROC gl3wVertexAttribL1d; +extern PFNGLVERTEXATTRIBL2DPROC gl3wVertexAttribL2d; +extern PFNGLVERTEXATTRIBL3DPROC gl3wVertexAttribL3d; +extern PFNGLVERTEXATTRIBL4DPROC gl3wVertexAttribL4d; +extern PFNGLVERTEXATTRIBL1DVPROC gl3wVertexAttribL1dv; +extern PFNGLVERTEXATTRIBL2DVPROC gl3wVertexAttribL2dv; +extern PFNGLVERTEXATTRIBL3DVPROC gl3wVertexAttribL3dv; +extern PFNGLVERTEXATTRIBL4DVPROC gl3wVertexAttribL4dv; +extern PFNGLVERTEXATTRIBLPOINTERPROC gl3wVertexAttribLPointer; +extern PFNGLGETVERTEXATTRIBLDVPROC gl3wGetVertexAttribLdv; +extern PFNGLVIEWPORTARRAYVPROC gl3wViewportArrayv; +extern PFNGLVIEWPORTINDEXEDFPROC gl3wViewportIndexedf; +extern PFNGLVIEWPORTINDEXEDFVPROC gl3wViewportIndexedfv; +extern PFNGLSCISSORARRAYVPROC gl3wScissorArrayv; +extern PFNGLSCISSORINDEXEDPROC gl3wScissorIndexed; +extern PFNGLSCISSORINDEXEDVPROC gl3wScissorIndexedv; +extern PFNGLDEPTHRANGEARRAYVPROC gl3wDepthRangeArrayv; +extern PFNGLDEPTHRANGEINDEXEDPROC gl3wDepthRangeIndexed; +extern PFNGLGETFLOATI_VPROC gl3wGetFloati_v; +extern PFNGLGETDOUBLEI_VPROC gl3wGetDoublei_v; +extern PFNGLCREATESYNCFROMCLEVENTARBPROC gl3wCreateSyncFromCLeventARB; +extern PFNGLDEBUGMESSAGECONTROLARBPROC gl3wDebugMessageControlARB; +extern PFNGLDEBUGMESSAGEINSERTARBPROC gl3wDebugMessageInsertARB; +extern PFNGLDEBUGMESSAGECALLBACKARBPROC gl3wDebugMessageCallbackARB; +extern PFNGLGETDEBUGMESSAGELOGARBPROC gl3wGetDebugMessageLogARB; +extern PFNGLGETGRAPHICSRESETSTATUSARBPROC gl3wGetGraphicsResetStatusARB; +extern PFNGLGETNTEXIMAGEARBPROC gl3wGetnTexImageARB; +extern PFNGLREADNPIXELSARBPROC gl3wReadnPixelsARB; +extern PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC gl3wGetnCompressedTexImageARB; +extern PFNGLGETNUNIFORMFVARBPROC gl3wGetnUniformfvARB; +extern PFNGLGETNUNIFORMIVARBPROC gl3wGetnUniformivARB; +extern PFNGLGETNUNIFORMUIVARBPROC gl3wGetnUniformuivARB; +extern PFNGLGETNUNIFORMDVARBPROC gl3wGetnUniformdvARB; +extern PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC gl3wDrawArraysInstancedBaseInstance; +extern PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC gl3wDrawElementsInstancedBaseInstance; +extern PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC gl3wDrawElementsInstancedBaseVertexBaseInstance; +extern PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC gl3wDrawTransformFeedbackInstanced; +extern PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC gl3wDrawTransformFeedbackStreamInstanced; +extern PFNGLGETINTERNALFORMATIVPROC gl3wGetInternalformativ; +extern PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC gl3wGetActiveAtomicCounterBufferiv; +extern PFNGLBINDIMAGETEXTUREPROC gl3wBindImageTexture; +extern PFNGLMEMORYBARRIERPROC gl3wMemoryBarrier; +extern PFNGLTEXSTORAGE1DPROC gl3wTexStorage1D; +extern PFNGLTEXSTORAGE2DPROC gl3wTexStorage2D; +extern PFNGLTEXSTORAGE3DPROC gl3wTexStorage3D; +extern PFNGLTEXTURESTORAGE1DEXTPROC gl3wTextureStorage1DEXT; +extern PFNGLTEXTURESTORAGE2DEXTPROC gl3wTextureStorage2DEXT; +extern PFNGLTEXTURESTORAGE3DEXTPROC gl3wTextureStorage3DEXT; +extern PFNGLDEBUGMESSAGECONTROLPROC gl3wDebugMessageControl; +extern PFNGLDEBUGMESSAGEINSERTPROC gl3wDebugMessageInsert; +extern PFNGLDEBUGMESSAGECALLBACKPROC gl3wDebugMessageCallback; +extern PFNGLGETDEBUGMESSAGELOGPROC gl3wGetDebugMessageLog; +extern PFNGLPUSHDEBUGGROUPPROC gl3wPushDebugGroup; +extern PFNGLPOPDEBUGGROUPPROC gl3wPopDebugGroup; +extern PFNGLOBJECTLABELPROC gl3wObjectLabel; +extern PFNGLGETOBJECTLABELPROC gl3wGetObjectLabel; +extern PFNGLOBJECTPTRLABELPROC gl3wObjectPtrLabel; +extern PFNGLGETOBJECTPTRLABELPROC gl3wGetObjectPtrLabel; +extern PFNGLCLEARBUFFERDATAPROC gl3wClearBufferData; +extern PFNGLCLEARBUFFERSUBDATAPROC gl3wClearBufferSubData; +extern PFNGLCLEARNAMEDBUFFERDATAEXTPROC gl3wClearNamedBufferDataEXT; +extern PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC gl3wClearNamedBufferSubDataEXT; +extern PFNGLDISPATCHCOMPUTEPROC gl3wDispatchCompute; +extern PFNGLDISPATCHCOMPUTEINDIRECTPROC gl3wDispatchComputeIndirect; +extern PFNGLCOPYIMAGESUBDATAPROC gl3wCopyImageSubData; +extern PFNGLTEXTUREVIEWPROC gl3wTextureView; +extern PFNGLBINDVERTEXBUFFERPROC gl3wBindVertexBuffer; +extern PFNGLVERTEXATTRIBFORMATPROC gl3wVertexAttribFormat; +extern PFNGLVERTEXATTRIBIFORMATPROC gl3wVertexAttribIFormat; +extern PFNGLVERTEXATTRIBLFORMATPROC gl3wVertexAttribLFormat; +extern PFNGLVERTEXATTRIBBINDINGPROC gl3wVertexAttribBinding; +extern PFNGLVERTEXBINDINGDIVISORPROC gl3wVertexBindingDivisor; +extern PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC gl3wVertexArrayBindVertexBufferEXT; +extern PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC gl3wVertexArrayVertexAttribFormatEXT; +extern PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC gl3wVertexArrayVertexAttribIFormatEXT; +extern PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC gl3wVertexArrayVertexAttribLFormatEXT; +extern PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC gl3wVertexArrayVertexAttribBindingEXT; +extern PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC gl3wVertexArrayVertexBindingDivisorEXT; +extern PFNGLFRAMEBUFFERPARAMETERIPROC gl3wFramebufferParameteri; +extern PFNGLGETFRAMEBUFFERPARAMETERIVPROC gl3wGetFramebufferParameteriv; +extern PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC gl3wNamedFramebufferParameteriEXT; +extern PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC gl3wGetNamedFramebufferParameterivEXT; +extern PFNGLGETINTERNALFORMATI64VPROC gl3wGetInternalformati64v; +extern PFNGLINVALIDATETEXSUBIMAGEPROC gl3wInvalidateTexSubImage; +extern PFNGLINVALIDATETEXIMAGEPROC gl3wInvalidateTexImage; +extern PFNGLINVALIDATEBUFFERSUBDATAPROC gl3wInvalidateBufferSubData; +extern PFNGLINVALIDATEBUFFERDATAPROC gl3wInvalidateBufferData; +extern PFNGLINVALIDATEFRAMEBUFFERPROC gl3wInvalidateFramebuffer; +extern PFNGLINVALIDATESUBFRAMEBUFFERPROC gl3wInvalidateSubFramebuffer; +extern PFNGLMULTIDRAWARRAYSINDIRECTPROC gl3wMultiDrawArraysIndirect; +extern PFNGLMULTIDRAWELEMENTSINDIRECTPROC gl3wMultiDrawElementsIndirect; +extern PFNGLGETPROGRAMINTERFACEIVPROC gl3wGetProgramInterfaceiv; +extern PFNGLGETPROGRAMRESOURCEINDEXPROC gl3wGetProgramResourceIndex; +extern PFNGLGETPROGRAMRESOURCENAMEPROC gl3wGetProgramResourceName; +extern PFNGLGETPROGRAMRESOURCEIVPROC gl3wGetProgramResourceiv; +extern PFNGLGETPROGRAMRESOURCELOCATIONPROC gl3wGetProgramResourceLocation; +extern PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC gl3wGetProgramResourceLocationIndex; +extern PFNGLSHADERSTORAGEBLOCKBINDINGPROC gl3wShaderStorageBlockBinding; +extern PFNGLTEXBUFFERRANGEPROC gl3wTexBufferRange; +extern PFNGLTEXTUREBUFFERRANGEEXTPROC gl3wTextureBufferRangeEXT; +extern PFNGLTEXSTORAGE2DMULTISAMPLEPROC gl3wTexStorage2DMultisample; +extern PFNGLTEXSTORAGE3DMULTISAMPLEPROC gl3wTexStorage3DMultisample; +extern PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC gl3wTextureStorage2DMultisampleEXT; +extern PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC gl3wTextureStorage3DMultisampleEXT; + +#define glCullFace gl3wCullFace +#define glFrontFace gl3wFrontFace +#define glHint gl3wHint +#define glLineWidth gl3wLineWidth +#define glPointSize gl3wPointSize +#define glPolygonMode gl3wPolygonMode +#define glScissor gl3wScissor +#define glTexParameterf gl3wTexParameterf +#define glTexParameterfv gl3wTexParameterfv +#define glTexParameteri gl3wTexParameteri +#define glTexParameteriv gl3wTexParameteriv +#define glTexImage1D gl3wTexImage1D +#define glTexImage2D gl3wTexImage2D +#define glDrawBuffer gl3wDrawBuffer +#define glClear gl3wClear +#define glClearColor gl3wClearColor +#define glClearStencil gl3wClearStencil +#define glClearDepth gl3wClearDepth +#define glStencilMask gl3wStencilMask +#define glColorMask gl3wColorMask +#define glDepthMask gl3wDepthMask +#define glDisable gl3wDisable +#define glEnable gl3wEnable +#define glFinish gl3wFinish +#define glFlush gl3wFlush +#define glBlendFunc gl3wBlendFunc +#define glLogicOp gl3wLogicOp +#define glStencilFunc gl3wStencilFunc +#define glStencilOp gl3wStencilOp +#define glDepthFunc gl3wDepthFunc +#define glPixelStoref gl3wPixelStoref +#define glPixelStorei gl3wPixelStorei +#define glReadBuffer gl3wReadBuffer +#define glReadPixels gl3wReadPixels +#define glGetBooleanv gl3wGetBooleanv +#define glGetDoublev gl3wGetDoublev +#define glGetError gl3wGetError +#define glGetFloatv gl3wGetFloatv +#define glGetIntegerv gl3wGetIntegerv +#define glGetString gl3wGetString +#define glGetTexImage gl3wGetTexImage +#define glGetTexParameterfv gl3wGetTexParameterfv +#define glGetTexParameteriv gl3wGetTexParameteriv +#define glGetTexLevelParameterfv gl3wGetTexLevelParameterfv +#define glGetTexLevelParameteriv gl3wGetTexLevelParameteriv +#define glIsEnabled gl3wIsEnabled +#define glDepthRange gl3wDepthRange +#define glViewport gl3wViewport +#define glDrawArrays gl3wDrawArrays +#define glDrawElements gl3wDrawElements +#define glGetPointerv gl3wGetPointerv +#define glPolygonOffset gl3wPolygonOffset +#define glCopyTexImage1D gl3wCopyTexImage1D +#define glCopyTexImage2D gl3wCopyTexImage2D +#define glCopyTexSubImage1D gl3wCopyTexSubImage1D +#define glCopyTexSubImage2D gl3wCopyTexSubImage2D +#define glTexSubImage1D gl3wTexSubImage1D +#define glTexSubImage2D gl3wTexSubImage2D +#define glBindTexture gl3wBindTexture +#define glDeleteTextures gl3wDeleteTextures +#define glGenTextures gl3wGenTextures +#define glIsTexture gl3wIsTexture +#define glBlendColor gl3wBlendColor +#define glBlendEquation gl3wBlendEquation +#define glDrawRangeElements gl3wDrawRangeElements +#define glTexImage3D gl3wTexImage3D +#define glTexSubImage3D gl3wTexSubImage3D +#define glCopyTexSubImage3D gl3wCopyTexSubImage3D +#define glActiveTexture gl3wActiveTexture +#define glSampleCoverage gl3wSampleCoverage +#define glCompressedTexImage3D gl3wCompressedTexImage3D +#define glCompressedTexImage2D gl3wCompressedTexImage2D +#define glCompressedTexImage1D gl3wCompressedTexImage1D +#define glCompressedTexSubImage3D gl3wCompressedTexSubImage3D +#define glCompressedTexSubImage2D gl3wCompressedTexSubImage2D +#define glCompressedTexSubImage1D gl3wCompressedTexSubImage1D +#define glGetCompressedTexImage gl3wGetCompressedTexImage +#define glBlendFuncSeparate gl3wBlendFuncSeparate +#define glMultiDrawArrays gl3wMultiDrawArrays +#define glMultiDrawElements gl3wMultiDrawElements +#define glPointParameterf gl3wPointParameterf +#define glPointParameterfv gl3wPointParameterfv +#define glPointParameteri gl3wPointParameteri +#define glPointParameteriv gl3wPointParameteriv +#define glGenQueries gl3wGenQueries +#define glDeleteQueries gl3wDeleteQueries +#define glIsQuery gl3wIsQuery +#define glBeginQuery gl3wBeginQuery +#define glEndQuery gl3wEndQuery +#define glGetQueryiv gl3wGetQueryiv +#define glGetQueryObjectiv gl3wGetQueryObjectiv +#define glGetQueryObjectuiv gl3wGetQueryObjectuiv +#define glBindBuffer gl3wBindBuffer +#define glDeleteBuffers gl3wDeleteBuffers +#define glGenBuffers gl3wGenBuffers +#define glIsBuffer gl3wIsBuffer +#define glBufferData gl3wBufferData +#define glBufferSubData gl3wBufferSubData +#define glGetBufferSubData gl3wGetBufferSubData +#define glMapBuffer gl3wMapBuffer +#define glUnmapBuffer gl3wUnmapBuffer +#define glGetBufferParameteriv gl3wGetBufferParameteriv +#define glGetBufferPointerv gl3wGetBufferPointerv +#define glBlendEquationSeparate gl3wBlendEquationSeparate +#define glDrawBuffers gl3wDrawBuffers +#define glStencilOpSeparate gl3wStencilOpSeparate +#define glStencilFuncSeparate gl3wStencilFuncSeparate +#define glStencilMaskSeparate gl3wStencilMaskSeparate +#define glAttachShader gl3wAttachShader +#define glBindAttribLocation gl3wBindAttribLocation +#define glCompileShader gl3wCompileShader +#define glCreateProgram gl3wCreateProgram +#define glCreateShader gl3wCreateShader +#define glDeleteProgram gl3wDeleteProgram +#define glDeleteShader gl3wDeleteShader +#define glDetachShader gl3wDetachShader +#define glDisableVertexAttribArray gl3wDisableVertexAttribArray +#define glEnableVertexAttribArray gl3wEnableVertexAttribArray +#define glGetActiveAttrib gl3wGetActiveAttrib +#define glGetActiveUniform gl3wGetActiveUniform +#define glGetAttachedShaders gl3wGetAttachedShaders +#define glGetAttribLocation gl3wGetAttribLocation +#define glGetProgramiv gl3wGetProgramiv +#define glGetProgramInfoLog gl3wGetProgramInfoLog +#define glGetShaderiv gl3wGetShaderiv +#define glGetShaderInfoLog gl3wGetShaderInfoLog +#define glGetShaderSource gl3wGetShaderSource +#define glGetUniformLocation gl3wGetUniformLocation +#define glGetUniformfv gl3wGetUniformfv +#define glGetUniformiv gl3wGetUniformiv +#define glGetVertexAttribdv gl3wGetVertexAttribdv +#define glGetVertexAttribfv gl3wGetVertexAttribfv +#define glGetVertexAttribiv gl3wGetVertexAttribiv +#define glGetVertexAttribPointerv gl3wGetVertexAttribPointerv +#define glIsProgram gl3wIsProgram +#define glIsShader gl3wIsShader +#define glLinkProgram gl3wLinkProgram +#define glShaderSource gl3wShaderSource +#define glUseProgram gl3wUseProgram +#define glUniform1f gl3wUniform1f +#define glUniform2f gl3wUniform2f +#define glUniform3f gl3wUniform3f +#define glUniform4f gl3wUniform4f +#define glUniform1i gl3wUniform1i +#define glUniform2i gl3wUniform2i +#define glUniform3i gl3wUniform3i +#define glUniform4i gl3wUniform4i +#define glUniform1fv gl3wUniform1fv +#define glUniform2fv gl3wUniform2fv +#define glUniform3fv gl3wUniform3fv +#define glUniform4fv gl3wUniform4fv +#define glUniform1iv gl3wUniform1iv +#define glUniform2iv gl3wUniform2iv +#define glUniform3iv gl3wUniform3iv +#define glUniform4iv gl3wUniform4iv +#define glUniformMatrix2fv gl3wUniformMatrix2fv +#define glUniformMatrix3fv gl3wUniformMatrix3fv +#define glUniformMatrix4fv gl3wUniformMatrix4fv +#define glValidateProgram gl3wValidateProgram +#define glVertexAttrib1d gl3wVertexAttrib1d +#define glVertexAttrib1dv gl3wVertexAttrib1dv +#define glVertexAttrib1f gl3wVertexAttrib1f +#define glVertexAttrib1fv gl3wVertexAttrib1fv +#define glVertexAttrib1s gl3wVertexAttrib1s +#define glVertexAttrib1sv gl3wVertexAttrib1sv +#define glVertexAttrib2d gl3wVertexAttrib2d +#define glVertexAttrib2dv gl3wVertexAttrib2dv +#define glVertexAttrib2f gl3wVertexAttrib2f +#define glVertexAttrib2fv gl3wVertexAttrib2fv +#define glVertexAttrib2s gl3wVertexAttrib2s +#define glVertexAttrib2sv gl3wVertexAttrib2sv +#define glVertexAttrib3d gl3wVertexAttrib3d +#define glVertexAttrib3dv gl3wVertexAttrib3dv +#define glVertexAttrib3f gl3wVertexAttrib3f +#define glVertexAttrib3fv gl3wVertexAttrib3fv +#define glVertexAttrib3s gl3wVertexAttrib3s +#define glVertexAttrib3sv gl3wVertexAttrib3sv +#define glVertexAttrib4Nbv gl3wVertexAttrib4Nbv +#define glVertexAttrib4Niv gl3wVertexAttrib4Niv +#define glVertexAttrib4Nsv gl3wVertexAttrib4Nsv +#define glVertexAttrib4Nub gl3wVertexAttrib4Nub +#define glVertexAttrib4Nubv gl3wVertexAttrib4Nubv +#define glVertexAttrib4Nuiv gl3wVertexAttrib4Nuiv +#define glVertexAttrib4Nusv gl3wVertexAttrib4Nusv +#define glVertexAttrib4bv gl3wVertexAttrib4bv +#define glVertexAttrib4d gl3wVertexAttrib4d +#define glVertexAttrib4dv gl3wVertexAttrib4dv +#define glVertexAttrib4f gl3wVertexAttrib4f +#define glVertexAttrib4fv gl3wVertexAttrib4fv +#define glVertexAttrib4iv gl3wVertexAttrib4iv +#define glVertexAttrib4s gl3wVertexAttrib4s +#define glVertexAttrib4sv gl3wVertexAttrib4sv +#define glVertexAttrib4ubv gl3wVertexAttrib4ubv +#define glVertexAttrib4uiv gl3wVertexAttrib4uiv +#define glVertexAttrib4usv gl3wVertexAttrib4usv +#define glVertexAttribPointer gl3wVertexAttribPointer +#define glUniformMatrix2x3fv gl3wUniformMatrix2x3fv +#define glUniformMatrix3x2fv gl3wUniformMatrix3x2fv +#define glUniformMatrix2x4fv gl3wUniformMatrix2x4fv +#define glUniformMatrix4x2fv gl3wUniformMatrix4x2fv +#define glUniformMatrix3x4fv gl3wUniformMatrix3x4fv +#define glUniformMatrix4x3fv gl3wUniformMatrix4x3fv +#define glColorMaski gl3wColorMaski +#define glGetBooleani_v gl3wGetBooleani_v +#define glGetIntegeri_v gl3wGetIntegeri_v +#define glEnablei gl3wEnablei +#define glDisablei gl3wDisablei +#define glIsEnabledi gl3wIsEnabledi +#define glBeginTransformFeedback gl3wBeginTransformFeedback +#define glEndTransformFeedback gl3wEndTransformFeedback +#define glBindBufferRange gl3wBindBufferRange +#define glBindBufferBase gl3wBindBufferBase +#define glTransformFeedbackVaryings gl3wTransformFeedbackVaryings +#define glGetTransformFeedbackVarying gl3wGetTransformFeedbackVarying +#define glClampColor gl3wClampColor +#define glBeginConditionalRender gl3wBeginConditionalRender +#define glEndConditionalRender gl3wEndConditionalRender +#define glVertexAttribIPointer gl3wVertexAttribIPointer +#define glGetVertexAttribIiv gl3wGetVertexAttribIiv +#define glGetVertexAttribIuiv gl3wGetVertexAttribIuiv +#define glVertexAttribI1i gl3wVertexAttribI1i +#define glVertexAttribI2i gl3wVertexAttribI2i +#define glVertexAttribI3i gl3wVertexAttribI3i +#define glVertexAttribI4i gl3wVertexAttribI4i +#define glVertexAttribI1ui gl3wVertexAttribI1ui +#define glVertexAttribI2ui gl3wVertexAttribI2ui +#define glVertexAttribI3ui gl3wVertexAttribI3ui +#define glVertexAttribI4ui gl3wVertexAttribI4ui +#define glVertexAttribI1iv gl3wVertexAttribI1iv +#define glVertexAttribI2iv gl3wVertexAttribI2iv +#define glVertexAttribI3iv gl3wVertexAttribI3iv +#define glVertexAttribI4iv gl3wVertexAttribI4iv +#define glVertexAttribI1uiv gl3wVertexAttribI1uiv +#define glVertexAttribI2uiv gl3wVertexAttribI2uiv +#define glVertexAttribI3uiv gl3wVertexAttribI3uiv +#define glVertexAttribI4uiv gl3wVertexAttribI4uiv +#define glVertexAttribI4bv gl3wVertexAttribI4bv +#define glVertexAttribI4sv gl3wVertexAttribI4sv +#define glVertexAttribI4ubv gl3wVertexAttribI4ubv +#define glVertexAttribI4usv gl3wVertexAttribI4usv +#define glGetUniformuiv gl3wGetUniformuiv +#define glBindFragDataLocation gl3wBindFragDataLocation +#define glGetFragDataLocation gl3wGetFragDataLocation +#define glUniform1ui gl3wUniform1ui +#define glUniform2ui gl3wUniform2ui +#define glUniform3ui gl3wUniform3ui +#define glUniform4ui gl3wUniform4ui +#define glUniform1uiv gl3wUniform1uiv +#define glUniform2uiv gl3wUniform2uiv +#define glUniform3uiv gl3wUniform3uiv +#define glUniform4uiv gl3wUniform4uiv +#define glTexParameterIiv gl3wTexParameterIiv +#define glTexParameterIuiv gl3wTexParameterIuiv +#define glGetTexParameterIiv gl3wGetTexParameterIiv +#define glGetTexParameterIuiv gl3wGetTexParameterIuiv +#define glClearBufferiv gl3wClearBufferiv +#define glClearBufferuiv gl3wClearBufferuiv +#define glClearBufferfv gl3wClearBufferfv +#define glClearBufferfi gl3wClearBufferfi +#define glGetStringi gl3wGetStringi +#define glDrawArraysInstanced gl3wDrawArraysInstanced +#define glDrawElementsInstanced gl3wDrawElementsInstanced +#define glTexBuffer gl3wTexBuffer +#define glPrimitiveRestartIndex gl3wPrimitiveRestartIndex +#define glGetInteger64i_v gl3wGetInteger64i_v +#define glGetBufferParameteri64v gl3wGetBufferParameteri64v +#define glFramebufferTexture gl3wFramebufferTexture +#define glVertexAttribDivisor gl3wVertexAttribDivisor +#define glMinSampleShading gl3wMinSampleShading +#define glBlendEquationi gl3wBlendEquationi +#define glBlendEquationSeparatei gl3wBlendEquationSeparatei +#define glBlendFunci gl3wBlendFunci +#define glBlendFuncSeparatei gl3wBlendFuncSeparatei +#define glIsRenderbuffer gl3wIsRenderbuffer +#define glBindRenderbuffer gl3wBindRenderbuffer +#define glDeleteRenderbuffers gl3wDeleteRenderbuffers +#define glGenRenderbuffers gl3wGenRenderbuffers +#define glRenderbufferStorage gl3wRenderbufferStorage +#define glGetRenderbufferParameteriv gl3wGetRenderbufferParameteriv +#define glIsFramebuffer gl3wIsFramebuffer +#define glBindFramebuffer gl3wBindFramebuffer +#define glDeleteFramebuffers gl3wDeleteFramebuffers +#define glGenFramebuffers gl3wGenFramebuffers +#define glCheckFramebufferStatus gl3wCheckFramebufferStatus +#define glFramebufferTexture1D gl3wFramebufferTexture1D +#define glFramebufferTexture2D gl3wFramebufferTexture2D +#define glFramebufferTexture3D gl3wFramebufferTexture3D +#define glFramebufferRenderbuffer gl3wFramebufferRenderbuffer +#define glGetFramebufferAttachmentParameteriv gl3wGetFramebufferAttachmentParameteriv +#define glGenerateMipmap gl3wGenerateMipmap +#define glBlitFramebuffer gl3wBlitFramebuffer +#define glRenderbufferStorageMultisample gl3wRenderbufferStorageMultisample +#define glFramebufferTextureLayer gl3wFramebufferTextureLayer +#define glMapBufferRange gl3wMapBufferRange +#define glFlushMappedBufferRange gl3wFlushMappedBufferRange +#define glBindVertexArray gl3wBindVertexArray +#define glDeleteVertexArrays gl3wDeleteVertexArrays +#define glGenVertexArrays gl3wGenVertexArrays +#define glIsVertexArray gl3wIsVertexArray +#define glGetUniformIndices gl3wGetUniformIndices +#define glGetActiveUniformsiv gl3wGetActiveUniformsiv +#define glGetActiveUniformName gl3wGetActiveUniformName +#define glGetUniformBlockIndex gl3wGetUniformBlockIndex +#define glGetActiveUniformBlockiv gl3wGetActiveUniformBlockiv +#define glGetActiveUniformBlockName gl3wGetActiveUniformBlockName +#define glUniformBlockBinding gl3wUniformBlockBinding +#define glCopyBufferSubData gl3wCopyBufferSubData +#define glDrawElementsBaseVertex gl3wDrawElementsBaseVertex +#define glDrawRangeElementsBaseVertex gl3wDrawRangeElementsBaseVertex +#define glDrawElementsInstancedBaseVertex gl3wDrawElementsInstancedBaseVertex +#define glMultiDrawElementsBaseVertex gl3wMultiDrawElementsBaseVertex +#define glProvokingVertex gl3wProvokingVertex +#define glFenceSync gl3wFenceSync +#define glIsSync gl3wIsSync +#define glDeleteSync gl3wDeleteSync +#define glClientWaitSync gl3wClientWaitSync +#define glWaitSync gl3wWaitSync +#define glGetInteger64v gl3wGetInteger64v +#define glGetSynciv gl3wGetSynciv +#define glTexImage2DMultisample gl3wTexImage2DMultisample +#define glTexImage3DMultisample gl3wTexImage3DMultisample +#define glGetMultisamplefv gl3wGetMultisamplefv +#define glSampleMaski gl3wSampleMaski +#define glBlendEquationiARB gl3wBlendEquationiARB +#define glBlendEquationSeparateiARB gl3wBlendEquationSeparateiARB +#define glBlendFunciARB gl3wBlendFunciARB +#define glBlendFuncSeparateiARB gl3wBlendFuncSeparateiARB +#define glMinSampleShadingARB gl3wMinSampleShadingARB +#define glNamedStringARB gl3wNamedStringARB +#define glDeleteNamedStringARB gl3wDeleteNamedStringARB +#define glCompileShaderIncludeARB gl3wCompileShaderIncludeARB +#define glIsNamedStringARB gl3wIsNamedStringARB +#define glGetNamedStringARB gl3wGetNamedStringARB +#define glGetNamedStringivARB gl3wGetNamedStringivARB +#define glBindFragDataLocationIndexed gl3wBindFragDataLocationIndexed +#define glGetFragDataIndex gl3wGetFragDataIndex +#define glGenSamplers gl3wGenSamplers +#define glDeleteSamplers gl3wDeleteSamplers +#define glIsSampler gl3wIsSampler +#define glBindSampler gl3wBindSampler +#define glSamplerParameteri gl3wSamplerParameteri +#define glSamplerParameteriv gl3wSamplerParameteriv +#define glSamplerParameterf gl3wSamplerParameterf +#define glSamplerParameterfv gl3wSamplerParameterfv +#define glSamplerParameterIiv gl3wSamplerParameterIiv +#define glSamplerParameterIuiv gl3wSamplerParameterIuiv +#define glGetSamplerParameteriv gl3wGetSamplerParameteriv +#define glGetSamplerParameterIiv gl3wGetSamplerParameterIiv +#define glGetSamplerParameterfv gl3wGetSamplerParameterfv +#define glGetSamplerParameterIuiv gl3wGetSamplerParameterIuiv +#define glQueryCounter gl3wQueryCounter +#define glGetQueryObjecti64v gl3wGetQueryObjecti64v +#define glGetQueryObjectui64v gl3wGetQueryObjectui64v +#define glVertexP2ui gl3wVertexP2ui +#define glVertexP2uiv gl3wVertexP2uiv +#define glVertexP3ui gl3wVertexP3ui +#define glVertexP3uiv gl3wVertexP3uiv +#define glVertexP4ui gl3wVertexP4ui +#define glVertexP4uiv gl3wVertexP4uiv +#define glTexCoordP1ui gl3wTexCoordP1ui +#define glTexCoordP1uiv gl3wTexCoordP1uiv +#define glTexCoordP2ui gl3wTexCoordP2ui +#define glTexCoordP2uiv gl3wTexCoordP2uiv +#define glTexCoordP3ui gl3wTexCoordP3ui +#define glTexCoordP3uiv gl3wTexCoordP3uiv +#define glTexCoordP4ui gl3wTexCoordP4ui +#define glTexCoordP4uiv gl3wTexCoordP4uiv +#define glMultiTexCoordP1ui gl3wMultiTexCoordP1ui +#define glMultiTexCoordP1uiv gl3wMultiTexCoordP1uiv +#define glMultiTexCoordP2ui gl3wMultiTexCoordP2ui +#define glMultiTexCoordP2uiv gl3wMultiTexCoordP2uiv +#define glMultiTexCoordP3ui gl3wMultiTexCoordP3ui +#define glMultiTexCoordP3uiv gl3wMultiTexCoordP3uiv +#define glMultiTexCoordP4ui gl3wMultiTexCoordP4ui +#define glMultiTexCoordP4uiv gl3wMultiTexCoordP4uiv +#define glNormalP3ui gl3wNormalP3ui +#define glNormalP3uiv gl3wNormalP3uiv +#define glColorP3ui gl3wColorP3ui +#define glColorP3uiv gl3wColorP3uiv +#define glColorP4ui gl3wColorP4ui +#define glColorP4uiv gl3wColorP4uiv +#define glSecondaryColorP3ui gl3wSecondaryColorP3ui +#define glSecondaryColorP3uiv gl3wSecondaryColorP3uiv +#define glVertexAttribP1ui gl3wVertexAttribP1ui +#define glVertexAttribP1uiv gl3wVertexAttribP1uiv +#define glVertexAttribP2ui gl3wVertexAttribP2ui +#define glVertexAttribP2uiv gl3wVertexAttribP2uiv +#define glVertexAttribP3ui gl3wVertexAttribP3ui +#define glVertexAttribP3uiv gl3wVertexAttribP3uiv +#define glVertexAttribP4ui gl3wVertexAttribP4ui +#define glVertexAttribP4uiv gl3wVertexAttribP4uiv +#define glDrawArraysIndirect gl3wDrawArraysIndirect +#define glDrawElementsIndirect gl3wDrawElementsIndirect +#define glUniform1d gl3wUniform1d +#define glUniform2d gl3wUniform2d +#define glUniform3d gl3wUniform3d +#define glUniform4d gl3wUniform4d +#define glUniform1dv gl3wUniform1dv +#define glUniform2dv gl3wUniform2dv +#define glUniform3dv gl3wUniform3dv +#define glUniform4dv gl3wUniform4dv +#define glUniformMatrix2dv gl3wUniformMatrix2dv +#define glUniformMatrix3dv gl3wUniformMatrix3dv +#define glUniformMatrix4dv gl3wUniformMatrix4dv +#define glUniformMatrix2x3dv gl3wUniformMatrix2x3dv +#define glUniformMatrix2x4dv gl3wUniformMatrix2x4dv +#define glUniformMatrix3x2dv gl3wUniformMatrix3x2dv +#define glUniformMatrix3x4dv gl3wUniformMatrix3x4dv +#define glUniformMatrix4x2dv gl3wUniformMatrix4x2dv +#define glUniformMatrix4x3dv gl3wUniformMatrix4x3dv +#define glGetUniformdv gl3wGetUniformdv +#define glGetSubroutineUniformLocation gl3wGetSubroutineUniformLocation +#define glGetSubroutineIndex gl3wGetSubroutineIndex +#define glGetActiveSubroutineUniformiv gl3wGetActiveSubroutineUniformiv +#define glGetActiveSubroutineUniformName gl3wGetActiveSubroutineUniformName +#define glGetActiveSubroutineName gl3wGetActiveSubroutineName +#define glUniformSubroutinesuiv gl3wUniformSubroutinesuiv +#define glGetUniformSubroutineuiv gl3wGetUniformSubroutineuiv +#define glGetProgramStageiv gl3wGetProgramStageiv +#define glPatchParameteri gl3wPatchParameteri +#define glPatchParameterfv gl3wPatchParameterfv +#define glBindTransformFeedback gl3wBindTransformFeedback +#define glDeleteTransformFeedbacks gl3wDeleteTransformFeedbacks +#define glGenTransformFeedbacks gl3wGenTransformFeedbacks +#define glIsTransformFeedback gl3wIsTransformFeedback +#define glPauseTransformFeedback gl3wPauseTransformFeedback +#define glResumeTransformFeedback gl3wResumeTransformFeedback +#define glDrawTransformFeedback gl3wDrawTransformFeedback +#define glDrawTransformFeedbackStream gl3wDrawTransformFeedbackStream +#define glBeginQueryIndexed gl3wBeginQueryIndexed +#define glEndQueryIndexed gl3wEndQueryIndexed +#define glGetQueryIndexediv gl3wGetQueryIndexediv +#define glReleaseShaderCompiler gl3wReleaseShaderCompiler +#define glShaderBinary gl3wShaderBinary +#define glGetShaderPrecisionFormat gl3wGetShaderPrecisionFormat +#define glDepthRangef gl3wDepthRangef +#define glClearDepthf gl3wClearDepthf +#define glGetProgramBinary gl3wGetProgramBinary +#define glProgramBinary gl3wProgramBinary +#define glProgramParameteri gl3wProgramParameteri +#define glUseProgramStages gl3wUseProgramStages +#define glActiveShaderProgram gl3wActiveShaderProgram +#define glCreateShaderProgramv gl3wCreateShaderProgramv +#define glBindProgramPipeline gl3wBindProgramPipeline +#define glDeleteProgramPipelines gl3wDeleteProgramPipelines +#define glGenProgramPipelines gl3wGenProgramPipelines +#define glIsProgramPipeline gl3wIsProgramPipeline +#define glGetProgramPipelineiv gl3wGetProgramPipelineiv +#define glProgramUniform1i gl3wProgramUniform1i +#define glProgramUniform1iv gl3wProgramUniform1iv +#define glProgramUniform1f gl3wProgramUniform1f +#define glProgramUniform1fv gl3wProgramUniform1fv +#define glProgramUniform1d gl3wProgramUniform1d +#define glProgramUniform1dv gl3wProgramUniform1dv +#define glProgramUniform1ui gl3wProgramUniform1ui +#define glProgramUniform1uiv gl3wProgramUniform1uiv +#define glProgramUniform2i gl3wProgramUniform2i +#define glProgramUniform2iv gl3wProgramUniform2iv +#define glProgramUniform2f gl3wProgramUniform2f +#define glProgramUniform2fv gl3wProgramUniform2fv +#define glProgramUniform2d gl3wProgramUniform2d +#define glProgramUniform2dv gl3wProgramUniform2dv +#define glProgramUniform2ui gl3wProgramUniform2ui +#define glProgramUniform2uiv gl3wProgramUniform2uiv +#define glProgramUniform3i gl3wProgramUniform3i +#define glProgramUniform3iv gl3wProgramUniform3iv +#define glProgramUniform3f gl3wProgramUniform3f +#define glProgramUniform3fv gl3wProgramUniform3fv +#define glProgramUniform3d gl3wProgramUniform3d +#define glProgramUniform3dv gl3wProgramUniform3dv +#define glProgramUniform3ui gl3wProgramUniform3ui +#define glProgramUniform3uiv gl3wProgramUniform3uiv +#define glProgramUniform4i gl3wProgramUniform4i +#define glProgramUniform4iv gl3wProgramUniform4iv +#define glProgramUniform4f gl3wProgramUniform4f +#define glProgramUniform4fv gl3wProgramUniform4fv +#define glProgramUniform4d gl3wProgramUniform4d +#define glProgramUniform4dv gl3wProgramUniform4dv +#define glProgramUniform4ui gl3wProgramUniform4ui +#define glProgramUniform4uiv gl3wProgramUniform4uiv +#define glProgramUniformMatrix2fv gl3wProgramUniformMatrix2fv +#define glProgramUniformMatrix3fv gl3wProgramUniformMatrix3fv +#define glProgramUniformMatrix4fv gl3wProgramUniformMatrix4fv +#define glProgramUniformMatrix2dv gl3wProgramUniformMatrix2dv +#define glProgramUniformMatrix3dv gl3wProgramUniformMatrix3dv +#define glProgramUniformMatrix4dv gl3wProgramUniformMatrix4dv +#define glProgramUniformMatrix2x3fv gl3wProgramUniformMatrix2x3fv +#define glProgramUniformMatrix3x2fv gl3wProgramUniformMatrix3x2fv +#define glProgramUniformMatrix2x4fv gl3wProgramUniformMatrix2x4fv +#define glProgramUniformMatrix4x2fv gl3wProgramUniformMatrix4x2fv +#define glProgramUniformMatrix3x4fv gl3wProgramUniformMatrix3x4fv +#define glProgramUniformMatrix4x3fv gl3wProgramUniformMatrix4x3fv +#define glProgramUniformMatrix2x3dv gl3wProgramUniformMatrix2x3dv +#define glProgramUniformMatrix3x2dv gl3wProgramUniformMatrix3x2dv +#define glProgramUniformMatrix2x4dv gl3wProgramUniformMatrix2x4dv +#define glProgramUniformMatrix4x2dv gl3wProgramUniformMatrix4x2dv +#define glProgramUniformMatrix3x4dv gl3wProgramUniformMatrix3x4dv +#define glProgramUniformMatrix4x3dv gl3wProgramUniformMatrix4x3dv +#define glValidateProgramPipeline gl3wValidateProgramPipeline +#define glGetProgramPipelineInfoLog gl3wGetProgramPipelineInfoLog +#define glVertexAttribL1d gl3wVertexAttribL1d +#define glVertexAttribL2d gl3wVertexAttribL2d +#define glVertexAttribL3d gl3wVertexAttribL3d +#define glVertexAttribL4d gl3wVertexAttribL4d +#define glVertexAttribL1dv gl3wVertexAttribL1dv +#define glVertexAttribL2dv gl3wVertexAttribL2dv +#define glVertexAttribL3dv gl3wVertexAttribL3dv +#define glVertexAttribL4dv gl3wVertexAttribL4dv +#define glVertexAttribLPointer gl3wVertexAttribLPointer +#define glGetVertexAttribLdv gl3wGetVertexAttribLdv +#define glViewportArrayv gl3wViewportArrayv +#define glViewportIndexedf gl3wViewportIndexedf +#define glViewportIndexedfv gl3wViewportIndexedfv +#define glScissorArrayv gl3wScissorArrayv +#define glScissorIndexed gl3wScissorIndexed +#define glScissorIndexedv gl3wScissorIndexedv +#define glDepthRangeArrayv gl3wDepthRangeArrayv +#define glDepthRangeIndexed gl3wDepthRangeIndexed +#define glGetFloati_v gl3wGetFloati_v +#define glGetDoublei_v gl3wGetDoublei_v +#define glCreateSyncFromCLeventARB gl3wCreateSyncFromCLeventARB +#define glDebugMessageControlARB gl3wDebugMessageControlARB +#define glDebugMessageInsertARB gl3wDebugMessageInsertARB +#define glDebugMessageCallbackARB gl3wDebugMessageCallbackARB +#define glGetDebugMessageLogARB gl3wGetDebugMessageLogARB +#define glGetGraphicsResetStatusARB gl3wGetGraphicsResetStatusARB +#define glGetnTexImageARB gl3wGetnTexImageARB +#define glReadnPixelsARB gl3wReadnPixelsARB +#define glGetnCompressedTexImageARB gl3wGetnCompressedTexImageARB +#define glGetnUniformfvARB gl3wGetnUniformfvARB +#define glGetnUniformivARB gl3wGetnUniformivARB +#define glGetnUniformuivARB gl3wGetnUniformuivARB +#define glGetnUniformdvARB gl3wGetnUniformdvARB +#define glDrawArraysInstancedBaseInstance gl3wDrawArraysInstancedBaseInstance +#define glDrawElementsInstancedBaseInstance gl3wDrawElementsInstancedBaseInstance +#define glDrawElementsInstancedBaseVertexBaseInstance gl3wDrawElementsInstancedBaseVertexBaseInstance +#define glDrawTransformFeedbackInstanced gl3wDrawTransformFeedbackInstanced +#define glDrawTransformFeedbackStreamInstanced gl3wDrawTransformFeedbackStreamInstanced +#define glGetInternalformativ gl3wGetInternalformativ +#define glGetActiveAtomicCounterBufferiv gl3wGetActiveAtomicCounterBufferiv +#define glBindImageTexture gl3wBindImageTexture +#define glMemoryBarrier gl3wMemoryBarrier +#define glTexStorage1D gl3wTexStorage1D +#define glTexStorage2D gl3wTexStorage2D +#define glTexStorage3D gl3wTexStorage3D +#define glTextureStorage1DEXT gl3wTextureStorage1DEXT +#define glTextureStorage2DEXT gl3wTextureStorage2DEXT +#define glTextureStorage3DEXT gl3wTextureStorage3DEXT +#define glDebugMessageControl gl3wDebugMessageControl +#define glDebugMessageInsert gl3wDebugMessageInsert +#define glDebugMessageCallback gl3wDebugMessageCallback +#define glGetDebugMessageLog gl3wGetDebugMessageLog +#define glPushDebugGroup gl3wPushDebugGroup +#define glPopDebugGroup gl3wPopDebugGroup +#define glObjectLabel gl3wObjectLabel +#define glGetObjectLabel gl3wGetObjectLabel +#define glObjectPtrLabel gl3wObjectPtrLabel +#define glGetObjectPtrLabel gl3wGetObjectPtrLabel +#define glClearBufferData gl3wClearBufferData +#define glClearBufferSubData gl3wClearBufferSubData +#define glClearNamedBufferDataEXT gl3wClearNamedBufferDataEXT +#define glClearNamedBufferSubDataEXT gl3wClearNamedBufferSubDataEXT +#define glDispatchCompute gl3wDispatchCompute +#define glDispatchComputeIndirect gl3wDispatchComputeIndirect +#define glCopyImageSubData gl3wCopyImageSubData +#define glTextureView gl3wTextureView +#define glBindVertexBuffer gl3wBindVertexBuffer +#define glVertexAttribFormat gl3wVertexAttribFormat +#define glVertexAttribIFormat gl3wVertexAttribIFormat +#define glVertexAttribLFormat gl3wVertexAttribLFormat +#define glVertexAttribBinding gl3wVertexAttribBinding +#define glVertexBindingDivisor gl3wVertexBindingDivisor +#define glVertexArrayBindVertexBufferEXT gl3wVertexArrayBindVertexBufferEXT +#define glVertexArrayVertexAttribFormatEXT gl3wVertexArrayVertexAttribFormatEXT +#define glVertexArrayVertexAttribIFormatEXT gl3wVertexArrayVertexAttribIFormatEXT +#define glVertexArrayVertexAttribLFormatEXT gl3wVertexArrayVertexAttribLFormatEXT +#define glVertexArrayVertexAttribBindingEXT gl3wVertexArrayVertexAttribBindingEXT +#define glVertexArrayVertexBindingDivisorEXT gl3wVertexArrayVertexBindingDivisorEXT +#define glFramebufferParameteri gl3wFramebufferParameteri +#define glGetFramebufferParameteriv gl3wGetFramebufferParameteriv +#define glNamedFramebufferParameteriEXT gl3wNamedFramebufferParameteriEXT +#define glGetNamedFramebufferParameterivEXT gl3wGetNamedFramebufferParameterivEXT +#define glGetInternalformati64v gl3wGetInternalformati64v +#define glInvalidateTexSubImage gl3wInvalidateTexSubImage +#define glInvalidateTexImage gl3wInvalidateTexImage +#define glInvalidateBufferSubData gl3wInvalidateBufferSubData +#define glInvalidateBufferData gl3wInvalidateBufferData +#define glInvalidateFramebuffer gl3wInvalidateFramebuffer +#define glInvalidateSubFramebuffer gl3wInvalidateSubFramebuffer +#define glMultiDrawArraysIndirect gl3wMultiDrawArraysIndirect +#define glMultiDrawElementsIndirect gl3wMultiDrawElementsIndirect +#define glGetProgramInterfaceiv gl3wGetProgramInterfaceiv +#define glGetProgramResourceIndex gl3wGetProgramResourceIndex +#define glGetProgramResourceName gl3wGetProgramResourceName +#define glGetProgramResourceiv gl3wGetProgramResourceiv +#define glGetProgramResourceLocation gl3wGetProgramResourceLocation +#define glGetProgramResourceLocationIndex gl3wGetProgramResourceLocationIndex +#define glShaderStorageBlockBinding gl3wShaderStorageBlockBinding +#define glTexBufferRange gl3wTexBufferRange +#define glTextureBufferRangeEXT gl3wTextureBufferRangeEXT +#define glTexStorage2DMultisample gl3wTexStorage2DMultisample +#define glTexStorage3DMultisample gl3wTexStorage3DMultisample +#define glTextureStorage2DMultisampleEXT gl3wTextureStorage2DMultisampleEXT +#define glTextureStorage3DMultisampleEXT gl3wTextureStorage3DMultisampleEXT + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/glcorearb.h b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/glcorearb.h new file mode 100644 index 0000000..07cb03e --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/gl3w/GL/glcorearb.h @@ -0,0 +1,4533 @@ +#ifndef __glcorearb_h_ +#define __glcorearb_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* glcorearb.h replaces gl3.h. It is for use with OpenGL core + * profile implementations. + * + * glcorearb.h last updated on $Date: 2012-09-19 19:02:24 -0700 (Wed, 19 Sep 2012) $ + * + * RELEASE NOTES - 2012/09/19 + * + * glcorearb.h should be placed in the same directory as gl.h and + * included as + * ''. + * + * glcorearb.h includes only APIs in the latest OpenGL core profile + * implementation together with APIs in newer ARB extensions which can be + * can be supported by the core profile. It does not, and never will + * include functionality removed from the core profile, such as + * fixed-function vertex and fragment processing. + * + * It is not possible to #include both and either of + * or in the same source file. + * + * Feedback can be given by registering for the Khronos Bugzilla + * (www.khronos.org/bugzilla) and filing issues there under product + * "OpenGL", category "Registry". + */ + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/* Base GL types */ + +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef signed char GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef unsigned char GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef unsigned short GLhalf; +typedef float GLfloat; +typedef float GLclampf; +typedef double GLdouble; +typedef double GLclampd; +typedef void GLvoid; + +/*************************************************************/ + +#ifndef GL_VERSION_1_1 +/* AttribMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 +/* BeginMode */ +#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 +/* AlphaFunction */ +#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 +/* BlendingFactorDest */ +#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 +/* BlendingFactorSrc */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* DrawBufferMode */ +#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 +/* ErrorCode */ +#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 +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 +/* GetPName */ +#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_COLOR_LOGIC_OP 0x0BF2 +#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_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 +/* GetTextureParameter */ +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 +/* DataType */ +#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_DOUBLE 0x140A +/* ErrorCode */ +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +/* LogicOp */ +#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 +/* MatrixMode (for gl3.h, FBO attachment type) */ +#define GL_TEXTURE 0x1702 +/* PixelCopyType */ +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +/* PixelFormat */ +#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 +/* PolygonMode */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 +/* StencilOp */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 +/* TextureMinFilter */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +/* TextureTarget */ +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +/* PixelInternalFormat */ +#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 +#endif + +#ifndef GL_VERSION_1_2 +#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 +#endif + +#ifndef GL_ARB_imaging +#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_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#endif + +#ifndef GL_VERSION_1_3 +#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 +#endif + +#ifndef GL_VERSION_1_4 +#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 +#endif + +#ifndef GL_VERSION_1_5 +#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 +#endif + +#ifndef GL_VERSION_2_0 +#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 +#endif + +#ifndef GL_VERSION_2_1 +#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 +#endif + +#ifndef GL_VERSION_3_0 +#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 0x0001 +#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 +/* Reuse tokens from ARB_depth_buffer_float */ +/* reuse GL_DEPTH_COMPONENT32F */ +/* reuse GL_DEPTH32F_STENCIL8 */ +/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_DEFAULT */ +/* reuse GL_FRAMEBUFFER_UNDEFINED */ +/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ +/* reuse GL_INDEX */ +/* reuse GL_MAX_RENDERBUFFER_SIZE */ +/* reuse GL_DEPTH_STENCIL */ +/* reuse GL_UNSIGNED_INT_24_8 */ +/* reuse GL_DEPTH24_STENCIL8 */ +/* reuse GL_TEXTURE_STENCIL_SIZE */ +/* reuse GL_TEXTURE_RED_TYPE */ +/* reuse GL_TEXTURE_GREEN_TYPE */ +/* reuse GL_TEXTURE_BLUE_TYPE */ +/* reuse GL_TEXTURE_ALPHA_TYPE */ +/* reuse GL_TEXTURE_DEPTH_TYPE */ +/* reuse GL_UNSIGNED_NORMALIZED */ +/* reuse GL_FRAMEBUFFER_BINDING */ +/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_BINDING */ +/* reuse GL_READ_FRAMEBUFFER */ +/* reuse GL_DRAW_FRAMEBUFFER */ +/* reuse GL_READ_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_SAMPLES */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* reuse GL_FRAMEBUFFER_COMPLETE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ +/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ +/* reuse GL_MAX_COLOR_ATTACHMENTS */ +/* reuse GL_COLOR_ATTACHMENT0 */ +/* reuse GL_COLOR_ATTACHMENT1 */ +/* reuse GL_COLOR_ATTACHMENT2 */ +/* reuse GL_COLOR_ATTACHMENT3 */ +/* reuse GL_COLOR_ATTACHMENT4 */ +/* reuse GL_COLOR_ATTACHMENT5 */ +/* reuse GL_COLOR_ATTACHMENT6 */ +/* reuse GL_COLOR_ATTACHMENT7 */ +/* reuse GL_COLOR_ATTACHMENT8 */ +/* reuse GL_COLOR_ATTACHMENT9 */ +/* reuse GL_COLOR_ATTACHMENT10 */ +/* reuse GL_COLOR_ATTACHMENT11 */ +/* reuse GL_COLOR_ATTACHMENT12 */ +/* reuse GL_COLOR_ATTACHMENT13 */ +/* reuse GL_COLOR_ATTACHMENT14 */ +/* reuse GL_COLOR_ATTACHMENT15 */ +/* reuse GL_DEPTH_ATTACHMENT */ +/* reuse GL_STENCIL_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_RENDERBUFFER_WIDTH */ +/* reuse GL_RENDERBUFFER_HEIGHT */ +/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ +/* reuse GL_STENCIL_INDEX1 */ +/* reuse GL_STENCIL_INDEX4 */ +/* reuse GL_STENCIL_INDEX8 */ +/* reuse GL_STENCIL_INDEX16 */ +/* reuse GL_RENDERBUFFER_RED_SIZE */ +/* reuse GL_RENDERBUFFER_GREEN_SIZE */ +/* reuse GL_RENDERBUFFER_BLUE_SIZE */ +/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ +/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ +/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ +/* reuse GL_MAX_SAMPLES */ +/* Reuse tokens from ARB_framebuffer_sRGB */ +/* reuse GL_FRAMEBUFFER_SRGB */ +/* Reuse tokens from ARB_half_float_vertex */ +/* reuse GL_HALF_FLOAT */ +/* Reuse tokens from ARB_map_buffer_range */ +/* reuse GL_MAP_READ_BIT */ +/* reuse GL_MAP_WRITE_BIT */ +/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ +/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ +/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ +/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ +/* Reuse tokens from ARB_texture_compression_rgtc */ +/* reuse GL_COMPRESSED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_RG_RGTC2 */ +/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ +/* Reuse tokens from ARB_texture_rg */ +/* reuse GL_RG */ +/* reuse GL_RG_INTEGER */ +/* reuse GL_R8 */ +/* reuse GL_R16 */ +/* reuse GL_RG8 */ +/* reuse GL_RG16 */ +/* reuse GL_R16F */ +/* reuse GL_R32F */ +/* reuse GL_RG16F */ +/* reuse GL_RG32F */ +/* reuse GL_R8I */ +/* reuse GL_R8UI */ +/* reuse GL_R16I */ +/* reuse GL_R16UI */ +/* reuse GL_R32I */ +/* reuse GL_R32UI */ +/* reuse GL_RG8I */ +/* reuse GL_RG8UI */ +/* reuse GL_RG16I */ +/* reuse GL_RG16UI */ +/* reuse GL_RG32I */ +/* reuse GL_RG32UI */ +/* Reuse tokens from ARB_vertex_array_object */ +/* reuse GL_VERTEX_ARRAY_BINDING */ +#endif + +#ifndef GL_VERSION_3_1 +#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_RED_SNORM 0x8F90 +#define GL_RG_SNORM 0x8F91 +#define GL_RGB_SNORM 0x8F92 +#define GL_RGBA_SNORM 0x8F93 +#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 +/* Reuse tokens from ARB_copy_buffer */ +/* reuse GL_COPY_READ_BUFFER */ +/* reuse GL_COPY_WRITE_BUFFER */ +/* Reuse tokens from ARB_draw_instanced (none) */ +/* Reuse tokens from ARB_uniform_buffer_object */ +/* reuse GL_UNIFORM_BUFFER */ +/* reuse GL_UNIFORM_BUFFER_BINDING */ +/* reuse GL_UNIFORM_BUFFER_START */ +/* reuse GL_UNIFORM_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ +/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ +/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ +/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ +/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ +/* reuse GL_UNIFORM_TYPE */ +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_INDEX */ +/* reuse GL_UNIFORM_OFFSET */ +/* reuse GL_UNIFORM_ARRAY_STRIDE */ +/* reuse GL_UNIFORM_MATRIX_STRIDE */ +/* reuse GL_UNIFORM_IS_ROW_MAJOR */ +/* reuse GL_UNIFORM_BLOCK_BINDING */ +/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ +/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_INVALID_INDEX */ +#endif + +#ifndef GL_VERSION_3_2 +#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 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* Reuse tokens from ARB_depth_clamp */ +/* reuse GL_DEPTH_CLAMP */ +/* Reuse tokens from ARB_draw_elements_base_vertex (none) */ +/* Reuse tokens from ARB_fragment_coord_conventions (none) */ +/* Reuse tokens from ARB_provoking_vertex */ +/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +/* Reuse tokens from ARB_seamless_cube_map */ +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ +/* Reuse tokens from ARB_sync */ +/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ +/* reuse GL_OBJECT_TYPE */ +/* reuse GL_SYNC_CONDITION */ +/* reuse GL_SYNC_STATUS */ +/* reuse GL_SYNC_FLAGS */ +/* reuse GL_SYNC_FENCE */ +/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ +/* reuse GL_UNSIGNALED */ +/* reuse GL_SIGNALED */ +/* reuse GL_ALREADY_SIGNALED */ +/* reuse GL_TIMEOUT_EXPIRED */ +/* reuse GL_CONDITION_SATISFIED */ +/* reuse GL_WAIT_FAILED */ +/* reuse GL_TIMEOUT_IGNORED */ +/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ +/* reuse GL_TIMEOUT_IGNORED */ +/* Reuse tokens from ARB_texture_multisample */ +/* reuse GL_SAMPLE_POSITION */ +/* reuse GL_SAMPLE_MASK */ +/* reuse GL_SAMPLE_MASK_VALUE */ +/* reuse GL_MAX_SAMPLE_MASK_WORDS */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_SAMPLES */ +/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ +/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ +/* reuse GL_MAX_INTEGER_SAMPLES */ +/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +/* Reuse tokens from ARB_blend_func_extended */ +/* reuse GL_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_ALPHA */ +/* reuse GL_MAX_DUAL_SOURCE_DRAW_BUFFERS */ +/* Reuse tokens from ARB_explicit_attrib_location (none) */ +/* Reuse tokens from ARB_occlusion_query2 */ +/* reuse GL_ANY_SAMPLES_PASSED */ +/* Reuse tokens from ARB_sampler_objects */ +/* reuse GL_SAMPLER_BINDING */ +/* Reuse tokens from ARB_shader_bit_encoding (none) */ +/* Reuse tokens from ARB_texture_rgb10_a2ui */ +/* reuse GL_RGB10_A2UI */ +/* Reuse tokens from ARB_texture_swizzle */ +/* reuse GL_TEXTURE_SWIZZLE_R */ +/* reuse GL_TEXTURE_SWIZZLE_G */ +/* reuse GL_TEXTURE_SWIZZLE_B */ +/* reuse GL_TEXTURE_SWIZZLE_A */ +/* reuse GL_TEXTURE_SWIZZLE_RGBA */ +/* Reuse tokens from ARB_timer_query */ +/* reuse GL_TIME_ELAPSED */ +/* reuse GL_TIMESTAMP */ +/* Reuse tokens from ARB_vertex_type_2_10_10_10_rev */ +/* reuse GL_INT_2_10_10_10_REV */ +#endif + +#ifndef GL_VERSION_4_0 +#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 +/* Reuse tokens from ARB_texture_query_lod (none) */ +/* Reuse tokens from ARB_draw_buffers_blend (none) */ +/* Reuse tokens from ARB_draw_indirect */ +/* reuse GL_DRAW_INDIRECT_BUFFER */ +/* reuse GL_DRAW_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_gpu_shader5 */ +/* reuse GL_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MAX_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MIN_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_MAX_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_FRAGMENT_INTERPOLATION_OFFSET_BITS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +/* Reuse tokens from ARB_gpu_shader_fp64 */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +/* Reuse tokens from ARB_shader_subroutine */ +/* reuse GL_ACTIVE_SUBROUTINES */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORMS */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_ACTIVE_SUBROUTINE_MAX_LENGTH */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH */ +/* reuse GL_MAX_SUBROUTINES */ +/* reuse GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +/* Reuse tokens from ARB_tessellation_shader */ +/* reuse GL_PATCHES */ +/* reuse GL_PATCH_VERTICES */ +/* reuse GL_PATCH_DEFAULT_INNER_LEVEL */ +/* reuse GL_PATCH_DEFAULT_OUTER_LEVEL */ +/* reuse GL_TESS_CONTROL_OUTPUT_VERTICES */ +/* reuse GL_TESS_GEN_MODE */ +/* reuse GL_TESS_GEN_SPACING */ +/* reuse GL_TESS_GEN_VERTEX_ORDER */ +/* reuse GL_TESS_GEN_POINT_MODE */ +/* reuse GL_ISOLINES */ +/* reuse GL_FRACTIONAL_ODD */ +/* reuse GL_FRACTIONAL_EVEN */ +/* reuse GL_MAX_PATCH_VERTICES */ +/* reuse GL_MAX_TESS_GEN_LEVEL */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_PATCH_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_INPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_CONTROL_SHADER */ +/* Reuse tokens from ARB_texture_buffer_object_rgb32 (none) */ +/* Reuse tokens from ARB_transform_feedback2 */ +/* reuse GL_TRANSFORM_FEEDBACK */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE */ +/* reuse GL_TRANSFORM_FEEDBACK_BINDING */ +/* Reuse tokens from ARB_transform_feedback3 */ +/* reuse GL_MAX_TRANSFORM_FEEDBACK_BUFFERS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_VERSION_4_1 +/* Reuse tokens from ARB_ES2_compatibility */ +/* reuse GL_FIXED */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_TYPE */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_FORMAT */ +/* reuse GL_LOW_FLOAT */ +/* reuse GL_MEDIUM_FLOAT */ +/* reuse GL_HIGH_FLOAT */ +/* reuse GL_LOW_INT */ +/* reuse GL_MEDIUM_INT */ +/* reuse GL_HIGH_INT */ +/* reuse GL_SHADER_COMPILER */ +/* reuse GL_SHADER_BINARY_FORMATS */ +/* reuse GL_NUM_SHADER_BINARY_FORMATS */ +/* reuse GL_MAX_VERTEX_UNIFORM_VECTORS */ +/* reuse GL_MAX_VARYING_VECTORS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_VECTORS */ +/* reuse GL_RGB565 */ +/* Reuse tokens from ARB_get_program_binary */ +/* reuse GL_PROGRAM_BINARY_RETRIEVABLE_HINT */ +/* reuse GL_PROGRAM_BINARY_LENGTH */ +/* reuse GL_NUM_PROGRAM_BINARY_FORMATS */ +/* reuse GL_PROGRAM_BINARY_FORMATS */ +/* Reuse tokens from ARB_separate_shader_objects */ +/* reuse GL_VERTEX_SHADER_BIT */ +/* reuse GL_FRAGMENT_SHADER_BIT */ +/* reuse GL_GEOMETRY_SHADER_BIT */ +/* reuse GL_TESS_CONTROL_SHADER_BIT */ +/* reuse GL_TESS_EVALUATION_SHADER_BIT */ +/* reuse GL_ALL_SHADER_BITS */ +/* reuse GL_PROGRAM_SEPARABLE */ +/* reuse GL_ACTIVE_PROGRAM */ +/* reuse GL_PROGRAM_PIPELINE_BINDING */ +/* Reuse tokens from ARB_shader_precision (none) */ +/* Reuse tokens from ARB_vertex_attrib_64bit - all are in GL 3.0 and 4.0 already */ +/* Reuse tokens from ARB_viewport_array - some are in GL 1.1 and ARB_provoking_vertex already */ +/* reuse GL_MAX_VIEWPORTS */ +/* reuse GL_VIEWPORT_SUBPIXEL_BITS */ +/* reuse GL_VIEWPORT_BOUNDS_RANGE */ +/* reuse GL_LAYER_PROVOKING_VERTEX */ +/* reuse GL_VIEWPORT_INDEX_PROVOKING_VERTEX */ +/* reuse GL_UNDEFINED_VERTEX */ +#endif + +#ifndef GL_VERSION_4_2 +/* Reuse tokens from ARB_base_instance (none) */ +/* Reuse tokens from ARB_shading_language_420pack (none) */ +/* Reuse tokens from ARB_transform_feedback_instanced (none) */ +/* Reuse tokens from ARB_compressed_texture_pixel_storage */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_DEPTH */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_SIZE */ +/* reuse GL_PACK_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_PACK_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_PACK_COMPRESSED_BLOCK_DEPTH */ +/* reuse GL_PACK_COMPRESSED_BLOCK_SIZE */ +/* Reuse tokens from ARB_conservative_depth (none) */ +/* Reuse tokens from ARB_internalformat_query */ +/* reuse GL_NUM_SAMPLE_COUNTS */ +/* Reuse tokens from ARB_map_buffer_alignment */ +/* reuse GL_MIN_MAP_BUFFER_ALIGNMENT */ +/* Reuse tokens from ARB_shader_atomic_counters */ +/* reuse GL_ATOMIC_COUNTER_BUFFER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_BINDING */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_START */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_SIZE */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_VERTEX_ATOMIC_COUNTERS */ +/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS */ +/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS */ +/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTERS */ +/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTERS */ +/* reuse GL_MAX_COMBINED_ATOMIC_COUNTERS */ +/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE */ +/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS */ +/* reuse GL_ACTIVE_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX */ +/* reuse GL_UNSIGNED_INT_ATOMIC_COUNTER */ +/* Reuse tokens from ARB_shader_image_load_store */ +/* reuse GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT */ +/* reuse GL_ELEMENT_ARRAY_BARRIER_BIT */ +/* reuse GL_UNIFORM_BARRIER_BIT */ +/* reuse GL_TEXTURE_FETCH_BARRIER_BIT */ +/* reuse GL_SHADER_IMAGE_ACCESS_BARRIER_BIT */ +/* reuse GL_COMMAND_BARRIER_BIT */ +/* reuse GL_PIXEL_BUFFER_BARRIER_BIT */ +/* reuse GL_TEXTURE_UPDATE_BARRIER_BIT */ +/* reuse GL_BUFFER_UPDATE_BARRIER_BIT */ +/* reuse GL_FRAMEBUFFER_BARRIER_BIT */ +/* reuse GL_TRANSFORM_FEEDBACK_BARRIER_BIT */ +/* reuse GL_ATOMIC_COUNTER_BARRIER_BIT */ +/* reuse GL_ALL_BARRIER_BITS */ +/* reuse GL_MAX_IMAGE_UNITS */ +/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ +/* reuse GL_IMAGE_BINDING_NAME */ +/* reuse GL_IMAGE_BINDING_LEVEL */ +/* reuse GL_IMAGE_BINDING_LAYERED */ +/* reuse GL_IMAGE_BINDING_LAYER */ +/* reuse GL_IMAGE_BINDING_ACCESS */ +/* reuse GL_IMAGE_1D */ +/* reuse GL_IMAGE_2D */ +/* reuse GL_IMAGE_3D */ +/* reuse GL_IMAGE_2D_RECT */ +/* reuse GL_IMAGE_CUBE */ +/* reuse GL_IMAGE_BUFFER */ +/* reuse GL_IMAGE_1D_ARRAY */ +/* reuse GL_IMAGE_2D_ARRAY */ +/* reuse GL_IMAGE_CUBE_MAP_ARRAY */ +/* reuse GL_IMAGE_2D_MULTISAMPLE */ +/* reuse GL_IMAGE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_IMAGE_1D */ +/* reuse GL_INT_IMAGE_2D */ +/* reuse GL_INT_IMAGE_3D */ +/* reuse GL_INT_IMAGE_2D_RECT */ +/* reuse GL_INT_IMAGE_CUBE */ +/* reuse GL_INT_IMAGE_BUFFER */ +/* reuse GL_INT_IMAGE_1D_ARRAY */ +/* reuse GL_INT_IMAGE_2D_ARRAY */ +/* reuse GL_INT_IMAGE_CUBE_MAP_ARRAY */ +/* reuse GL_INT_IMAGE_2D_MULTISAMPLE */ +/* reuse GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_1D */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D */ +/* reuse GL_UNSIGNED_INT_IMAGE_3D */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_RECT */ +/* reuse GL_UNSIGNED_INT_IMAGE_CUBE */ +/* reuse GL_UNSIGNED_INT_IMAGE_BUFFER */ +/* reuse GL_UNSIGNED_INT_IMAGE_1D_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_IMAGE_SAMPLES */ +/* reuse GL_IMAGE_BINDING_FORMAT */ +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE */ +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS */ +/* reuse GL_MAX_VERTEX_IMAGE_UNIFORMS */ +/* reuse GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS */ +/* reuse GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS */ +/* reuse GL_MAX_GEOMETRY_IMAGE_UNIFORMS */ +/* reuse GL_MAX_FRAGMENT_IMAGE_UNIFORMS */ +/* reuse GL_MAX_COMBINED_IMAGE_UNIFORMS */ +/* Reuse tokens from ARB_shading_language_packing (none) */ +/* Reuse tokens from ARB_texture_storage */ +/* reuse GL_TEXTURE_IMMUTABLE_FORMAT */ +#endif + +#ifndef GL_VERSION_4_3 +#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 +#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E +/* Reuse tokens from ARB_arrays_of_arrays (none, GLSL only) */ +/* Reuse tokens from ARB_fragment_layer_viewport (none, GLSL only) */ +/* Reuse tokens from ARB_shader_image_size (none, GLSL only) */ +/* Reuse tokens from ARB_ES3_compatibility */ +/* reuse GL_COMPRESSED_RGB8_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_ETC2 */ +/* reuse GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_RGBA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_R11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_R11_EAC */ +/* reuse GL_COMPRESSED_RG11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_RG11_EAC */ +/* reuse GL_PRIMITIVE_RESTART_FIXED_INDEX */ +/* reuse GL_ANY_SAMPLES_PASSED_CONSERVATIVE */ +/* reuse GL_MAX_ELEMENT_INDEX */ +/* Reuse tokens from ARB_clear_buffer_object (none) */ +/* Reuse tokens from ARB_compute_shader */ +/* reuse GL_COMPUTE_SHADER */ +/* reuse GL_MAX_COMPUTE_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_COMPUTE_IMAGE_UNIFORMS */ +/* reuse GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */ +/* reuse GL_MAX_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTERS */ +/* reuse GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_LOCAL_INVOCATIONS */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_COUNT */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_SIZE */ +/* reuse GL_COMPUTE_LOCAL_WORK_SIZE */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_copy_image (none) */ +/* Reuse tokens from KHR_debug */ +/* reuse GL_DEBUG_OUTPUT_SYNCHRONOUS */ +/* reuse GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH */ +/* reuse GL_DEBUG_CALLBACK_FUNCTION */ +/* reuse GL_DEBUG_CALLBACK_USER_PARAM */ +/* reuse GL_DEBUG_SOURCE_API */ +/* reuse GL_DEBUG_SOURCE_WINDOW_SYSTEM */ +/* reuse GL_DEBUG_SOURCE_SHADER_COMPILER */ +/* reuse GL_DEBUG_SOURCE_THIRD_PARTY */ +/* reuse GL_DEBUG_SOURCE_APPLICATION */ +/* reuse GL_DEBUG_SOURCE_OTHER */ +/* reuse GL_DEBUG_TYPE_ERROR */ +/* reuse GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_PORTABILITY */ +/* reuse GL_DEBUG_TYPE_PERFORMANCE */ +/* reuse GL_DEBUG_TYPE_OTHER */ +/* reuse GL_MAX_DEBUG_MESSAGE_LENGTH */ +/* reuse GL_MAX_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_SEVERITY_HIGH */ +/* reuse GL_DEBUG_SEVERITY_MEDIUM */ +/* reuse GL_DEBUG_SEVERITY_LOW */ +/* reuse GL_DEBUG_TYPE_MARKER */ +/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ +/* reuse GL_DEBUG_TYPE_POP_GROUP */ +/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ +/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_BUFFER */ +/* reuse GL_SHADER */ +/* reuse GL_PROGRAM */ +/* reuse GL_QUERY */ +/* reuse GL_PROGRAM_PIPELINE */ +/* reuse GL_SAMPLER */ +/* reuse GL_DISPLAY_LIST */ +/* reuse GL_MAX_LABEL_LENGTH */ +/* reuse GL_DEBUG_OUTPUT */ +/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +/* Reuse tokens from ARB_explicit_uniform_location */ +/* reuse GL_MAX_UNIFORM_LOCATIONS */ +/* Reuse tokens from ARB_framebuffer_no_attachments */ +/* reuse GL_FRAMEBUFFER_DEFAULT_WIDTH */ +/* reuse GL_FRAMEBUFFER_DEFAULT_HEIGHT */ +/* reuse GL_FRAMEBUFFER_DEFAULT_LAYERS */ +/* reuse GL_FRAMEBUFFER_DEFAULT_SAMPLES */ +/* reuse GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_MAX_FRAMEBUFFER_WIDTH */ +/* reuse GL_MAX_FRAMEBUFFER_HEIGHT */ +/* reuse GL_MAX_FRAMEBUFFER_LAYERS */ +/* reuse GL_MAX_FRAMEBUFFER_SAMPLES */ +/* Reuse tokens from ARB_internalformat_query2 */ +/* reuse GL_INTERNALFORMAT_SUPPORTED */ +/* reuse GL_INTERNALFORMAT_PREFERRED */ +/* reuse GL_INTERNALFORMAT_RED_SIZE */ +/* reuse GL_INTERNALFORMAT_GREEN_SIZE */ +/* reuse GL_INTERNALFORMAT_BLUE_SIZE */ +/* reuse GL_INTERNALFORMAT_ALPHA_SIZE */ +/* reuse GL_INTERNALFORMAT_DEPTH_SIZE */ +/* reuse GL_INTERNALFORMAT_STENCIL_SIZE */ +/* reuse GL_INTERNALFORMAT_SHARED_SIZE */ +/* reuse GL_INTERNALFORMAT_RED_TYPE */ +/* reuse GL_INTERNALFORMAT_GREEN_TYPE */ +/* reuse GL_INTERNALFORMAT_BLUE_TYPE */ +/* reuse GL_INTERNALFORMAT_ALPHA_TYPE */ +/* reuse GL_INTERNALFORMAT_DEPTH_TYPE */ +/* reuse GL_INTERNALFORMAT_STENCIL_TYPE */ +/* reuse GL_MAX_WIDTH */ +/* reuse GL_MAX_HEIGHT */ +/* reuse GL_MAX_DEPTH */ +/* reuse GL_MAX_LAYERS */ +/* reuse GL_MAX_COMBINED_DIMENSIONS */ +/* reuse GL_COLOR_COMPONENTS */ +/* reuse GL_DEPTH_COMPONENTS */ +/* reuse GL_STENCIL_COMPONENTS */ +/* reuse GL_COLOR_RENDERABLE */ +/* reuse GL_DEPTH_RENDERABLE */ +/* reuse GL_STENCIL_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE_LAYERED */ +/* reuse GL_FRAMEBUFFER_BLEND */ +/* reuse GL_READ_PIXELS */ +/* reuse GL_READ_PIXELS_FORMAT */ +/* reuse GL_READ_PIXELS_TYPE */ +/* reuse GL_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_TEXTURE_IMAGE_TYPE */ +/* reuse GL_GET_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_GET_TEXTURE_IMAGE_TYPE */ +/* reuse GL_MIPMAP */ +/* reuse GL_MANUAL_GENERATE_MIPMAP */ +/* reuse GL_AUTO_GENERATE_MIPMAP */ +/* reuse GL_COLOR_ENCODING */ +/* reuse GL_SRGB_READ */ +/* reuse GL_SRGB_WRITE */ +/* reuse GL_FILTER */ +/* reuse GL_VERTEX_TEXTURE */ +/* reuse GL_TESS_CONTROL_TEXTURE */ +/* reuse GL_TESS_EVALUATION_TEXTURE */ +/* reuse GL_GEOMETRY_TEXTURE */ +/* reuse GL_FRAGMENT_TEXTURE */ +/* reuse GL_COMPUTE_TEXTURE */ +/* reuse GL_TEXTURE_SHADOW */ +/* reuse GL_TEXTURE_GATHER */ +/* reuse GL_TEXTURE_GATHER_SHADOW */ +/* reuse GL_SHADER_IMAGE_LOAD */ +/* reuse GL_SHADER_IMAGE_STORE */ +/* reuse GL_SHADER_IMAGE_ATOMIC */ +/* reuse GL_IMAGE_TEXEL_SIZE */ +/* reuse GL_IMAGE_COMPATIBILITY_CLASS */ +/* reuse GL_IMAGE_PIXEL_FORMAT */ +/* reuse GL_IMAGE_PIXEL_TYPE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_SIZE */ +/* reuse GL_CLEAR_BUFFER */ +/* reuse GL_TEXTURE_VIEW */ +/* reuse GL_VIEW_COMPATIBILITY_CLASS */ +/* reuse GL_FULL_SUPPORT */ +/* reuse GL_CAVEAT_SUPPORT */ +/* reuse GL_IMAGE_CLASS_4_X_32 */ +/* reuse GL_IMAGE_CLASS_2_X_32 */ +/* reuse GL_IMAGE_CLASS_1_X_32 */ +/* reuse GL_IMAGE_CLASS_4_X_16 */ +/* reuse GL_IMAGE_CLASS_2_X_16 */ +/* reuse GL_IMAGE_CLASS_1_X_16 */ +/* reuse GL_IMAGE_CLASS_4_X_8 */ +/* reuse GL_IMAGE_CLASS_2_X_8 */ +/* reuse GL_IMAGE_CLASS_1_X_8 */ +/* reuse GL_IMAGE_CLASS_11_11_10 */ +/* reuse GL_IMAGE_CLASS_10_10_10_2 */ +/* reuse GL_VIEW_CLASS_128_BITS */ +/* reuse GL_VIEW_CLASS_96_BITS */ +/* reuse GL_VIEW_CLASS_64_BITS */ +/* reuse GL_VIEW_CLASS_48_BITS */ +/* reuse GL_VIEW_CLASS_32_BITS */ +/* reuse GL_VIEW_CLASS_24_BITS */ +/* reuse GL_VIEW_CLASS_16_BITS */ +/* reuse GL_VIEW_CLASS_8_BITS */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGB */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT3_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT5_RGBA */ +/* reuse GL_VIEW_CLASS_RGTC1_RED */ +/* reuse GL_VIEW_CLASS_RGTC2_RG */ +/* reuse GL_VIEW_CLASS_BPTC_UNORM */ +/* reuse GL_VIEW_CLASS_BPTC_FLOAT */ +/* Reuse tokens from ARB_invalidate_subdata (none) */ +/* Reuse tokens from ARB_multi_draw_indirect (none) */ +/* Reuse tokens from ARB_program_interface_query */ +/* reuse GL_UNIFORM */ +/* reuse GL_UNIFORM_BLOCK */ +/* reuse GL_PROGRAM_INPUT */ +/* reuse GL_PROGRAM_OUTPUT */ +/* reuse GL_BUFFER_VARIABLE */ +/* reuse GL_SHADER_STORAGE_BLOCK */ +/* reuse GL_VERTEX_SUBROUTINE */ +/* reuse GL_TESS_CONTROL_SUBROUTINE */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE */ +/* reuse GL_GEOMETRY_SUBROUTINE */ +/* reuse GL_FRAGMENT_SUBROUTINE */ +/* reuse GL_COMPUTE_SUBROUTINE */ +/* reuse GL_VERTEX_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_CONTROL_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE_UNIFORM */ +/* reuse GL_GEOMETRY_SUBROUTINE_UNIFORM */ +/* reuse GL_FRAGMENT_SUBROUTINE_UNIFORM */ +/* reuse GL_COMPUTE_SUBROUTINE_UNIFORM */ +/* reuse GL_TRANSFORM_FEEDBACK_VARYING */ +/* reuse GL_ACTIVE_RESOURCES */ +/* reuse GL_MAX_NAME_LENGTH */ +/* reuse GL_MAX_NUM_ACTIVE_VARIABLES */ +/* reuse GL_MAX_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_NAME_LENGTH */ +/* reuse GL_TYPE */ +/* reuse GL_ARRAY_SIZE */ +/* reuse GL_OFFSET */ +/* reuse GL_BLOCK_INDEX */ +/* reuse GL_ARRAY_STRIDE */ +/* reuse GL_MATRIX_STRIDE */ +/* reuse GL_IS_ROW_MAJOR */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_INDEX */ +/* reuse GL_BUFFER_BINDING */ +/* reuse GL_BUFFER_DATA_SIZE */ +/* reuse GL_NUM_ACTIVE_VARIABLES */ +/* reuse GL_ACTIVE_VARIABLES */ +/* reuse GL_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_REFERENCED_BY_GEOMETRY_SHADER */ +/* reuse GL_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_TOP_LEVEL_ARRAY_SIZE */ +/* reuse GL_TOP_LEVEL_ARRAY_STRIDE */ +/* reuse GL_LOCATION */ +/* reuse GL_LOCATION_INDEX */ +/* reuse GL_IS_PER_PATCH */ +/* Reuse tokens from ARB_robust_buffer_access_behavior (none) */ +/* Reuse tokens from ARB_shader_storage_buffer_object */ +/* reuse GL_SHADER_STORAGE_BUFFER */ +/* reuse GL_SHADER_STORAGE_BUFFER_BINDING */ +/* reuse GL_SHADER_STORAGE_BUFFER_START */ +/* reuse GL_SHADER_STORAGE_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS */ +/* reuse GL_MAX_SHADER_STORAGE_BLOCK_SIZE */ +/* reuse GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_SHADER_STORAGE_BARRIER_BIT */ +/* reuse GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES */ +/* Reuse tokens from ARB_stencil_texturing */ +/* reuse GL_DEPTH_STENCIL_TEXTURE_MODE */ +/* Reuse tokens from ARB_texture_buffer_range */ +/* reuse GL_TEXTURE_BUFFER_OFFSET */ +/* reuse GL_TEXTURE_BUFFER_SIZE */ +/* reuse GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT */ +/* Reuse tokens from ARB_texture_query_levels (none) */ +/* Reuse tokens from ARB_texture_storage_multisample (none) */ +/* Reuse tokens from ARB_texture_view */ +/* reuse GL_TEXTURE_VIEW_MIN_LEVEL */ +/* reuse GL_TEXTURE_VIEW_NUM_LEVELS */ +/* reuse GL_TEXTURE_VIEW_MIN_LAYER */ +/* reuse GL_TEXTURE_VIEW_NUM_LAYERS */ +/* reuse GL_TEXTURE_IMMUTABLE_LEVELS */ +/* Reuse tokens from ARB_vertex_attrib_binding */ +/* reuse GL_VERTEX_ATTRIB_BINDING */ +/* reuse GL_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_VERTEX_BINDING_DIVISOR */ +/* reuse GL_VERTEX_BINDING_OFFSET */ +/* reuse GL_VERTEX_BINDING_STRIDE */ +/* reuse GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_MAX_VERTEX_ATTRIB_BINDINGS */ +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_ARB_framebuffer_object +#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 GL_FRAMEBUFFER_BINDING +#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_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 +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_HALF_FLOAT 0x140B +#endif + +#ifndef GL_ARB_map_buffer_range +#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 +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#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 +#endif + +#ifndef GL_ARB_texture_rg +#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 +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#endif + +#ifndef GL_ARB_uniform_buffer_object +#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 0xFFFFFFFFu +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_COPY_READ_BUFFER_BINDING 0x8F36 +#define GL_COPY_READ_BUFFER GL_COPY_READ_BUFFER_BINDING +#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37 +#define GL_COPY_WRITE_BUFFER GL_COPY_WRITE_BUFFER_BINDING +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_DEPTH_CLAMP 0x864F +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#endif + +#ifndef GL_ARB_provoking_vertex +#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 +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#endif + +#ifndef GL_ARB_sync +#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_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + +#ifndef GL_ARB_texture_multisample +#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 +#endif + +#ifndef GL_ARB_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_ARB_draw_buffers_blend +#endif + +#ifndef GL_ARB_sample_shading +#define GL_SAMPLE_SHADING_ARB 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F +#endif + +#ifndef GL_ARB_texture_gather +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F +#define GL_MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS_ARB 0x8F9F +#endif + +#ifndef GL_ARB_texture_query_lod +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_SHADER_INCLUDE_ARB 0x8DAE +#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 +#define GL_NAMED_STRING_TYPE_ARB 0x8DEA +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_SRC1_COLOR 0x88F9 +/* reuse GL_SRC1_ALPHA */ +#define GL_ONE_MINUS_SRC1_COLOR 0x88FA +#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB +#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC +#endif + +#ifndef GL_ARB_explicit_attrib_location +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_SAMPLER_BINDING 0x8919 +#endif + +#ifndef GL_ARB_shader_bit_encoding +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_RGB10_A2UI 0x906F +#endif + +#ifndef GL_ARB_texture_swizzle +#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 +#endif + +#ifndef GL_ARB_timer_query +#define GL_TIME_ELAPSED 0x88BF +#define GL_TIMESTAMP 0x8E28 +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +/* reuse GL_UNSIGNED_INT_2_10_10_10_REV */ +#define GL_INT_2_10_10_10_REV 0x8D9F +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_DRAW_INDIRECT_BUFFER 0x8F3F +#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 +#endif + +#ifndef GL_ARB_gpu_shader5 +#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 +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +/* reuse GL_DOUBLE */ +#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 +#endif + +#ifndef GL_ARB_shader_subroutine +#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 +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +#endif + +#ifndef GL_ARB_tessellation_shader +#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 +/* reuse GL_TRIANGLES */ +/* reuse GL_QUADS */ +#define GL_ISOLINES 0x8E7A +/* reuse GL_EQUAL */ +#define GL_FRACTIONAL_ODD 0x8E7B +#define GL_FRACTIONAL_EVEN 0x8E7C +/* reuse GL_CCW */ +/* reuse GL_CW */ +#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 +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +/* reuse GL_RGB32F */ +/* reuse GL_RGB32UI */ +/* reuse GL_RGB32I */ +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED GL_TRANSFORM_FEEDBACK_PAUSED +#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE GL_TRANSFORM_FEEDBACK_ACTIVE +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 +#define GL_MAX_VERTEX_STREAMS 0x8E71 +#endif + +#ifndef GL_ARB_ES2_compatibility +#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 +#endif + +#ifndef GL_ARB_get_program_binary +#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 +#endif + +#ifndef GL_ARB_separate_shader_objects +#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 +#endif + +#ifndef GL_ARB_shader_precision +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +/* reuse GL_RGB32I */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +#endif + +#ifndef GL_ARB_viewport_array +/* reuse GL_SCISSOR_BOX */ +/* reuse GL_VIEWPORT */ +/* reuse GL_DEPTH_RANGE */ +/* reuse GL_SCISSOR_TEST */ +#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 +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +#endif + +#ifndef GL_ARB_cl_event +#define GL_SYNC_CL_EVENT_ARB 0x8240 +#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 +#endif + +#ifndef GL_ARB_debug_output +#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 +#define GL_DEBUG_SOURCE_API_ARB 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A +#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B +#define GL_DEBUG_TYPE_ERROR_ARB 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E +#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 +#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 +#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 +#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 +#endif + +#ifndef GL_ARB_robustness +/* reuse GL_NO_ERROR */ +#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 +#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef GL_ARB_shader_stencil_export +#endif + +#ifndef GL_ARB_base_instance +#endif + +#ifndef GL_ARB_shading_language_420pack +#endif + +#ifndef GL_ARB_transform_feedback_instanced +#endif + +#ifndef GL_ARB_compressed_texture_pixel_storage +#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127 +#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128 +#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129 +#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A +#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B +#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C +#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D +#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E +#endif + +#ifndef GL_ARB_conservative_depth +#endif + +#ifndef GL_ARB_internalformat_query +#define GL_NUM_SAMPLE_COUNTS 0x9380 +#endif + +#ifndef GL_ARB_map_buffer_alignment +#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC +#endif + +#ifndef GL_ARB_shader_atomic_counters +#define GL_ATOMIC_COUNTER_BUFFER 0x92C0 +#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1 +#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2 +#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3 +#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB +#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE +#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF +#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0 +#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1 +#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2 +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3 +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4 +#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5 +#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6 +#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC +#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9 +#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA +#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB +#endif + +#ifndef GL_ARB_shader_image_load_store +#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001 +#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002 +#define GL_UNIFORM_BARRIER_BIT 0x00000004 +#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008 +#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020 +#define GL_COMMAND_BARRIER_BIT 0x00000040 +#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080 +#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100 +#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200 +#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400 +#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800 +#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000 +#define GL_ALL_BARRIER_BITS 0xFFFFFFFF +#define GL_MAX_IMAGE_UNITS 0x8F38 +#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39 +#define GL_IMAGE_BINDING_NAME 0x8F3A +#define GL_IMAGE_BINDING_LEVEL 0x8F3B +#define GL_IMAGE_BINDING_LAYERED 0x8F3C +#define GL_IMAGE_BINDING_LAYER 0x8F3D +#define GL_IMAGE_BINDING_ACCESS 0x8F3E +#define GL_IMAGE_1D 0x904C +#define GL_IMAGE_2D 0x904D +#define GL_IMAGE_3D 0x904E +#define GL_IMAGE_2D_RECT 0x904F +#define GL_IMAGE_CUBE 0x9050 +#define GL_IMAGE_BUFFER 0x9051 +#define GL_IMAGE_1D_ARRAY 0x9052 +#define GL_IMAGE_2D_ARRAY 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056 +#define GL_INT_IMAGE_1D 0x9057 +#define GL_INT_IMAGE_2D 0x9058 +#define GL_INT_IMAGE_3D 0x9059 +#define GL_INT_IMAGE_2D_RECT 0x905A +#define GL_INT_IMAGE_CUBE 0x905B +#define GL_INT_IMAGE_BUFFER 0x905C +#define GL_INT_IMAGE_1D_ARRAY 0x905D +#define GL_INT_IMAGE_2D_ARRAY 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C +#define GL_MAX_IMAGE_SAMPLES 0x906D +#define GL_IMAGE_BINDING_FORMAT 0x906E +#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7 +#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8 +#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9 +#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA +#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB +#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC +#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD +#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE +#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF +#endif + +#ifndef GL_ARB_shading_language_packing +#endif + +#ifndef GL_ARB_texture_storage +#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F +#endif + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD +#endif + +#ifndef GL_KHR_debug +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_BUFFER 0x82E0 +#define GL_SHADER 0x82E1 +#define GL_PROGRAM 0x82E2 +#define GL_QUERY 0x82E3 +#define GL_PROGRAM_PIPELINE 0x82E4 +#define GL_SAMPLER 0x82E6 +#define GL_DISPLAY_LIST 0x82E7 +/* DISPLAY_LIST used in compatibility profile only */ +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +#endif + +#ifndef GL_ARB_arrays_of_arrays +#endif + +#ifndef GL_ARB_clear_buffer_object +#endif + +#ifndef GL_ARB_compute_shader +#define GL_COMPUTE_SHADER 0x91B9 +#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB +#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC +#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD +#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 +#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 +#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 +#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 +#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 +#define GL_MAX_COMPUTE_LOCAL_INVOCATIONS 0x90EB +#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE +#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF +#define GL_COMPUTE_LOCAL_WORK_SIZE 0x8267 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED +#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE +#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF +#define GL_COMPUTE_SHADER_BIT 0x00000020 +#endif + +#ifndef GL_ARB_copy_image +#endif + +#ifndef GL_ARB_texture_view +#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB +#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC +#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD +#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_VERTEX_ATTRIB_BINDING 0x82D4 +#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 +#define GL_VERTEX_BINDING_DIVISOR 0x82D6 +#define GL_VERTEX_BINDING_OFFSET 0x82D7 +#define GL_VERTEX_BINDING_STRIDE 0x82D8 +#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 +#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA +#endif + +#ifndef GL_ARB_robustness_isolation +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_MAX_UNIFORM_LOCATIONS 0x826E +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 +#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 +#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 +#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 +#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 +#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 +#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 +#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 +#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 +#endif + +#ifndef GL_ARB_internalformat_query2 +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ +/* reuse GL_NUM_SAMPLE_COUNTS */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_SAMPLES */ +/* reuse GL_TEXTURE_1D */ +/* reuse GL_TEXTURE_1D_ARRAY */ +/* reuse GL_TEXTURE_2D */ +/* reuse GL_TEXTURE_2D_ARRAY */ +/* reuse GL_TEXTURE_3D */ +/* reuse GL_TEXTURE_CUBE_MAP */ +/* reuse GL_TEXTURE_CUBE_MAP_ARRAY */ +/* reuse GL_TEXTURE_RECTANGLE */ +/* reuse GL_TEXTURE_BUFFER */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_COMPRESSED */ +#define GL_INTERNALFORMAT_SUPPORTED 0x826F +#define GL_INTERNALFORMAT_PREFERRED 0x8270 +#define GL_INTERNALFORMAT_RED_SIZE 0x8271 +#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 +#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 +#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 +#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 +#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 +#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 +#define GL_INTERNALFORMAT_RED_TYPE 0x8278 +#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 +#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A +#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B +#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C +#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D +#define GL_MAX_WIDTH 0x827E +#define GL_MAX_HEIGHT 0x827F +#define GL_MAX_DEPTH 0x8280 +#define GL_MAX_LAYERS 0x8281 +#define GL_MAX_COMBINED_DIMENSIONS 0x8282 +#define GL_COLOR_COMPONENTS 0x8283 +#define GL_DEPTH_COMPONENTS 0x8284 +#define GL_STENCIL_COMPONENTS 0x8285 +#define GL_COLOR_RENDERABLE 0x8286 +#define GL_DEPTH_RENDERABLE 0x8287 +#define GL_STENCIL_RENDERABLE 0x8288 +#define GL_FRAMEBUFFER_RENDERABLE 0x8289 +#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A +#define GL_FRAMEBUFFER_BLEND 0x828B +#define GL_READ_PIXELS 0x828C +#define GL_READ_PIXELS_FORMAT 0x828D +#define GL_READ_PIXELS_TYPE 0x828E +#define GL_TEXTURE_IMAGE_FORMAT 0x828F +#define GL_TEXTURE_IMAGE_TYPE 0x8290 +#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 +#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 +#define GL_MIPMAP 0x8293 +#define GL_MANUAL_GENERATE_MIPMAP 0x8294 +#define GL_AUTO_GENERATE_MIPMAP 0x8295 +#define GL_COLOR_ENCODING 0x8296 +#define GL_SRGB_READ 0x8297 +#define GL_SRGB_WRITE 0x8298 +#define GL_SRGB_DECODE_ARB 0x8299 +#define GL_FILTER 0x829A +#define GL_VERTEX_TEXTURE 0x829B +#define GL_TESS_CONTROL_TEXTURE 0x829C +#define GL_TESS_EVALUATION_TEXTURE 0x829D +#define GL_GEOMETRY_TEXTURE 0x829E +#define GL_FRAGMENT_TEXTURE 0x829F +#define GL_COMPUTE_TEXTURE 0x82A0 +#define GL_TEXTURE_SHADOW 0x82A1 +#define GL_TEXTURE_GATHER 0x82A2 +#define GL_TEXTURE_GATHER_SHADOW 0x82A3 +#define GL_SHADER_IMAGE_LOAD 0x82A4 +#define GL_SHADER_IMAGE_STORE 0x82A5 +#define GL_SHADER_IMAGE_ATOMIC 0x82A6 +#define GL_IMAGE_TEXEL_SIZE 0x82A7 +#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 +#define GL_IMAGE_PIXEL_FORMAT 0x82A9 +#define GL_IMAGE_PIXEL_TYPE 0x82AA +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF +#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 +#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 +#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 +#define GL_CLEAR_BUFFER 0x82B4 +#define GL_TEXTURE_VIEW 0x82B5 +#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 +#define GL_FULL_SUPPORT 0x82B7 +#define GL_CAVEAT_SUPPORT 0x82B8 +#define GL_IMAGE_CLASS_4_X_32 0x82B9 +#define GL_IMAGE_CLASS_2_X_32 0x82BA +#define GL_IMAGE_CLASS_1_X_32 0x82BB +#define GL_IMAGE_CLASS_4_X_16 0x82BC +#define GL_IMAGE_CLASS_2_X_16 0x82BD +#define GL_IMAGE_CLASS_1_X_16 0x82BE +#define GL_IMAGE_CLASS_4_X_8 0x82BF +#define GL_IMAGE_CLASS_2_X_8 0x82C0 +#define GL_IMAGE_CLASS_1_X_8 0x82C1 +#define GL_IMAGE_CLASS_11_11_10 0x82C2 +#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 +#define GL_VIEW_CLASS_128_BITS 0x82C4 +#define GL_VIEW_CLASS_96_BITS 0x82C5 +#define GL_VIEW_CLASS_64_BITS 0x82C6 +#define GL_VIEW_CLASS_48_BITS 0x82C7 +#define GL_VIEW_CLASS_32_BITS 0x82C8 +#define GL_VIEW_CLASS_24_BITS 0x82C9 +#define GL_VIEW_CLASS_16_BITS 0x82CA +#define GL_VIEW_CLASS_8_BITS 0x82CB +#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC +#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD +#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE +#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF +#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 +#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 +#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 +#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 +#endif + +#ifndef GL_ARB_invalidate_subdata +#endif + +#ifndef GL_ARB_multi_draw_indirect +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_UNIFORM 0x92E1 +#define GL_UNIFORM_BLOCK 0x92E2 +#define GL_PROGRAM_INPUT 0x92E3 +#define GL_PROGRAM_OUTPUT 0x92E4 +#define GL_BUFFER_VARIABLE 0x92E5 +#define GL_SHADER_STORAGE_BLOCK 0x92E6 +/* reuse GL_ATOMIC_COUNTER_BUFFER */ +#define GL_VERTEX_SUBROUTINE 0x92E8 +#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 +#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA +#define GL_GEOMETRY_SUBROUTINE 0x92EB +#define GL_FRAGMENT_SUBROUTINE 0x92EC +#define GL_COMPUTE_SUBROUTINE 0x92ED +#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE +#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF +#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 +#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 +#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 +#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 +#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 +#define GL_ACTIVE_RESOURCES 0x92F5 +#define GL_MAX_NAME_LENGTH 0x92F6 +#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 +#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 +#define GL_NAME_LENGTH 0x92F9 +#define GL_TYPE 0x92FA +#define GL_ARRAY_SIZE 0x92FB +#define GL_OFFSET 0x92FC +#define GL_BLOCK_INDEX 0x92FD +#define GL_ARRAY_STRIDE 0x92FE +#define GL_MATRIX_STRIDE 0x92FF +#define GL_IS_ROW_MAJOR 0x9300 +#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 +#define GL_BUFFER_BINDING 0x9302 +#define GL_BUFFER_DATA_SIZE 0x9303 +#define GL_NUM_ACTIVE_VARIABLES 0x9304 +#define GL_ACTIVE_VARIABLES 0x9305 +#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 +#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 +#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 +#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 +#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A +#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B +#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C +#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D +#define GL_LOCATION 0x930E +#define GL_LOCATION_INDEX 0x930F +#define GL_IS_PER_PATCH 0x92E7 +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#endif + +#ifndef GL_ARB_shader_image_size +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_SHADER_STORAGE_BUFFER 0x90D2 +#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 +#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 +#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 +#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 +#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 +#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 +#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 +#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA +#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB +#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC +#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD +#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE +#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF +#define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 +#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS +/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_TEXTURE_BUFFER_OFFSET 0x919D +#define GL_TEXTURE_BUFFER_SIZE 0x919E +#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F +#endif + +#ifndef GL_ARB_texture_query_levels +#endif + +#ifndef GL_ARB_texture_storage_multisample +#endif + + +/*************************************************************/ + +#include +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for program/shader text and shader object handles */ +typedef char GLcharARB; +typedef unsigned int GLhandleARB; +#endif + +/* GL type for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glxext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GL_EXT_timer_query extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include +#endif +#endif + +#ifndef GL_EXT_timer_query +typedef int64_t GLint64EXT; +typedef uint64_t GLuint64EXT; +#endif + +#ifndef GL_ARB_sync +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#ifndef GL_ARB_cl_event +/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */ +struct _cl_context; +struct _cl_event; +#endif + +#ifndef GL_ARB_debug_output +typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_AMD_debug_output +typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_KHR_debug +typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_NV_vdpau_interop +typedef GLintptr GLvdpauSurfaceNV; +#endif + +#ifndef GL_VERSION_1_0 +#define GL_VERSION_1_0 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCullFace (GLenum mode); +GLAPI void APIENTRY glFrontFace (GLenum mode); +GLAPI void APIENTRY glHint (GLenum target, GLenum mode); +GLAPI void APIENTRY glLineWidth (GLfloat width); +GLAPI void APIENTRY glPointSize (GLfloat size); +GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode); +GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glDrawBuffer (GLenum mode); +GLAPI void APIENTRY glClear (GLbitfield mask); +GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GLAPI void APIENTRY glClearStencil (GLint s); +GLAPI void APIENTRY glClearDepth (GLdouble depth); +GLAPI void APIENTRY glStencilMask (GLuint mask); +GLAPI void APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GLAPI void APIENTRY glDepthMask (GLboolean flag); +GLAPI void APIENTRY glDisable (GLenum cap); +GLAPI void APIENTRY glEnable (GLenum cap); +GLAPI void APIENTRY glFinish (void); +GLAPI void APIENTRY glFlush (void); +GLAPI void APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GLAPI void APIENTRY glLogicOp (GLenum opcode); +GLAPI void APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GLAPI void APIENTRY glDepthFunc (GLenum func); +GLAPI void APIENTRY glPixelStoref (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); +GLAPI void APIENTRY glReadBuffer (GLenum mode); +GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); +GLAPI void APIENTRY glGetDoublev (GLenum pname, GLdouble *params); +GLAPI GLenum APIENTRY glGetError (void); +GLAPI void APIENTRY glGetFloatv (GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *params); +GLAPI const GLubyte * APIENTRY glGetString (GLenum name); +GLAPI void APIENTRY glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); +GLAPI void APIENTRY glDepthRange (GLdouble near, GLdouble far); +GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLFRONTFACEPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLHINTPROC) (GLenum target, GLenum mode); +typedef void (APIENTRYP PFNGLLINEWIDTHPROC) (GLfloat width); +typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size); +typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXIMAGE1DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLDRAWBUFFERPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s); +typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth); +typedef void (APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask); +typedef void (APIENTRYP PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag); +typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLFINISHPROC) (void); +typedef void (APIENTRYP PFNGLFLUSHPROC) (void); +typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor); +typedef void (APIENTRYP PFNGLLOGICOPPROC) (GLenum opcode); +typedef void (APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass); +typedef void (APIENTRYP PFNGLDEPTHFUNCPROC) (GLenum func); +typedef void (APIENTRYP PFNGLPIXELSTOREFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLREADBUFFERPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETBOOLEANVPROC) (GLenum pname, GLboolean *params); +typedef void (APIENTRYP PFNGLGETDOUBLEVPROC) (GLenum pname, GLdouble *params); +typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); +typedef void (APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); +typedef void (APIENTRYP PFNGLGETTEXIMAGEPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERFVPROC) (GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERIVPROC) (GLenum target, GLint level, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLDEPTHRANGEPROC) (GLdouble near, GLdouble far); +typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_1 +#define GL_VERSION_1_1 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +GLAPI void APIENTRY glGetPointerv (GLenum pname, GLvoid* *params); +GLAPI void APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GLAPI void APIENTRY glCopyTexImage1D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); +GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); +GLAPI GLboolean APIENTRY glIsTexture (GLuint texture); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLGETPOINTERVPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLPOLYGONOFFSETPROC) (GLfloat factor, GLfloat units); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREPROC) (GLuint texture); +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GLAPI void APIENTRY glBlendEquation (GLenum mode); +GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +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 GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum texture); +GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +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 GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); +GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQuery (GLuint id); +GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQuery (GLenum target); +GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); +GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); +GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); +GLAPI void APIENTRY glCompileShader (GLuint shader); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum type); +GLAPI void APIENTRY glDeleteProgram (GLuint program); +GLAPI void APIENTRY glDeleteShader (GLuint shader); +GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgram (GLuint program); +GLAPI GLboolean APIENTRY glIsShader (GLuint shader); +GLAPI void APIENTRY glLinkProgram (GLuint program); +GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); +GLAPI void APIENTRY glUseProgram (GLuint program); +GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glValidateProgram (GLuint program); +GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_VERSION_2_1 +#define GL_VERSION_2_1 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif + +#ifndef GL_VERSION_3_0 +#define GL_VERSION_3_0 1 +/* OpenGL 3.0 also reuses entry points from these extensions: */ +/* ARB_framebuffer_object */ +/* ARB_map_buffer_range */ +/* ARB_vertex_array_object */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); +GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); +GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedback (void); +GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); +GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRender (void); +GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); +GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); +GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); +GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); +GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); +#endif + +#ifndef GL_VERSION_3_1 +#define GL_VERSION_3_1 1 +/* OpenGL 3.1 also reuses entry points from these extensions: */ +/* ARB_copy_buffer */ +/* ARB_uniform_buffer_object */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); +GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); +typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); +#endif + +#ifndef GL_VERSION_3_2 +#define GL_VERSION_3_2 1 +/* OpenGL 3.2 also reuses entry points from these extensions: */ +/* ARB_draw_elements_base_vertex */ +/* ARB_provoking_vertex */ +/* ARB_sync */ +/* ARB_texture_multisample */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); +GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERSION_3_3 1 +/* OpenGL 3.3 also reuses entry points from these extensions: */ +/* ARB_blend_func_extended */ +/* ARB_sampler_objects */ +/* ARB_explicit_attrib_location, but it has none */ +/* ARB_occlusion_query2 (no entry points) */ +/* ARB_shader_bit_encoding (no entry points) */ +/* ARB_texture_rgb10_a2ui (no entry points) */ +/* ARB_texture_swizzle (no entry points) */ +/* ARB_timer_query */ +/* ARB_vertex_type_2_10_10_10_rev */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_VERSION_4_0 +#define GL_VERSION_4_0 1 +/* OpenGL 4.0 also reuses entry points from these extensions: */ +/* ARB_texture_query_lod (no entry points) */ +/* ARB_draw_indirect */ +/* ARB_gpu_shader5 (no entry points) */ +/* ARB_gpu_shader_fp64 */ +/* ARB_shader_subroutine */ +/* ARB_tessellation_shader */ +/* ARB_texture_buffer_object_rgb32 (no entry points) */ +/* ARB_texture_cube_map_array (no entry points) */ +/* ARB_texture_gather (no entry points) */ +/* ARB_transform_feedback2 */ +/* ARB_transform_feedback3 */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMinSampleShading (GLfloat value); +GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value); +typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_VERSION_4_1 +#define GL_VERSION_4_1 1 +/* OpenGL 4.1 reuses entry points from these extensions: */ +/* ARB_ES2_compatibility */ +/* ARB_get_program_binary */ +/* ARB_separate_shader_objects */ +/* ARB_shader_precision (no entry points) */ +/* ARB_vertex_attrib_64bit */ +/* ARB_viewport_array */ +#endif + +#ifndef GL_VERSION_4_2 +#define GL_VERSION_4_2 1 +/* OpenGL 4.2 reuses entry points from these extensions: */ +/* ARB_base_instance */ +/* ARB_shading_language_420pack (no entry points) */ +/* ARB_transform_feedback_instanced */ +/* ARB_compressed_texture_pixel_storage (no entry points) */ +/* ARB_conservative_depth (no entry points) */ +/* ARB_internalformat_query */ +/* ARB_map_buffer_alignment (no entry points) */ +/* ARB_shader_atomic_counters */ +/* ARB_shader_image_load_store */ +/* ARB_shading_language_packing (no entry points) */ +/* ARB_texture_storage */ +#endif + +#ifndef GL_VERSION_4_3 +#define GL_VERSION_4_3 1 +/* OpenGL 4.3 reuses entry points from these extensions: */ +/* ARB_arrays_of_arrays (no entry points, GLSL only) */ +/* ARB_fragment_layer_viewport (no entry points, GLSL only) */ +/* ARB_shader_image_size (no entry points, GLSL only) */ +/* ARB_ES3_compatibility (no entry points) */ +/* ARB_clear_buffer_object */ +/* ARB_compute_shader */ +/* ARB_copy_image */ +/* KHR_debug (includes ARB_debug_output commands promoted to KHR without suffixes) */ +/* ARB_explicit_uniform_location (no entry points) */ +/* ARB_framebuffer_no_attachments */ +/* ARB_internalformat_query2 */ +/* ARB_invalidate_subdata */ +/* ARB_multi_draw_indirect */ +/* ARB_program_interface_query */ +/* ARB_robust_buffer_access_behavior (no entry points) */ +/* ARB_shader_storage_buffer_object */ +/* ARB_stencil_texturing (no entry points) */ +/* ARB_texture_buffer_range */ +/* ARB_texture_query_levels (no entry points) */ +/* ARB_texture_storage_multisample */ +/* ARB_texture_view */ +/* ARB_vertex_attrib_binding */ +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_ARB_depth_buffer_float 1 +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_ARB_framebuffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmap (GLenum target); +GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_ARB_half_float_vertex 1 +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_ARB_texture_compression_rgtc 1 +#endif + +#ifndef GL_ARB_texture_rg +#define GL_ARB_texture_rg 1 +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_ARB_vertex_array_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindVertexArray (GLuint array); +GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_ARB_uniform_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); +GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); +GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_ARB_copy_buffer 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_ARB_depth_clamp 1 +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#define GL_ARB_fragment_coord_conventions 1 +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_ARB_provoking_vertex 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glProvokingVertex (GLenum mode); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_ARB_seamless_cube_map 1 +#endif + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GLAPI GLboolean APIENTRY glIsSync (GLsync sync); +GLAPI void APIENTRY glDeleteSync (GLsync sync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_ARB_texture_multisample 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); +#endif + +#ifndef GL_ARB_vertex_array_bgra +#define GL_ARB_vertex_array_bgra 1 +#endif + +#ifndef GL_ARB_draw_buffers_blend +#define GL_ARB_draw_buffers_blend 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_ARB_sample_shading +#define GL_ARB_sample_shading 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_ARB_texture_cube_map_array 1 +#endif + +#ifndef GL_ARB_texture_gather +#define GL_ARB_texture_gather 1 +#endif + +#ifndef GL_ARB_texture_query_lod +#define GL_ARB_texture_query_lod 1 +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_ARB_shading_language_include 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_ARB_texture_compression_bptc 1 +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_ARB_blend_func_extended 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); +#endif + +#ifndef GL_ARB_explicit_attrib_location +#define GL_ARB_explicit_attrib_location 1 +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ARB_occlusion_query2 1 +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_ARB_sampler_objects 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); +GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); +GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); +GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); +GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); +typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); +typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); +typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_shader_bit_encoding +#define GL_ARB_shader_bit_encoding 1 +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_ARB_texture_rgb10_a2ui 1 +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_ARB_texture_swizzle 1 +#endif + +#ifndef GL_ARB_timer_query +#define GL_ARB_timer_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); +GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +#define GL_ARB_vertex_type_2_10_10_10_rev 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_ARB_draw_indirect 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); +GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_ARB_gpu_shader5 1 +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +#define GL_ARB_gpu_shader_fp64 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); +GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ARB_shader_subroutine 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); +GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); +GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); +typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_ARB_tessellation_shader 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); +GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +#define GL_ARB_texture_buffer_object_rgb32 1 +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_ARB_transform_feedback2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedback (void); +GLAPI void APIENTRY glResumeTransformFeedback (void); +GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_ARB_transform_feedback3 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); +GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); +GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); +GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); +typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_ARB_ES2_compatibility 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glReleaseShaderCompiler (void); +GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f); +GLAPI void APIENTRY glClearDepthf (GLfloat d); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); +typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f); +typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d); +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_ARB_get_program_binary 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_ARB_separate_shader_objects 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); +GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* const *strings); +GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); +GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); +GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); +GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); +GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); +GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); +typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* const *strings); +typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); +typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +#define GL_ARB_vertex_attrib_64bit 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); +#endif + +#ifndef GL_ARB_viewport_array +#define GL_ARB_viewport_array 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); +GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); +GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f); +GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f); +typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); +#endif + +#ifndef GL_ARB_cl_event +#define GL_ARB_cl_event 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif + +#ifndef GL_ARB_debug_output +#define GL_ARB_debug_output 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif + +#ifndef GL_ARB_robustness +#define GL_ARB_robustness 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); +GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); +GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); +typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_stencil_export +#define GL_ARB_shader_stencil_export 1 +#endif + +#ifndef GL_ARB_base_instance +#define GL_ARB_base_instance 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +#endif + +#ifndef GL_ARB_shading_language_420pack +#define GL_ARB_shading_language_420pack 1 +#endif + +#ifndef GL_ARB_transform_feedback_instanced +#define GL_ARB_transform_feedback_instanced 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); +GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#endif + +#ifndef GL_ARB_compressed_texture_pixel_storage +#define GL_ARB_compressed_texture_pixel_storage 1 +#endif + +#ifndef GL_ARB_conservative_depth +#define GL_ARB_conservative_depth 1 +#endif + +#ifndef GL_ARB_internalformat_query +#define GL_ARB_internalformat_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); +#endif + +#ifndef GL_ARB_map_buffer_alignment +#define GL_ARB_map_buffer_alignment 1 +#endif + +#ifndef GL_ARB_shader_atomic_counters +#define GL_ARB_shader_atomic_counters 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_shader_image_load_store +#define GL_ARB_shader_image_load_store 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); +#endif + +#ifndef GL_ARB_shading_language_packing +#define GL_ARB_shading_language_packing 1 +#endif + +#ifndef GL_ARB_texture_storage +#define GL_ARB_texture_storage 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_KHR_texture_compression_astc_ldr 1 +#endif + +#ifndef GL_KHR_debug +#define GL_KHR_debug 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); +GLAPI void APIENTRY glPopDebugGroup (void); +GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); +typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); +typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif + +#ifndef GL_ARB_arrays_of_arrays +#define GL_ARB_arrays_of_arrays 1 +#endif + +#ifndef GL_ARB_clear_buffer_object +#define GL_ARB_clear_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif + +#ifndef GL_ARB_compute_shader +#define GL_ARB_compute_shader 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); +#endif + +#ifndef GL_ARB_copy_image +#define GL_ARB_copy_image 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif + +#ifndef GL_ARB_texture_view +#define GL_ARB_texture_view 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_ARB_vertex_attrib_binding 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif + +#ifndef GL_ARB_robustness_isolation +#define GL_ARB_robustness_isolation 1 +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_ARB_ES3_compatibility 1 +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_ARB_explicit_uniform_location 1 +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#define GL_ARB_fragment_layer_viewport 1 +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_ARB_framebuffer_no_attachments 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); +GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_internalformat_query2 +#define GL_ARB_internalformat_query2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif + +#ifndef GL_ARB_invalidate_subdata +#define GL_ARB_invalidate_subdata 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); +GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); +GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); +GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_ARB_multi_draw_indirect +#define GL_ARB_multi_draw_indirect 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_ARB_program_interface_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#define GL_ARB_robust_buffer_access_behavior 1 +#endif + +#ifndef GL_ARB_shader_image_size +#define GL_ARB_shader_image_size 1 +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_ARB_shader_storage_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_ARB_stencil_texturing 1 +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_ARB_texture_buffer_range 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_texture_query_levels +#define GL_ARB_texture_query_levels 1 +#endif + +#ifndef GL_ARB_texture_storage_multisample +#define GL_ARB_texture_storage_multisample 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/COPYING.txt b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/COPYING.txt new file mode 100644 index 0000000..b30c701 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/COPYING.txt @@ -0,0 +1,22 @@ +Copyright (c) 2002-2006 Marcus Geelnard +Copyright (c) 2006-2010 Camilla Berglund + +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/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3.h b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3.h new file mode 100644 index 0000000..f8ca3d6 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3.h @@ -0,0 +1,4227 @@ +/************************************************************************* + * GLFW 3.2 - www.glfw.org + * A library for OpenGL, window and input + *------------------------------------------------------------------------ + * Copyright (c) 2002-2006 Marcus Geelnard + * Copyright (c) 2006-2010 Camilla Berglund + * + * 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. + * + *************************************************************************/ + +#ifndef _glfw3_h_ +#define _glfw3_h_ + +#ifdef __cplusplus +extern "C" { +#endif + + +/************************************************************************* + * Doxygen documentation + *************************************************************************/ + +/*! @file glfw3.h + * @brief The header of the GLFW 3 API. + * + * This is the header file of the GLFW 3 API. It defines all its types and + * declares all its functions. + * + * For more information about how to use this file, see @ref build_include. + */ +/*! @defgroup context Context reference + * + * This is the reference documentation for OpenGL and OpenGL ES context related + * functions. For more task-oriented information, see the @ref context_guide. + */ +/*! @defgroup vulkan Vulkan reference + * + * This is the reference documentation for Vulkan related functions and types. + * For more task-oriented information, see the @ref vulkan_guide. + */ +/*! @defgroup init Initialization, version and error reference + * + * This is the reference documentation for initialization and termination of + * the library, version management and error handling. For more task-oriented + * information, see the @ref intro_guide. + */ +/*! @defgroup input Input reference + * + * This is the reference documentation for input related functions and types. + * For more task-oriented information, see the @ref input_guide. + */ +/*! @defgroup monitor Monitor reference + * + * This is the reference documentation for monitor related functions and types. + * For more task-oriented information, see the @ref monitor_guide. + */ +/*! @defgroup window Window reference + * + * This is the reference documentation for window related functions and types, + * including creation, deletion and event polling. For more task-oriented + * information, see the @ref window_guide. + */ + + +/************************************************************************* + * Compiler- and platform-specific preprocessor work + *************************************************************************/ + +/* If we are we on Windows, we want a single define for it. + */ +#if !defined(_WIN32) && (defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__)) + #define _WIN32 +#endif /* _WIN32 */ + +/* It is customary to use APIENTRY for OpenGL function pointer declarations on + * all platforms. Additionally, the Windows OpenGL header needs APIENTRY. + */ +#ifndef APIENTRY + #ifdef _WIN32 + #define APIENTRY __stdcall + #else + #define APIENTRY + #endif +#endif /* APIENTRY */ + +/* Some Windows OpenGL headers need this. + */ +#if !defined(WINGDIAPI) && defined(_WIN32) + #define WINGDIAPI __declspec(dllimport) + #define GLFW_WINGDIAPI_DEFINED +#endif /* WINGDIAPI */ + +/* Some Windows GLU headers need this. + */ +#if !defined(CALLBACK) && defined(_WIN32) + #define CALLBACK __stdcall + #define GLFW_CALLBACK_DEFINED +#endif /* CALLBACK */ + +/* Most Windows GLU headers need wchar_t. + * The OS X OpenGL header blocks the definition of ptrdiff_t by glext.h. + * Include it unconditionally to avoid surprising side-effects. + */ +#include +#include + +/* Include the chosen client API headers. + */ +#if defined(__APPLE__) + #if defined(GLFW_INCLUDE_GLCOREARB) + #include + #if defined(GLFW_INCLUDE_GLEXT) + #include + #endif + #elif !defined(GLFW_INCLUDE_NONE) + #if !defined(GLFW_INCLUDE_GLEXT) + #define GL_GLEXT_LEGACY + #endif + #include + #endif + #if defined(GLFW_INCLUDE_GLU) + #include + #endif +#else + #if defined(GLFW_INCLUDE_GLCOREARB) + #include + #elif defined(GLFW_INCLUDE_ES1) + #include + #if defined(GLFW_INCLUDE_GLEXT) + #include + #endif + #elif defined(GLFW_INCLUDE_ES2) + #include + #if defined(GLFW_INCLUDE_GLEXT) + #include + #endif + #elif defined(GLFW_INCLUDE_ES3) + #include + #if defined(GLFW_INCLUDE_GLEXT) + #include + #endif + #elif defined(GLFW_INCLUDE_ES31) + #include + #if defined(GLFW_INCLUDE_GLEXT) + #include + #endif + #elif defined(GLFW_INCLUDE_VULKAN) + #include + #elif !defined(GLFW_INCLUDE_NONE) + #include + #if defined(GLFW_INCLUDE_GLEXT) + #include + #endif + #endif + #if defined(GLFW_INCLUDE_GLU) + #include + #endif +#endif + +#if defined(GLFW_DLL) && defined(_GLFW_BUILD_DLL) + /* GLFW_DLL must be defined by applications that are linking against the DLL + * version of the GLFW library. _GLFW_BUILD_DLL is defined by the GLFW + * configuration header when compiling the DLL version of the library. + */ + #error "You must not have both GLFW_DLL and _GLFW_BUILD_DLL defined" +#endif + +/* GLFWAPI is used to declare public API functions for export + * from the DLL / shared library / dynamic library. + */ +#if defined(_WIN32) && defined(_GLFW_BUILD_DLL) + /* We are building GLFW as a Win32 DLL */ + #define GLFWAPI __declspec(dllexport) +#elif defined(_WIN32) && defined(GLFW_DLL) + /* We are calling GLFW as a Win32 DLL */ + #define GLFWAPI __declspec(dllimport) +#elif defined(__GNUC__) && defined(_GLFW_BUILD_DLL) + /* We are building GLFW as a shared / dynamic library */ + #define GLFWAPI __attribute__((visibility("default"))) +#else + /* We are building or calling GLFW as a static library */ + #define GLFWAPI +#endif + + +/************************************************************************* + * GLFW API tokens + *************************************************************************/ + +/*! @name GLFW version macros + * @{ */ +/*! @brief The major version number of the GLFW library. + * + * This is incremented when the API is changed in non-compatible ways. + * @ingroup init + */ +#define GLFW_VERSION_MAJOR 3 +/*! @brief The minor version number of the GLFW library. + * + * This is incremented when features are added to the API but it remains + * backward-compatible. + * @ingroup init + */ +#define GLFW_VERSION_MINOR 2 +/*! @brief The revision number of the GLFW library. + * + * This is incremented when a bug fix release is made that does not contain any + * API changes. + * @ingroup init + */ +#define GLFW_VERSION_REVISION 0 +/*! @} */ + +/*! @name Boolean values + * @{ */ +/*! @brief One. + * + * One. Seriously. You don't _need_ to use this symbol in your code. It's + * just semantic sugar for the number 1. You can use `1` or `true` or `_True` + * or `GL_TRUE` or whatever you want. + */ +#define GLFW_TRUE 1 +/*! @brief Zero. + * + * Zero. Seriously. You don't _need_ to use this symbol in your code. It's + * just just semantic sugar for the number 0. You can use `0` or `false` or + * `_False` or `GL_FALSE` or whatever you want. + */ +#define GLFW_FALSE 0 +/*! @} */ + +/*! @name Key and button actions + * @{ */ +/*! @brief The key or mouse button was released. + * + * The key or mouse button was released. + * + * @ingroup input + */ +#define GLFW_RELEASE 0 +/*! @brief The key or mouse button was pressed. + * + * The key or mouse button was pressed. + * + * @ingroup input + */ +#define GLFW_PRESS 1 +/*! @brief The key was held down until it repeated. + * + * The key was held down until it repeated. + * + * @ingroup input + */ +#define GLFW_REPEAT 2 +/*! @} */ + +/*! @defgroup keys Keyboard keys + * + * See [key input](@ref input_key) for how these are used. + * + * These key codes are inspired by the _USB HID Usage Tables v1.12_ (p. 53-60), + * but re-arranged to map to 7-bit ASCII for printable keys (function keys are + * put in the 256+ range). + * + * The naming of the key codes follow these rules: + * - The US keyboard layout is used + * - Names of printable alpha-numeric characters are used (e.g. "A", "R", + * "3", etc.) + * - For non-alphanumeric characters, Unicode:ish names are used (e.g. + * "COMMA", "LEFT_SQUARE_BRACKET", etc.). Note that some names do not + * correspond to the Unicode standard (usually for brevity) + * - Keys that lack a clear US mapping are named "WORLD_x" + * - For non-printable keys, custom names are used (e.g. "F4", + * "BACKSPACE", etc.) + * + * @ingroup input + * @{ + */ + +/* The unknown key */ +#define GLFW_KEY_UNKNOWN -1 + +/* Printable keys */ +#define GLFW_KEY_SPACE 32 +#define GLFW_KEY_APOSTROPHE 39 /* ' */ +#define GLFW_KEY_COMMA 44 /* , */ +#define GLFW_KEY_MINUS 45 /* - */ +#define GLFW_KEY_PERIOD 46 /* . */ +#define GLFW_KEY_SLASH 47 /* / */ +#define GLFW_KEY_0 48 +#define GLFW_KEY_1 49 +#define GLFW_KEY_2 50 +#define GLFW_KEY_3 51 +#define GLFW_KEY_4 52 +#define GLFW_KEY_5 53 +#define GLFW_KEY_6 54 +#define GLFW_KEY_7 55 +#define GLFW_KEY_8 56 +#define GLFW_KEY_9 57 +#define GLFW_KEY_SEMICOLON 59 /* ; */ +#define GLFW_KEY_EQUAL 61 /* = */ +#define GLFW_KEY_A 65 +#define GLFW_KEY_B 66 +#define GLFW_KEY_C 67 +#define GLFW_KEY_D 68 +#define GLFW_KEY_E 69 +#define GLFW_KEY_F 70 +#define GLFW_KEY_G 71 +#define GLFW_KEY_H 72 +#define GLFW_KEY_I 73 +#define GLFW_KEY_J 74 +#define GLFW_KEY_K 75 +#define GLFW_KEY_L 76 +#define GLFW_KEY_M 77 +#define GLFW_KEY_N 78 +#define GLFW_KEY_O 79 +#define GLFW_KEY_P 80 +#define GLFW_KEY_Q 81 +#define GLFW_KEY_R 82 +#define GLFW_KEY_S 83 +#define GLFW_KEY_T 84 +#define GLFW_KEY_U 85 +#define GLFW_KEY_V 86 +#define GLFW_KEY_W 87 +#define GLFW_KEY_X 88 +#define GLFW_KEY_Y 89 +#define GLFW_KEY_Z 90 +#define GLFW_KEY_LEFT_BRACKET 91 /* [ */ +#define GLFW_KEY_BACKSLASH 92 /* \ */ +#define GLFW_KEY_RIGHT_BRACKET 93 /* ] */ +#define GLFW_KEY_GRAVE_ACCENT 96 /* ` */ +#define GLFW_KEY_WORLD_1 161 /* non-US #1 */ +#define GLFW_KEY_WORLD_2 162 /* non-US #2 */ + +/* Function keys */ +#define GLFW_KEY_ESCAPE 256 +#define GLFW_KEY_ENTER 257 +#define GLFW_KEY_TAB 258 +#define GLFW_KEY_BACKSPACE 259 +#define GLFW_KEY_INSERT 260 +#define GLFW_KEY_DELETE 261 +#define GLFW_KEY_RIGHT 262 +#define GLFW_KEY_LEFT 263 +#define GLFW_KEY_DOWN 264 +#define GLFW_KEY_UP 265 +#define GLFW_KEY_PAGE_UP 266 +#define GLFW_KEY_PAGE_DOWN 267 +#define GLFW_KEY_HOME 268 +#define GLFW_KEY_END 269 +#define GLFW_KEY_CAPS_LOCK 280 +#define GLFW_KEY_SCROLL_LOCK 281 +#define GLFW_KEY_NUM_LOCK 282 +#define GLFW_KEY_PRINT_SCREEN 283 +#define GLFW_KEY_PAUSE 284 +#define GLFW_KEY_F1 290 +#define GLFW_KEY_F2 291 +#define GLFW_KEY_F3 292 +#define GLFW_KEY_F4 293 +#define GLFW_KEY_F5 294 +#define GLFW_KEY_F6 295 +#define GLFW_KEY_F7 296 +#define GLFW_KEY_F8 297 +#define GLFW_KEY_F9 298 +#define GLFW_KEY_F10 299 +#define GLFW_KEY_F11 300 +#define GLFW_KEY_F12 301 +#define GLFW_KEY_F13 302 +#define GLFW_KEY_F14 303 +#define GLFW_KEY_F15 304 +#define GLFW_KEY_F16 305 +#define GLFW_KEY_F17 306 +#define GLFW_KEY_F18 307 +#define GLFW_KEY_F19 308 +#define GLFW_KEY_F20 309 +#define GLFW_KEY_F21 310 +#define GLFW_KEY_F22 311 +#define GLFW_KEY_F23 312 +#define GLFW_KEY_F24 313 +#define GLFW_KEY_F25 314 +#define GLFW_KEY_KP_0 320 +#define GLFW_KEY_KP_1 321 +#define GLFW_KEY_KP_2 322 +#define GLFW_KEY_KP_3 323 +#define GLFW_KEY_KP_4 324 +#define GLFW_KEY_KP_5 325 +#define GLFW_KEY_KP_6 326 +#define GLFW_KEY_KP_7 327 +#define GLFW_KEY_KP_8 328 +#define GLFW_KEY_KP_9 329 +#define GLFW_KEY_KP_DECIMAL 330 +#define GLFW_KEY_KP_DIVIDE 331 +#define GLFW_KEY_KP_MULTIPLY 332 +#define GLFW_KEY_KP_SUBTRACT 333 +#define GLFW_KEY_KP_ADD 334 +#define GLFW_KEY_KP_ENTER 335 +#define GLFW_KEY_KP_EQUAL 336 +#define GLFW_KEY_LEFT_SHIFT 340 +#define GLFW_KEY_LEFT_CONTROL 341 +#define GLFW_KEY_LEFT_ALT 342 +#define GLFW_KEY_LEFT_SUPER 343 +#define GLFW_KEY_RIGHT_SHIFT 344 +#define GLFW_KEY_RIGHT_CONTROL 345 +#define GLFW_KEY_RIGHT_ALT 346 +#define GLFW_KEY_RIGHT_SUPER 347 +#define GLFW_KEY_MENU 348 + +#define GLFW_KEY_LAST GLFW_KEY_MENU + +/*! @} */ + +/*! @defgroup mods Modifier key flags + * + * See [key input](@ref input_key) for how these are used. + * + * @ingroup input + * @{ */ + +/*! @brief If this bit is set one or more Shift keys were held down. + */ +#define GLFW_MOD_SHIFT 0x0001 +/*! @brief If this bit is set one or more Control keys were held down. + */ +#define GLFW_MOD_CONTROL 0x0002 +/*! @brief If this bit is set one or more Alt keys were held down. + */ +#define GLFW_MOD_ALT 0x0004 +/*! @brief If this bit is set one or more Super keys were held down. + */ +#define GLFW_MOD_SUPER 0x0008 + +/*! @} */ + +/*! @defgroup buttons Mouse buttons + * + * See [mouse button input](@ref input_mouse_button) for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_MOUSE_BUTTON_1 0 +#define GLFW_MOUSE_BUTTON_2 1 +#define GLFW_MOUSE_BUTTON_3 2 +#define GLFW_MOUSE_BUTTON_4 3 +#define GLFW_MOUSE_BUTTON_5 4 +#define GLFW_MOUSE_BUTTON_6 5 +#define GLFW_MOUSE_BUTTON_7 6 +#define GLFW_MOUSE_BUTTON_8 7 +#define GLFW_MOUSE_BUTTON_LAST GLFW_MOUSE_BUTTON_8 +#define GLFW_MOUSE_BUTTON_LEFT GLFW_MOUSE_BUTTON_1 +#define GLFW_MOUSE_BUTTON_RIGHT GLFW_MOUSE_BUTTON_2 +#define GLFW_MOUSE_BUTTON_MIDDLE GLFW_MOUSE_BUTTON_3 +/*! @} */ + +/*! @defgroup joysticks Joysticks + * + * See [joystick input](@ref joystick) for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_JOYSTICK_1 0 +#define GLFW_JOYSTICK_2 1 +#define GLFW_JOYSTICK_3 2 +#define GLFW_JOYSTICK_4 3 +#define GLFW_JOYSTICK_5 4 +#define GLFW_JOYSTICK_6 5 +#define GLFW_JOYSTICK_7 6 +#define GLFW_JOYSTICK_8 7 +#define GLFW_JOYSTICK_9 8 +#define GLFW_JOYSTICK_10 9 +#define GLFW_JOYSTICK_11 10 +#define GLFW_JOYSTICK_12 11 +#define GLFW_JOYSTICK_13 12 +#define GLFW_JOYSTICK_14 13 +#define GLFW_JOYSTICK_15 14 +#define GLFW_JOYSTICK_16 15 +#define GLFW_JOYSTICK_LAST GLFW_JOYSTICK_16 +/*! @} */ + +/*! @defgroup errors Error codes + * + * See [error handling](@ref error_handling) for how these are used. + * + * @ingroup init + * @{ */ +/*! @brief GLFW has not been initialized. + * + * This occurs if a GLFW function was called that must not be called unless the + * library is [initialized](@ref intro_init). + * + * @analysis Application programmer error. Initialize GLFW before calling any + * function that requires initialization. + */ +#define GLFW_NOT_INITIALIZED 0x00010001 +/*! @brief No context is current for this thread. + * + * This occurs if a GLFW function was called that needs and operates on the + * current OpenGL or OpenGL ES context but no context is current on the calling + * thread. One such function is @ref glfwSwapInterval. + * + * @analysis Application programmer error. Ensure a context is current before + * calling functions that require a current context. + */ +#define GLFW_NO_CURRENT_CONTEXT 0x00010002 +/*! @brief One of the arguments to the function was an invalid enum value. + * + * One of the arguments to the function was an invalid enum value, for example + * requesting [GLFW_RED_BITS](@ref window_hints_fb) with @ref + * glfwGetWindowAttrib. + * + * @analysis Application programmer error. Fix the offending call. + */ +#define GLFW_INVALID_ENUM 0x00010003 +/*! @brief One of the arguments to the function was an invalid value. + * + * One of the arguments to the function was an invalid value, for example + * requesting a non-existent OpenGL or OpenGL ES version like 2.7. + * + * Requesting a valid but unavailable OpenGL or OpenGL ES version will instead + * result in a @ref GLFW_VERSION_UNAVAILABLE error. + * + * @analysis Application programmer error. Fix the offending call. + */ +#define GLFW_INVALID_VALUE 0x00010004 +/*! @brief A memory allocation failed. + * + * A memory allocation failed. + * + * @analysis A bug in GLFW or the underlying operating system. Report the bug + * to our [issue tracker](https://github.com/glfw/glfw/issues). + */ +#define GLFW_OUT_OF_MEMORY 0x00010005 +/*! @brief GLFW could not find support for the requested API on the system. + * + * GLFW could not find support for the requested API on the system. + * + * @analysis The installed graphics driver does not support the requested + * API, or does not support it via the chosen context creation backend. + * Below are a few examples. + * + * @par + * Some pre-installed Windows graphics drivers do not support OpenGL. AMD only + * supports OpenGL ES via EGL, while Nvidia and Intel only support it via + * a WGL or GLX extension. OS X does not provide OpenGL ES at all. The Mesa + * EGL, OpenGL and OpenGL ES libraries do not interface with the Nvidia binary + * driver. Older graphics drivers do not support Vulkan. + */ +#define GLFW_API_UNAVAILABLE 0x00010006 +/*! @brief The requested OpenGL or OpenGL ES version is not available. + * + * The requested OpenGL or OpenGL ES version (including any requested context + * or framebuffer hints) is not available on this machine. + * + * @analysis The machine does not support your requirements. If your + * application is sufficiently flexible, downgrade your requirements and try + * again. Otherwise, inform the user that their machine does not match your + * requirements. + * + * @par + * Future invalid OpenGL and OpenGL ES versions, for example OpenGL 4.8 if 5.0 + * comes out before the 4.x series gets that far, also fail with this error and + * not @ref GLFW_INVALID_VALUE, because GLFW cannot know what future versions + * will exist. + */ +#define GLFW_VERSION_UNAVAILABLE 0x00010007 +/*! @brief A platform-specific error occurred that does not match any of the + * more specific categories. + * + * A platform-specific error occurred that does not match any of the more + * specific categories. + * + * @analysis A bug or configuration error in GLFW, the underlying operating + * system or its drivers, or a lack of required resources. Report the issue to + * our [issue tracker](https://github.com/glfw/glfw/issues). + */ +#define GLFW_PLATFORM_ERROR 0x00010008 +/*! @brief The requested format is not supported or available. + * + * If emitted during window creation, the requested pixel format is not + * supported. + * + * If emitted when querying the clipboard, the contents of the clipboard could + * not be converted to the requested format. + * + * @analysis If emitted during window creation, one or more + * [hard constraints](@ref window_hints_hard) did not match any of the + * available pixel formats. If your application is sufficiently flexible, + * downgrade your requirements and try again. Otherwise, inform the user that + * their machine does not match your requirements. + * + * @par + * If emitted when querying the clipboard, ignore the error or report it to + * the user, as appropriate. + */ +#define GLFW_FORMAT_UNAVAILABLE 0x00010009 +/*! @brief The specified window does not have an OpenGL or OpenGL ES context. + * + * A window that does not have an OpenGL or OpenGL ES context was passed to + * a function that requires it to have one. + * + * @analysis Application programmer error. Fix the offending call. + */ +#define GLFW_NO_WINDOW_CONTEXT 0x0001000A +/*! @} */ + +#define GLFW_FOCUSED 0x00020001 +#define GLFW_ICONIFIED 0x00020002 +#define GLFW_RESIZABLE 0x00020003 +#define GLFW_VISIBLE 0x00020004 +#define GLFW_DECORATED 0x00020005 +#define GLFW_AUTO_ICONIFY 0x00020006 +#define GLFW_FLOATING 0x00020007 +#define GLFW_MAXIMIZED 0x00020008 + +#define GLFW_RED_BITS 0x00021001 +#define GLFW_GREEN_BITS 0x00021002 +#define GLFW_BLUE_BITS 0x00021003 +#define GLFW_ALPHA_BITS 0x00021004 +#define GLFW_DEPTH_BITS 0x00021005 +#define GLFW_STENCIL_BITS 0x00021006 +#define GLFW_ACCUM_RED_BITS 0x00021007 +#define GLFW_ACCUM_GREEN_BITS 0x00021008 +#define GLFW_ACCUM_BLUE_BITS 0x00021009 +#define GLFW_ACCUM_ALPHA_BITS 0x0002100A +#define GLFW_AUX_BUFFERS 0x0002100B +#define GLFW_STEREO 0x0002100C +#define GLFW_SAMPLES 0x0002100D +#define GLFW_SRGB_CAPABLE 0x0002100E +#define GLFW_REFRESH_RATE 0x0002100F +#define GLFW_DOUBLEBUFFER 0x00021010 + +#define GLFW_CLIENT_API 0x00022001 +#define GLFW_CONTEXT_VERSION_MAJOR 0x00022002 +#define GLFW_CONTEXT_VERSION_MINOR 0x00022003 +#define GLFW_CONTEXT_REVISION 0x00022004 +#define GLFW_CONTEXT_ROBUSTNESS 0x00022005 +#define GLFW_OPENGL_FORWARD_COMPAT 0x00022006 +#define GLFW_OPENGL_DEBUG_CONTEXT 0x00022007 +#define GLFW_OPENGL_PROFILE 0x00022008 +#define GLFW_CONTEXT_RELEASE_BEHAVIOR 0x00022009 +#define GLFW_CONTEXT_NO_ERROR 0x0002200A + +#define GLFW_NO_API 0 +#define GLFW_OPENGL_API 0x00030001 +#define GLFW_OPENGL_ES_API 0x00030002 + +#define GLFW_NO_ROBUSTNESS 0 +#define GLFW_NO_RESET_NOTIFICATION 0x00031001 +#define GLFW_LOSE_CONTEXT_ON_RESET 0x00031002 + +#define GLFW_OPENGL_ANY_PROFILE 0 +#define GLFW_OPENGL_CORE_PROFILE 0x00032001 +#define GLFW_OPENGL_COMPAT_PROFILE 0x00032002 + +#define GLFW_CURSOR 0x00033001 +#define GLFW_STICKY_KEYS 0x00033002 +#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003 + +#define GLFW_CURSOR_NORMAL 0x00034001 +#define GLFW_CURSOR_HIDDEN 0x00034002 +#define GLFW_CURSOR_DISABLED 0x00034003 + +#define GLFW_ANY_RELEASE_BEHAVIOR 0 +#define GLFW_RELEASE_BEHAVIOR_FLUSH 0x00035001 +#define GLFW_RELEASE_BEHAVIOR_NONE 0x00035002 + +/*! @defgroup shapes Standard cursor shapes + * + * See [standard cursor creation](@ref cursor_standard) for how these are used. + * + * @ingroup input + * @{ */ + +/*! @brief The regular arrow cursor shape. + * + * The regular arrow cursor. + */ +#define GLFW_ARROW_CURSOR 0x00036001 +/*! @brief The text input I-beam cursor shape. + * + * The text input I-beam cursor shape. + */ +#define GLFW_IBEAM_CURSOR 0x00036002 +/*! @brief The crosshair shape. + * + * The crosshair shape. + */ +#define GLFW_CROSSHAIR_CURSOR 0x00036003 +/*! @brief The hand shape. + * + * The hand shape. + */ +#define GLFW_HAND_CURSOR 0x00036004 +/*! @brief The horizontal resize arrow shape. + * + * The horizontal resize arrow shape. + */ +#define GLFW_HRESIZE_CURSOR 0x00036005 +/*! @brief The vertical resize arrow shape. + * + * The vertical resize arrow shape. + */ +#define GLFW_VRESIZE_CURSOR 0x00036006 +/*! @} */ + +#define GLFW_CONNECTED 0x00040001 +#define GLFW_DISCONNECTED 0x00040002 + +#define GLFW_DONT_CARE -1 + + +/************************************************************************* + * GLFW API types + *************************************************************************/ + +/*! @brief Client API function pointer type. + * + * Generic function pointer used for returning client API function pointers + * without forcing a cast from a regular pointer. + * + * @sa @ref context_glext + * @sa glfwGetProcAddress + * + * @since Added in version 3.0. + + * @ingroup context + */ +typedef void (*GLFWglproc)(void); + +/*! @brief Vulkan API function pointer type. + * + * Generic function pointer used for returning Vulkan API function pointers + * without forcing a cast from a regular pointer. + * + * @sa @ref vulkan_proc + * @sa glfwGetInstanceProcAddress + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +typedef void (*GLFWvkproc)(void); + +/*! @brief Opaque monitor object. + * + * Opaque monitor object. + * + * @see @ref monitor_object + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +typedef struct GLFWmonitor GLFWmonitor; + +/*! @brief Opaque window object. + * + * Opaque window object. + * + * @see @ref window_object + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef struct GLFWwindow GLFWwindow; + +/*! @brief Opaque cursor object. + * + * Opaque cursor object. + * + * @see @ref cursor_object + * + * @since Added in version 3.1. + * + * @ingroup cursor + */ +typedef struct GLFWcursor GLFWcursor; + +/*! @brief The function signature for error callbacks. + * + * This is the function signature for error callback functions. + * + * @param[in] error An [error code](@ref errors). + * @param[in] description A UTF-8 encoded string describing the error. + * + * @sa @ref error_handling + * @sa glfwSetErrorCallback + * + * @since Added in version 3.0. + * + * @ingroup init + */ +typedef void (* GLFWerrorfun)(int,const char*); + +/*! @brief The function signature for window position callbacks. + * + * This is the function signature for window position callback functions. + * + * @param[in] window The window that was moved. + * @param[in] xpos The new x-coordinate, in screen coordinates, of the + * upper-left corner of the client area of the window. + * @param[in] ypos The new y-coordinate, in screen coordinates, of the + * upper-left corner of the client area of the window. + * + * @sa @ref window_pos + * @sa glfwSetWindowPosCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWwindowposfun)(GLFWwindow*,int,int); + +/*! @brief The function signature for window resize callbacks. + * + * This is the function signature for window size callback functions. + * + * @param[in] window The window that was resized. + * @param[in] width The new width, in screen coordinates, of the window. + * @param[in] height The new height, in screen coordinates, of the window. + * + * @sa @ref window_size + * @sa glfwSetWindowSizeCallback + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int); + +/*! @brief The function signature for window close callbacks. + * + * This is the function signature for window close callback functions. + * + * @param[in] window The window that the user attempted to close. + * + * @sa @ref window_close + * @sa glfwSetWindowCloseCallback + * + * @since Added in version 2.5. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +typedef void (* GLFWwindowclosefun)(GLFWwindow*); + +/*! @brief The function signature for window content refresh callbacks. + * + * This is the function signature for window refresh callback functions. + * + * @param[in] window The window whose content needs to be refreshed. + * + * @sa @ref window_refresh + * @sa glfwSetWindowRefreshCallback + * + * @since Added in version 2.5. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +typedef void (* GLFWwindowrefreshfun)(GLFWwindow*); + +/*! @brief The function signature for window focus/defocus callbacks. + * + * This is the function signature for window focus callback functions. + * + * @param[in] window The window that gained or lost input focus. + * @param[in] focused `GLFW_TRUE` if the window was given input focus, or + * `GLFW_FALSE` if it lost it. + * + * @sa @ref window_focus + * @sa glfwSetWindowFocusCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWwindowfocusfun)(GLFWwindow*,int); + +/*! @brief The function signature for window iconify/restore callbacks. + * + * This is the function signature for window iconify/restore callback + * functions. + * + * @param[in] window The window that was iconified or restored. + * @param[in] iconified `GLFW_TRUE` if the window was iconified, or + * `GLFW_FALSE` if it was restored. + * + * @sa @ref window_iconify + * @sa glfwSetWindowIconifyCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWwindowiconifyfun)(GLFWwindow*,int); + +/*! @brief The function signature for framebuffer resize callbacks. + * + * This is the function signature for framebuffer resize callback + * functions. + * + * @param[in] window The window whose framebuffer was resized. + * @param[in] width The new width, in pixels, of the framebuffer. + * @param[in] height The new height, in pixels, of the framebuffer. + * + * @sa @ref window_fbsize + * @sa glfwSetFramebufferSizeCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWframebuffersizefun)(GLFWwindow*,int,int); + +/*! @brief The function signature for mouse button callbacks. + * + * This is the function signature for mouse button callback functions. + * + * @param[in] window The window that received the event. + * @param[in] button The [mouse button](@ref buttons) that was pressed or + * released. + * @param[in] action One of `GLFW_PRESS` or `GLFW_RELEASE`. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. + * + * @sa @ref input_mouse_button + * @sa glfwSetMouseButtonCallback + * + * @since Added in version 1.0. + * @glfw3 Added window handle and modifier mask parameters. + * + * @ingroup input + */ +typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int); + +/*! @brief The function signature for cursor position callbacks. + * + * This is the function signature for cursor position callback functions. + * + * @param[in] window The window that received the event. + * @param[in] xpos The new cursor x-coordinate, relative to the left edge of + * the client area. + * @param[in] ypos The new cursor y-coordinate, relative to the top edge of the + * client area. + * + * @sa @ref cursor_pos + * @sa glfwSetCursorPosCallback + * + * @since Added in version 3.0. Replaces `GLFWmouseposfun`. + * + * @ingroup input + */ +typedef void (* GLFWcursorposfun)(GLFWwindow*,double,double); + +/*! @brief The function signature for cursor enter/leave callbacks. + * + * This is the function signature for cursor enter/leave callback functions. + * + * @param[in] window The window that received the event. + * @param[in] entered `GLFW_TRUE` if the cursor entered the window's client + * area, or `GLFW_FALSE` if it left it. + * + * @sa @ref cursor_enter + * @sa glfwSetCursorEnterCallback + * + * @since Added in version 3.0. + * + * @ingroup input + */ +typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); + +/*! @brief The function signature for scroll callbacks. + * + * This is the function signature for scroll callback functions. + * + * @param[in] window The window that received the event. + * @param[in] xoffset The scroll offset along the x-axis. + * @param[in] yoffset The scroll offset along the y-axis. + * + * @sa @ref scrolling + * @sa glfwSetScrollCallback + * + * @since Added in version 3.0. Replaces `GLFWmousewheelfun`. + * + * @ingroup input + */ +typedef void (* GLFWscrollfun)(GLFWwindow*,double,double); + +/*! @brief The function signature for keyboard key callbacks. + * + * This is the function signature for keyboard key callback functions. + * + * @param[in] window The window that received the event. + * @param[in] key The [keyboard key](@ref keys) that was pressed or released. + * @param[in] scancode The system-specific scancode of the key. + * @param[in] action `GLFW_PRESS`, `GLFW_RELEASE` or `GLFW_REPEAT`. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. + * + * @sa @ref input_key + * @sa glfwSetKeyCallback + * + * @since Added in version 1.0. + * @glfw3 Added window handle, scancode and modifier mask parameters. + * + * @ingroup input + */ +typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); + +/*! @brief The function signature for Unicode character callbacks. + * + * This is the function signature for Unicode character callback functions. + * + * @param[in] window The window that received the event. + * @param[in] codepoint The Unicode code point of the character. + * + * @sa @ref input_char + * @sa glfwSetCharCallback + * + * @since Added in version 2.4. + * @glfw3 Added window handle parameter. + * + * @ingroup input + */ +typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int); + +/*! @brief The function signature for Unicode character with modifiers + * callbacks. + * + * This is the function signature for Unicode character with modifiers callback + * functions. It is called for each input character, regardless of what + * modifier keys are held down. + * + * @param[in] window The window that received the event. + * @param[in] codepoint The Unicode code point of the character. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. + * + * @sa @ref input_char + * @sa glfwSetCharModsCallback + * + * @since Added in version 3.1. + * + * @ingroup input + */ +typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); + +/*! @brief The function signature for file drop callbacks. + * + * This is the function signature for file drop callbacks. + * + * @param[in] window The window that received the event. + * @param[in] count The number of dropped files. + * @param[in] paths The UTF-8 encoded file and/or directory path names. + * + * @sa @ref path_drop + * @sa glfwSetDropCallback + * + * @since Added in version 3.1. + * + * @ingroup input + */ +typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); + +/*! @brief The function signature for monitor configuration callbacks. + * + * This is the function signature for monitor configuration callback functions. + * + * @param[in] monitor The monitor that was connected or disconnected. + * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. + * + * @sa @ref monitor_event + * @sa glfwSetMonitorCallback + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +typedef void (* GLFWmonitorfun)(GLFWmonitor*,int); + +/*! @brief The function signature for joystick configuration callbacks. + * + * This is the function signature for joystick configuration callback + * functions. + * + * @param[in] joy The joystick that was connected or disconnected. + * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. + * + * @sa @ref joystick_event + * @sa glfwSetJoystickCallback + * + * @since Added in version 3.2. + * + * @ingroup input + */ +typedef void (* GLFWjoystickfun)(int,int); + +/*! @brief Video mode type. + * + * This describes a single video mode. + * + * @sa @ref monitor_modes + * @sa glfwGetVideoMode glfwGetVideoModes + * + * @since Added in version 1.0. + * @glfw3 Added refresh rate member. + * + * @ingroup monitor + */ +typedef struct GLFWvidmode +{ + /*! The width, in screen coordinates, of the video mode. + */ + int width; + /*! The height, in screen coordinates, of the video mode. + */ + int height; + /*! The bit depth of the red channel of the video mode. + */ + int redBits; + /*! The bit depth of the green channel of the video mode. + */ + int greenBits; + /*! The bit depth of the blue channel of the video mode. + */ + int blueBits; + /*! The refresh rate, in Hz, of the video mode. + */ + int refreshRate; +} GLFWvidmode; + +/*! @brief Gamma ramp. + * + * This describes the gamma ramp for a monitor. + * + * @sa @ref monitor_gamma + * @sa glfwGetGammaRamp glfwSetGammaRamp + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +typedef struct GLFWgammaramp +{ + /*! An array of value describing the response of the red channel. + */ + unsigned short* red; + /*! An array of value describing the response of the green channel. + */ + unsigned short* green; + /*! An array of value describing the response of the blue channel. + */ + unsigned short* blue; + /*! The number of elements in each array. + */ + unsigned int size; +} GLFWgammaramp; + +/*! @brief Image data. + * + * @sa @ref cursor_custom + * + * @since Added in version 2.1. + * @glfw3 Removed format and bytes-per-pixel members. + */ +typedef struct GLFWimage +{ + /*! The width, in pixels, of this image. + */ + int width; + /*! The height, in pixels, of this image. + */ + int height; + /*! The pixel data of this image, arranged left-to-right, top-to-bottom. + */ + unsigned char* pixels; +} GLFWimage; + + +/************************************************************************* + * GLFW API functions + *************************************************************************/ + +/*! @brief Initializes the GLFW library. + * + * This function initializes the GLFW library. Before most GLFW functions can + * be used, GLFW must be initialized, and before an application terminates GLFW + * should be terminated in order to free any resources allocated during or + * after initialization. + * + * If this function fails, it calls @ref glfwTerminate before returning. If it + * succeeds, you should call @ref glfwTerminate before the application exits. + * + * Additional calls to this function after successful initialization but before + * termination will return `GLFW_TRUE` immediately. + * + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_PLATFORM_ERROR. + * + * @remark @osx This function will change the current directory of the + * application to the `Contents/Resources` subdirectory of the application's + * bundle, if present. This can be disabled with a + * [compile-time option](@ref compile_options_osx). + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref intro_init + * @sa glfwTerminate + * + * @since Added in version 1.0. + * + * @ingroup init + */ +GLFWAPI int glfwInit(void); + +/*! @brief Terminates the GLFW library. + * + * This function destroys all remaining windows and cursors, restores any + * modified gamma ramps and frees any other allocated resources. Once this + * function is called, you must again call @ref glfwInit successfully before + * you will be able to use most GLFW functions. + * + * If GLFW has been successfully initialized, this function should be called + * before the application exits. If initialization fails, there is no need to + * call this function, as it is called by @ref glfwInit before it returns + * failure. + * + * @errors Possible errors include @ref GLFW_PLATFORM_ERROR. + * + * @remark This function may be called before @ref glfwInit. + * + * @warning The contexts of any remaining windows must not be current on any + * other thread when this function is called. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref intro_init + * @sa glfwInit + * + * @since Added in version 1.0. + * + * @ingroup init + */ +GLFWAPI void glfwTerminate(void); + +/*! @brief Retrieves the version of the GLFW library. + * + * This function retrieves the major, minor and revision numbers of the GLFW + * library. It is intended for when you are using GLFW as a shared library and + * want to ensure that you are using the minimum required version. + * + * Any or all of the version arguments may be `NULL`. + * + * @param[out] major Where to store the major version number, or `NULL`. + * @param[out] minor Where to store the minor version number, or `NULL`. + * @param[out] rev Where to store the revision number, or `NULL`. + * + * @errors None. + * + * @remark This function may be called before @ref glfwInit. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref intro_version + * @sa glfwGetVersionString + * + * @since Added in version 1.0. + * + * @ingroup init + */ +GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev); + +/*! @brief Returns a string describing the compile-time configuration. + * + * This function returns the compile-time generated + * [version string](@ref intro_version_string) of the GLFW library binary. It + * describes the version, platform, compiler and any platform-specific + * compile-time options. It should not be confused with the OpenGL or OpenGL + * ES version string, queried with `glGetString`. + * + * __Do not use the version string__ to parse the GLFW library version. The + * @ref glfwGetVersion function provides the version of the running library + * binary in numerical format. + * + * @return The ASCII encoded GLFW version string. + * + * @errors None. + * + * @remark This function may be called before @ref glfwInit. + * + * @pointer_lifetime The returned string is static and compile-time generated. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref intro_version + * @sa glfwGetVersion + * + * @since Added in version 3.0. + * + * @ingroup init + */ +GLFWAPI const char* glfwGetVersionString(void); + +/*! @brief Sets the error callback. + * + * This function sets the error callback, which is called with an error code + * and a human-readable description each time a GLFW error occurs. + * + * The error callback is called on the thread where the error occurred. If you + * are using GLFW from multiple threads, your error callback needs to be + * written accordingly. + * + * Because the description string may have been generated specifically for that + * error, it is not guaranteed to be valid after the callback has returned. If + * you wish to use it after the callback returns, you need to make a copy. + * + * Once set, the error callback remains set even after the library has been + * terminated. + * + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set. + * + * @errors None. + * + * @remark This function may be called before @ref glfwInit. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref error_handling + * + * @since Added in version 3.0. + * + * @ingroup init + */ +GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun); + +/*! @brief Returns the currently connected monitors. + * + * This function returns an array of handles for all currently connected + * monitors. The primary monitor is always first in the returned array. If no + * monitors were found, this function returns `NULL`. + * + * @param[out] count Where to store the number of monitors in the returned + * array. This is set to zero if an error occurred. + * @return An array of monitor handles, or `NULL` if no monitors were found or + * if an [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is guaranteed to be valid only until the + * monitor configuration changes or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_monitors + * @sa @ref monitor_event + * @sa glfwGetPrimaryMonitor + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI GLFWmonitor** glfwGetMonitors(int* count); + +/*! @brief Returns the primary monitor. + * + * This function returns the primary monitor. This is usually the monitor + * where elements like the task bar or global menu bar are located. + * + * @return The primary monitor, or `NULL` if no monitors were found or if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @remark The primary monitor is always first in the array returned by @ref + * glfwGetMonitors. + * + * @sa @ref monitor_monitors + * @sa glfwGetMonitors + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void); + +/*! @brief Returns the position of the monitor's viewport on the virtual screen. + * + * This function returns the position, in screen coordinates, of the upper-left + * corner of the specified monitor. + * + * Any or all of the position arguments may be `NULL`. If an error occurs, all + * non-`NULL` position arguments will be set to zero. + * + * @param[in] monitor The monitor to query. + * @param[out] xpos Where to store the monitor x-coordinate, or `NULL`. + * @param[out] ypos Where to store the monitor y-coordinate, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_properties + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos); + +/*! @brief Returns the physical size of the monitor. + * + * This function returns the size, in millimetres, of the display area of the + * specified monitor. + * + * Some systems do not provide accurate monitor size information, either + * because the monitor + * [EDID](https://en.wikipedia.org/wiki/Extended_display_identification_data) + * data is incorrect or because the driver does not report it accurately. + * + * Any or all of the size arguments may be `NULL`. If an error occurs, all + * non-`NULL` size arguments will be set to zero. + * + * @param[in] monitor The monitor to query. + * @param[out] widthMM Where to store the width, in millimetres, of the + * monitor's display area, or `NULL`. + * @param[out] heightMM Where to store the height, in millimetres, of the + * monitor's display area, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @remark @win32 calculates the returned physical size from the + * current resolution and system DPI instead of querying the monitor EDID data. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_properties + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* widthMM, int* heightMM); + +/*! @brief Returns the name of the specified monitor. + * + * This function returns a human-readable name, encoded as UTF-8, of the + * specified monitor. The name typically reflects the make and model of the + * monitor and is not guaranteed to be unique among the connected monitors. + * + * @param[in] monitor The monitor to query. + * @return The UTF-8 encoded name of the monitor, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified monitor is + * disconnected or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_properties + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* monitor); + +/*! @brief Sets the monitor configuration callback. + * + * This function sets the monitor configuration callback, or removes the + * currently set callback. This is called when a monitor is connected to or + * disconnected from the system. + * + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_event + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun); + +/*! @brief Returns the available video modes for the specified monitor. + * + * This function returns an array of all video modes supported by the specified + * monitor. The returned array is sorted in ascending order, first by color + * bit depth (the sum of all channel depths) and then by resolution area (the + * product of width and height). + * + * @param[in] monitor The monitor to query. + * @param[out] count Where to store the number of video modes in the returned + * array. This is set to zero if an error occurred. + * @return An array of video modes, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified monitor is + * disconnected, this function is called again for that monitor or the library + * is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_modes + * @sa glfwGetVideoMode + * + * @since Added in version 1.0. + * @glfw3 Changed to return an array of modes for a specific monitor. + * + * @ingroup monitor + */ +GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count); + +/*! @brief Returns the current mode of the specified monitor. + * + * This function returns the current video mode of the specified monitor. If + * you have created a full screen window for that monitor, the return value + * will depend on whether that window is iconified. + * + * @param[in] monitor The monitor to query. + * @return The current mode of the monitor, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified monitor is + * disconnected or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_modes + * @sa glfwGetVideoModes + * + * @since Added in version 3.0. Replaces `glfwGetDesktopMode`. + * + * @ingroup monitor + */ +GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor); + +/*! @brief Generates a gamma ramp and sets it for the specified monitor. + * + * This function generates a 256-element gamma ramp from the specified exponent + * and then calls @ref glfwSetGammaRamp with it. The value must be a finite + * number greater than zero. + * + * @param[in] monitor The monitor whose gamma ramp to set. + * @param[in] gamma The desired exponent. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_gamma + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma); + +/*! @brief Returns the current gamma ramp for the specified monitor. + * + * This function returns the current gamma ramp of the specified monitor. + * + * @param[in] monitor The monitor to query. + * @return The current gamma ramp, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned structure and its arrays are allocated and + * freed by GLFW. You should not free them yourself. They are valid until the + * specified monitor is disconnected, this function is called again for that + * monitor or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_gamma + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor); + +/*! @brief Sets the current gamma ramp for the specified monitor. + * + * This function sets the current gamma ramp for the specified monitor. The + * original gamma ramp for that monitor is saved by GLFW the first time this + * function is called and is restored by @ref glfwTerminate. + * + * @param[in] monitor The monitor whose gamma ramp to set. + * @param[in] ramp The gamma ramp to use. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @remark Gamma ramp sizes other than 256 are not supported by all platforms + * or graphics hardware. + * + * @remark @win32 The gamma ramp size must be 256. + * + * @pointer_lifetime The specified gamma ramp is copied before this function + * returns. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref monitor_gamma + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +GLFWAPI void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp); + +/*! @brief Resets all window hints to their default values. + * + * This function resets all window hints to their + * [default values](@ref window_hints_values). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_hints + * @sa glfwWindowHint + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwDefaultWindowHints(void); + +/*! @brief Sets the specified window hint to the desired value. + * + * This function sets hints for the next call to @ref glfwCreateWindow. The + * hints, once set, retain their values until changed by a call to @ref + * glfwWindowHint or @ref glfwDefaultWindowHints, or until the library is + * terminated. + * + * This function does not check whether the specified hint values are valid. + * If you set hints to invalid values this will instead be reported by the next + * call to @ref glfwCreateWindow. + * + * @param[in] hint The [window hint](@ref window_hints) to set. + * @param[in] value The new value of the window hint. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_hints + * @sa glfwDefaultWindowHints + * + * @since Added in version 3.0. Replaces `glfwOpenWindowHint`. + * + * @ingroup window + */ +GLFWAPI void glfwWindowHint(int hint, int value); + +/*! @brief Creates a window and its associated context. + * + * This function creates a window and its associated OpenGL or OpenGL ES + * context. Most of the options controlling how the window and its context + * should be created are specified with [window hints](@ref window_hints). + * + * Successful creation does not change which context is current. Before you + * can use the newly created context, you need to + * [make it current](@ref context_current). For information about the `share` + * parameter, see @ref context_sharing. + * + * The created window, framebuffer and context may differ from what you + * requested, as not all parameters and hints are + * [hard constraints](@ref window_hints_hard). This includes the size of the + * window, especially for full screen windows. To query the actual attributes + * of the created window, framebuffer and context, see @ref + * glfwGetWindowAttrib, @ref glfwGetWindowSize and @ref glfwGetFramebufferSize. + * + * To create a full screen window, you need to specify the monitor the window + * will cover. If no monitor is specified, the window will be windowed mode. + * Unless you have a way for the user to choose a specific monitor, it is + * recommended that you pick the primary monitor. For more information on how + * to query connected monitors, see @ref monitor_monitors. + * + * For full screen windows, the specified size becomes the resolution of the + * window's _desired video mode_. As long as a full screen window is not + * iconified, the supported video mode most closely matching the desired video + * mode is set for the specified monitor. For more information about full + * screen windows, including the creation of so called _windowed full screen_ + * or _borderless full screen_ windows, see @ref window_windowed_full_screen. + * + * By default, newly created windows use the placement recommended by the + * window system. To create the window at a specific position, make it + * initially invisible using the [GLFW_VISIBLE](@ref window_hints_wnd) window + * hint, set its [position](@ref window_pos) and then [show](@ref window_hide) + * it. + * + * As long as at least one full screen window is not iconified, the screensaver + * is prohibited from starting. + * + * Window systems put limits on window sizes. Very large or very small window + * dimensions may be overridden by the window system on creation. Check the + * actual [size](@ref window_size) after creation. + * + * The [swap interval](@ref buffer_swap) is not set during window creation and + * the initial value may vary depending on driver settings and defaults. + * + * @param[in] width The desired width, in screen coordinates, of the window. + * This must be greater than zero. + * @param[in] height The desired height, in screen coordinates, of the window. + * This must be greater than zero. + * @param[in] title The initial, UTF-8 encoded window title. + * @param[in] monitor The monitor to use for full screen mode, or `NULL` for + * windowed mode. + * @param[in] share The window whose context to share resources with, or `NULL` + * to not share resources. + * @return The handle of the created window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE, @ref GLFW_API_UNAVAILABLE, @ref + * GLFW_VERSION_UNAVAILABLE, @ref GLFW_FORMAT_UNAVAILABLE and @ref + * GLFW_PLATFORM_ERROR. + * + * @remark @win32 Window creation will fail if the Microsoft GDI software + * OpenGL implementation is the only one available. + * + * @remark @win32 If the executable has an icon resource named `GLFW_ICON,` + * it will be set as the icon for the window. If no such icon is present, the + * `IDI_WINLOGO` icon will be used instead. + * + * @remark @win32 The context to share resources with must not be current on + * any other thread. + * + * @remark @osx The GLFW window has no icon, as it is not a document + * window, but the dock icon will be the same as the application bundle's icon. + * For more information on bundles, see the + * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) + * in the Mac Developer Library. + * + * @remark @osx The first time a window is created the menu bar is populated + * with common commands like Hide, Quit and About. The About entry opens + * a minimal about dialog with information from the application's bundle. The + * menu bar can be disabled with a + * [compile-time option](@ref compile_options_osx). + * + * @remark @osx On OS X 10.10 and later the window frame will not be rendered + * at full resolution on Retina displays unless the `NSHighResolutionCapable` + * key is enabled in the application bundle's `Info.plist`. For more + * information, see + * [High Resolution Guidelines for OS X](https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html) + * in the Mac Developer Library. The GLFW test and example programs use + * a custom `Info.plist` template for this, which can be found as + * `CMake/MacOSXBundleInfo.plist.in` in the source tree. + * + * @remark @x11 There is no mechanism for setting the window icon yet. + * + * @remark @x11 Some window managers will not respect the placement of + * initially hidden windows. + * + * @remark @x11 Due to the asynchronous nature of X11, it may take a moment for + * a window to reach its requested state. This means you may not be able to + * query the final size, position or other attributes directly after window + * creation. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_creation + * @sa glfwDestroyWindow + * + * @since Added in version 3.0. Replaces `glfwOpenWindow`. + * + * @ingroup window + */ +GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share); + +/*! @brief Destroys the specified window and its context. + * + * This function destroys the specified window and its context. On calling + * this function, no further callbacks will be called for that window. + * + * If the context of the specified window is current on the main thread, it is + * detached before being destroyed. + * + * @param[in] window The window to destroy. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @note The context of the specified window must not be current on any other + * thread when this function is called. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_creation + * @sa glfwCreateWindow + * + * @since Added in version 3.0. Replaces `glfwCloseWindow`. + * + * @ingroup window + */ +GLFWAPI void glfwDestroyWindow(GLFWwindow* window); + +/*! @brief Checks the close flag of the specified window. + * + * This function returns the value of the close flag of the specified window. + * + * @param[in] window The window to query. + * @return The value of the close flag. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @sa @ref window_close + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI int glfwWindowShouldClose(GLFWwindow* window); + +/*! @brief Sets the close flag of the specified window. + * + * This function sets the value of the close flag of the specified window. + * This can be used to override the user's attempt to close the window, or + * to signal that it should be closed. + * + * @param[in] window The window whose flag to change. + * @param[in] value The new value. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @sa @ref window_close + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value); + +/*! @brief Sets the title of the specified window. + * + * This function sets the window title, encoded as UTF-8, of the specified + * window. + * + * @param[in] window The window whose title to change. + * @param[in] title The UTF-8 encoded window title. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @remark @osx The window title will not be updated until the next time you + * process events. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_title + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title); + +/*! @brief Sets the icon for the specified window. + * + * This function sets the icon of the specified window. If passed an array of + * candidate images, those of or closest to the sizes desired by the system are + * selected. If no images are specified, the window reverts to its default + * icon. + * + * The desired image sizes varies depending on platform and system settings. + * The selected images will be rescaled as needed. Good sizes include 16x16, + * 32x32 and 48x48. + * + * @param[in] window The window whose icon to set. + * @param[in] count The number of images in the specified array, or zero to + * revert to the default window icon. + * @param[in] images The images to create the icon from. This is ignored if + * count is zero. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The specified image data is copied before this function + * returns. + * + * @remark @osx The GLFW window has no icon, as it is not a document + * window, but the dock icon will be the same as the application bundle's icon. + * For more information on bundles, see the + * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) + * in the Mac Developer Library. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_icon + * + * @since Added in version 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images); + +/*! @brief Retrieves the position of the client area of the specified window. + * + * This function retrieves the position, in screen coordinates, of the + * upper-left corner of the client area of the specified window. + * + * Any or all of the position arguments may be `NULL`. If an error occurs, all + * non-`NULL` position arguments will be set to zero. + * + * @param[in] window The window to query. + * @param[out] xpos Where to store the x-coordinate of the upper-left corner of + * the client area, or `NULL`. + * @param[out] ypos Where to store the y-coordinate of the upper-left corner of + * the client area, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_pos + * @sa glfwSetWindowPos + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos); + +/*! @brief Sets the position of the client area of the specified window. + * + * This function sets the position, in screen coordinates, of the upper-left + * corner of the client area of the specified windowed mode window. If the + * window is a full screen window, this function does nothing. + * + * __Do not use this function__ to move an already visible window unless you + * have very good reasons for doing so, as it will confuse and annoy the user. + * + * The window manager may put limits on what positions are allowed. GLFW + * cannot and should not override these limits. + * + * @param[in] window The window to query. + * @param[in] xpos The x-coordinate of the upper-left corner of the client area. + * @param[in] ypos The y-coordinate of the upper-left corner of the client area. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_pos + * @sa glfwGetWindowPos + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos); + +/*! @brief Retrieves the size of the client area of the specified window. + * + * This function retrieves the size, in screen coordinates, of the client area + * of the specified window. If you wish to retrieve the size of the + * framebuffer of the window in pixels, see @ref glfwGetFramebufferSize. + * + * Any or all of the size arguments may be `NULL`. If an error occurs, all + * non-`NULL` size arguments will be set to zero. + * + * @param[in] window The window whose size to retrieve. + * @param[out] width Where to store the width, in screen coordinates, of the + * client area, or `NULL`. + * @param[out] height Where to store the height, in screen coordinates, of the + * client area, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_size + * @sa glfwSetWindowSize + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height); + +/*! @brief Sets the size limits of the specified window. + * + * This function sets the size limits of the client area of the specified + * window. If the window is full screen, the size limits only take effect if + * once it is made windowed. If the window is not resizable, this function + * does nothing. + * + * The size limits are applied immediately to a windowed mode window and may + * cause it to be resized. + * + * @param[in] window The window to set limits for. + * @param[in] minwidth The minimum width, in screen coordinates, of the client + * area, or `GLFW_DONT_CARE`. + * @param[in] minheight The minimum height, in screen coordinates, of the + * client area, or `GLFW_DONT_CARE`. + * @param[in] maxwidth The maximum width, in screen coordinates, of the client + * area, or `GLFW_DONT_CARE`. + * @param[in] maxheight The maximum height, in screen coordinates, of the + * client area, or `GLFW_DONT_CARE`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @remark If you set size limits and an aspect ratio that conflict, the + * results are undefined. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_sizelimits + * @sa glfwSetWindowAspectRatio + * + * @since Added in version 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); + +/*! @brief Sets the aspect ratio of the specified window. + * + * This function sets the required aspect ratio of the client area of the + * specified window. If the window is full screen, the aspect ratio only takes + * effect once it is made windowed. If the window is not resizable, this + * function does nothing. + * + * The aspect ratio is specified as a numerator and a denominator and both + * values must be greater than zero. For example, the common 16:9 aspect ratio + * is specified as 16 and 9, respectively. + * + * If the numerator and denominator is set to `GLFW_DONT_CARE` then the aspect + * ratio limit is disabled. + * + * The aspect ratio is applied immediately to a windowed mode window and may + * cause it to be resized. + * + * @param[in] window The window to set limits for. + * @param[in] numer The numerator of the desired aspect ratio, or + * `GLFW_DONT_CARE`. + * @param[in] denom The denominator of the desired aspect ratio, or + * `GLFW_DONT_CARE`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. + * + * @remark If you set size limits and an aspect ratio that conflict, the + * results are undefined. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_sizelimits + * @sa glfwSetWindowSizeLimits + * + * @since Added in version 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom); + +/*! @brief Sets the size of the client area of the specified window. + * + * This function sets the size, in screen coordinates, of the client area of + * the specified window. + * + * For full screen windows, this function updates the resolution of its desired + * video mode and switches to the video mode closest to it, without affecting + * the window's context. As the context is unaffected, the bit depths of the + * framebuffer remain unchanged. + * + * If you wish to update the refresh rate of the desired video mode in addition + * to its resolution, see @ref glfwSetWindowMonitor. + * + * The window manager may put limits on what sizes are allowed. GLFW cannot + * and should not override these limits. + * + * @param[in] window The window to resize. + * @param[in] width The desired width, in screen coordinates, of the window + * client area. + * @param[in] height The desired height, in screen coordinates, of the window + * client area. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_size + * @sa glfwGetWindowSize + * @sa glfwSetWindowMonitor + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height); + +/*! @brief Retrieves the size of the framebuffer of the specified window. + * + * This function retrieves the size, in pixels, of the framebuffer of the + * specified window. If you wish to retrieve the size of the window in screen + * coordinates, see @ref glfwGetWindowSize. + * + * Any or all of the size arguments may be `NULL`. If an error occurs, all + * non-`NULL` size arguments will be set to zero. + * + * @param[in] window The window whose framebuffer to query. + * @param[out] width Where to store the width, in pixels, of the framebuffer, + * or `NULL`. + * @param[out] height Where to store the height, in pixels, of the framebuffer, + * or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_fbsize + * @sa glfwSetFramebufferSizeCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height); + +/*! @brief Retrieves the size of the frame of the window. + * + * This function retrieves the size, in screen coordinates, of each edge of the + * frame of the specified window. This size includes the title bar, if the + * window has one. The size of the frame may vary depending on the + * [window-related hints](@ref window_hints_wnd) used to create it. + * + * Because this function retrieves the size of each window frame edge and not + * the offset along a particular coordinate axis, the retrieved values will + * always be zero or positive. + * + * Any or all of the size arguments may be `NULL`. If an error occurs, all + * non-`NULL` size arguments will be set to zero. + * + * @param[in] window The window whose frame size to query. + * @param[out] left Where to store the size, in screen coordinates, of the left + * edge of the window frame, or `NULL`. + * @param[out] top Where to store the size, in screen coordinates, of the top + * edge of the window frame, or `NULL`. + * @param[out] right Where to store the size, in screen coordinates, of the + * right edge of the window frame, or `NULL`. + * @param[out] bottom Where to store the size, in screen coordinates, of the + * bottom edge of the window frame, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_size + * + * @since Added in version 3.1. + * + * @ingroup window + */ +GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom); + +/*! @brief Iconifies the specified window. + * + * This function iconifies (minimizes) the specified window if it was + * previously restored. If the window is already iconified, this function does + * nothing. + * + * If the specified window is a full screen window, the original monitor + * resolution is restored until the window is restored. + * + * @param[in] window The window to iconify. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_iconify + * @sa glfwRestoreWindow + * @sa glfwMaximizeWindow + * + * @since Added in version 2.1. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwIconifyWindow(GLFWwindow* window); + +/*! @brief Restores the specified window. + * + * This function restores the specified window if it was previously iconified + * (minimized) or maximized. If the window is already restored, this function + * does nothing. + * + * If the specified window is a full screen window, the resolution chosen for + * the window is restored on the selected monitor. + * + * @param[in] window The window to restore. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_iconify + * @sa glfwIconifyWindow + * @sa glfwMaximizeWindow + * + * @since Added in version 2.1. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwRestoreWindow(GLFWwindow* window); + +/*! @brief Maximizes the specified window. + * + * This function maximizes the specified window if it was previously not + * maximized. If the window is already maximized, this function does nothing. + * + * If the specified window is a full screen window, this function does nothing. + * + * @param[in] window The window to maximize. + * + * @par Thread Safety + * This function may only be called from the main thread. + * + * @sa @ref window_iconify + * @sa glfwIconifyWindow + * @sa glfwRestoreWindow + * + * @since Added in GLFW 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwMaximizeWindow(GLFWwindow* window); + +/*! @brief Makes the specified window visible. + * + * This function makes the specified window visible if it was previously + * hidden. If the window is already visible or is in full screen mode, this + * function does nothing. + * + * @param[in] window The window to make visible. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_hide + * @sa glfwHideWindow + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwShowWindow(GLFWwindow* window); + +/*! @brief Hides the specified window. + * + * This function hides the specified window if it was previously visible. If + * the window is already hidden or is in full screen mode, this function does + * nothing. + * + * @param[in] window The window to hide. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_hide + * @sa glfwShowWindow + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwHideWindow(GLFWwindow* window); + +/*! @brief Brings the specified window to front and sets input focus. + * + * This function brings the specified window to front and sets input focus. + * The window should already be visible and not iconified. + * + * By default, both windowed and full screen mode windows are focused when + * initially created. Set the [GLFW_FOCUSED](@ref window_hints_wnd) to disable + * this behavior. + * + * __Do not use this function__ to steal focus from other applications unless + * you are certain that is what the user wants. Focus stealing can be + * extremely disruptive. + * + * @param[in] window The window to give input focus. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_focus + * + * @since Added in version 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwFocusWindow(GLFWwindow* window); + +/*! @brief Returns the monitor that the window uses for full screen mode. + * + * This function returns the handle of the monitor that the specified window is + * in full screen on. + * + * @param[in] window The window to query. + * @return The monitor, or `NULL` if the window is in windowed mode or an error + * occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_monitor + * @sa glfwSetWindowMonitor + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window); + +/*! @brief Sets the mode, monitor, video mode and placement of a window. + * + * This function sets the monitor that the window uses for full screen mode or, + * if the monitor is `NULL`, makes it windowed mode. + * + * When setting a monitor, this function updates the width, height and refresh + * rate of the desired video mode and switches to the video mode closest to it. + * The window position is ignored when setting a monitor. + * + * When the monitor is `NULL`, the position, width and height are used to + * place the window client area. The refresh rate is ignored when no monitor + * is specified. + * + * If you only wish to update the resolution of a full screen window or the + * size of a windowed mode window, see @ref glfwSetWindowSize. + * + * When a window transitions from full screen to windowed mode, this function + * restores any previous window settings such as whether it is decorated, + * floating, resizable, has size or aspect ratio limits, etc.. + * + * @param[in] window The window whose monitor, size or video mode to set. + * @param[in] monitor The desired monitor, or `NULL` to set windowed mode. + * @param[in] xpos The desired x-coordinate of the upper-left corner of the + * client area. + * @param[in] ypos The desired y-coordinate of the upper-left corner of the + * client area. + * @param[in] width The desired with, in screen coordinates, of the client area + * or video mode. + * @param[in] height The desired height, in screen coordinates, of the client + * area or video mode. + * @param[in] refreshRate The desired refresh rate, in Hz, of the video mode. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_monitor + * @sa @ref window_full_screen + * @sa glfwGetWindowMonitor + * @sa glfwSetWindowSize + * + * @since Added in version 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); + +/*! @brief Returns an attribute of the specified window. + * + * This function returns the value of an attribute of the specified window or + * its OpenGL or OpenGL ES context. + * + * @param[in] window The window to query. + * @param[in] attrib The [window attribute](@ref window_attribs) whose value to + * return. + * @return The value of the attribute, or zero if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @remark Framebuffer related hints are not window attributes. See @ref + * window_attribs_fb for more information. + * + * @remark Zero is a valid value for many window and context related + * attributes so you cannot use a return value of zero as an indication of + * errors. However, this function should not fail as long as it is passed + * valid arguments and the library has been [initialized](@ref intro_init). + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_attribs + * + * @since Added in version 3.0. Replaces `glfwGetWindowParam` and + * `glfwGetGLVersion`. + * + * @ingroup window + */ +GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib); + +/*! @brief Sets the user pointer of the specified window. + * + * This function sets the user-defined pointer of the specified window. The + * current value is retained until the window is destroyed. The initial value + * is `NULL`. + * + * @param[in] window The window whose pointer to set. + * @param[in] pointer The new value. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @sa @ref window_userptr + * @sa glfwGetWindowUserPointer + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer); + +/*! @brief Returns the user pointer of the specified window. + * + * This function returns the current value of the user-defined pointer of the + * specified window. The initial value is `NULL`. + * + * @param[in] window The window whose pointer to return. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @sa @ref window_userptr + * @sa glfwSetWindowUserPointer + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window); + +/*! @brief Sets the position callback for the specified window. + * + * This function sets the position callback of the specified window, which is + * called when the window is moved. The callback is provided with the screen + * position of the upper-left corner of the client area of the window. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_pos + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun); + +/*! @brief Sets the size callback for the specified window. + * + * This function sets the size callback of the specified window, which is + * called when the window is resized. The callback is provided with the size, + * in screen coordinates, of the client area of the window. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_size + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter and return value. + * + * @ingroup window + */ +GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun); + +/*! @brief Sets the close callback for the specified window. + * + * This function sets the close callback of the specified window, which is + * called when the user attempts to close the window, for example by clicking + * the close widget in the title bar. + * + * The close flag is set before this callback is called, but you can modify it + * at any time with @ref glfwSetWindowShouldClose. + * + * The close callback is not triggered by @ref glfwDestroyWindow. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @remark @osx Selecting Quit from the application menu will trigger the close + * callback for all windows. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_close + * + * @since Added in version 2.5. + * @glfw3 Added window handle parameter and return value. + * + * @ingroup window + */ +GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun); + +/*! @brief Sets the refresh callback for the specified window. + * + * This function sets the refresh callback of the specified window, which is + * called when the client area of the window needs to be redrawn, for example + * if the window has been exposed after having been covered by another window. + * + * On compositing window systems such as Aero, Compiz or Aqua, where the window + * contents are saved off-screen, this callback may be called only very + * infrequently or never at all. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_refresh + * + * @since Added in version 2.5. + * @glfw3 Added window handle parameter and return value. + * + * @ingroup window + */ +GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun); + +/*! @brief Sets the focus callback for the specified window. + * + * This function sets the focus callback of the specified window, which is + * called when the window gains or loses input focus. + * + * After the focus callback is called for a window that lost input focus, + * synthetic key and mouse button release events will be generated for all such + * that had been pressed. For more information, see @ref glfwSetKeyCallback + * and @ref glfwSetMouseButtonCallback. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_focus + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun); + +/*! @brief Sets the iconify callback for the specified window. + * + * This function sets the iconification callback of the specified window, which + * is called when the window is iconified or restored. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_iconify + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun); + +/*! @brief Sets the framebuffer resize callback for the specified window. + * + * This function sets the framebuffer resize callback of the specified window, + * which is called when the framebuffer of the specified window is resized. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_fbsize + * + * @since Added in version 3.0. + * + * @ingroup window + */ +GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun cbfun); + +/*! @brief Processes all pending events. + * + * This function processes only those events that are already in the event + * queue and then returns immediately. Processing events will cause the window + * and input callbacks associated with those events to be called. + * + * On some platforms, a window move, resize or menu operation will cause event + * processing to block. This is due to how event processing is designed on + * those platforms. You can use the + * [window refresh callback](@ref window_refresh) to redraw the contents of + * your window when necessary during such operations. + * + * On some platforms, certain events are sent directly to the application + * without going through the event queue, causing callbacks to be called + * outside of a call to one of the event processing functions. + * + * Event processing is not required for joystick input to work. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref events + * @sa glfwWaitEvents + * @sa glfwWaitEventsTimeout + * + * @since Added in version 1.0. + * + * @ingroup window + */ +GLFWAPI void glfwPollEvents(void); + +/*! @brief Waits until events are queued and processes them. + * + * This function puts the calling thread to sleep until at least one event is + * available in the event queue. Once one or more events are available, + * it behaves exactly like @ref glfwPollEvents, i.e. the events in the queue + * are processed and the function then returns immediately. Processing events + * will cause the window and input callbacks associated with those events to be + * called. + * + * Since not all events are associated with callbacks, this function may return + * without a callback having been called even if you are monitoring all + * callbacks. + * + * On some platforms, a window move, resize or menu operation will cause event + * processing to block. This is due to how event processing is designed on + * those platforms. You can use the + * [window refresh callback](@ref window_refresh) to redraw the contents of + * your window when necessary during such operations. + * + * On some platforms, certain callbacks may be called outside of a call to one + * of the event processing functions. + * + * If no windows exist, this function returns immediately. For synchronization + * of threads in applications that do not create windows, use your threading + * library of choice. + * + * Event processing is not required for joystick input to work. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref events + * @sa glfwPollEvents + * @sa glfwWaitEventsTimeout + * + * @since Added in version 2.5. + * + * @ingroup window + */ +GLFWAPI void glfwWaitEvents(void); + +/*! @brief Waits with timeout until events are queued and processes them. + * + * This function puts the calling thread to sleep until at least one event is + * available in the event queue, or until the specified timeout is reached. If + * one or more events are available, it behaves exactly like @ref + * glfwPollEvents, i.e. the events in the queue are processed and the function + * then returns immediately. Processing events will cause the window and input + * callbacks associated with those events to be called. + * + * The timeout value must be a positive finite number. + * + * Since not all events are associated with callbacks, this function may return + * without a callback having been called even if you are monitoring all + * callbacks. + * + * On some platforms, a window move, resize or menu operation will cause event + * processing to block. This is due to how event processing is designed on + * those platforms. You can use the + * [window refresh callback](@ref window_refresh) to redraw the contents of + * your window when necessary during such operations. + * + * On some platforms, certain callbacks may be called outside of a call to one + * of the event processing functions. + * + * If no windows exist, this function returns immediately. For synchronization + * of threads in applications that do not create windows, use your threading + * library of choice. + * + * Event processing is not required for joystick input to work. + * + * @param[in] timeout The maximum amount of time, in seconds, to wait. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref events + * @sa glfwPollEvents + * @sa glfwWaitEvents + * + * @since Added in version 3.2. + * + * @ingroup window + */ +GLFWAPI void glfwWaitEventsTimeout(double timeout); + +/*! @brief Posts an empty event to the event queue. + * + * This function posts an empty event from the current thread to the event + * queue, causing @ref glfwWaitEvents to return. + * + * If no windows exist, this function returns immediately. For synchronization + * of threads in applications that do not create windows, use your threading + * library of choice. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref events + * @sa glfwWaitEvents + * + * @since Added in version 3.1. + * + * @ingroup window + */ +GLFWAPI void glfwPostEmptyEvent(void); + +/*! @brief Returns the value of an input option for the specified window. + * + * This function returns the value of an input option for the specified window. + * The mode must be one of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or + * `GLFW_STICKY_MOUSE_BUTTONS`. + * + * @param[in] window The window to query. + * @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or + * `GLFW_STICKY_MOUSE_BUTTONS`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa glfwSetInputMode + * + * @since Added in version 3.0. + * + * @ingroup input + */ +GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); + +/*! @brief Sets an input option for the specified window. + * + * This function sets an input mode option for the specified window. The mode + * must be one of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or + * `GLFW_STICKY_MOUSE_BUTTONS`. + * + * If the mode is `GLFW_CURSOR`, the value must be one of the following cursor + * modes: + * - `GLFW_CURSOR_NORMAL` makes the cursor visible and behaving normally. + * - `GLFW_CURSOR_HIDDEN` makes the cursor invisible when it is over the client + * area of the window but does not restrict the cursor from leaving. + * - `GLFW_CURSOR_DISABLED` hides and grabs the cursor, providing virtual + * and unlimited cursor movement. This is useful for implementing for + * example 3D camera controls. + * + * If the mode is `GLFW_STICKY_KEYS`, the value must be either `GLFW_TRUE` to + * enable sticky keys, or `GLFW_FALSE` to disable it. If sticky keys are + * enabled, a key press will ensure that @ref glfwGetKey returns `GLFW_PRESS` + * the next time it is called even if the key had been released before the + * call. This is useful when you are only interested in whether keys have been + * pressed but not when or in which order. + * + * If the mode is `GLFW_STICKY_MOUSE_BUTTONS`, the value must be either + * `GLFW_TRUE` to enable sticky mouse buttons, or `GLFW_FALSE` to disable it. + * If sticky mouse buttons are enabled, a mouse button press will ensure that + * @ref glfwGetMouseButton returns `GLFW_PRESS` the next time it is called even + * if the mouse button had been released before the call. This is useful when + * you are only interested in whether mouse buttons have been pressed but not + * when or in which order. + * + * @param[in] window The window whose input mode to set. + * @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or + * `GLFW_STICKY_MOUSE_BUTTONS`. + * @param[in] value The new value of the specified input mode. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa glfwGetInputMode + * + * @since Added in version 3.0. Replaces `glfwEnable` and `glfwDisable`. + * + * @ingroup input + */ +GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); + +/*! @brief Returns the localized name of the specified printable key. + * + * This function returns the localized name of the specified printable key. + * This is intended for displaying key bindings to the user. + * + * If the key is `GLFW_KEY_UNKNOWN`, the scancode is used instead, otherwise + * the scancode is ignored. If a non-printable key or (if the key is + * `GLFW_KEY_UNKNOWN`) a scancode that maps to a non-printable key is + * specified, this function returns `NULL`. + * + * This behavior allows you to pass in the arguments passed to the + * [key callback](@ref input_key) without modification. + * + * The printable keys are: + * - `GLFW_KEY_APOSTROPHE` + * - `GLFW_KEY_COMMA` + * - `GLFW_KEY_MINUS` + * - `GLFW_KEY_PERIOD` + * - `GLFW_KEY_SLASH` + * - `GLFW_KEY_SEMICOLON` + * - `GLFW_KEY_EQUAL` + * - `GLFW_KEY_LEFT_BRACKET` + * - `GLFW_KEY_RIGHT_BRACKET` + * - `GLFW_KEY_BACKSLASH` + * - `GLFW_KEY_WORLD_1` + * - `GLFW_KEY_WORLD_2` + * - `GLFW_KEY_0` to `GLFW_KEY_9` + * - `GLFW_KEY_A` to `GLFW_KEY_Z` + * - `GLFW_KEY_KP_0` to `GLFW_KEY_KP_9` + * - `GLFW_KEY_KP_DECIMAL` + * - `GLFW_KEY_KP_DIVIDE` + * - `GLFW_KEY_KP_MULTIPLY` + * - `GLFW_KEY_KP_SUBTRACT` + * - `GLFW_KEY_KP_ADD` + * - `GLFW_KEY_KP_EQUAL` + * + * @param[in] key The key to query, or `GLFW_KEY_UNKNOWN`. + * @param[in] scancode The scancode of the key to query. + * @return The localized name of the key, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the next call to @ref + * glfwGetKeyName, or until the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_key_name + * + * @since Added in version 3.2. + * + * @ingroup input + */ +GLFWAPI const char* glfwGetKeyName(int key, int scancode); + +/*! @brief Returns the last reported state of a keyboard key for the specified + * window. + * + * This function returns the last state reported for the specified key to the + * specified window. The returned state is one of `GLFW_PRESS` or + * `GLFW_RELEASE`. The higher-level action `GLFW_REPEAT` is only reported to + * the key callback. + * + * If the `GLFW_STICKY_KEYS` input mode is enabled, this function returns + * `GLFW_PRESS` the first time you call it for a key that was pressed, even if + * that key has already been released. + * + * The key functions deal with physical keys, with [key tokens](@ref keys) + * named after their use on the standard US keyboard layout. If you want to + * input text, use the Unicode character callback instead. + * + * The [modifier key bit masks](@ref mods) are not key tokens and cannot be + * used with this function. + * + * __Do not use this function__ to implement [text input](@ref input_char). + * + * @param[in] window The desired window. + * @param[in] key The desired [keyboard key](@ref keys). `GLFW_KEY_UNKNOWN` is + * not a valid key for this function. + * @return One of `GLFW_PRESS` or `GLFW_RELEASE`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_key + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup input + */ +GLFWAPI int glfwGetKey(GLFWwindow* window, int key); + +/*! @brief Returns the last reported state of a mouse button for the specified + * window. + * + * This function returns the last state reported for the specified mouse button + * to the specified window. The returned state is one of `GLFW_PRESS` or + * `GLFW_RELEASE`. + * + * If the `GLFW_STICKY_MOUSE_BUTTONS` input mode is enabled, this function + * `GLFW_PRESS` the first time you call it for a mouse button that was pressed, + * even if that mouse button has already been released. + * + * @param[in] window The desired window. + * @param[in] button The desired [mouse button](@ref buttons). + * @return One of `GLFW_PRESS` or `GLFW_RELEASE`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_mouse_button + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup input + */ +GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button); + +/*! @brief Retrieves the position of the cursor relative to the client area of + * the window. + * + * This function returns the position of the cursor, in screen coordinates, + * relative to the upper-left corner of the client area of the specified + * window. + * + * If the cursor is disabled (with `GLFW_CURSOR_DISABLED`) then the cursor + * position is unbounded and limited only by the minimum and maximum values of + * a `double`. + * + * The coordinate can be converted to their integer equivalents with the + * `floor` function. Casting directly to an integer type works for positive + * coordinates, but fails for negative ones. + * + * Any or all of the position arguments may be `NULL`. If an error occurs, all + * non-`NULL` position arguments will be set to zero. + * + * @param[in] window The desired window. + * @param[out] xpos Where to store the cursor x-coordinate, relative to the + * left edge of the client area, or `NULL`. + * @param[out] ypos Where to store the cursor y-coordinate, relative to the to + * top edge of the client area, or `NULL`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_pos + * @sa glfwSetCursorPos + * + * @since Added in version 3.0. Replaces `glfwGetMousePos`. + * + * @ingroup input + */ +GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos); + +/*! @brief Sets the position of the cursor, relative to the client area of the + * window. + * + * This function sets the position, in screen coordinates, of the cursor + * relative to the upper-left corner of the client area of the specified + * window. The window must have input focus. If the window does not have + * input focus when this function is called, it fails silently. + * + * __Do not use this function__ to implement things like camera controls. GLFW + * already provides the `GLFW_CURSOR_DISABLED` cursor mode that hides the + * cursor, transparently re-centers it and provides unconstrained cursor + * motion. See @ref glfwSetInputMode for more information. + * + * If the cursor mode is `GLFW_CURSOR_DISABLED` then the cursor position is + * unconstrained and limited only by the minimum and maximum values of + * a `double`. + * + * @param[in] window The desired window. + * @param[in] xpos The desired x-coordinate, relative to the left edge of the + * client area. + * @param[in] ypos The desired y-coordinate, relative to the top edge of the + * client area. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @remark @x11 Due to the asynchronous nature of X11, it may take a moment for + * the window focus event to arrive. This means you may not be able to set the + * cursor position directly after window creation. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_pos + * @sa glfwGetCursorPos + * + * @since Added in version 3.0. Replaces `glfwSetMousePos`. + * + * @ingroup input + */ +GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos); + +/*! @brief Creates a custom cursor. + * + * Creates a new custom cursor image that can be set for a window with @ref + * glfwSetCursor. The cursor can be destroyed with @ref glfwDestroyCursor. + * Any remaining cursors are destroyed by @ref glfwTerminate. + * + * The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight + * bits per channel. They are arranged canonically as packed sequential rows, + * starting from the top-left corner. + * + * The cursor hotspot is specified in pixels, relative to the upper-left corner + * of the cursor image. Like all other coordinate systems in GLFW, the X-axis + * points to the right and the Y-axis points down. + * + * @param[in] image The desired cursor image. + * @param[in] xhot The desired x-coordinate, in pixels, of the cursor hotspot. + * @param[in] yhot The desired y-coordinate, in pixels, of the cursor hotspot. + * @return The handle of the created cursor, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The specified image data is copied before this function + * returns. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_object + * @sa glfwDestroyCursor + * @sa glfwCreateStandardCursor + * + * @since Added in version 3.1. + * + * @ingroup input + */ +GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot); + +/*! @brief Creates a cursor with a standard shape. + * + * Returns a cursor with a [standard shape](@ref shapes), that can be set for + * a window with @ref glfwSetCursor. + * + * @param[in] shape One of the [standard shapes](@ref shapes). + * @return A new cursor ready to use or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_object + * @sa glfwCreateCursor + * + * @since Added in version 3.1. + * + * @ingroup input + */ +GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape); + +/*! @brief Destroys a cursor. + * + * This function destroys a cursor previously created with @ref + * glfwCreateCursor. Any remaining cursors will be destroyed by @ref + * glfwTerminate. + * + * @param[in] cursor The cursor object to destroy. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @reentrancy This function must not be called from a callback. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_object + * @sa glfwCreateCursor + * + * @since Added in version 3.1. + * + * @ingroup input + */ +GLFWAPI void glfwDestroyCursor(GLFWcursor* cursor); + +/*! @brief Sets the cursor for the window. + * + * This function sets the cursor image to be used when the cursor is over the + * client area of the specified window. The set cursor will only be visible + * when the [cursor mode](@ref cursor_mode) of the window is + * `GLFW_CURSOR_NORMAL`. + * + * On some platforms, the set cursor may not be visible unless the window also + * has input focus. + * + * @param[in] window The window to set the cursor for. + * @param[in] cursor The cursor to set, or `NULL` to switch back to the default + * arrow cursor. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_object + * + * @since Added in version 3.1. + * + * @ingroup input + */ +GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor); + +/*! @brief Sets the key callback. + * + * This function sets the key callback of the specified window, which is called + * when a key is pressed, repeated or released. + * + * The key functions deal with physical keys, with layout independent + * [key tokens](@ref keys) named after their values in the standard US keyboard + * layout. If you want to input text, use the + * [character callback](@ref glfwSetCharCallback) instead. + * + * When a window loses input focus, it will generate synthetic key release + * events for all pressed keys. You can tell these events from user-generated + * events by the fact that the synthetic ones are generated after the focus + * loss event has been processed, i.e. after the + * [window focus callback](@ref glfwSetWindowFocusCallback) has been called. + * + * The scancode of a key is specific to that platform or sometimes even to that + * machine. Scancodes are intended to allow users to bind keys that don't have + * a GLFW key token. Such keys have `key` set to `GLFW_KEY_UNKNOWN`, their + * state is not saved and so it cannot be queried with @ref glfwGetKey. + * + * Sometimes GLFW needs to generate synthetic key events, in which case the + * scancode may be zero. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new key callback, or `NULL` to remove the currently + * set callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_key + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter and return value. + * + * @ingroup input + */ +GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun); + +/*! @brief Sets the Unicode character callback. + * + * This function sets the character callback of the specified window, which is + * called when a Unicode character is input. + * + * The character callback is intended for Unicode text input. As it deals with + * characters, it is keyboard layout dependent, whereas the + * [key callback](@ref glfwSetKeyCallback) is not. Characters do not map 1:1 + * to physical keys, as a key may produce zero, one or more characters. If you + * want to know whether a specific physical key was pressed or released, see + * the key callback instead. + * + * The character callback behaves as system text input normally does and will + * not be called if modifier keys are held down that would prevent normal text + * input on that platform, for example a Super (Command) key on OS X or Alt key + * on Windows. There is a + * [character with modifiers callback](@ref glfwSetCharModsCallback) that + * receives these events. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_char + * + * @since Added in version 2.4. + * @glfw3 Added window handle parameter and return value. + * + * @ingroup input + */ +GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun); + +/*! @brief Sets the Unicode character with modifiers callback. + * + * This function sets the character with modifiers callback of the specified + * window, which is called when a Unicode character is input regardless of what + * modifier keys are used. + * + * The character with modifiers callback is intended for implementing custom + * Unicode character input. For regular Unicode text input, see the + * [character callback](@ref glfwSetCharCallback). Like the character + * callback, the character with modifiers callback deals with characters and is + * keyboard layout dependent. Characters do not map 1:1 to physical keys, as + * a key may produce zero, one or more characters. If you want to know whether + * a specific physical key was pressed or released, see the + * [key callback](@ref glfwSetKeyCallback) instead. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or an + * error occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_char + * + * @since Added in version 3.1. + * + * @ingroup input + */ +GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun cbfun); + +/*! @brief Sets the mouse button callback. + * + * This function sets the mouse button callback of the specified window, which + * is called when a mouse button is pressed or released. + * + * When a window loses input focus, it will generate synthetic mouse button + * release events for all pressed mouse buttons. You can tell these events + * from user-generated events by the fact that the synthetic ones are generated + * after the focus loss event has been processed, i.e. after the + * [window focus callback](@ref glfwSetWindowFocusCallback) has been called. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref input_mouse_button + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter and return value. + * + * @ingroup input + */ +GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun); + +/*! @brief Sets the cursor position callback. + * + * This function sets the cursor position callback of the specified window, + * which is called when the cursor is moved. The callback is provided with the + * position, in screen coordinates, relative to the upper-left corner of the + * client area of the window. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_pos + * + * @since Added in version 3.0. Replaces `glfwSetMousePosCallback`. + * + * @ingroup input + */ +GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun); + +/*! @brief Sets the cursor enter/exit callback. + * + * This function sets the cursor boundary crossing callback of the specified + * window, which is called when the cursor enters or leaves the client area of + * the window. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref cursor_enter + * + * @since Added in version 3.0. + * + * @ingroup input + */ +GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun cbfun); + +/*! @brief Sets the scroll callback. + * + * This function sets the scroll callback of the specified window, which is + * called when a scrolling device is used, such as a mouse wheel or scrolling + * area of a touchpad. + * + * The scroll callback receives all scrolling input, like that from a mouse + * wheel or a touchpad scrolling area. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently + * set callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref scrolling + * + * @since Added in version 3.0. Replaces `glfwSetMouseWheelCallback`. + * + * @ingroup input + */ +GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun); + +/*! @brief Sets the file drop callback. + * + * This function sets the file drop callback of the specified window, which is + * called when one or more dragged files are dropped on the window. + * + * Because the path array and its strings may have been generated specifically + * for that event, they are not guaranteed to be valid after the callback has + * returned. If you wish to use them after the callback returns, you need to + * make a deep copy. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new file drop callback, or `NULL` to remove the + * currently set callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref path_drop + * + * @since Added in version 3.1. + * + * @ingroup input + */ +GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); + +/*! @brief Returns whether the specified joystick is present. + * + * This function returns whether the specified joystick is present. + * + * @param[in] joy The [joystick](@ref joysticks) to query. + * @return `GLFW_TRUE` if the joystick is present, or `GLFW_FALSE` otherwise. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref joystick + * + * @since Added in version 3.0. Replaces `glfwGetJoystickParam`. + * + * @ingroup input + */ +GLFWAPI int glfwJoystickPresent(int joy); + +/*! @brief Returns the values of all axes of the specified joystick. + * + * This function returns the values of all axes of the specified joystick. + * Each element in the array is a value between -1.0 and 1.0. + * + * Querying a joystick slot with no device present is not an error, but will + * cause this function to return `NULL`. Call @ref glfwJoystickPresent to + * check device presence. + * + * @param[in] joy The [joystick](@ref joysticks) to query. + * @param[out] count Where to store the number of axis values in the returned + * array. This is set to zero if an error occurred. + * @return An array of axis values, or `NULL` if the joystick is not present. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified joystick is + * disconnected, this function is called again for that joystick or the library + * is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref joystick_axis + * + * @since Added in version 3.0. Replaces `glfwGetJoystickPos`. + * + * @ingroup input + */ +GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count); + +/*! @brief Returns the state of all buttons of the specified joystick. + * + * This function returns the state of all buttons of the specified joystick. + * Each element in the array is either `GLFW_PRESS` or `GLFW_RELEASE`. + * + * Querying a joystick slot with no device present is not an error, but will + * cause this function to return `NULL`. Call @ref glfwJoystickPresent to + * check device presence. + * + * @param[in] joy The [joystick](@ref joysticks) to query. + * @param[out] count Where to store the number of button states in the returned + * array. This is set to zero if an error occurred. + * @return An array of button states, or `NULL` if the joystick is not present. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified joystick is + * disconnected, this function is called again for that joystick or the library + * is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref joystick_button + * + * @since Added in version 2.2. + * @glfw3 Changed to return a dynamic array. + * + * @ingroup input + */ +GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count); + +/*! @brief Returns the name of the specified joystick. + * + * This function returns the name, encoded as UTF-8, of the specified joystick. + * The returned string is allocated and freed by GLFW. You should not free it + * yourself. + * + * Querying a joystick slot with no device present is not an error, but will + * cause this function to return `NULL`. Call @ref glfwJoystickPresent to + * check device presence. + * + * @param[in] joy The [joystick](@ref joysticks) to query. + * @return The UTF-8 encoded name of the joystick, or `NULL` if the joystick + * is not present. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified joystick is + * disconnected, this function is called again for that joystick or the library + * is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref joystick_name + * + * @since Added in version 3.0. + * + * @ingroup input + */ +GLFWAPI const char* glfwGetJoystickName(int joy); + +/*! @brief Sets the joystick configuration callback. + * + * This function sets the joystick configuration callback, or removes the + * currently set callback. This is called when a joystick is connected to or + * disconnected from the system. + * + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref joystick_event + * + * @since Added in version 3.2. + * + * @ingroup input + */ +GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun); + +/*! @brief Sets the clipboard to the specified string. + * + * This function sets the system clipboard to the specified, UTF-8 encoded + * string. + * + * @param[in] window The window that will own the clipboard contents. + * @param[in] string A UTF-8 encoded string. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The specified string is copied before this function + * returns. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref clipboard + * @sa glfwGetClipboardString + * + * @since Added in version 3.0. + * + * @ingroup input + */ +GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); + +/*! @brief Returns the contents of the clipboard as a string. + * + * This function returns the contents of the system clipboard, if it contains + * or is convertible to a UTF-8 encoded string. If the clipboard is empty or + * if its contents cannot be converted, `NULL` is returned and a @ref + * GLFW_FORMAT_UNAVAILABLE error is generated. + * + * @param[in] window The window that will request the clipboard contents. + * @return The contents of the clipboard as a UTF-8 encoded string, or `NULL` + * if an [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the next call to @ref + * glfwGetClipboardString or @ref glfwSetClipboardString, or until the library + * is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref clipboard + * @sa glfwSetClipboardString + * + * @since Added in version 3.0. + * + * @ingroup input + */ +GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window); + +/*! @brief Returns the value of the GLFW timer. + * + * This function returns the value of the GLFW timer. Unless the timer has + * been set using @ref glfwSetTime, the timer measures time elapsed since GLFW + * was initialized. + * + * The resolution of the timer is system dependent, but is usually on the order + * of a few micro- or nanoseconds. It uses the highest-resolution monotonic + * time source on each supported platform. + * + * @return The current value, in seconds, or zero if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. Reading of the + * internal timer offset is not atomic. + * + * @sa @ref time + * + * @since Added in version 1.0. + * + * @ingroup input + */ +GLFWAPI double glfwGetTime(void); + +/*! @brief Sets the GLFW timer. + * + * This function sets the value of the GLFW timer. It then continues to count + * up from that value. The value must be a positive finite number less than + * or equal to 18446744073.0, which is approximately 584.5 years. + * + * @param[in] time The new value, in seconds. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_VALUE. + * + * @remark The upper limit of the timer is calculated as + * floor((264 - 1) / 109) and is due to implementations + * storing nanoseconds in 64 bits. The limit may be increased in the future. + * + * @thread_safety This function may be called from any thread. Writing of the + * internal timer offset is not atomic. + * + * @sa @ref time + * + * @since Added in version 2.2. + * + * @ingroup input + */ +GLFWAPI void glfwSetTime(double time); + +/*! @brief Returns the current value of the raw timer. + * + * This function returns the current value of the raw timer, measured in + * 1 / frequency seconds. To get the frequency, call @ref + * glfwGetTimerFrequency. + * + * @return The value of the timer, or zero if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref time + * @sa glfwGetTimerFrequency + * + * @since Added in version 3.2. + * + * @ingroup input + */ +GLFWAPI uint64_t glfwGetTimerValue(void); + +/*! @brief Returns the frequency, in Hz, of the raw timer. + * + * This function returns the frequency, in Hz, of the raw timer. + * + * @return The frequency of the timer, in Hz, or zero if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref time + * @sa glfwGetTimerValue + * + * @since Added in version 3.2. + * + * @ingroup input + */ +GLFWAPI uint64_t glfwGetTimerFrequency(void); + +/*! @brief Makes the context of the specified window current for the calling + * thread. + * + * This function makes the OpenGL or OpenGL ES context of the specified window + * current on the calling thread. A context can only be made current on + * a single thread at a time and each thread can have only a single current + * context at a time. + * + * By default, making a context non-current implicitly forces a pipeline flush. + * On machines that support `GL_KHR_context_flush_control`, you can control + * whether a context performs this flush by setting the + * [GLFW_CONTEXT_RELEASE_BEHAVIOR](@ref window_hints_ctx) window hint. + * + * The specified window must have an OpenGL or OpenGL ES context. Specifying + * a window without a context will generate a @ref GLFW_NO_WINDOW_CONTEXT + * error. + * + * @param[in] window The window whose context to make current, or `NULL` to + * detach the current context. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref context_current + * @sa glfwGetCurrentContext + * + * @since Added in version 3.0. + * + * @ingroup context + */ +GLFWAPI void glfwMakeContextCurrent(GLFWwindow* window); + +/*! @brief Returns the window whose context is current on the calling thread. + * + * This function returns the window whose OpenGL or OpenGL ES context is + * current on the calling thread. + * + * @return The window whose context is current, or `NULL` if no window's + * context is current. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref context_current + * @sa glfwMakeContextCurrent + * + * @since Added in version 3.0. + * + * @ingroup context + */ +GLFWAPI GLFWwindow* glfwGetCurrentContext(void); + +/*! @brief Swaps the front and back buffers of the specified window. + * + * This function swaps the front and back buffers of the specified window when + * rendering with OpenGL or OpenGL ES. If the swap interval is greater than + * zero, the GPU driver waits the specified number of screen updates before + * swapping the buffers. + * + * The specified window must have an OpenGL or OpenGL ES context. Specifying + * a window without a context will generate a @ref GLFW_NO_WINDOW_CONTEXT + * error. + * + * This function does not apply to Vulkan. If you are rendering with Vulkan, + * see `vkQueuePresentKHR` instead. + * + * @param[in] window The window whose buffers to swap. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR. + * + * @remark __EGL:__ The context of the specified window must be current on the + * calling thread. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref buffer_swap + * @sa glfwSwapInterval + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +GLFWAPI void glfwSwapBuffers(GLFWwindow* window); + +/*! @brief Sets the swap interval for the current context. + * + * This function sets the swap interval for the current OpenGL or OpenGL ES + * context, i.e. the number of screen updates to wait from the time @ref + * glfwSwapBuffers was called before swapping the buffers and returning. This + * is sometimes called _vertical synchronization_, _vertical retrace + * synchronization_ or just _vsync_. + * + * Contexts that support either of the `WGL_EXT_swap_control_tear` and + * `GLX_EXT_swap_control_tear` extensions also accept negative swap intervals, + * which allow the driver to swap even if a frame arrives a little bit late. + * You can check for the presence of these extensions using @ref + * glfwExtensionSupported. For more information about swap tearing, see the + * extension specifications. + * + * A context must be current on the calling thread. Calling this function + * without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error. + * + * This function does not apply to Vulkan. If you are rendering with Vulkan, + * see the present mode of your swapchain instead. + * + * @param[in] interval The minimum number of screen updates to wait for + * until the buffers are swapped by @ref glfwSwapBuffers. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_NO_CURRENT_CONTEXT and @ref GLFW_PLATFORM_ERROR. + * + * @remark This function is not called during context creation, leaving the + * swap interval set to whatever is the default on that platform. This is done + * because some swap interval extensions used by GLFW do not allow the swap + * interval to be reset to zero once it has been set to a non-zero value. + * + * @remark Some GPU drivers do not honor the requested swap interval, either + * because of a user setting that overrides the application's request or due to + * bugs in the driver. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref buffer_swap + * @sa glfwSwapBuffers + * + * @since Added in version 1.0. + * + * @ingroup context + */ +GLFWAPI void glfwSwapInterval(int interval); + +/*! @brief Returns whether the specified extension is available. + * + * This function returns whether the specified + * [API extension](@ref context_glext) is supported by the current OpenGL or + * OpenGL ES context. It searches both for client API extension and context + * creation API extensions. + * + * A context must be current on the calling thread. Calling this function + * without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error. + * + * As this functions retrieves and searches one or more extension strings each + * call, it is recommended that you cache its results if it is going to be used + * frequently. The extension strings will not change during the lifetime of + * a context, so there is no danger in doing this. + * + * This function does not apply to Vulkan. If you are using Vulkan, see @ref + * glfwGetRequiredInstanceExtensions, `vkEnumerateInstanceExtensionProperties` + * and `vkEnumerateDeviceExtensionProperties` instead. + * + * @param[in] extension The ASCII encoded name of the extension. + * @return `GLFW_TRUE` if the extension is available, or `GLFW_FALSE` + * otherwise. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_NO_CURRENT_CONTEXT, @ref GLFW_INVALID_VALUE and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref context_glext + * @sa glfwGetProcAddress + * + * @since Added in version 1.0. + * + * @ingroup context + */ +GLFWAPI int glfwExtensionSupported(const char* extension); + +/*! @brief Returns the address of the specified function for the current + * context. + * + * This function returns the address of the specified OpenGL or OpenGL ES + * [core or extension function](@ref context_glext), if it is supported + * by the current context. + * + * A context must be current on the calling thread. Calling this function + * without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error. + * + * This function does not apply to Vulkan. If you are rendering with Vulkan, + * see @ref glfwGetInstanceProcAddress, `vkGetInstanceProcAddr` and + * `vkGetDeviceProcAddr` instead. + * + * @param[in] procname The ASCII encoded name of the function. + * @return The address of the function, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_NO_CURRENT_CONTEXT and @ref GLFW_PLATFORM_ERROR. + * + * @remark The address of a given function is not guaranteed to be the same + * between contexts. + * + * @remark This function may return a non-`NULL` address despite the + * associated version or extension not being available. Always check the + * context version or extension string first. + * + * @pointer_lifetime The returned function pointer is valid until the context + * is destroyed or the library is terminated. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref context_glext + * @sa glfwExtensionSupported + * + * @since Added in version 1.0. + * + * @ingroup context + */ +GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); + +/*! @brief Returns whether the Vulkan loader has been found. + * + * This function returns whether the Vulkan loader has been found. This check + * is performed by @ref glfwInit. + * + * The availability of a Vulkan loader does not by itself guarantee that window + * surface creation or even device creation is possible. Call @ref + * glfwGetRequiredInstanceExtensions to check whether the extensions necessary + * for Vulkan surface creation are available and @ref + * glfwGetPhysicalDevicePresentationSupport to check whether a queue family of + * a physical device supports image presentation. + * + * @return `GLFW_TRUE` if Vulkan is available, or `GLFW_FALSE` otherwise. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref vulkan_support + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +GLFWAPI int glfwVulkanSupported(void); + +/*! @brief Returns the Vulkan instance extensions required by GLFW. + * + * This function returns an array of names of Vulkan instance extensions required + * by GLFW for creating Vulkan surfaces for GLFW windows. If successful, the + * list will always contains `VK_KHR_surface`, so if you don't require any + * additional extensions you can pass this list directly to the + * `VkInstanceCreateInfo` struct. + * + * If Vulkan is not available on the machine, this function returns `NULL` and + * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported + * to check whether Vulkan is available. + * + * If Vulkan is available but no set of extensions allowing window surface + * creation was found, this function returns `NULL`. You may still use Vulkan + * for off-screen rendering and compute work. + * + * @param[out] count Where to store the number of extensions in the returned + * array. This is set to zero if an error occurred. + * @return An array of ASCII encoded extension names, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_API_UNAVAILABLE. + * + * @remarks Additional extensions may be required by future versions of GLFW. + * You should check if any extensions you wish to enable are already in the + * returned array, as it is an error to specify an extension more than once in + * the `VkInstanceCreateInfo` struct. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is guaranteed to be valid only until the + * library is terminated. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref vulkan_ext + * @sa glfwCreateWindowSurface + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count); + +#if defined(VK_VERSION_1_0) + +/*! @brief Returns the address of the specified Vulkan instance function. + * + * This function returns the address of the specified Vulkan core or extension + * function for the specified instance. If instance is set to `NULL` it can + * return any function exported from the Vulkan loader, including at least the + * following functions: + * + * - `vkEnumerateInstanceExtensionProperties` + * - `vkEnumerateInstanceLayerProperties` + * - `vkCreateInstance` + * - `vkGetInstanceProcAddr` + * + * If Vulkan is not available on the machine, this function returns `NULL` and + * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported + * to check whether Vulkan is available. + * + * This function is equivalent to calling `vkGetInstanceProcAddr` with + * a platform-specific query of the Vulkan loader as a fallback. + * + * @param[in] instance The Vulkan instance to query, or `NULL` to retrieve + * functions related to instance creation. + * @param[in] procname The ASCII encoded name of the function. + * @return The address of the function, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_API_UNAVAILABLE. + * + * @pointer_lifetime The returned function pointer is valid until the library + * is terminated. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref vulkan_proc + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname); + +/*! @brief Returns whether the specified queue family can present images. + * + * This function returns whether the specified queue family of the specified + * physical device supports presentation to the platform GLFW was built for. + * + * If Vulkan or the required window surface creation instance extensions are + * not available on the machine, or if the specified instance was not created + * with the required extensions, this function returns `GLFW_FALSE` and + * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported + * to check whether Vulkan is available and @ref + * glfwGetRequiredInstanceExtensions to check what instance extensions are + * required. + * + * @param[in] instance The instance that the physical device belongs to. + * @param[in] device The physical device that the queue family belongs to. + * @param[in] queuefamily The index of the queue family to query. + * @return `GLFW_TRUE` if the queue family supports presentation, or + * `GLFW_FALSE` otherwise. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. + * + * @thread_safety This function may be called from any thread. For + * synchronization details of Vulkan objects, see the Vulkan specification. + * + * @sa @ref vulkan_present + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); + +/*! @brief Creates a Vulkan surface for the specified window. + * + * This function creates a Vulkan surface for the specified window. + * + * If the Vulkan loader was not found at initialization, this function returns + * `VK_ERROR_INITIALIZATION_FAILED` and generates a @ref GLFW_API_UNAVAILABLE + * error. Call @ref glfwVulkanSupported to check whether the Vulkan loader was + * found. + * + * If the required window surface creation instance extensions are not + * available or if the specified instance was not created with these extensions + * enabled, this function returns `VK_ERROR_EXTENSION_NOT_PRESENT` and + * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref + * glfwGetRequiredInstanceExtensions to check what instance extensions are + * required. + * + * The window surface must be destroyed before the specified Vulkan instance. + * It is the responsibility of the caller to destroy the window surface. GLFW + * does not destroy it for you. Call `vkDestroySurfaceKHR` to destroy the + * surface. + * + * @param[in] instance The Vulkan instance to create the surface in. + * @param[in] window The window to create the surface for. + * @param[in] allocator The allocator to use, or `NULL` to use the default + * allocator. + * @param[out] surface Where to store the handle of the surface. This is set + * to `VK_NULL_HANDLE` if an error occurred. + * @return `VK_SUCCESS` if successful, or a Vulkan error code if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. + * + * @remarks If an error occurs before the creation call is made, GLFW returns + * the Vulkan error code most appropriate for the error. Appropriate use of + * @ref glfwVulkanSupported and @ref glfwGetRequiredInstanceExtensions should + * eliminate almost all occurrences of these errors. + * + * @thread_safety This function may be called from any thread. For + * synchronization details of Vulkan objects, see the Vulkan specification. + * + * @sa @ref vulkan_surface + * @sa glfwGetRequiredInstanceExtensions + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); + +#endif /*VK_VERSION_1_0*/ + + +/************************************************************************* + * Global definition cleanup + *************************************************************************/ + +/* ------------------- BEGIN SYSTEM/COMPILER SPECIFIC -------------------- */ + +#ifdef GLFW_WINGDIAPI_DEFINED + #undef WINGDIAPI + #undef GLFW_WINGDIAPI_DEFINED +#endif + +#ifdef GLFW_CALLBACK_DEFINED + #undef CALLBACK + #undef GLFW_CALLBACK_DEFINED +#endif + +/* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ + + +#ifdef __cplusplus +} +#endif + +#endif /* _glfw3_h_ */ + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3native.h b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3native.h new file mode 100644 index 0000000..9fa955e --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/glfw/include/GLFW/glfw3native.h @@ -0,0 +1,456 @@ +/************************************************************************* + * GLFW 3.2 - www.glfw.org + * A library for OpenGL, window and input + *------------------------------------------------------------------------ + * Copyright (c) 2002-2006 Marcus Geelnard + * Copyright (c) 2006-2010 Camilla Berglund + * + * 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. + * + *************************************************************************/ + +#ifndef _glfw3_native_h_ +#define _glfw3_native_h_ + +#ifdef __cplusplus +extern "C" { +#endif + + +/************************************************************************* + * Doxygen documentation + *************************************************************************/ + +/*! @file glfw3native.h + * @brief The header of the native access functions. + * + * This is the header file of the native access functions. See @ref native for + * more information. + */ +/*! @defgroup native Native access + * + * **By using the native access functions you assert that you know what you're + * doing and how to fix problems caused by using them. If you don't, you + * shouldn't be using them.** + * + * Before the inclusion of @ref glfw3native.h, you may define exactly one + * window system API macro and zero or more context creation API macros. + * + * The chosen backends must match those the library was compiled for. Failure + * to do this will cause a link-time error. + * + * The available window API macros are: + * * `GLFW_EXPOSE_NATIVE_WIN32` + * * `GLFW_EXPOSE_NATIVE_COCOA` + * * `GLFW_EXPOSE_NATIVE_X11` + * * `GLFW_EXPOSE_NATIVE_WAYLAND` + * * `GLFW_EXPOSE_NATIVE_MIR` + * + * The available context API macros are: + * * `GLFW_EXPOSE_NATIVE_WGL` + * * `GLFW_EXPOSE_NATIVE_NSGL` + * * `GLFW_EXPOSE_NATIVE_GLX` + * * `GLFW_EXPOSE_NATIVE_EGL` + * + * These macros select which of the native access functions that are declared + * and which platform-specific headers to include. It is then up your (by + * definition platform-specific) code to handle which of these should be + * defined. + */ + + +/************************************************************************* + * System headers and types + *************************************************************************/ + +#if defined(GLFW_EXPOSE_NATIVE_WIN32) + // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for + // example to allow applications to correctly declare a GL_ARB_debug_output + // callback) but windows.h assumes no one will define APIENTRY before it does + #undef APIENTRY + #include +#elif defined(GLFW_EXPOSE_NATIVE_COCOA) + #include + #if defined(__OBJC__) + #import + #else + typedef void* id; + #endif +#elif defined(GLFW_EXPOSE_NATIVE_X11) + #include + #include +#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) + #include +#elif defined(GLFW_EXPOSE_NATIVE_MIR) + #include +#endif + +#if defined(GLFW_EXPOSE_NATIVE_WGL) + /* WGL is declared by windows.h */ +#endif +#if defined(GLFW_EXPOSE_NATIVE_NSGL) + /* NSGL is declared by Cocoa.h */ +#endif +#if defined(GLFW_EXPOSE_NATIVE_GLX) + #include +#endif +#if defined(GLFW_EXPOSE_NATIVE_EGL) + #include +#endif + + +/************************************************************************* + * Functions + *************************************************************************/ + +#if defined(GLFW_EXPOSE_NATIVE_WIN32) +/*! @brief Returns the adapter device name of the specified monitor. + * + * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`) + * of the specified monitor, or `NULL` if an [error](@ref error_handling) + * occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.1. + * + * @ingroup native + */ +GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor); + +/*! @brief Returns the display device name of the specified monitor. + * + * @return The UTF-8 encoded display device name (for example + * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.1. + * + * @ingroup native + */ +GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); + +/*! @brief Returns the `HWND` of the specified window. + * + * @return The `HWND` of the specified window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_WGL) +/*! @brief Returns the `HGLRC` of the specified window. + * + * @return The `HGLRC` of the specified window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_COCOA) +/*! @brief Returns the `CGDirectDisplayID` of the specified monitor. + * + * @return The `CGDirectDisplayID` of the specified monitor, or + * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.1. + * + * @ingroup native + */ +GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); + +/*! @brief Returns the `NSWindow` of the specified window. + * + * @return The `NSWindow` of the specified window, or `nil` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_NSGL) +/*! @brief Returns the `NSOpenGLContext` of the specified window. + * + * @return The `NSOpenGLContext` of the specified window, or `nil` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_X11) +/*! @brief Returns the `Display` used by GLFW. + * + * @return The `Display` used by GLFW, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI Display* glfwGetX11Display(void); + +/*! @brief Returns the `RRCrtc` of the specified monitor. + * + * @return The `RRCrtc` of the specified monitor, or `None` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.1. + * + * @ingroup native + */ +GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor); + +/*! @brief Returns the `RROutput` of the specified monitor. + * + * @return The `RROutput` of the specified monitor, or `None` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.1. + * + * @ingroup native + */ +GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor); + +/*! @brief Returns the `Window` of the specified window. + * + * @return The `Window` of the specified window, or `None` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI Window glfwGetX11Window(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_GLX) +/*! @brief Returns the `GLXContext` of the specified window. + * + * @return The `GLXContext` of the specified window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); + +/*! @brief Returns the `GLXWindow` of the specified window. + * + * @return The `GLXWindow` of the specified window, or `None` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_WAYLAND) +/*! @brief Returns the `struct wl_display*` used by GLFW. + * + * @return The `struct wl_display*` used by GLFW, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI struct wl_display* glfwGetWaylandDisplay(void); + +/*! @brief Returns the `struct wl_output*` of the specified monitor. + * + * @return The `struct wl_output*` of the specified monitor, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor); + +/*! @brief Returns the main `struct wl_surface*` of the specified window. + * + * @return The main `struct wl_surface*` of the specified window, or `NULL` if + * an [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_MIR) +/*! @brief Returns the `MirConnection*` used by GLFW. + * + * @return The `MirConnection*` used by GLFW, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI MirConnection* glfwGetMirDisplay(void); + +/*! @brief Returns the Mir output ID of the specified monitor. + * + * @return The Mir output ID of the specified monitor, or zero if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor); + +/*! @brief Returns the `MirSurface*` of the specified window. + * + * @return The `MirSurface*` of the specified window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.2. + * + * @ingroup native + */ +GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_EGL) +/*! @brief Returns the `EGLDisplay` used by GLFW. + * + * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI EGLDisplay glfwGetEGLDisplay(void); + +/*! @brief Returns the `EGLContext` of the specified window. + * + * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); + +/*! @brief Returns the `EGLSurface` of the specified window. + * + * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _glfw3_native_h_ */ + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.c b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.c new file mode 100644 index 0000000..a8d01da --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.c @@ -0,0 +1,636 @@ +/* +uSynergy client -- Implementation for the embedded Synergy client library + version 1.0.0, July 7th, 2012 + +Copyright (c) 2012 Alex Evans + +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. +*/ +#include "uSynergy.h" +#include +#include + + + +//--------------------------------------------------------------------------------------------------------------------- +// Internal helpers +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Read 16 bit integer in network byte order and convert to native byte order +**/ +static int16_t sNetToNative16(const unsigned char *value) +{ +#ifdef USYNERGY_LITTLE_ENDIAN + return value[1] | (value[0] << 8); +#else + return value[0] | (value[1] << 8); +#endif +} + + + +/** +@brief Read 32 bit integer in network byte order and convert to native byte order +**/ +static int32_t sNetToNative32(const unsigned char *value) +{ +#ifdef USYNERGY_LITTLE_ENDIAN + return value[3] | (value[2] << 8) | (value[1] << 16) | (value[0] << 24); +#else + return value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); +#endif +} + + + +/** +@brief Trace text to client +**/ +static void sTrace(uSynergyContext *context, const char* text) +{ + // Don't trace if we don't have a trace function + if (context->m_traceFunc != 0L) + context->m_traceFunc(context->m_cookie, text); +} + + + +/** +@brief Add string to reply packet +**/ +static void sAddString(uSynergyContext *context, const char *string) +{ + size_t len = strlen(string); + memcpy(context->m_replyCur, string, len); + context->m_replyCur += len; +} + + + +/** +@brief Add uint8 to reply packet +**/ +static void sAddUInt8(uSynergyContext *context, uint8_t value) +{ + *context->m_replyCur++ = value; +} + + + +/** +@brief Add uint16 to reply packet +**/ +static void sAddUInt16(uSynergyContext *context, uint16_t value) +{ + uint8_t *reply = context->m_replyCur; + *reply++ = (uint8_t)(value >> 8); + *reply++ = (uint8_t)value; + context->m_replyCur = reply; +} + + + +/** +@brief Add uint32 to reply packet +**/ +static void sAddUInt32(uSynergyContext *context, uint32_t value) +{ + uint8_t *reply = context->m_replyCur; + *reply++ = (uint8_t)(value >> 24); + *reply++ = (uint8_t)(value >> 16); + *reply++ = (uint8_t)(value >> 8); + *reply++ = (uint8_t)value; + context->m_replyCur = reply; +} + + + +/** +@brief Send reply packet +**/ +static uSynergyBool sSendReply(uSynergyContext *context) +{ + // Set header size + uint8_t *reply_buf = context->m_replyBuffer; + uint32_t reply_len = (uint32_t)(context->m_replyCur - reply_buf); /* Total size of reply */ + uint32_t body_len = reply_len - 4; /* Size of body */ + uSynergyBool ret; + reply_buf[0] = (uint8_t)(body_len >> 24); + reply_buf[1] = (uint8_t)(body_len >> 16); + reply_buf[2] = (uint8_t)(body_len >> 8); + reply_buf[3] = (uint8_t)body_len; + + // Send reply + ret = context->m_sendFunc(context->m_cookie, context->m_replyBuffer, reply_len); + + // Reset reply buffer write pointer + context->m_replyCur = context->m_replyBuffer+4; + return ret; +} + + + +/** +@brief Call mouse callback after a mouse event +**/ +static void sSendMouseCallback(uSynergyContext *context) +{ + // Skip if no callback is installed + if (context->m_mouseCallback == 0L) + return; + + // Send callback + context->m_mouseCallback(context->m_cookie, context->m_mouseX, context->m_mouseY, context->m_mouseWheelX, + context->m_mouseWheelY, context->m_mouseButtonLeft, context->m_mouseButtonRight, context->m_mouseButtonMiddle); +} + + + +/** +@brief Send keyboard callback when a key has been pressed or released +**/ +static void sSendKeyboardCallback(uSynergyContext *context, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) +{ + // Skip if no callback is installed + if (context->m_keyboardCallback == 0L) + return; + + // Send callback + context->m_keyboardCallback(context->m_cookie, key, modifiers, down, repeat); +} + + + +/** +@brief Send joystick callback +**/ +static void sSendJoystickCallback(uSynergyContext *context, uint8_t joyNum) +{ + int8_t *sticks; + + // Skip if no callback is installed + if (context->m_joystickCallback == 0L) + return; + + // Send callback + sticks = context->m_joystickSticks[joyNum]; + context->m_joystickCallback(context->m_cookie, joyNum, context->m_joystickButtons[joyNum], sticks[0], sticks[1], sticks[2], sticks[3]); +} + + + +/** +@brief Parse a single client message, update state, send callbacks and send replies +**/ +#define USYNERGY_IS_PACKET(pkt_id) memcmp(message+4, pkt_id, 4)==0 +static void sProcessMessage(uSynergyContext *context, const uint8_t *message) +{ + // We have a packet! + if (memcmp(message+4, "Synergy", 7)==0) + { + // Welcome message + // kMsgHello = "Synergy%2i%2i" + // kMsgHelloBack = "Synergy%2i%2i%s" + sAddString(context, "Synergy"); + sAddUInt16(context, USYNERGY_PROTOCOL_MAJOR); + sAddUInt16(context, USYNERGY_PROTOCOL_MINOR); + sAddUInt32(context, (uint32_t)strlen(context->m_clientName)); + sAddString(context, context->m_clientName); + if (!sSendReply(context)) + { + // Send reply failed, let's try to reconnect + sTrace(context, "SendReply failed, trying to reconnect in a second"); + context->m_connected = USYNERGY_FALSE; + context->m_sleepFunc(context->m_cookie, 1000); + } + else + { + // Let's assume we're connected + char buffer[256+1]; + sprintf(buffer, "Connected as client \"%s\"", context->m_clientName); + sTrace(context, buffer); + context->m_hasReceivedHello = USYNERGY_TRUE; + } + return; + } + else if (USYNERGY_IS_PACKET("QINF")) + { + // Screen info. Reply with DINF + // kMsgQInfo = "QINF" + // kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i" + uint16_t x = 0, y = 0, warp = 0; + sAddString(context, "DINF"); + sAddUInt16(context, x); + sAddUInt16(context, y); + sAddUInt16(context, context->m_clientWidth); + sAddUInt16(context, context->m_clientHeight); + sAddUInt16(context, warp); + sAddUInt16(context, 0); // mx? + sAddUInt16(context, 0); // my? + sSendReply(context); + return; + } + else if (USYNERGY_IS_PACKET("CIAK")) + { + // Do nothing? + // kMsgCInfoAck = "CIAK" + return; + } + else if (USYNERGY_IS_PACKET("CROP")) + { + // Do nothing? + // kMsgCResetOptions = "CROP" + return; + } + else if (USYNERGY_IS_PACKET("CINN")) + { + // Screen enter. Reply with CNOP + // kMsgCEnter = "CINN%2i%2i%4i%2i" + + // Obtain the Synergy sequence number + context->m_sequenceNumber = sNetToNative32(message + 12); + context->m_isCaptured = USYNERGY_TRUE; + + // Call callback + if (context->m_screenActiveCallback != 0L) + context->m_screenActiveCallback(context->m_cookie, USYNERGY_TRUE); + } + else if (USYNERGY_IS_PACKET("COUT")) + { + // Screen leave + // kMsgCLeave = "COUT" + context->m_isCaptured = USYNERGY_FALSE; + + // Call callback + if (context->m_screenActiveCallback != 0L) + context->m_screenActiveCallback(context->m_cookie, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DMDN")) + { + // Mouse down + // kMsgDMouseDown = "DMDN%1i" + char btn = message[8]-1; + if (btn==2) + context->m_mouseButtonRight = USYNERGY_TRUE; + else if (btn==1) + context->m_mouseButtonMiddle = USYNERGY_TRUE; + else + context->m_mouseButtonLeft = USYNERGY_TRUE; + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMUP")) + { + // Mouse up + // kMsgDMouseUp = "DMUP%1i" + char btn = message[8]-1; + if (btn==2) + context->m_mouseButtonRight = USYNERGY_FALSE; + else if (btn==1) + context->m_mouseButtonMiddle = USYNERGY_FALSE; + else + context->m_mouseButtonLeft = USYNERGY_FALSE; + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMMV")) + { + // Mouse move. Reply with CNOP + // kMsgDMouseMove = "DMMV%2i%2i" + context->m_mouseX = sNetToNative16(message+8); + context->m_mouseY = sNetToNative16(message+10); + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMWM")) + { + // Mouse wheel + // kMsgDMouseWheel = "DMWM%2i%2i" + // kMsgDMouseWheel1_0 = "DMWM%2i" + context->m_mouseWheelX += sNetToNative16(message+8); + context->m_mouseWheelY += sNetToNative16(message+10); + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DKDN")) + { + // Key down + // kMsgDKeyDown = "DKDN%2i%2i%2i" + // kMsgDKeyDown1_0 = "DKDN%2i%2i" + //uint16_t id = sNetToNative16(message+8); + uint16_t mod = sNetToNative16(message+10); + uint16_t key = sNetToNative16(message+12); + sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DKRP")) + { + // Key repeat + // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" + // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" + uint16_t mod = sNetToNative16(message+10); +// uint16_t count = sNetToNative16(message+12); + uint16_t key = sNetToNative16(message+14); + sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_TRUE); + } + else if (USYNERGY_IS_PACKET("DKUP")) + { + // Key up + // kMsgDKeyUp = "DKUP%2i%2i%2i" + // kMsgDKeyUp1_0 = "DKUP%2i%2i" + //uint16 id=Endian::sNetToNative(sbuf[4]); + uint16_t mod = sNetToNative16(message+10); + uint16_t key = sNetToNative16(message+12); + sSendKeyboardCallback(context, key, mod, USYNERGY_FALSE, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DGBT")) + { + // Joystick buttons + // kMsgDGameButtons = "DGBT%1i%2i"; + uint8_t joy_num = message[8]; + if (joy_numm_joystickButtons[joy_num] = (message[9] << 8) | message[10]; + sSendJoystickCallback(context, joy_num); + } + } + else if (USYNERGY_IS_PACKET("DGST")) + { + // Joystick sticks + // kMsgDGameSticks = "DGST%1i%1i%1i%1i%1i"; + uint8_t joy_num = message[8]; + if (joy_numm_joystickSticks[joy_num], message+9, 4); + sSendJoystickCallback(context, joy_num); + } + } + else if (USYNERGY_IS_PACKET("DSOP")) + { + // Set options + // kMsgDSetOptions = "DSOP%4I" + } + else if (USYNERGY_IS_PACKET("CALV")) + { + // Keepalive, reply with CALV and then CNOP + // kMsgCKeepAlive = "CALV" + sAddString(context, "CALV"); + sSendReply(context); + // now reply with CNOP + } + else if (USYNERGY_IS_PACKET("DCLP")) + { + // Clipboard message + // kMsgDClipboard = "DCLP%1i%4i%s" + // + // The clipboard message contains: + // 1 uint32: The size of the message + // 4 chars: The identifier ("DCLP") + // 1 uint8: The clipboard index + // 1 uint32: The sequence number. It's zero, because this message is always coming from the server? + // 1 uint32: The total size of the remaining 'string' (as per the Synergy %s string format (which is 1 uint32 for size followed by a char buffer (not necessarily null terminated)). + // 1 uint32: The number of formats present in the message + // And then 'number of formats' times the following: + // 1 uint32: The format of the clipboard data + // 1 uint32: The size n of the clipboard data + // n uint8: The clipboard data + const uint8_t * parse_msg = message+17; + uint32_t num_formats = sNetToNative32(parse_msg); + parse_msg += 4; + for (; num_formats; num_formats--) + { + // Parse clipboard format header + uint32_t format = sNetToNative32(parse_msg); + uint32_t size = sNetToNative32(parse_msg+4); + parse_msg += 8; + + // Call callback + if (context->m_clipboardCallback) + context->m_clipboardCallback(context->m_cookie, format, parse_msg, size); + + parse_msg += size; + } + } + else + { + // Unknown packet, could be any of these + // kMsgCNoop = "CNOP" + // kMsgCClose = "CBYE" + // kMsgCClipboard = "CCLP%1i%4i" + // kMsgCScreenSaver = "CSEC%1i" + // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" + // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" + // kMsgDMouseRelMove = "DMRM%2i%2i" + // kMsgEIncompatible = "EICV%2i%2i" + // kMsgEBusy = "EBSY" + // kMsgEUnknown = "EUNK" + // kMsgEBad = "EBAD" + char buffer[64]; + sprintf(buffer, "Unknown packet '%c%c%c%c'", message[4], message[5], message[6], message[7]); + sTrace(context, buffer); + return; + } + + // Reply with CNOP maybe? + sAddString(context, "CNOP"); + sSendReply(context); +} +#undef USYNERGY_IS_PACKET + + + +/** +@brief Mark context as being disconnected +**/ +static void sSetDisconnected(uSynergyContext *context) +{ + context->m_connected = USYNERGY_FALSE; + context->m_hasReceivedHello = USYNERGY_FALSE; + context->m_isCaptured = USYNERGY_FALSE; + context->m_replyCur = context->m_replyBuffer + 4; + context->m_sequenceNumber = 0; +} + + + +/** +@brief Update a connected context +**/ +static void sUpdateContext(uSynergyContext *context) +{ + /* Receive data (blocking) */ + int receive_size = USYNERGY_RECEIVE_BUFFER_SIZE - context->m_receiveOfs; + int num_received = 0; + int packlen = 0; + if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer + context->m_receiveOfs, receive_size, &num_received) == USYNERGY_FALSE) + { + /* Receive failed, let's try to reconnect */ + char buffer[128]; + sprintf(buffer, "Receive failed (%d bytes asked, %d bytes received), trying to reconnect in a second", receive_size, num_received); + sTrace(context, buffer); + sSetDisconnected(context); + context->m_sleepFunc(context->m_cookie, 1000); + return; + } + context->m_receiveOfs += num_received; + + /* If we didn't receive any data then we're probably still polling to get connected and + therefore not getting any data back. To avoid overloading the system with a Synergy + thread that would hammer on polling, we let it rest for a bit if there's no data. */ + if (num_received == 0) + context->m_sleepFunc(context->m_cookie, 500); + + /* Check for timeouts */ + if (context->m_hasReceivedHello) + { + uint32_t cur_time = context->m_getTimeFunc(); + if (num_received == 0) + { + /* Timeout after 2 secs of inactivity (we received no CALV) */ + if ((cur_time - context->m_lastMessageTime) > USYNERGY_IDLE_TIMEOUT) + sSetDisconnected(context); + } + else + context->m_lastMessageTime = cur_time; + } + + /* Eat packets */ + for (;;) + { + /* Grab packet length and bail out if the packet goes beyond the end of the buffer */ + packlen = sNetToNative32(context->m_receiveBuffer); + if (packlen+4 > context->m_receiveOfs) + break; + + /* Process message */ + sProcessMessage(context, context->m_receiveBuffer); + + /* Move packet to front of buffer */ + memmove(context->m_receiveBuffer, context->m_receiveBuffer+packlen+4, context->m_receiveOfs-packlen-4); + context->m_receiveOfs -= packlen+4; + } + + /* Throw away over-sized packets */ + if (packlen > USYNERGY_RECEIVE_BUFFER_SIZE) + { + /* Oversized packet, ditch tail end */ + char buffer[128]; + sprintf(buffer, "Oversized packet: '%c%c%c%c' (length %d)", context->m_receiveBuffer[4], context->m_receiveBuffer[5], context->m_receiveBuffer[6], context->m_receiveBuffer[7], packlen); + sTrace(context, buffer); + num_received = context->m_receiveOfs-4; // 4 bytes for the size field + while (num_received != packlen) + { + int buffer_left = packlen - num_received; + int to_receive = buffer_left < USYNERGY_RECEIVE_BUFFER_SIZE ? buffer_left : USYNERGY_RECEIVE_BUFFER_SIZE; + int ditch_received = 0; + if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer, to_receive, &ditch_received) == USYNERGY_FALSE) + { + /* Receive failed, let's try to reconnect */ + sTrace(context, "Receive failed, trying to reconnect in a second"); + sSetDisconnected(context); + context->m_sleepFunc(context->m_cookie, 1000); + break; + } + else + { + num_received += ditch_received; + } + } + context->m_receiveOfs = 0; + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +// Public interface +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Initialize uSynergy context +**/ +void uSynergyInit(uSynergyContext *context) +{ + /* Zero memory */ + memset(context, 0, sizeof(uSynergyContext)); + + /* Initialize to default state */ + sSetDisconnected(context); +} + + +/** +@brief Update uSynergy +**/ +void uSynergyUpdate(uSynergyContext *context) +{ + if (context->m_connected) + { + /* Update context, receive data, call callbacks */ + sUpdateContext(context); + } + else + { + /* Try to connect */ + if (context->m_connectFunc(context->m_cookie)) + context->m_connected = USYNERGY_TRUE; + } +} + + + +/** +@brief Send clipboard data +**/ +void uSynergySendClipboard(uSynergyContext *context, const char *text) +{ + // Calculate maximum size that will fit in a reply packet + uint32_t overhead_size = 4 + /* Message size */ + 4 + /* Message ID */ + 1 + /* Clipboard index */ + 4 + /* Sequence number */ + 4 + /* Rest of message size (because it's a Synergy string from here on) */ + 4 + /* Number of clipboard formats */ + 4 + /* Clipboard format */ + 4; /* Clipboard data length */ + uint32_t max_length = USYNERGY_REPLY_BUFFER_SIZE - overhead_size; + + // Clip text to max length + uint32_t text_length = (uint32_t)strlen(text); + if (text_length > max_length) + { + char buffer[128]; + sprintf(buffer, "Clipboard buffer too small, clipboard truncated at %d characters", max_length); + sTrace(context, buffer); + text_length = max_length; + } + + // Assemble packet + sAddString(context, "DCLP"); + sAddUInt8(context, 0); /* Clipboard index */ + sAddUInt32(context, context->m_sequenceNumber); + sAddUInt32(context, 4+4+4+text_length); /* Rest of message size: numFormats, format, length, data */ + sAddUInt32(context, 1); /* Number of formats (only text for now) */ + sAddUInt32(context, USYNERGY_CLIPBOARD_FORMAT_TEXT); + sAddUInt32(context, text_length); + sAddString(context, text); + sSendReply(context); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.h b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.h new file mode 100644 index 0000000..cedc387 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/libs/usynergy/uSynergy.h @@ -0,0 +1,420 @@ +/* +uSynergy client -- Interface for the embedded Synergy client library + version 1.0.0, July 7th, 2012 + +Copyright (C) 2012 Synergy Si Ltd. +Copyright (c) 2012 Alex Evans + +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. +*/ +#include + +#ifdef __cplusplus +extern "C" { +#endif + + + +//--------------------------------------------------------------------------------------------------------------------- +// Configuration +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Determine endianness +**/ +#if defined(USYNERGY_LITTLE_ENDIAN) && defined(USYNERGY_BIG_ENDIAN) + /* Ambiguous: both endians specified */ + #error "Can't define both USYNERGY_LITTLE_ENDIAN and USYNERGY_BIG_ENDIAN" +#elif !defined(USYNERGY_LITTLE_ENDIAN) && !defined(USYNERGY_BIG_ENDIAN) + /* Attempt to auto detect */ + #if defined(__LITTLE_ENDIAN__) || defined(LITTLE_ENDIAN) || (_BYTE_ORDER == _LITTLE_ENDIAN) + #define USYNERGY_LITTLE_ENDIAN + #elif defined(__BIG_ENDIAN__) || defined(BIG_ENDIAN) || (_BYTE_ORDER == _BIG_ENDIAN) + #define USYNERGY_BIG_ENDIAN + #else + #error "Can't detect endian-nes, please defined either USYNERGY_LITTLE_ENDIAN or USYNERGY_BIG_ENDIAN"; + #endif +#else + /* User-specified endian-nes, nothing to do for us */ +#endif + + + +//--------------------------------------------------------------------------------------------------------------------- +// Types and Constants +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Boolean type +**/ +typedef int uSynergyBool; +#define USYNERGY_FALSE 0 /* False value */ +#define USYNERGY_TRUE 1 /* True value */ + + +/** +@brief User context type + +The uSynergyCookie type is an opaque type that is used by uSynergy to communicate to the client. It is passed along to +callback functions as context. +**/ +typedef struct { int ignored; } * uSynergyCookie; + + + +/** +@brief Clipboard types +**/ +enum uSynergyClipboardFormat +{ + USYNERGY_CLIPBOARD_FORMAT_TEXT = 0, /* Text format, UTF-8, newline is LF */ + USYNERGY_CLIPBOARD_FORMAT_BITMAP = 1, /* Bitmap format, BMP 24/32bpp, BI_RGB */ + USYNERGY_CLIPBOARD_FORMAT_HTML = 2, /* HTML format, HTML fragment, UTF-8, newline is LF */ +}; + + + +/** +@brief Constants and limits +**/ +#define USYNERGY_NUM_JOYSTICKS 4 /* Maximum number of supported joysticks */ + +#define USYNERGY_PROTOCOL_MAJOR 1 /* Major protocol version */ +#define USYNERGY_PROTOCOL_MINOR 4 /* Minor protocol version */ + +#define USYNERGY_IDLE_TIMEOUT 2000 /* Timeout in milliseconds before reconnecting */ + +#define USYNERGY_TRACE_BUFFER_SIZE 1024 /* Maximum length of traced message */ +#define USYNERGY_REPLY_BUFFER_SIZE 1024 /* Maximum size of a reply packet */ +#define USYNERGY_RECEIVE_BUFFER_SIZE 4096 /* Maximum size of an incoming packet */ + + + +/** +@brief Keyboard constants +**/ +#define USYNERGY_MODIFIER_SHIFT 0x0001 /* Shift key modifier */ +#define USYNERGY_MODIFIER_CTRL 0x0002 /* Ctrl key modifier */ +#define USYNERGY_MODIFIER_ALT 0x0004 /* Alt key modifier */ +#define USYNERGY_MODIFIER_META 0x0008 /* Meta key modifier */ +#define USYNERGY_MODIFIER_WIN 0x0010 /* Windows key modifier */ +#define USYNERGY_MODIFIER_ALT_GR 0x0020 /* AltGr key modifier */ +#define USYNERGY_MODIFIER_LEVEL5LOCK 0x0040 /* Level5Lock key modifier */ +#define USYNERGY_MODIFIER_CAPSLOCK 0x1000 /* CapsLock key modifier */ +#define USYNERGY_MODIFIER_NUMLOCK 0x2000 /* NumLock key modifier */ +#define USYNERGY_MODIFIER_SCROLLOCK 0x4000 /* ScrollLock key modifier */ + + + + +//--------------------------------------------------------------------------------------------------------------------- +// Functions and Callbacks +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Connect function + +This function is called when uSynergy needs to connect to the host. It doesn't imply a network implementation or +destination address, that must all be handled on the user side. The function should return USYNERGY_TRUE if a +connection was established or USYNERGY_FALSE if it could not connect. + +When network errors occur (e.g. uSynergySend or uSynergyReceive fail) then the connect call will be called again +so the implementation of the function must close any old connections and clean up resources before retrying. + +@param cookie Cookie supplied in the Synergy context +**/ +typedef uSynergyBool (*uSynergyConnectFunc)(uSynergyCookie cookie); + + + +/** +@brief Send function + +This function is called when uSynergy needs to send something over the default connection. It should return +USYNERGY_TRUE if sending succeeded and USYNERGY_FALSE otherwise. This function should block until the send +operation is completed. + +@param cookie Cookie supplied in the Synergy context +@param buffer Address of buffer to send +@param length Length of buffer to send +**/ +typedef uSynergyBool (*uSynergySendFunc)(uSynergyCookie cookie, const uint8_t *buffer, int length); + + + +/** +@brief Receive function + +This function is called when uSynergy needs to receive data from the default connection. It should return +USYNERGY_TRUE if receiving data succeeded and USYNERGY_FALSE otherwise. This function should block until data +has been received and wait for data to become available. If @a outLength is set to 0 upon completion it is +assumed that the connection is alive, but still in a connecting state and needs time to settle. + +@param cookie Cookie supplied in the Synergy context +@param buffer Address of buffer to receive data into +@param maxLength Maximum amount of bytes to write into the receive buffer +@param outLength Address of integer that receives the actual amount of bytes written into @a buffer +**/ +typedef uSynergyBool (*uSynergyReceiveFunc)(uSynergyCookie cookie, uint8_t *buffer, int maxLength, int* outLength); + + + +/** +@brief Thread sleep function + +This function is called when uSynergy wants to suspend operation for a while before retrying an operation. It +is mostly used when a socket times out or disconnect occurs to prevent uSynergy from continuously hammering a +network connection in case the network is down. + +@param cookie Cookie supplied in the Synergy context +@param timeMs Time to sleep the current thread (in milliseconds) +**/ +typedef void (*uSynergySleepFunc)(uSynergyCookie cookie, int timeMs); + + + +/** +@brief Get time function + +This function is called when uSynergy needs to know the current time. This is used to determine when timeouts +have occured. The time base should be a cyclic millisecond time value. + +@returns Time value in milliseconds +**/ +typedef uint32_t (*uSynergyGetTimeFunc)(); + + + +/** +@brief Trace function + +This function is called when uSynergy wants to trace something. It is optional to show these messages, but they +are often useful when debugging. uSynergy only traces major events like connecting and disconnecting. Usually +only a single trace is shown when the connection is established and no more trace are called. + +@param cookie Cookie supplied in the Synergy context +@param text Text to be traced +**/ +typedef void (*uSynergyTraceFunc)(uSynergyCookie cookie, const char *text); + + + +/** +@brief Screen active callback + +This callback is called when Synergy makes the screen active or inactive. This +callback is usually sent when the mouse enters or leaves the screen. + +@param cookie Cookie supplied in the Synergy context +@param active Activation flag, 1 if the screen has become active, 0 if the screen has become inactive +**/ +typedef void (*uSynergyScreenActiveCallback)(uSynergyCookie cookie, uSynergyBool active); + + + +/** +@brief Mouse callback + +This callback is called when a mouse events happens. The mouse X and Y position, +wheel and button state is communicated in the message. It's up to the user to +interpret if this is a mouse up, down, double-click or other message. + +@param cookie Cookie supplied in the Synergy context +@param x Mouse X position +@param y Mouse Y position +@param wheelX Mouse wheel X position +@param wheelY Mouse wheel Y position +@param buttonLeft Left button pressed status, 0 for released, 1 for pressed +@param buttonMiddle Middle button pressed status, 0 for released, 1 for pressed +@param buttonRight Right button pressed status, 0 for released, 1 for pressed +**/ +typedef void (*uSynergyMouseCallback)(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_t wheelX, int16_t wheelY, uSynergyBool buttonLeft, uSynergyBool buttonRight, uSynergyBool buttonMiddle); + + + +/** +@brief Key event callback + +This callback is called when a key is pressed or released. + +@param cookie Cookie supplied in the Synergy context +@param key Key code of key that was pressed or released +@param modifiers Status of modifier keys (alt, shift, etc.) +@param down Down or up status, 1 is key is pressed down, 0 if key is released (up) +@param repeat Repeat flag, 1 if the key is down because the key is repeating, 0 if the key is initially pressed by the user +**/ +typedef void (*uSynergyKeyboardCallback)(uSynergyCookie cookie, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat); + + + +/** +@brief Joystick event callback + +This callback is called when a joystick stick or button changes. It is possible that multiple callbacks are +fired when different sticks or buttons change as these are individual messages in the packet stream. Each +callback will contain all the valid state for the different axes and buttons. The last callback received will +represent the most current joystick state. + +@param cookie Cookie supplied in the Synergy context +@param joyNum Joystick number, always in the range [0 ... USYNERGY_NUM_JOYSTICKS> +@param buttons Button pressed mask +@param leftStickX Left stick X position, in range [-127 ... 127] +@param leftStickY Left stick Y position, in range [-127 ... 127] +@param rightStickX Right stick X position, in range [-127 ... 127] +@param rightStickY Right stick Y position, in range [-127 ... 127] +**/ +typedef void (*uSynergyJoystickCallback)(uSynergyCookie cookie, uint8_t joyNum, uint16_t buttons, int8_t leftStickX, int8_t leftStickY, int8_t rightStickX, int8_t rightStickY); + + + +/** +@brief Clipboard event callback + +This callback is called when something is placed on the clipboard. Multiple callbacks may be fired for +multiple clipboard formats if they are supported. The data provided is read-only and may not be modified +by the application. + +@param cookie Cookie supplied in the Synergy context +@param format Clipboard format +@param data Memory area containing the clipboard raw data +@param size Size of clipboard data +**/ +typedef void (*uSynergyClipboardCallback)(uSynergyCookie cookie, enum uSynergyClipboardFormat format, const uint8_t *data, uint32_t size); + + + +//--------------------------------------------------------------------------------------------------------------------- +// Context +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief uSynergy context +**/ +typedef struct +{ + /* Mandatory configuration data, filled in by client */ + uSynergyConnectFunc m_connectFunc; /* Connect function */ + uSynergySendFunc m_sendFunc; /* Send data function */ + uSynergyReceiveFunc m_receiveFunc; /* Receive data function */ + uSynergySleepFunc m_sleepFunc; /* Thread sleep function */ + uSynergyGetTimeFunc m_getTimeFunc; /* Get current time function */ + const char* m_clientName; /* Name of Synergy Screen / Client */ + uint16_t m_clientWidth; /* Width of screen */ + uint16_t m_clientHeight; /* Height of screen */ + + /* Optional configuration data, filled in by client */ + uSynergyCookie m_cookie; /* Cookie pointer passed to callback functions (can be NULL) */ + uSynergyTraceFunc m_traceFunc; /* Function for tracing status (can be NULL) */ + uSynergyScreenActiveCallback m_screenActiveCallback; /* Callback for entering and leaving screen */ + uSynergyMouseCallback m_mouseCallback; /* Callback for mouse events */ + uSynergyKeyboardCallback m_keyboardCallback; /* Callback for keyboard events */ + uSynergyJoystickCallback m_joystickCallback; /* Callback for joystick events */ + uSynergyClipboardCallback m_clipboardCallback; /* Callback for clipboard events */ + + /* State data, used internall by client, initialized by uSynergyInit() */ + uSynergyBool m_connected; /* Is our socket connected? */ + uSynergyBool m_hasReceivedHello; /* Have we received a 'Hello' from the server? */ + uSynergyBool m_isCaptured; /* Is Synergy active (i.e. this client is receiving input messages?) */ + uint32_t m_lastMessageTime; /* Time at which last message was received */ + uint32_t m_sequenceNumber; /* Packet sequence number */ + uint8_t m_receiveBuffer[USYNERGY_RECEIVE_BUFFER_SIZE]; /* Receive buffer */ + int m_receiveOfs; /* Receive buffer offset */ + uint8_t m_replyBuffer[USYNERGY_REPLY_BUFFER_SIZE]; /* Reply buffer */ + uint8_t* m_replyCur; /* Write offset into reply buffer */ + uint16_t m_mouseX; /* Mouse X position */ + uint16_t m_mouseY; /* Mouse Y position */ + int16_t m_mouseWheelX; /* Mouse wheel X position */ + int16_t m_mouseWheelY; /* Mouse wheel Y position */ + uSynergyBool m_mouseButtonLeft; /* Mouse left button */ + uSynergyBool m_mouseButtonRight; /* Mouse right button */ + uSynergyBool m_mouseButtonMiddle; /* Mouse middle button */ + int8_t m_joystickSticks[USYNERGY_NUM_JOYSTICKS][4]; /* Joystick stick position in 2 axes for 2 sticks */ + uint16_t m_joystickButtons[USYNERGY_NUM_JOYSTICKS]; /* Joystick button state */ +} uSynergyContext; + + + +//--------------------------------------------------------------------------------------------------------------------- +// Interface +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Initialize uSynergy context + +This function initializes @a context for use. Call this function directly after +creating the context, before filling in any configuration data in it. Not calling +this function will cause undefined behavior. + +@param context Context to be initialized +**/ +extern void uSynergyInit(uSynergyContext *context); + + + +/** +@brief Update uSynergy + +This function updates uSynergy and does the bulk of the work. It does connection management, +receiving data, reconnecting after errors or timeouts and so on. It assumes that networking +operations are blocking and it can suspend the current thread if it needs to wait. It is +best practice to call uSynergyUpdate from a background thread so it is responsive. + +Because uSynergy relies mostly on blocking calls it will mostly stay in thread sleep state +waiting for system mutexes and won't eat much memory. + +uSynergyUpdate doesn't do any memory allocations or have any side effects beyond those of +the callbacks it calls. + +@param context Context to be updated +**/ +extern void uSynergyUpdate(uSynergyContext *context); + + + +/** +@brief Send clipboard data + +This function sets new clipboard data and sends it to the server. Use this function if +your client cuts or copies data onto the clipboard that it needs to share with the +server. + +Currently there is only support for plaintext, but HTML and image data could be +supported with some effort. + +@param context Context to send clipboard data to +@param text Text to set to the clipboard +**/ +extern void uSynergySendClipboard(uSynergyContext *context, const char *text); + + + +#ifdef __cplusplus +}; +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/data/app.icf b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/data/app.icf new file mode 100644 index 0000000..fcd6585 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/data/app.icf @@ -0,0 +1,32 @@ +# This file is for configuration settings for your +# application. +# +# The syntax is similar to windows .ini files ie +# +# [GroupName] +# Setting = Value +# +# Which can be read by your application using +# e.g s3eConfigGetString("GroupName", "Setting", string) +# +# All settings must be documented in .config.txt files. +# New settings specific to this application should be +# documented in app.config.txt +# +# Some conditional operations are also permitted, see the +# S3E documentation for details. + +[S3E] +MemSize=6000000 +MemSizeDebug=6000000 +DispFixRot=FixedLandscape + +# emulate iphone 5 resolution, change these settings to emulate other display resolution +WinWidth=1136 +WinHeight=640 + +[GX] +DataCacheSize=131070 + +[Util] +#MemoryBreakpoint=1282 diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.cpp new file mode 100644 index 0000000..6ecffa7 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.cpp @@ -0,0 +1,312 @@ +// ImGui Marmalade binding with IwGx +// In this binding, ImTextureID is used to store a 'CIwTexture*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +// Copyright (C) 2015 by Giovanni Zito +// This file is part of ImGui + +#include +#include "imgui_impl_marmalade.h" + +#include +#include +#include +#include +#include + +// Data +static double g_Time = 0.0f; +static bool g_MousePressed[3] = { false, false, false }; +static float g_MouseWheel = 0.0f; +static CIwTexture* g_FontTexture = NULL; +static char* g_ClipboardText = NULL; +static bool g_osdKeyboardEnabled = false; + +// use this setting to scale the interface - e.g. on device you could use 2 or 3 scale factor +static ImVec2 g_RenderScale = ImVec2(1.0f,1.0f); + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data) +{ + // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) + ImGuiIO& io = ImGui::GetIO(); + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + + // Render command lists + for(int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; + const int nVert = cmd_list->VtxBuffer.Size; + CIwFVec2* pVertStream = IW_GX_ALLOC(CIwFVec2, nVert); + CIwFVec2* pUVStream = IW_GX_ALLOC(CIwFVec2, nVert); + CIwColour* pColStream = IW_GX_ALLOC(CIwColour, nVert); + + for( int i=0; i < nVert; i++ ) + { + // TODO: optimize multiplication on gpu using vertex shader/projection matrix. + pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_RenderScale.x; + pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_RenderScale.y; + pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x; + pUVStream[i].y = cmd_list->VtxBuffer[i].uv.y; + pColStream[i] = cmd_list->VtxBuffer[i].col; + } + + IwGxSetVertStreamScreenSpace(pVertStream, nVert); + IwGxSetUVStream(pUVStream); + IwGxSetColStream(pColStream, nVert); + IwGxSetNormStream(0); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + CIwMaterial* pCurrentMaterial = IW_GX_ALLOC_MATERIAL(); + pCurrentMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT); + pCurrentMaterial->SetCullMode(CIwMaterial::CULL_NONE); + pCurrentMaterial->SetFiltering(false); + pCurrentMaterial->SetAlphaMode(CIwMaterial::ALPHA_BLEND); + pCurrentMaterial->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_NORMAL); + pCurrentMaterial->SetAlphaTestMode(CIwMaterial::ALPHATEST_DISABLED); + pCurrentMaterial->SetTexture((CIwTexture*)pcmd->TextureId); + IwGxSetMaterial(pCurrentMaterial); + IwGxDrawPrims(IW_GX_TRI_LIST, (uint16*)idx_buffer, pcmd->ElemCount); + } + idx_buffer += pcmd->ElemCount; + } + IwGxFlush(); + } + + // TODO: restore modified state (i.e. mvp matrix) +} + +static const char* ImGui_Marmalade_GetClipboardText(void* /*user_data*/) +{ + if (!s3eClipboardAvailable()) + return NULL; + + if (int size = s3eClipboardGetText(NULL, 0)) + { + if (g_ClipboardText) + delete[] g_ClipboardText; + g_ClipboardText = new char[size]; + g_ClipboardText[0] = '\0'; + s3eClipboardGetText(g_ClipboardText, size); + } + + return g_ClipboardText; +} + +static void ImGui_Marmalade_SetClipboardText(void* /*user_data*/, const char* text) +{ + if (s3eClipboardAvailable()) + s3eClipboardSetText(text); +} + +int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData) +{ + // pEvent->m_Button is of type s3ePointerButton and indicates which mouse + // button was pressed. For touchscreen this should always have the value + // S3E_POINTER_BUTTON_SELECT + s3ePointerEvent* pEvent = (s3ePointerEvent*)SystemData; + + if (pEvent->m_Pressed == 1) + { + if (pEvent->m_Button == S3E_POINTER_BUTTON_LEFTMOUSE) + g_MousePressed[0] = true; + if (pEvent->m_Button == S3E_POINTER_BUTTON_RIGHTMOUSE) + g_MousePressed[1] = true; + if (pEvent->m_Button == S3E_POINTER_BUTTON_MIDDLEMOUSE) + g_MousePressed[2] = true; + if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELUP) + g_MouseWheel += pEvent->m_y; + if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELDOWN) + g_MouseWheel += pEvent->m_y; + } + + return 0; +} + +int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData) +{ + ImGuiIO& io = ImGui::GetIO(); + s3eKeyboardEvent* e = (s3eKeyboardEvent*)SystemData; + if (e->m_Pressed == 1) + io.KeysDown[e->m_Key] = true; + if (e->m_Pressed == 0) + io.KeysDown[e->m_Key] = false; + + io.KeyCtrl = s3eKeyboardGetState(s3eKeyLeftControl) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightControl) == S3E_KEY_STATE_DOWN; + io.KeyShift = s3eKeyboardGetState(s3eKeyLeftShift) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightShift) == S3E_KEY_STATE_DOWN; + io.KeyAlt = s3eKeyboardGetState(s3eKeyLeftAlt) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightAlt) == S3E_KEY_STATE_DOWN; + io.KeySuper = s3eKeyboardGetState(s3eKeyLeftWindows) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightWindows) == S3E_KEY_STATE_DOWN; + + return 0; +} + +int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData) +{ + ImGuiIO& io = ImGui::GetIO(); + s3eKeyboardCharEvent* e = (s3eKeyboardCharEvent*)SystemData; + if ((e->m_Char > 0 && e->m_Char < 0x10000)) + io.AddInputCharacter((unsigned short)e->m_Char); + + return 0; +} + +bool ImGui_Marmalade_CreateDeviceObjects() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + // Upload texture to graphics system + g_FontTexture = new CIwTexture(); + g_FontTexture->SetModifiable(true); + CIwImage& image = g_FontTexture->GetImage(); + image.SetFormat(CIwImage::ARGB_8888); + image.SetWidth(width); + image.SetHeight(height); + image.SetBuffers(); // allocates and own buffers + image.ReadTexels(pixels); + g_FontTexture->SetMipMapping(false); + g_FontTexture->SetFiltering(false); + g_FontTexture->Upload(); + + // Store our identifier + io.Fonts->TexID = (void *)g_FontTexture; + + return true; +} + +void ImGui_Marmalade_InvalidateDeviceObjects() +{ + if (g_ClipboardText) + { + delete[] g_ClipboardText; + g_ClipboardText = NULL; + } + + if (g_FontTexture) + { + delete g_FontTexture; + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture = NULL; + } +} + +bool ImGui_Marmalade_Init(bool install_callbacks) +{ + IwGxInit(); + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = s3eKeyTab; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = s3eKeyLeft; + io.KeyMap[ImGuiKey_RightArrow] = s3eKeyRight; + io.KeyMap[ImGuiKey_UpArrow] = s3eKeyUp; + io.KeyMap[ImGuiKey_DownArrow] = s3eKeyDown; + io.KeyMap[ImGuiKey_PageUp] = s3eKeyPageUp; + io.KeyMap[ImGuiKey_PageDown] = s3eKeyPageDown; + io.KeyMap[ImGuiKey_Home] = s3eKeyHome; + io.KeyMap[ImGuiKey_End] = s3eKeyEnd; + io.KeyMap[ImGuiKey_Delete] = s3eKeyDelete; + io.KeyMap[ImGuiKey_Backspace] = s3eKeyBackspace; + io.KeyMap[ImGuiKey_Enter] = s3eKeyEnter; + io.KeyMap[ImGuiKey_Escape] = s3eKeyEsc; + io.KeyMap[ImGuiKey_A] = s3eKeyA; + io.KeyMap[ImGuiKey_C] = s3eKeyC; + io.KeyMap[ImGuiKey_V] = s3eKeyV; + io.KeyMap[ImGuiKey_X] = s3eKeyX; + io.KeyMap[ImGuiKey_Y] = s3eKeyY; + io.KeyMap[ImGuiKey_Z] = s3eKeyZ; + + io.RenderDrawListsFn = ImGui_Marmalade_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.SetClipboardTextFn = ImGui_Marmalade_SetClipboardText; + io.GetClipboardTextFn = ImGui_Marmalade_GetClipboardText; + + if (install_callbacks) + { + s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, ImGui_Marmalade_PointerButtonEventCallback, 0); + s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, ImGui_Marmalade_KeyCallback, 0); + s3eKeyboardRegister(S3E_KEYBOARD_CHAR_EVENT, ImGui_Marmalade_CharCallback, 0); + } + + return true; +} + +void ImGui_Marmalade_Shutdown() +{ + ImGui_Marmalade_InvalidateDeviceObjects(); + ImGui::Shutdown(); + IwGxTerminate(); +} + +void ImGui_Marmalade_NewFrame() +{ + if (!g_FontTexture) + ImGui_Marmalade_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w = IwGxGetScreenWidth(), h = IwGxGetScreenHeight(); + io.DisplaySize = ImVec2((float)w, (float)h); + // For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui. + io.DisplayFramebufferScale = g_scale; + + // Setup time step + double current_time = s3eTimerGetUST() / 1000.0f; + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); + g_Time = current_time; + + double mouse_x, mouse_y; + mouse_x = s3ePointerGetX(); + mouse_y = s3ePointerGetY(); + io.MousePos = ImVec2((float)mouse_x/g_scale.x, (float)mouse_y/g_scale.y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.) + + for (int i = 0; i < 3; i++) + { + io.MouseDown[i] = g_MousePressed[i] || s3ePointerGetState((s3ePointerButton)i) != S3E_POINTER_STATE_UP; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + g_MousePressed[i] = false; + } + + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; + + // TODO: Hide OS mouse cursor if ImGui is drawing it + // s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1)); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); + + // Show/hide OSD keyboard + if (io.WantTextInput) + { + // Some text input widget is active? + if (!g_osdKeyboardEnabled) + { + g_osdKeyboardEnabled = true; + s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 1); // show OSD keyboard + } + } + else + { + // No text input widget is active + if (g_osdKeyboardEnabled) + { + g_osdKeyboardEnabled = false; + s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 0); // hide OSD keyboard + } + } +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.h b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.h new file mode 100644 index 0000000..5342cb7 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/imgui_impl_marmalade.h @@ -0,0 +1,24 @@ +// ImGui Marmalade binding with IwGx +// In this binding, ImTextureID is used to store a 'CIwTexture*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +// Copyright (C) 2015 by Giovanni Zito +// This file is part of ImGui + +IMGUI_API bool ImGui_Marmalade_Init(bool install_callbacks); +IMGUI_API void ImGui_Marmalade_Shutdown(); +IMGUI_API void ImGui_Marmalade_NewFrame(); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_Marmalade_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_Marmalade_CreateDeviceObjects(); + +// callbacks (installed by default if you enable 'install_callbacks' during initialization) +// You can also handle inputs yourself and use those as a reference. +IMGUI_API int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData); +IMGUI_API int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData); +IMGUI_API int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData); diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/main.cpp new file mode 100644 index 0000000..2b5edb7 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/main.cpp @@ -0,0 +1,100 @@ +// ImGui - standalone example application for Marmalade +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +// Copyright (C) 2015 by Giovanni Zito +// This file is part of ImGui + +#include +#include "imgui_impl_marmalade.h" +#include + +#include +#include +#include + +int main(int, char**) +{ + // Setup ImGui binding + ImGui_Marmalade_Init(true); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + while (true) + { + if (s3eDeviceCheckQuitRequest()) + break; + + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + s3eKeyboardUpdate(); + s3ePointerUpdate(); + ImGui_Marmalade_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + IwGxSetColClear(clear_color.x * 255, clear_color.y * 255, clear_color.z * 255, clear_color.w * 255); + IwGxClear(); + ImGui::Render(); + IwGxSwapBuffers(); + + s3eDeviceYield(0); + } + + // Cleanup + ImGui_Marmalade_Shutdown(); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/marmalade_example.mkb b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/marmalade_example.mkb new file mode 100644 index 0000000..9f8ea44 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/marmalade_example/marmalade_example.mkb @@ -0,0 +1,44 @@ +#!/usr/bin/env mkb + +# ImGui - standalone example application for Marmalade +# Copyright (C) 2015 by Giovanni Zito +# This file is part of ImGui +# https://github.com/ocornut/imgui + +define IMGUI_DISABLE_INCLUDE_IMCONFIG_H +define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS +define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS +define _snprintf=snprintf + +options +{ + optimise-speed=1 +} + +includepaths +{ + ../.. +} + +subprojects +{ + iwgx +} + +files +{ + (.) + ["imgui"] + ../../imgui.cpp + ../../imgui_demo.cpp + ../../imgui_draw.cpp + ../../imconfig.h + ../../imgui.h + ../../imgui_internal.h + + ["imgui","Marmalade binding"] + imgui_impl_marmalade.h + imgui_impl_marmalade.cpp + main.cpp + +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/null_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/null_example/build_win32.bat new file mode 100644 index 0000000..7bb7823 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/null_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. *.cpp ..\..\*.cpp /FeDebug/null_example.exe /FoDebug/ /link gdi32.lib shell32.lib diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/null_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/null_example/main.cpp new file mode 100644 index 0000000..04c1bda --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/null_example/main.cpp @@ -0,0 +1,33 @@ +// ImGui - null/dummy example application (compile and link imgui with no inputs, no outputs) +#include +#include + +int main(int, char**) +{ + ImGuiIO& io = ImGui::GetIO(); + + // Build atlas + unsigned char* tex_pixels = NULL; + int tex_w, tex_h; + io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h); + + for (int n = 0; n < 50; n++) + { + printf("NewFrame() %d\n", n); + io.DisplaySize = ImVec2(1920, 1080); + io.DeltaTime = 1.0f / 60.0f; + ImGui::NewFrame(); + + static float f = 0.0f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::ShowDemoWindow(NULL); + + ImGui::Render(); + } + + printf("Shutdown()\n"); + ImGui::Shutdown(); + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/Makefile b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/Makefile new file mode 100644 index 0000000..932aebe --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/Makefile @@ -0,0 +1,60 @@ +# +# Cross Platform Makefile +# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X +# +# +# if you using Mac OS X: +# You'll need glfw +# http://www.glfw.org +# + +#CXX = g++ + +EXE = opengl2_example +OBJS = main.o imgui_impl_glfw.o +OBJS += ../../imgui.o ../../imgui_demo.o ../../imgui_draw.o + +UNAME_S := $(shell uname -s) + + +ifeq ($(UNAME_S), Linux) #LINUX + ECHO_MESSAGE = "Linux" + LIBS = -lGL `pkg-config --static --libs glfw3` + + CXXFLAGS = -I../../ `pkg-config --cflags glfw3` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(UNAME_S), Darwin) #APPLE + ECHO_MESSAGE = "Mac OS X" + LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo + #LIBS += -L/usr/local/lib -lglfw3 + LIBS += -L/usr/local/lib -lglfw + + CXXFLAGS = -I../../ -I/usr/local/include + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) + ECHO_MESSAGE = "Windows" + LIBS = -lglfw3 -lgdi32 -lopengl32 -limm32 + + CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +.cpp.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +all: $(EXE) + @echo Build complete for $(ECHO_MESSAGE) + +$(EXE): $(OBJS) + $(CXX) -o $(EXE) $(OBJS) $(CXXFLAGS) $(LIBS) + +clean: + rm $(EXE) $(OBJS) + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/build_win32.bat new file mode 100644 index 0000000..28e6752 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include *.cpp ..\..\*.cpp /FeDebug/opengl2_example.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.cpp new file mode 100644 index 0000000..364d928 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.cpp @@ -0,0 +1,307 @@ +// ImGui GLFW binding with OpenGL (legacy, fixed pipeline) +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the opengl3_example/ folder** +// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. +// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more +// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might +// confuse your GPU driver. +// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include +#include "imgui_impl_glfw.h" + +// GLFW +#include +#ifdef _WIN32 +#undef APIENTRY +#define GLFW_EXPOSE_NATIVE_WIN32 +#define GLFW_EXPOSE_NATIVE_WGL +#include +#endif + +// Data +static GLFWwindow* g_Window = NULL; +static double g_Time = 0.0f; +static bool g_MouseJustPressed[3] = { false, false, false }; +static float g_MouseWheel = 0.0f; +static GLuint g_FontTexture = 0; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +void ImGui_ImplGlfwGL2_RenderDrawLists(ImDrawData* draw_data) +// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so. +// If text or lines are blurry when integrating ImGui in your engine: in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +{ + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + + // We are using the OpenGL fixed pipeline to make the example code simpler to read! + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill. + GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); + GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); + GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnable(GL_TEXTURE_2D); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound + + // Setup viewport, orthographic projection matrix + glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + // Render command lists + #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; + const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; + glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, pos))); + glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, uv))); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, col))); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer); + } + idx_buffer += pcmd->ElemCount; + } + } + #undef OFFSETOF + + // Restore modified state + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + glPolygonMode(GL_FRONT, last_polygon_mode[0]); glPolygonMode(GL_BACK, last_polygon_mode[1]); + glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); + glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); +} + +static const char* ImGui_ImplGlfwGL2_GetClipboardText(void* user_data) +{ + return glfwGetClipboardString((GLFWwindow*)user_data); +} + +static void ImGui_ImplGlfwGL2_SetClipboardText(void* user_data, const char* text) +{ + glfwSetClipboardString((GLFWwindow*)user_data, text); +} + +void ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/) +{ + if (action == GLFW_PRESS && button >= 0 && button < 3) + g_MouseJustPressed[button] = true; +} + +void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset) +{ + g_MouseWheel += (float)yoffset; // Use fractional mouse wheel. +} + +void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow*, int key, int, int action, int mods) +{ + ImGuiIO& io = ImGui::GetIO(); + if (action == GLFW_PRESS) + io.KeysDown[key] = true; + if (action == GLFW_RELEASE) + io.KeysDown[key] = false; + + (void)mods; // Modifiers are not reliable across systems + io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL]; + io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT]; + io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT]; + io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER]; +} + +void ImGui_ImplGlfwGL2_CharCallback(GLFWwindow*, unsigned int c) +{ + ImGuiIO& io = ImGui::GetIO(); + if (c > 0 && c < 0x10000) + io.AddInputCharacter((unsigned short)c); +} + +bool ImGui_ImplGlfwGL2_CreateDeviceObjects() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. + + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGenTextures(1, &g_FontTexture); + glBindTexture(GL_TEXTURE_2D, g_FontTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + // Store our identifier + io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); + + return true; +} + +void ImGui_ImplGlfwGL2_InvalidateDeviceObjects() +{ + if (g_FontTexture) + { + glDeleteTextures(1, &g_FontTexture); + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture = 0; + } +} + +bool ImGui_ImplGlfwGL2_Init(GLFWwindow* window, bool install_callbacks) +{ + g_Window = window; + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; + io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; + io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; + io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; + io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; + io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; + io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; + io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; + io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; + io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; + io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; + io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; + io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; + io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; + io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; + + io.RenderDrawListsFn = ImGui_ImplGlfwGL2_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.SetClipboardTextFn = ImGui_ImplGlfwGL2_SetClipboardText; + io.GetClipboardTextFn = ImGui_ImplGlfwGL2_GetClipboardText; + io.ClipboardUserData = g_Window; +#ifdef _WIN32 + io.ImeWindowHandle = glfwGetWin32Window(g_Window); +#endif + + if (install_callbacks) + { + glfwSetMouseButtonCallback(window, ImGui_ImplGlfwGL2_MouseButtonCallback); + glfwSetScrollCallback(window, ImGui_ImplGlfwGL2_ScrollCallback); + glfwSetKeyCallback(window, ImGui_ImplGlfwGL2_KeyCallback); + glfwSetCharCallback(window, ImGui_ImplGlfwGL2_CharCallback); + } + + return true; +} + +void ImGui_ImplGlfwGL2_Shutdown() +{ + ImGui_ImplGlfwGL2_InvalidateDeviceObjects(); + ImGui::Shutdown(); +} + +void ImGui_ImplGlfwGL2_NewFrame() +{ + if (!g_FontTexture) + ImGui_ImplGlfwGL2_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + glfwGetWindowSize(g_Window, &w, &h); + glfwGetFramebufferSize(g_Window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); + + // Setup time step + double current_time = glfwGetTime(); + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); + g_Time = current_time; + + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) + if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) + { + if (io.WantMoveMouse) + { + glfwSetCursorPos(g_Window, (double)io.MousePos.x, (double)io.MousePos.y); // Set mouse position if requested by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation) + } + else + { + double mouse_x, mouse_y; + glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Get mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.) + } + } + else + { + io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX); + } + + for (int i = 0; i < 3; i++) + { + // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0; + g_MouseJustPressed[i] = false; + } + + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; + + // Hide OS mouse cursor if ImGui is drawing it + glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.h b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.h new file mode 100644 index 0000000..d04a84f --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/imgui_impl_glfw.h @@ -0,0 +1,29 @@ +// ImGui GLFW binding with OpenGL (legacy, fixed pipeline) +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the opengl3_example/ folder** +// See imgui_impl_glfw.cpp for details. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct GLFWwindow; + +IMGUI_API bool ImGui_ImplGlfwGL2_Init(GLFWwindow* window, bool install_callbacks); +IMGUI_API void ImGui_ImplGlfwGL2_Shutdown(); +IMGUI_API void ImGui_ImplGlfwGL2_NewFrame(); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplGlfwGL2_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplGlfwGL2_CreateDeviceObjects(); + +// GLFW callbacks (registered by default to GLFW if you enable 'install_callbacks' during initialization) +// Provided here if you want to chain callbacks yourself. You may also handle inputs yourself and use those as a reference. +IMGUI_API void ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); +IMGUI_API void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); +IMGUI_API void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); +IMGUI_API void ImGui_ImplGlfwGL2_CharCallback(GLFWwindow* window, unsigned int c); diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/main.cpp new file mode 100644 index 0000000..ef098e5 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/main.cpp @@ -0,0 +1,111 @@ +// ImGui - standalone example application for GLFW + OpenGL2, using legacy fixed pipeline +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the opengl3_example/ folder** +// See imgui_impl_glfw.cpp for details. + +#include +#include "imgui_impl_glfw.h" +#include +#include + +static void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +int main(int, char**) +{ + // Setup window + glfwSetErrorCallback(error_callback); + if (!glfwInit()) + return 1; + GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL); + glfwMakeContextCurrent(window); + glfwSwapInterval(1); // Enable vsync + + // Setup ImGui binding + ImGui_ImplGlfwGL2_Init(window, true); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + while (!glfwWindowShouldClose(window)) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + glfwPollEvents(); + ImGui_ImplGlfwGL2_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + int display_w, display_h; + glfwGetFramebufferSize(window, &display_w, &display_h); + glViewport(0, 0, display_w, display_h); + glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound, but prefer using the GL3+ code. + ImGui::Render(); + glfwSwapBuffers(window); + } + + // Cleanup + ImGui_ImplGlfwGL2_Shutdown(); + glfwTerminate(); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj new file mode 100644 index 0000000..bea2104 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj @@ -0,0 +1,169 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {9CDA7840-B7A5-496D-A527-E95571496D18} + opengl2_example + + + + Application + true + MultiByte + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + + Level4 + Disabled + $(SolutionDir)\libs\glfw\include;..\..;%(AdditionalIncludeDirectories) + + + true + $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + msvcrt.lib + + + + + Level4 + Disabled + $(SolutionDir)\libs\glfw\include;..\..;%(AdditionalIncludeDirectories) + + + true + $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + msvcrt.lib + + + + + Level4 + MaxSpeed + true + true + $(SolutionDir)\libs\glfw\include;..\..;%(AdditionalIncludeDirectories) + + + true + true + true + $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + + + + + + + Level4 + MaxSpeed + true + true + $(SolutionDir)\libs\glfw\include;..\..;%(AdditionalIncludeDirectories) + + + true + true + true + $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj.filters b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj.filters new file mode 100644 index 0000000..f2282bf --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl2_example/opengl2_example.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {c336cfe3-f0c4-464c-9ef0-a9e17a7ff222} + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + sources + + + imgui + + + sources + + + imgui + + + imgui + + + + + imgui + + + imgui + + + sources + + + imgui + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/Makefile b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/Makefile new file mode 100644 index 0000000..32343ed --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/Makefile @@ -0,0 +1,63 @@ +# +# Cross Platform Makefile +# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X +# +# +# You will need GLFW (http://www.glfw.org) +# +# apt-get install libglfw-dev # Linux +# brew install glfw # Mac OS X +# pacman -S --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-glfw # MSYS2 +# + +#CXX = g++ + +EXE = opengl3_example +OBJS = main.o imgui_impl_glfw_gl3.o +OBJS += ../../imgui.o ../../imgui_demo.o ../../imgui_draw.o +OBJS += ../libs/gl3w/GL/gl3w.o + +UNAME_S := $(shell uname -s) + + +ifeq ($(UNAME_S), Linux) #LINUX + ECHO_MESSAGE = "Linux" + LIBS = -lGL `pkg-config --static --libs glfw3` + + CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(UNAME_S), Darwin) #APPLE + ECHO_MESSAGE = "Mac OS X" + LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo + #LIBS += -L/usr/local/lib -lglfw3 + LIBS += -L/usr/local/lib -lglfw + + CXXFLAGS = -I../../ -I../libs/gl3w -I/usr/local/include + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) + ECHO_MESSAGE = "Windows" + LIBS = -lglfw3 -lgdi32 -lopengl32 -limm32 + + CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + + +.cpp.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +all: $(EXE) + @echo Build complete for $(ECHO_MESSAGE) + +$(EXE): $(OBJS) + $(CXX) -o $(EXE) $(OBJS) $(CXXFLAGS) $(LIBS) + +clean: + rm $(EXE) $(OBJS) diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/build_win32.bat new file mode 100644 index 0000000..9311591 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include /I ..\libs\gl3w *.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /FeDebug/opengl_example3.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.cpp new file mode 100644 index 0000000..7d924fc --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -0,0 +1,419 @@ +// ImGui GLFW binding with OpenGL3 + shaders +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include +#include "imgui_impl_glfw_gl3.h" + +// GL3W/GLFW +#include // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. +#include +#ifdef _WIN32 +#undef APIENTRY +#define GLFW_EXPOSE_NATIVE_WIN32 +#define GLFW_EXPOSE_NATIVE_WGL +#include +#endif + +// Data +static GLFWwindow* g_Window = NULL; +static double g_Time = 0.0f; +static bool g_MouseJustPressed[3] = { false, false, false }; +static float g_MouseWheel = 0.0f; +static GLuint g_FontTexture = 0; +static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; +static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; +static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0; +static unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so. +// If text or lines are blurry when integrating ImGui in your engine: in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data) +{ + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + + // Backup GL state + GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture); + glActiveTexture(GL_TEXTURE0); + GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); + GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler); + GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); + GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); + GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); + GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); + GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); + GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); + GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb); + GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb); + GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha); + GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha); + GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb); + GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha); + GLboolean last_enable_blend = glIsEnabled(GL_BLEND); + GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE); + GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST); + GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST); + + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + // Setup viewport, orthographic projection matrix + glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); + const float ortho_projection[4][4] = + { + { 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f }, + { 0.0f, 0.0f, -1.0f, 0.0f }, + {-1.0f, 1.0f, 0.0f, 1.0f }, + }; + glUseProgram(g_ShaderHandle); + glUniform1i(g_AttribLocationTex, 0); + glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); + glBindVertexArray(g_VaoHandle); + glBindSampler(0, 0); // Rely on combined texture/sampler state. + + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + const ImDrawIdx* idx_buffer_offset = 0; + + glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); + } + idx_buffer_offset += pcmd->ElemCount; + } + } + + // Restore modified GL state + glUseProgram(last_program); + glBindTexture(GL_TEXTURE_2D, last_texture); + glBindSampler(0, last_sampler); + glActiveTexture(last_active_texture); + glBindVertexArray(last_vertex_array); + glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); + glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); + glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha); + if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); + if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); + if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); + if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); + glPolygonMode(GL_FRONT_AND_BACK, last_polygon_mode[0]); + glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); + glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); +} + +static const char* ImGui_ImplGlfwGL3_GetClipboardText(void* user_data) +{ + return glfwGetClipboardString((GLFWwindow*)user_data); +} + +static void ImGui_ImplGlfwGL3_SetClipboardText(void* user_data, const char* text) +{ + glfwSetClipboardString((GLFWwindow*)user_data, text); +} + +void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/) +{ + if (action == GLFW_PRESS && button >= 0 && button < 3) + g_MouseJustPressed[button] = true; +} + +void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset) +{ + g_MouseWheel += (float)yoffset; // Use fractional mouse wheel. +} + +void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods) +{ + ImGuiIO& io = ImGui::GetIO(); + if (action == GLFW_PRESS) + io.KeysDown[key] = true; + if (action == GLFW_RELEASE) + io.KeysDown[key] = false; + + (void)mods; // Modifiers are not reliable across systems + io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL]; + io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT]; + io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT]; + io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER]; +} + +void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c) +{ + ImGuiIO& io = ImGui::GetIO(); + if (c > 0 && c < 0x10000) + io.AddInputCharacter((unsigned short)c); +} + +bool ImGui_ImplGlfwGL3_CreateFontsTexture() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. + + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGenTextures(1, &g_FontTexture); + glBindTexture(GL_TEXTURE_2D, g_FontTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + // Store our identifier + io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); + + return true; +} + +bool ImGui_ImplGlfwGL3_CreateDeviceObjects() +{ + // Backup GL state + GLint last_texture, last_array_buffer, last_vertex_array; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); + glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); + + const GLchar *vertex_shader = + "#version 330\n" + "uniform mat4 ProjMtx;\n" + "in vec2 Position;\n" + "in vec2 UV;\n" + "in vec4 Color;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Color;\n" + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Color = Color;\n" + " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" + "}\n"; + + const GLchar* fragment_shader = + "#version 330\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Color;\n" + "out vec4 Out_Color;\n" + "void main()\n" + "{\n" + " Out_Color = Frag_Color * texture( Texture, Frag_UV.st);\n" + "}\n"; + + g_ShaderHandle = glCreateProgram(); + g_VertHandle = glCreateShader(GL_VERTEX_SHADER); + g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(g_VertHandle, 1, &vertex_shader, 0); + glShaderSource(g_FragHandle, 1, &fragment_shader, 0); + glCompileShader(g_VertHandle); + glCompileShader(g_FragHandle); + glAttachShader(g_ShaderHandle, g_VertHandle); + glAttachShader(g_ShaderHandle, g_FragHandle); + glLinkProgram(g_ShaderHandle); + + g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture"); + g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx"); + g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position"); + g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV"); + g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color"); + + glGenBuffers(1, &g_VboHandle); + glGenBuffers(1, &g_ElementsHandle); + + glGenVertexArrays(1, &g_VaoHandle); + glBindVertexArray(g_VaoHandle); + glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); + glEnableVertexAttribArray(g_AttribLocationPosition); + glEnableVertexAttribArray(g_AttribLocationUV); + glEnableVertexAttribArray(g_AttribLocationColor); + +#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) + glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); +#undef OFFSETOF + + ImGui_ImplGlfwGL3_CreateFontsTexture(); + + // Restore modified GL state + glBindTexture(GL_TEXTURE_2D, last_texture); + glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); + glBindVertexArray(last_vertex_array); + + return true; +} + +void ImGui_ImplGlfwGL3_InvalidateDeviceObjects() +{ + if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle); + if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); + if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle); + g_VaoHandle = g_VboHandle = g_ElementsHandle = 0; + + if (g_ShaderHandle && g_VertHandle) glDetachShader(g_ShaderHandle, g_VertHandle); + if (g_VertHandle) glDeleteShader(g_VertHandle); + g_VertHandle = 0; + + if (g_ShaderHandle && g_FragHandle) glDetachShader(g_ShaderHandle, g_FragHandle); + if (g_FragHandle) glDeleteShader(g_FragHandle); + g_FragHandle = 0; + + if (g_ShaderHandle) glDeleteProgram(g_ShaderHandle); + g_ShaderHandle = 0; + + if (g_FontTexture) + { + glDeleteTextures(1, &g_FontTexture); + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture = 0; + } +} + +bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks) +{ + g_Window = window; + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; + io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; + io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; + io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; + io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; + io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; + io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; + io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; + io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; + io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; + io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; + io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; + io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; + io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; + io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; + + io.RenderDrawListsFn = ImGui_ImplGlfwGL3_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.SetClipboardTextFn = ImGui_ImplGlfwGL3_SetClipboardText; + io.GetClipboardTextFn = ImGui_ImplGlfwGL3_GetClipboardText; + io.ClipboardUserData = g_Window; +#ifdef _WIN32 + io.ImeWindowHandle = glfwGetWin32Window(g_Window); +#endif + + if (install_callbacks) + { + glfwSetMouseButtonCallback(window, ImGui_ImplGlfwGL3_MouseButtonCallback); + glfwSetScrollCallback(window, ImGui_ImplGlfwGL3_ScrollCallback); + glfwSetKeyCallback(window, ImGui_ImplGlfwGL3_KeyCallback); + glfwSetCharCallback(window, ImGui_ImplGlfwGL3_CharCallback); + } + + return true; +} + +void ImGui_ImplGlfwGL3_Shutdown() +{ + ImGui_ImplGlfwGL3_InvalidateDeviceObjects(); + ImGui::Shutdown(); +} + +void ImGui_ImplGlfwGL3_NewFrame() +{ + if (!g_FontTexture) + ImGui_ImplGlfwGL3_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + glfwGetWindowSize(g_Window, &w, &h); + glfwGetFramebufferSize(g_Window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); + + // Setup time step + double current_time = glfwGetTime(); + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); + g_Time = current_time; + + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) + if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) + { + if (io.WantMoveMouse) + { + glfwSetCursorPos(g_Window, (double)io.MousePos.x, (double)io.MousePos.y); // Set mouse position if requested by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation) + } + else + { + double mouse_x, mouse_y; + glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Get mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.) + } + } + else + { + io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX); + } + + for (int i = 0; i < 3; i++) + { + // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0; + g_MouseJustPressed[i] = false; + } + + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; + + // Hide OS mouse cursor if ImGui is drawing it + glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.h b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.h new file mode 100644 index 0000000..5f30439 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/imgui_impl_glfw_gl3.h @@ -0,0 +1,27 @@ +// ImGui GLFW binding with OpenGL3 + shaders +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct GLFWwindow; + +IMGUI_API bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks); +IMGUI_API void ImGui_ImplGlfwGL3_Shutdown(); +IMGUI_API void ImGui_ImplGlfwGL3_NewFrame(); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplGlfwGL3_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplGlfwGL3_CreateDeviceObjects(); + +// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization) +// Provided here if you want to chain callbacks. +// You can also handle inputs yourself and use those as a reference. +IMGUI_API void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); +IMGUI_API void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); +IMGUI_API void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); +IMGUI_API void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c); diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/main.cpp new file mode 100644 index 0000000..9e9a3fb --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/main.cpp @@ -0,0 +1,115 @@ +// ImGui - standalone example application for GLFW + OpenGL 3, using programmable pipeline +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) + +#include +#include "imgui_impl_glfw_gl3.h" +#include +#include // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. +#include + +static void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +int main(int, char**) +{ + // Setup window + glfwSetErrorCallback(error_callback); + if (!glfwInit()) + return 1; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#if __APPLE__ + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif + GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL); + glfwMakeContextCurrent(window); + glfwSwapInterval(1); // Enable vsync + gl3wInit(); + + // Setup ImGui binding + ImGui_ImplGlfwGL3_Init(window, true); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + while (!glfwWindowShouldClose(window)) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + glfwPollEvents(); + ImGui_ImplGlfwGL3_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + int display_w, display_h; + glfwGetFramebufferSize(window, &display_w, &display_h); + glViewport(0, 0, display_w, display_h); + glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + ImGui::Render(); + glfwSwapBuffers(window); + } + + // Cleanup + ImGui_ImplGlfwGL3_Shutdown(); + glfwTerminate(); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj new file mode 100644 index 0000000..8d8bec9 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj @@ -0,0 +1,172 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {4a1fb5ea-22f5-42a8-ab92-1d2df5d47fb9} + opengl3_example + + + + Application + true + MultiByte + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + + Level4 + Disabled + $(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;..\..;%(AdditionalIncludeDirectories) + + + true + $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + msvcrt.lib + + + + + Level4 + Disabled + $(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;..\..;%(AdditionalIncludeDirectories) + + + true + $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + msvcrt.lib + + + + + Level4 + MaxSpeed + true + true + $(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;..\..;%(AdditionalIncludeDirectories) + + + true + true + true + $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + + + + + + + Level4 + MaxSpeed + true + true + $(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;..\..;%(AdditionalIncludeDirectories) + + + true + true + true + $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) + opengl32.lib;glfw3.lib;%(AdditionalDependencies) + Console + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj.filters b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj.filters new file mode 100644 index 0000000..f19cd16 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/opengl3_example/opengl3_example.vcxproj.filters @@ -0,0 +1,58 @@ + + + + + {20b90ce4-7fcb-4731-b9a0-075f875de82d} + + + {f18ab499-84e1-499f-8eff-9754361e0e52} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {42f99867-3108-43b8-99d0-fabefaf1f2e3} + + + + + sources + + + imgui + + + sources + + + gl3w + + + imgui + + + imgui + + + + + imgui + + + imgui + + + sources + + + gl3w + + + gl3w + + + imgui + + + + + + \ No newline at end of file diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/README.md b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/README.md new file mode 100644 index 0000000..deae323 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/README.md @@ -0,0 +1,22 @@ + +# How to Build + +- On Windows with Visual Studio's CLI + +``` +set SDL2DIR=path_to_your_sdl2_folder +cl /Zi /MD /I %SDL2DIR%\include /I ..\.. main.cpp imgui_impl_sdl.cpp ..\..\imgui*.cpp /link /LIBPATH:%SDL2DIR%\lib SDL2.lib SDL2main.lib opengl32.lib /subsystem:console +``` + +- On Linux and similar Unixes + +``` +c++ `sdl2-config --cflags` -I ../.. main.cpp imgui_impl_sdl.cpp ../../imgui*.cpp `sdl2-config --libs` -lGL -o sdl2example +``` + +- On Mac OS X + +``` +brew install sdl2 +c++ `sdl2-config --cflags` -I ../.. main.cpp imgui_impl_sdl.cpp ../../imgui*.cpp `sdl2-config --libs` -framework OpenGl -o sdl2example +``` diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/build_win32.bat new file mode 100644 index 0000000..3cf81e6 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I ..\libs\gl3w /I %SDL_DIR%\include main.cpp imgui_impl_sdl.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /FeDebug/sdl_opengl2_example.exe /FoDebug/ /link /libpath:%SDL_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.cpp new file mode 100644 index 0000000..66f3ed5 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.cpp @@ -0,0 +1,296 @@ +// ImGui SDL2 binding with OpenGL (legacy, fixed pipeline) +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the sdl_opengl3_example/ folder** +// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. +// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more +// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might +// confuse your GPU driver. +// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include +#include +#include +#include +#include "imgui_impl_sdl.h" + +// Data +static double g_Time = 0.0f; +static bool g_MousePressed[3] = { false, false, false }; +static float g_MouseWheel = 0.0f; +static GLuint g_FontTexture = 0; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so. +// If text or lines are blurry when integrating ImGui in your engine: in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data) +{ + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + + // We are using the OpenGL fixed pipeline to make the example code simpler to read! + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill. + GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); + GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); + GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnable(GL_TEXTURE_2D); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound + + // Setup viewport, orthographic projection matrix + glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + // Render command lists + #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; + const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; + glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, pos))); + glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, uv))); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, col))); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer); + } + idx_buffer += pcmd->ElemCount; + } + } + #undef OFFSETOF + + // Restore modified state + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + glPolygonMode(GL_FRONT, last_polygon_mode[0]); glPolygonMode(GL_BACK, last_polygon_mode[1]); + glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); + glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); +} + +static const char* ImGui_ImplSdl_GetClipboardText(void*) +{ + return SDL_GetClipboardText(); +} + +static void ImGui_ImplSdl_SetClipboardText(void*, const char* text) +{ + SDL_SetClipboardText(text); +} + +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +bool ImGui_ImplSdlGL2_ProcessEvent(SDL_Event* event) +{ + ImGuiIO& io = ImGui::GetIO(); + switch (event->type) + { + case SDL_MOUSEWHEEL: + { + if (event->wheel.y > 0) + g_MouseWheel = 1; + if (event->wheel.y < 0) + g_MouseWheel = -1; + return true; + } + case SDL_MOUSEBUTTONDOWN: + { + if (event->button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true; + if (event->button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true; + if (event->button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true; + return true; + } + case SDL_TEXTINPUT: + { + io.AddInputCharactersUTF8(event->text.text); + return true; + } + case SDL_KEYDOWN: + case SDL_KEYUP: + { + int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK; + io.KeysDown[key] = (event->type == SDL_KEYDOWN); + io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); + io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0); + io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0); + io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0); + return true; + } + } + return false; +} + +bool ImGui_ImplSdlGL2_CreateDeviceObjects() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height); + + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGenTextures(1, &g_FontTexture); + glBindTexture(GL_TEXTURE_2D, g_FontTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels); + + // Store our identifier + io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); + + return true; +} + +void ImGui_ImplSdlGL2_InvalidateDeviceObjects() +{ + if (g_FontTexture) + { + glDeleteTextures(1, &g_FontTexture); + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture = 0; + } +} + +bool ImGui_ImplSdlGL2_Init(SDL_Window* window) +{ + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP; + io.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN; + io.KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP; + io.KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN; + io.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME; + io.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END; + io.KeyMap[ImGuiKey_Delete] = SDLK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = SDLK_RETURN; + io.KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE; + io.KeyMap[ImGuiKey_A] = SDLK_a; + io.KeyMap[ImGuiKey_C] = SDLK_c; + io.KeyMap[ImGuiKey_V] = SDLK_v; + io.KeyMap[ImGuiKey_X] = SDLK_x; + io.KeyMap[ImGuiKey_Y] = SDLK_y; + io.KeyMap[ImGuiKey_Z] = SDLK_z; + + io.RenderDrawListsFn = ImGui_ImplSdl_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.SetClipboardTextFn = ImGui_ImplSdl_SetClipboardText; + io.GetClipboardTextFn = ImGui_ImplSdl_GetClipboardText; + io.ClipboardUserData = NULL; + +#ifdef _WIN32 + SDL_SysWMinfo wmInfo; + SDL_VERSION(&wmInfo.version); + SDL_GetWindowWMInfo(window, &wmInfo); + io.ImeWindowHandle = wmInfo.info.win.window; +#else + (void)window; +#endif + + return true; +} + +void ImGui_ImplSdlGL2_Shutdown() +{ + ImGui_ImplSdlGL2_InvalidateDeviceObjects(); + ImGui::Shutdown(); +} + +void ImGui_ImplSdlGL2_NewFrame(SDL_Window *window) +{ + if (!g_FontTexture) + ImGui_ImplSdlGL2_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + SDL_GetWindowSize(window, &w, &h); + SDL_GL_GetDrawableSize(window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); + + // Setup time step + Uint32 time = SDL_GetTicks(); + double current_time = time / 1000.0; + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); + g_Time = current_time; + + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent()) + int mx, my; + Uint32 mouseMask = SDL_GetMouseState(&mx, &my); + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) + io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + else + io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX); + + io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0; + io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0; + g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false; + + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; + + // Hide OS mouse cursor if ImGui is drawing it + SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.h b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.h new file mode 100644 index 0000000..32d7bc0 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/imgui_impl_sdl.h @@ -0,0 +1,24 @@ +// ImGui SDL2 binding with OpenGL (legacy, fixed pipeline) +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the sdl_opengl3_example/ folder** +// See imgui_impl_sdl.cpp for details. + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct SDL_Window; +typedef union SDL_Event SDL_Event; + +IMGUI_API bool ImGui_ImplSdlGL2_Init(SDL_Window* window); +IMGUI_API void ImGui_ImplSdlGL2_Shutdown(); +IMGUI_API void ImGui_ImplSdlGL2_NewFrame(SDL_Window* window); +IMGUI_API bool ImGui_ImplSdlGL2_ProcessEvent(SDL_Event* event); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplSdlGL2_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplSdlGL2_CreateDeviceObjects(); diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/main.cpp new file mode 100644 index 0000000..1396fcc --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl2_example/main.cpp @@ -0,0 +1,124 @@ +// ImGui - standalone example application for SDL2 + OpenGL +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the sdl_opengl3_example/ folder** +// See imgui_impl_sdl.cpp for details. + +#include +#include "imgui_impl_sdl.h" +#include +#include +#include + +int main(int, char**) +{ + // Setup SDL + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + // Setup window + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_DisplayMode current; + SDL_GetCurrentDisplayMode(0, ¤t); + SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); + SDL_GLContext glcontext = SDL_GL_CreateContext(window); + + // Setup ImGui binding + ImGui_ImplSdlGL2_Init(window); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + bool done = false; + while (!done) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSdlGL2_ProcessEvent(&event); + if (event.type == SDL_QUIT) + done = true; + } + ImGui_ImplSdlGL2_NewFrame(window); + + // 1. Show a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y); + glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound + ImGui::Render(); + SDL_GL_SwapWindow(window); + } + + // Cleanup + ImGui_ImplSdlGL2_Shutdown(); + SDL_GL_DeleteContext(glcontext); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/Makefile b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/Makefile new file mode 100644 index 0000000..364ca12 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/Makefile @@ -0,0 +1,61 @@ +# +# Cross Platform Makefile +# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X +# +# +# You will need SDL2 (http://www.libsdl.org) +# +# apt-get install libsdl2-dev # Linux +# brew install sdl2 # Mac OS X +# pacman -S mingw-w64-i686-SDL # MSYS2 +# + +#CXX = g++ + +EXE = sdl_opengl3_example +OBJS = main.o imgui_impl_sdl_gl3.o +OBJS += ../../imgui.o ../../imgui_demo.o ../../imgui_draw.o +OBJS += ../libs/gl3w/GL/gl3w.o + +UNAME_S := $(shell uname -s) + + +ifeq ($(UNAME_S), Linux) #LINUX + ECHO_MESSAGE = "Linux" + LIBS = -lGL -ldl `sdl2-config --libs` + + CXXFLAGS = -I../../ -I../libs/gl3w `sdl2-config --cflags` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(UNAME_S), Darwin) #APPLE + ECHO_MESSAGE = "Mac OS X" + LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs` + + CXXFLAGS = -I../../ -I../libs/gl3w -I/usr/local/include `sdl2-config --cflags` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + +ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) + ECHO_MESSAGE = "Windows" + LIBS = -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2` + + CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags sdl2` + CXXFLAGS += -Wall -Wformat + CFLAGS = $(CXXFLAGS) +endif + + +.cpp.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +all: $(EXE) + @echo Build complete for $(ECHO_MESSAGE) + +$(EXE): $(OBJS) + $(CXX) -o $(EXE) $(OBJS) $(CXXFLAGS) $(LIBS) + +clean: + rm $(EXE) $(OBJS) diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/README.md b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/README.md new file mode 100644 index 0000000..a982ff5 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/README.md @@ -0,0 +1,22 @@ + +# How to Build + +- On Windows with Visual Studio's CLI + +``` +set SDL2DIR=path_to_your_sdl2_folder +cl /Zi /MD /I ..\.. /I ..\libs\gl3w /I %SDL2DIR%\include main.cpp imgui_impl_sdl_gl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /link /libpath:%SDL2DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console +``` + +- On Linux and similar Unixes + +``` +c++ `sdl2-config --cflags` -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdl_gl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -lGL -ldl -o sdl2example +``` + +- On Mac OS X + +``` +brew install sdl2 +c++ `sdl2-config --cflags` -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdl_gl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -framework OpenGl -framework CoreFoundation -o sdl2example +``` diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/build_win32.bat new file mode 100644 index 0000000..4356754 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I ..\libs\gl3w /I %SDL_DIR%\include main.cpp imgui_impl_sdl_gl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /FeDebug/sdl_opengl3_example.exe /FoDebug/ /link /libpath:%SDL_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp new file mode 100644 index 0000000..68e27a6 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -0,0 +1,407 @@ +// ImGui SDL2 binding with OpenGL3 +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include "imgui.h" +#include "imgui_impl_sdl_gl3.h" + +// SDL,GL3W +#include +#include +#include // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. + +// Data +static double g_Time = 0.0f; +static bool g_MousePressed[3] = { false, false, false }; +static float g_MouseWheel = 0.0f; +static GLuint g_FontTexture = 0; +static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; +static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; +static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0; +static unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so. +// If text or lines are blurry when integrating ImGui in your engine: in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_ImplSdlGL3_RenderDrawLists(ImDrawData* draw_data) +{ + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + + // Backup GL state + GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture); + glActiveTexture(GL_TEXTURE0); + GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); + GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler); + GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); + GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); + GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); + GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); + GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); + GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); + GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb); + GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb); + GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha); + GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha); + GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb); + GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha); + GLboolean last_enable_blend = glIsEnabled(GL_BLEND); + GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE); + GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST); + GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST); + + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + // Setup viewport, orthographic projection matrix + glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); + const float ortho_projection[4][4] = + { + { 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f }, + { 0.0f, 0.0f, -1.0f, 0.0f }, + {-1.0f, 1.0f, 0.0f, 1.0f }, + }; + glUseProgram(g_ShaderHandle); + glUniform1i(g_AttribLocationTex, 0); + glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); + glBindVertexArray(g_VaoHandle); + glBindSampler(0, 0); // Rely on combined texture/sampler state. + + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + const ImDrawIdx* idx_buffer_offset = 0; + + glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); + } + idx_buffer_offset += pcmd->ElemCount; + } + } + + // Restore modified GL state + glUseProgram(last_program); + glBindTexture(GL_TEXTURE_2D, last_texture); + glBindSampler(0, last_sampler); + glActiveTexture(last_active_texture); + glBindVertexArray(last_vertex_array); + glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); + glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); + glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha); + if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); + if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); + if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); + if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); + glPolygonMode(GL_FRONT_AND_BACK, last_polygon_mode[0]); + glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); + glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); +} + +static const char* ImGui_ImplSdlGL3_GetClipboardText(void*) +{ + return SDL_GetClipboardText(); +} + +static void ImGui_ImplSdlGL3_SetClipboardText(void*, const char* text) +{ + SDL_SetClipboardText(text); +} + +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event) +{ + ImGuiIO& io = ImGui::GetIO(); + switch (event->type) + { + case SDL_MOUSEWHEEL: + { + if (event->wheel.y > 0) + g_MouseWheel = 1; + if (event->wheel.y < 0) + g_MouseWheel = -1; + return true; + } + case SDL_MOUSEBUTTONDOWN: + { + if (event->button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true; + if (event->button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true; + if (event->button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true; + return true; + } + case SDL_TEXTINPUT: + { + io.AddInputCharactersUTF8(event->text.text); + return true; + } + case SDL_KEYDOWN: + case SDL_KEYUP: + { + int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK; + io.KeysDown[key] = (event->type == SDL_KEYDOWN); + io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); + io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0); + io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0); + io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0); + return true; + } + } + return false; +} + +void ImGui_ImplSdlGL3_CreateFontsTexture() +{ + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader. + + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGenTextures(1, &g_FontTexture); + glBindTexture(GL_TEXTURE_2D, g_FontTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + // Store our identifier + io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); +} + +bool ImGui_ImplSdlGL3_CreateDeviceObjects() +{ + // Backup GL state + GLint last_texture, last_array_buffer, last_vertex_array; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); + glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); + + const GLchar *vertex_shader = + "#version 330\n" + "uniform mat4 ProjMtx;\n" + "in vec2 Position;\n" + "in vec2 UV;\n" + "in vec4 Color;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Color;\n" + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Color = Color;\n" + " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" + "}\n"; + + const GLchar* fragment_shader = + "#version 330\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Color;\n" + "out vec4 Out_Color;\n" + "void main()\n" + "{\n" + " Out_Color = Frag_Color * texture( Texture, Frag_UV.st);\n" + "}\n"; + + g_ShaderHandle = glCreateProgram(); + g_VertHandle = glCreateShader(GL_VERTEX_SHADER); + g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(g_VertHandle, 1, &vertex_shader, 0); + glShaderSource(g_FragHandle, 1, &fragment_shader, 0); + glCompileShader(g_VertHandle); + glCompileShader(g_FragHandle); + glAttachShader(g_ShaderHandle, g_VertHandle); + glAttachShader(g_ShaderHandle, g_FragHandle); + glLinkProgram(g_ShaderHandle); + + g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture"); + g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx"); + g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position"); + g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV"); + g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color"); + + glGenBuffers(1, &g_VboHandle); + glGenBuffers(1, &g_ElementsHandle); + + glGenVertexArrays(1, &g_VaoHandle); + glBindVertexArray(g_VaoHandle); + glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); + glEnableVertexAttribArray(g_AttribLocationPosition); + glEnableVertexAttribArray(g_AttribLocationUV); + glEnableVertexAttribArray(g_AttribLocationColor); + +#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) + glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); +#undef OFFSETOF + + ImGui_ImplSdlGL3_CreateFontsTexture(); + + // Restore modified GL state + glBindTexture(GL_TEXTURE_2D, last_texture); + glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); + glBindVertexArray(last_vertex_array); + + return true; +} + +void ImGui_ImplSdlGL3_InvalidateDeviceObjects() +{ + if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle); + if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); + if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle); + g_VaoHandle = g_VboHandle = g_ElementsHandle = 0; + + if (g_ShaderHandle && g_VertHandle) glDetachShader(g_ShaderHandle, g_VertHandle); + if (g_VertHandle) glDeleteShader(g_VertHandle); + g_VertHandle = 0; + + if (g_ShaderHandle && g_FragHandle) glDetachShader(g_ShaderHandle, g_FragHandle); + if (g_FragHandle) glDeleteShader(g_FragHandle); + g_FragHandle = 0; + + if (g_ShaderHandle) glDeleteProgram(g_ShaderHandle); + g_ShaderHandle = 0; + + if (g_FontTexture) + { + glDeleteTextures(1, &g_FontTexture); + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture = 0; + } +} + +bool ImGui_ImplSdlGL3_Init(SDL_Window* window) +{ + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP; + io.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN; + io.KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP; + io.KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN; + io.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME; + io.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END; + io.KeyMap[ImGuiKey_Delete] = SDLK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = SDLK_RETURN; + io.KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE; + io.KeyMap[ImGuiKey_A] = SDLK_a; + io.KeyMap[ImGuiKey_C] = SDLK_c; + io.KeyMap[ImGuiKey_V] = SDLK_v; + io.KeyMap[ImGuiKey_X] = SDLK_x; + io.KeyMap[ImGuiKey_Y] = SDLK_y; + io.KeyMap[ImGuiKey_Z] = SDLK_z; + + io.RenderDrawListsFn = ImGui_ImplSdlGL3_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.SetClipboardTextFn = ImGui_ImplSdlGL3_SetClipboardText; + io.GetClipboardTextFn = ImGui_ImplSdlGL3_GetClipboardText; + io.ClipboardUserData = NULL; + +#ifdef _WIN32 + SDL_SysWMinfo wmInfo; + SDL_VERSION(&wmInfo.version); + SDL_GetWindowWMInfo(window, &wmInfo); + io.ImeWindowHandle = wmInfo.info.win.window; +#else + (void)window; +#endif + + return true; +} + +void ImGui_ImplSdlGL3_Shutdown() +{ + ImGui_ImplSdlGL3_InvalidateDeviceObjects(); + ImGui::Shutdown(); +} + +void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window) +{ + if (!g_FontTexture) + ImGui_ImplSdlGL3_CreateDeviceObjects(); + + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + SDL_GetWindowSize(window, &w, &h); + SDL_GL_GetDrawableSize(window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); + + // Setup time step + Uint32 time = SDL_GetTicks(); + double current_time = time / 1000.0; + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f); + g_Time = current_time; + + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent()) + int mx, my; + Uint32 mouseMask = SDL_GetMouseState(&mx, &my); + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) + io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + else + io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); + + io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0; + io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0; + g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false; + + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; + + // Hide OS mouse cursor if ImGui is drawing it + SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h new file mode 100644 index 0000000..5438186 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h @@ -0,0 +1,21 @@ +// ImGui SDL2 binding with OpenGL3 +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +struct SDL_Window; +typedef union SDL_Event SDL_Event; + +IMGUI_API bool ImGui_ImplSdlGL3_Init(SDL_Window* window); +IMGUI_API void ImGui_ImplSdlGL3_Shutdown(); +IMGUI_API void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window); +IMGUI_API bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event); + +// Use if you want to reset your rendering device without losing ImGui state. +IMGUI_API void ImGui_ImplSdlGL3_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplSdlGL3_CreateDeviceObjects(); diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/main.cpp new file mode 100644 index 0000000..7ee6038 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/sdl_opengl3_example/main.cpp @@ -0,0 +1,123 @@ +// ImGui - standalone example application for SDL2 + OpenGL +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) + +#include +#include "imgui_impl_sdl_gl3.h" +#include +#include // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. +#include + +int main(int, char**) +{ + // Setup SDL + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + // Setup window + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_DisplayMode current; + SDL_GetCurrentDisplayMode(0, ¤t); + SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); + SDL_GLContext glcontext = SDL_GL_CreateContext(window); + gl3wInit(); + + // Setup ImGui binding + ImGui_ImplSdlGL3_Init(window); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + bool done = false; + while (!done) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSdlGL3_ProcessEvent(&event); + if (event.type == SDL_QUIT) + done = true; + } + ImGui_ImplSdlGL3_NewFrame(window); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + // Rendering + glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y); + glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + ImGui::Render(); + SDL_GL_SwapWindow(window); + } + + // Cleanup + ImGui_ImplSdlGL3_Shutdown(); + SDL_GL_DeleteContext(glcontext); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win32.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win32.bat new file mode 100644 index 0000000..bacb639 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win32.bat @@ -0,0 +1,7 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. + +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include /I %VULKAN_SDK%\include *.cpp ..\..\*.cpp /FeDebug/vulkan_example.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 /libpath:%VULKAN_SDK%\lib32 glfw3.lib opengl32.lib gdi32.lib shell32.lib vulkan-1.lib + +mkdir Release +cl /nologo /Zi /MD /Ox /Oi /I ..\.. /I ..\libs\glfw\include /I %VULKAN_SDK%\include *.cpp ..\..\*.cpp /FeRelease/vulkan_example.exe /FoRelease/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 /libpath:%VULKAN_SDK%\lib32 glfw3.lib opengl32.lib gdi32.lib shell32.lib vulkan-1.lib diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win64.bat b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win64.bat new file mode 100644 index 0000000..71e557b --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/build_win64.bat @@ -0,0 +1,7 @@ +@REM Build for Visual Studio compiler. Run your copy of amd64/vcvars32.bat to setup 64-bit command-line compiler. + +mkdir Debug +cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include /I %VULKAN_SDK%\include *.cpp ..\..\*.cpp /FeDebug/vulkan_example.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-64 /libpath:%VULKAN_SDK%\lib glfw3.lib opengl32.lib gdi32.lib shell32.lib vulkan-1.lib + +mkdir Release +cl /nologo /Zi /MD /Ox /Oi /I ..\.. /I ..\libs\glfw\include /I %VULKAN_SDK%\include *.cpp ..\..\*.cpp /FeRelease/vulkan_example.exe /FoRelease/ /link /LIBPATH:..\libs\glfw\lib-vc2010-64 /libpath:%VULKAN_SDK%\lib glfw3.lib opengl32.lib gdi32.lib shell32.lib vulkan-1.lib diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/gen_spv.sh b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/gen_spv.sh new file mode 100755 index 0000000..e0d7f3b --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/gen_spv.sh @@ -0,0 +1,3 @@ +#!/bin/bash +glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag +glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.frag b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.frag new file mode 100644 index 0000000..313a888 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.frag @@ -0,0 +1,14 @@ +#version 450 core +layout(location = 0) out vec4 fColor; + +layout(set=0, binding=0) uniform sampler2D sTexture; + +layout(location = 0) in struct{ + vec4 Color; + vec2 UV; +} In; + +void main() +{ + fColor = In.Color * texture(sTexture, In.UV.st); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.vert b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.vert new file mode 100644 index 0000000..20b2908 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/glsl_shader.vert @@ -0,0 +1,25 @@ +#version 450 core +layout(location = 0) in vec2 aPos; +layout(location = 1) in vec2 aUV; +layout(location = 2) in vec4 aColor; + +layout(push_constant) uniform uPushConstant{ + vec2 uScale; + vec2 uTranslate; +} pc; + +out gl_PerVertex{ + vec4 gl_Position; +}; + +layout(location = 0) out struct{ + vec4 Color; + vec2 UV; +} Out; + +void main() +{ + Out.Color = aColor; + Out.UV = aUV; + gl_Position = vec4(aPos*pc.uScale+pc.uTranslate, 0, 1); +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp new file mode 100644 index 0000000..1d12e3f --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp @@ -0,0 +1,843 @@ +// ImGui GLFW binding with Vulkan + shaders +// FIXME: Changes of ImTextureID aren't supported by this binding! Please, someone add it! + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 5 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXX_CreateFontsTexture(), ImGui_ImplXXXX_NewFrame(), ImGui_ImplXXXX_Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include + +// GLFW +#define GLFW_INCLUDE_NONE +#define GLFW_INCLUDE_VULKAN +#include +#ifdef _WIN32 +#undef APIENTRY +#define GLFW_EXPOSE_NATIVE_WIN32 +#define GLFW_EXPOSE_NATIVE_WGL +#include +#endif + +#include "imgui_impl_glfw_vulkan.h" + +// GLFW Data +static GLFWwindow* g_Window = NULL; +static double g_Time = 0.0f; +static bool g_MousePressed[3] = { false, false, false }; +static float g_MouseWheel = 0.0f; + +// Vulkan Data +static VkAllocationCallbacks* g_Allocator = NULL; +static VkPhysicalDevice g_Gpu = VK_NULL_HANDLE; +static VkDevice g_Device = VK_NULL_HANDLE; +static VkRenderPass g_RenderPass = VK_NULL_HANDLE; +static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE; +static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE; +static void (*g_CheckVkResult)(VkResult err) = NULL; + +static VkCommandBuffer g_CommandBuffer = VK_NULL_HANDLE; +static size_t g_BufferMemoryAlignment = 256; +static VkPipelineCreateFlags g_PipelineCreateFlags = 0; +static int g_FrameIndex = 0; + +static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE; +static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE; +static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE; +static VkPipeline g_Pipeline = VK_NULL_HANDLE; + +static VkSampler g_FontSampler = VK_NULL_HANDLE; +static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE; +static VkImage g_FontImage = VK_NULL_HANDLE; +static VkImageView g_FontView = VK_NULL_HANDLE; + +static VkDeviceMemory g_VertexBufferMemory[IMGUI_VK_QUEUED_FRAMES] = {}; +static VkDeviceMemory g_IndexBufferMemory[IMGUI_VK_QUEUED_FRAMES] = {}; +static size_t g_VertexBufferSize[IMGUI_VK_QUEUED_FRAMES] = {}; +static size_t g_IndexBufferSize[IMGUI_VK_QUEUED_FRAMES] = {}; +static VkBuffer g_VertexBuffer[IMGUI_VK_QUEUED_FRAMES] = {}; +static VkBuffer g_IndexBuffer[IMGUI_VK_QUEUED_FRAMES] = {}; + +static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE; +static VkBuffer g_UploadBuffer = VK_NULL_HANDLE; + +static uint32_t __glsl_shader_vert_spv[] = +{ + 0x07230203,0x00010000,0x00080001,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015, + 0x0000001b,0x0000001c,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43, + 0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f, + 0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005, + 0x00000019,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000019,0x00000000, + 0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001b,0x00000000,0x00040005,0x0000001c, + 0x736f5061,0x00000000,0x00060005,0x0000001e,0x73755075,0x6e6f4368,0x6e617473,0x00000074, + 0x00050006,0x0000001e,0x00000000,0x61635375,0x0000656c,0x00060006,0x0000001e,0x00000001, + 0x61725475,0x616c736e,0x00006574,0x00030005,0x00000020,0x00006370,0x00040047,0x0000000b, + 0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000002,0x00040047,0x00000015, + 0x0000001e,0x00000001,0x00050048,0x00000019,0x00000000,0x0000000b,0x00000000,0x00030047, + 0x00000019,0x00000002,0x00040047,0x0000001c,0x0000001e,0x00000000,0x00050048,0x0000001e, + 0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001,0x00000023,0x00000008, + 0x00030047,0x0000001e,0x00000002,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002, + 0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040017, + 0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020, + 0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015, + 0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020, + 0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020, + 0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020, + 0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020, + 0x00000017,0x00000003,0x00000008,0x0003001e,0x00000019,0x00000007,0x00040020,0x0000001a, + 0x00000003,0x00000019,0x0004003b,0x0000001a,0x0000001b,0x00000003,0x0004003b,0x00000014, + 0x0000001c,0x00000001,0x0004001e,0x0000001e,0x00000008,0x00000008,0x00040020,0x0000001f, + 0x00000009,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x00040020,0x00000021, + 0x00000009,0x00000008,0x0004002b,0x00000006,0x00000028,0x00000000,0x0004002b,0x00000006, + 0x00000029,0x3f800000,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, + 0x00000005,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012, + 0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016, + 0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018, + 0x00000016,0x0004003d,0x00000008,0x0000001d,0x0000001c,0x00050041,0x00000021,0x00000022, + 0x00000020,0x0000000d,0x0004003d,0x00000008,0x00000023,0x00000022,0x00050085,0x00000008, + 0x00000024,0x0000001d,0x00000023,0x00050041,0x00000021,0x00000025,0x00000020,0x00000013, + 0x0004003d,0x00000008,0x00000026,0x00000025,0x00050081,0x00000008,0x00000027,0x00000024, + 0x00000026,0x00050051,0x00000006,0x0000002a,0x00000027,0x00000000,0x00050051,0x00000006, + 0x0000002b,0x00000027,0x00000001,0x00070050,0x00000007,0x0000002c,0x0000002a,0x0000002b, + 0x00000028,0x00000029,0x00050041,0x00000011,0x0000002d,0x0000001b,0x0000000d,0x0003003e, + 0x0000002d,0x0000002c,0x000100fd,0x00010038 +}; + +static uint32_t __glsl_shader_frag_spv[] = +{ + 0x07230203,0x00010000,0x00080001,0x0000001e,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000d,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000b,0x00000000, + 0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000b,0x00000001, + 0x00005655,0x00030005,0x0000000d,0x00006e49,0x00050005,0x00000016,0x78655473,0x65727574, + 0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x0000001e, + 0x00000000,0x00040047,0x00000016,0x00000022,0x00000000,0x00040047,0x00000016,0x00000021, + 0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006, + 0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003, + 0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006, + 0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,0x0000000c,0x00000001, + 0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,0x0000000e,0x00000020, + 0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,0x00000010,0x00000001, + 0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000, + 0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,0x00000015,0x00000000, + 0x00000014,0x0004003b,0x00000015,0x00000016,0x00000000,0x0004002b,0x0000000e,0x00000018, + 0x00000001,0x00040020,0x00000019,0x00000001,0x0000000a,0x00050036,0x00000002,0x00000004, + 0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000010,0x00000011,0x0000000d, + 0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011,0x0004003d,0x00000014,0x00000017, + 0x00000016,0x00050041,0x00000019,0x0000001a,0x0000000d,0x00000018,0x0004003d,0x0000000a, + 0x0000001b,0x0000001a,0x00050057,0x00000007,0x0000001c,0x00000017,0x0000001b,0x00050085, + 0x00000007,0x0000001d,0x00000012,0x0000001c,0x0003003e,0x00000009,0x0000001d,0x000100fd, + 0x00010038 +}; + +static uint32_t ImGui_ImplGlfwVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits) +{ + VkPhysicalDeviceMemoryProperties prop; + vkGetPhysicalDeviceMemoryProperties(g_Gpu, &prop); + for (uint32_t i = 0; i < prop.memoryTypeCount; i++) + if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1<TotalVtxCount * sizeof(ImDrawVert); + if (!g_VertexBuffer[g_FrameIndex] || g_VertexBufferSize[g_FrameIndex] < vertex_size) + { + if (g_VertexBuffer[g_FrameIndex]) + vkDestroyBuffer(g_Device, g_VertexBuffer[g_FrameIndex], g_Allocator); + if (g_VertexBufferMemory[g_FrameIndex]) + vkFreeMemory(g_Device, g_VertexBufferMemory[g_FrameIndex], g_Allocator); + size_t vertex_buffer_size = ((vertex_size-1) / g_BufferMemoryAlignment+1) * g_BufferMemoryAlignment; + VkBufferCreateInfo buffer_info = {}; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.size = vertex_buffer_size; + buffer_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_VertexBuffer[g_FrameIndex]); + ImGui_ImplGlfwVulkan_VkResult(err); + VkMemoryRequirements req; + vkGetBufferMemoryRequirements(g_Device, g_VertexBuffer[g_FrameIndex], &req); + g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment; + VkMemoryAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + alloc_info.allocationSize = req.size; + alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits); + err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_VertexBufferMemory[g_FrameIndex]); + ImGui_ImplGlfwVulkan_VkResult(err); + err = vkBindBufferMemory(g_Device, g_VertexBuffer[g_FrameIndex], g_VertexBufferMemory[g_FrameIndex], 0); + ImGui_ImplGlfwVulkan_VkResult(err); + g_VertexBufferSize[g_FrameIndex] = vertex_buffer_size; + } + + // Create the Index Buffer: + size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx); + if (!g_IndexBuffer[g_FrameIndex] || g_IndexBufferSize[g_FrameIndex] < index_size) + { + if (g_IndexBuffer[g_FrameIndex]) + vkDestroyBuffer(g_Device, g_IndexBuffer[g_FrameIndex], g_Allocator); + if (g_IndexBufferMemory[g_FrameIndex]) + vkFreeMemory(g_Device, g_IndexBufferMemory[g_FrameIndex], g_Allocator); + size_t index_buffer_size = ((index_size-1) / g_BufferMemoryAlignment+1) * g_BufferMemoryAlignment; + VkBufferCreateInfo buffer_info = {}; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.size = index_buffer_size; + buffer_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_IndexBuffer[g_FrameIndex]); + ImGui_ImplGlfwVulkan_VkResult(err); + VkMemoryRequirements req; + vkGetBufferMemoryRequirements(g_Device, g_IndexBuffer[g_FrameIndex], &req); + g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment; + VkMemoryAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + alloc_info.allocationSize = req.size; + alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits); + err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_IndexBufferMemory[g_FrameIndex]); + ImGui_ImplGlfwVulkan_VkResult(err); + err = vkBindBufferMemory(g_Device, g_IndexBuffer[g_FrameIndex], g_IndexBufferMemory[g_FrameIndex], 0); + ImGui_ImplGlfwVulkan_VkResult(err); + g_IndexBufferSize[g_FrameIndex] = index_buffer_size; + } + + // Upload Vertex and index Data: + { + ImDrawVert* vtx_dst; + ImDrawIdx* idx_dst; + err = vkMapMemory(g_Device, g_VertexBufferMemory[g_FrameIndex], 0, vertex_size, 0, (void**)(&vtx_dst)); + ImGui_ImplGlfwVulkan_VkResult(err); + err = vkMapMemory(g_Device, g_IndexBufferMemory[g_FrameIndex], 0, index_size, 0, (void**)(&idx_dst)); + ImGui_ImplGlfwVulkan_VkResult(err); + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); + memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); + vtx_dst += cmd_list->VtxBuffer.Size; + idx_dst += cmd_list->IdxBuffer.Size; + } + VkMappedMemoryRange range[2] = {}; + range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; + range[0].memory = g_VertexBufferMemory[g_FrameIndex]; + range[0].size = VK_WHOLE_SIZE; + range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; + range[1].memory = g_IndexBufferMemory[g_FrameIndex]; + range[1].size = VK_WHOLE_SIZE; + err = vkFlushMappedMemoryRanges(g_Device, 2, range); + ImGui_ImplGlfwVulkan_VkResult(err); + vkUnmapMemory(g_Device, g_VertexBufferMemory[g_FrameIndex]); + vkUnmapMemory(g_Device, g_IndexBufferMemory[g_FrameIndex]); + } + + // Bind pipeline and descriptor sets: + { + vkCmdBindPipeline(g_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Pipeline); + VkDescriptorSet desc_set[1] = {g_DescriptorSet}; + vkCmdBindDescriptorSets(g_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_PipelineLayout, 0, 1, desc_set, 0, NULL); + } + + // Bind Vertex And Index Buffer: + { + VkBuffer vertex_buffers[1] = {g_VertexBuffer[g_FrameIndex]}; + VkDeviceSize vertex_offset[1] = {0}; + vkCmdBindVertexBuffers(g_CommandBuffer, 0, 1, vertex_buffers, vertex_offset); + vkCmdBindIndexBuffer(g_CommandBuffer, g_IndexBuffer[g_FrameIndex], 0, VK_INDEX_TYPE_UINT16); + } + + // Setup viewport: + { + VkViewport viewport; + viewport.x = 0; + viewport.y = 0; + viewport.width = ImGui::GetIO().DisplaySize.x; + viewport.height = ImGui::GetIO().DisplaySize.y; + viewport.minDepth = 0.0f; + viewport.maxDepth = 1.0f; + vkCmdSetViewport(g_CommandBuffer, 0, 1, &viewport); + } + + // Setup scale and translation: + { + float scale[2]; + scale[0] = 2.0f/io.DisplaySize.x; + scale[1] = 2.0f/io.DisplaySize.y; + float translate[2]; + translate[0] = -1.0f; + translate[1] = -1.0f; + vkCmdPushConstants(g_CommandBuffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale); + vkCmdPushConstants(g_CommandBuffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate); + } + + // Render the command lists: + int vtx_offset = 0; + int idx_offset = 0; + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + VkRect2D scissor; + scissor.offset.x = (int32_t)(pcmd->ClipRect.x) > 0 ? (int32_t)(pcmd->ClipRect.x) : 0; + scissor.offset.y = (int32_t)(pcmd->ClipRect.y) > 0 ? (int32_t)(pcmd->ClipRect.y) : 0; + scissor.extent.width = (uint32_t)(pcmd->ClipRect.z - pcmd->ClipRect.x); + scissor.extent.height = (uint32_t)(pcmd->ClipRect.w - pcmd->ClipRect.y + 1); // FIXME: Why +1 here? + vkCmdSetScissor(g_CommandBuffer, 0, 1, &scissor); + vkCmdDrawIndexed(g_CommandBuffer, pcmd->ElemCount, 1, idx_offset, vtx_offset, 0); + } + idx_offset += pcmd->ElemCount; + } + vtx_offset += cmd_list->VtxBuffer.Size; + } +} + +static const char* ImGui_ImplGlfwVulkan_GetClipboardText(void* user_data) +{ + return glfwGetClipboardString((GLFWwindow*)user_data); +} + +static void ImGui_ImplGlfwVulkan_SetClipboardText(void* user_data, const char* text) +{ + glfwSetClipboardString((GLFWwindow*)user_data, text); +} + +void ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/) +{ + if (action == GLFW_PRESS && button >= 0 && button < 3) + g_MousePressed[button] = true; +} + +void ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset) +{ + g_MouseWheel += (float)yoffset; // Use fractional mouse wheel. +} + +void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow*, int key, int, int action, int mods) +{ + ImGuiIO& io = ImGui::GetIO(); + if (action == GLFW_PRESS) + io.KeysDown[key] = true; + if (action == GLFW_RELEASE) + io.KeysDown[key] = false; + + (void)mods; // Modifiers are not reliable across systems + io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL]; + io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT]; + io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT]; + io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER]; +} + +void ImGui_ImplGlfwVulkan_CharCallback(GLFWwindow*, unsigned int c) +{ + ImGuiIO& io = ImGui::GetIO(); + if (c > 0 && c < 0x10000) + io.AddInputCharacter((unsigned short)c); +} + +bool ImGui_ImplGlfwVulkan_CreateFontsTexture(VkCommandBuffer command_buffer) +{ + ImGuiIO& io = ImGui::GetIO(); + + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + size_t upload_size = width*height*4*sizeof(char); + + VkResult err; + + // Create the Image: + { + VkImageCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + info.imageType = VK_IMAGE_TYPE_2D; + info.format = VK_FORMAT_R8G8B8A8_UNORM; + info.extent.width = width; + info.extent.height = height; + info.extent.depth = 1; + info.mipLevels = 1; + info.arrayLayers = 1; + info.samples = VK_SAMPLE_COUNT_1_BIT; + info.tiling = VK_IMAGE_TILING_OPTIMAL; + info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + err = vkCreateImage(g_Device, &info, g_Allocator, &g_FontImage); + ImGui_ImplGlfwVulkan_VkResult(err); + VkMemoryRequirements req; + vkGetImageMemoryRequirements(g_Device, g_FontImage, &req); + VkMemoryAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + alloc_info.allocationSize = req.size; + alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits); + err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_FontMemory); + ImGui_ImplGlfwVulkan_VkResult(err); + err = vkBindImageMemory(g_Device, g_FontImage, g_FontMemory, 0); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + // Create the Image View: + { + VkImageViewCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + info.image = g_FontImage; + info.viewType = VK_IMAGE_VIEW_TYPE_2D; + info.format = VK_FORMAT_R8G8B8A8_UNORM; + info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + info.subresourceRange.levelCount = 1; + info.subresourceRange.layerCount = 1; + err = vkCreateImageView(g_Device, &info, g_Allocator, &g_FontView); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + // Update the Descriptor Set: + { + VkDescriptorImageInfo desc_image[1] = {}; + desc_image[0].sampler = g_FontSampler; + desc_image[0].imageView = g_FontView; + desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + VkWriteDescriptorSet write_desc[1] = {}; + write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_desc[0].dstSet = g_DescriptorSet; + write_desc[0].descriptorCount = 1; + write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_desc[0].pImageInfo = desc_image; + vkUpdateDescriptorSets(g_Device, 1, write_desc, 0, NULL); + } + + // Create the Upload Buffer: + { + VkBufferCreateInfo buffer_info = {}; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.size = upload_size; + buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_UploadBuffer); + ImGui_ImplGlfwVulkan_VkResult(err); + VkMemoryRequirements req; + vkGetBufferMemoryRequirements(g_Device, g_UploadBuffer, &req); + g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment; + VkMemoryAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + alloc_info.allocationSize = req.size; + alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits); + err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_UploadBufferMemory); + ImGui_ImplGlfwVulkan_VkResult(err); + err = vkBindBufferMemory(g_Device, g_UploadBuffer, g_UploadBufferMemory, 0); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + // Upload to Buffer: + { + char* map = NULL; + err = vkMapMemory(g_Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map)); + ImGui_ImplGlfwVulkan_VkResult(err); + memcpy(map, pixels, upload_size); + VkMappedMemoryRange range[1] = {}; + range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; + range[0].memory = g_UploadBufferMemory; + range[0].size = upload_size; + err = vkFlushMappedMemoryRanges(g_Device, 1, range); + ImGui_ImplGlfwVulkan_VkResult(err); + vkUnmapMemory(g_Device, g_UploadBufferMemory); + } + // Copy to Image: + { + VkImageMemoryBarrier copy_barrier[1] = {}; + copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + copy_barrier[0].image = g_FontImage; + copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copy_barrier[0].subresourceRange.levelCount = 1; + copy_barrier[0].subresourceRange.layerCount = 1; + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, copy_barrier); + + VkBufferImageCopy region = {}; + region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + region.imageSubresource.layerCount = 1; + region.imageExtent.width = width; + region.imageExtent.height = height; + region.imageExtent.depth = 1; + vkCmdCopyBufferToImage(command_buffer, g_UploadBuffer, g_FontImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + + VkImageMemoryBarrier use_barrier[1] = {}; + use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + use_barrier[0].image = g_FontImage; + use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + use_barrier[0].subresourceRange.levelCount = 1; + use_barrier[0].subresourceRange.layerCount = 1; + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, use_barrier); + } + + // Store our identifier + io.Fonts->TexID = (void *)(intptr_t)g_FontImage; + + return true; +} + +bool ImGui_ImplGlfwVulkan_CreateDeviceObjects() +{ + VkResult err; + VkShaderModule vert_module; + VkShaderModule frag_module; + + // Create The Shader Modules: + { + VkShaderModuleCreateInfo vert_info = {}; + vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + vert_info.codeSize = sizeof(__glsl_shader_vert_spv); + vert_info.pCode = (uint32_t*)__glsl_shader_vert_spv; + err = vkCreateShaderModule(g_Device, &vert_info, g_Allocator, &vert_module); + ImGui_ImplGlfwVulkan_VkResult(err); + VkShaderModuleCreateInfo frag_info = {}; + frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + frag_info.codeSize = sizeof(__glsl_shader_frag_spv); + frag_info.pCode = (uint32_t*)__glsl_shader_frag_spv; + err = vkCreateShaderModule(g_Device, &frag_info, g_Allocator, &frag_module); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + if (!g_FontSampler) + { + VkSamplerCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + info.magFilter = VK_FILTER_LINEAR; + info.minFilter = VK_FILTER_LINEAR; + info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + info.minLod = -1000; + info.maxLod = 1000; + info.maxAnisotropy = 1.0f; + err = vkCreateSampler(g_Device, &info, g_Allocator, &g_FontSampler); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + if (!g_DescriptorSetLayout) + { + VkSampler sampler[1] = {g_FontSampler}; + VkDescriptorSetLayoutBinding binding[1] = {}; + binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + binding[0].descriptorCount = 1; + binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + binding[0].pImmutableSamplers = sampler; + VkDescriptorSetLayoutCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + info.bindingCount = 1; + info.pBindings = binding; + err = vkCreateDescriptorSetLayout(g_Device, &info, g_Allocator, &g_DescriptorSetLayout); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + // Create Descriptor Set: + { + VkDescriptorSetAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = g_DescriptorPool; + alloc_info.descriptorSetCount = 1; + alloc_info.pSetLayouts = &g_DescriptorSetLayout; + err = vkAllocateDescriptorSets(g_Device, &alloc_info, &g_DescriptorSet); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + if (!g_PipelineLayout) + { + VkPushConstantRange push_constants[1] = {}; + push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + push_constants[0].offset = sizeof(float) * 0; + push_constants[0].size = sizeof(float) * 4; + VkDescriptorSetLayout set_layout[1] = {g_DescriptorSetLayout}; + VkPipelineLayoutCreateInfo layout_info = {}; + layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + layout_info.setLayoutCount = 1; + layout_info.pSetLayouts = set_layout; + layout_info.pushConstantRangeCount = 1; + layout_info.pPushConstantRanges = push_constants; + err = vkCreatePipelineLayout(g_Device, &layout_info, g_Allocator, &g_PipelineLayout); + ImGui_ImplGlfwVulkan_VkResult(err); + } + + VkPipelineShaderStageCreateInfo stage[2] = {}; + stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + stage[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + stage[0].module = vert_module; + stage[0].pName = "main"; + stage[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + stage[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + stage[1].module = frag_module; + stage[1].pName = "main"; + + VkVertexInputBindingDescription binding_desc[1] = {}; + binding_desc[0].stride = sizeof(ImDrawVert); + binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + VkVertexInputAttributeDescription attribute_desc[3] = {}; + attribute_desc[0].location = 0; + attribute_desc[0].binding = binding_desc[0].binding; + attribute_desc[0].format = VK_FORMAT_R32G32_SFLOAT; + attribute_desc[0].offset = (size_t)(&((ImDrawVert*)0)->pos); + attribute_desc[1].location = 1; + attribute_desc[1].binding = binding_desc[0].binding; + attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT; + attribute_desc[1].offset = (size_t)(&((ImDrawVert*)0)->uv); + attribute_desc[2].location = 2; + attribute_desc[2].binding = binding_desc[0].binding; + attribute_desc[2].format = VK_FORMAT_R8G8B8A8_UNORM; + attribute_desc[2].offset = (size_t)(&((ImDrawVert*)0)->col); + + VkPipelineVertexInputStateCreateInfo vertex_info = {}; + vertex_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_info.vertexBindingDescriptionCount = 1; + vertex_info.pVertexBindingDescriptions = binding_desc; + vertex_info.vertexAttributeDescriptionCount = 3; + vertex_info.pVertexAttributeDescriptions = attribute_desc; + + VkPipelineInputAssemblyStateCreateInfo ia_info = {}; + ia_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + ia_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + VkPipelineViewportStateCreateInfo viewport_info = {}; + viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_info.viewportCount = 1; + viewport_info.scissorCount = 1; + + VkPipelineRasterizationStateCreateInfo raster_info = {}; + raster_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + raster_info.polygonMode = VK_POLYGON_MODE_FILL; + raster_info.cullMode = VK_CULL_MODE_NONE; + raster_info.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + raster_info.lineWidth = 1.0f; + + VkPipelineMultisampleStateCreateInfo ms_info = {}; + ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + VkPipelineColorBlendAttachmentState color_attachment[1] = {}; + color_attachment[0].blendEnable = VK_TRUE; + color_attachment[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + color_attachment[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + color_attachment[0].colorBlendOp = VK_BLEND_OP_ADD; + color_attachment[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + color_attachment[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + color_attachment[0].alphaBlendOp = VK_BLEND_OP_ADD; + color_attachment[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + + VkPipelineDepthStencilStateCreateInfo depth_info = {}; + depth_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + + VkPipelineColorBlendStateCreateInfo blend_info = {}; + blend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + blend_info.attachmentCount = 1; + blend_info.pAttachments = color_attachment; + + VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; + VkPipelineDynamicStateCreateInfo dynamic_state = {}; + dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state.dynamicStateCount = 2; + dynamic_state.pDynamicStates = dynamic_states; + + VkGraphicsPipelineCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + info.flags = g_PipelineCreateFlags; + info.stageCount = 2; + info.pStages = stage; + info.pVertexInputState = &vertex_info; + info.pInputAssemblyState = &ia_info; + info.pViewportState = &viewport_info; + info.pRasterizationState = &raster_info; + info.pMultisampleState = &ms_info; + info.pDepthStencilState = &depth_info; + info.pColorBlendState = &blend_info; + info.pDynamicState = &dynamic_state; + info.layout = g_PipelineLayout; + info.renderPass = g_RenderPass; + err = vkCreateGraphicsPipelines(g_Device, g_PipelineCache, 1, &info, g_Allocator, &g_Pipeline); + ImGui_ImplGlfwVulkan_VkResult(err); + + vkDestroyShaderModule(g_Device, vert_module, g_Allocator); + vkDestroyShaderModule(g_Device, frag_module, g_Allocator); + + return true; +} + +void ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects() +{ + if (g_UploadBuffer) + { + vkDestroyBuffer(g_Device, g_UploadBuffer, g_Allocator); + g_UploadBuffer = VK_NULL_HANDLE; + } + if (g_UploadBufferMemory) + { + vkFreeMemory(g_Device, g_UploadBufferMemory, g_Allocator); + g_UploadBufferMemory = VK_NULL_HANDLE; + } +} + +void ImGui_ImplGlfwVulkan_InvalidateDeviceObjects() +{ + ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects(); + + for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++) + { + if (g_VertexBuffer[i]) { vkDestroyBuffer(g_Device, g_VertexBuffer[i], g_Allocator); g_VertexBuffer[i] = VK_NULL_HANDLE; } + if (g_VertexBufferMemory[i]) { vkFreeMemory(g_Device, g_VertexBufferMemory[i], g_Allocator); g_VertexBufferMemory[i] = VK_NULL_HANDLE; } + if (g_IndexBuffer[i]) { vkDestroyBuffer(g_Device, g_IndexBuffer[i], g_Allocator); g_IndexBuffer[i] = VK_NULL_HANDLE; } + if (g_IndexBufferMemory[i]) { vkFreeMemory(g_Device, g_IndexBufferMemory[i], g_Allocator); g_IndexBufferMemory[i] = VK_NULL_HANDLE; } + } + + if (g_FontView) { vkDestroyImageView(g_Device, g_FontView, g_Allocator); g_FontView = VK_NULL_HANDLE; } + if (g_FontImage) { vkDestroyImage(g_Device, g_FontImage, g_Allocator); g_FontImage = VK_NULL_HANDLE; } + if (g_FontMemory) { vkFreeMemory(g_Device, g_FontMemory, g_Allocator); g_FontMemory = VK_NULL_HANDLE; } + if (g_FontSampler) { vkDestroySampler(g_Device, g_FontSampler, g_Allocator); g_FontSampler = VK_NULL_HANDLE; } + if (g_DescriptorSetLayout) { vkDestroyDescriptorSetLayout(g_Device, g_DescriptorSetLayout, g_Allocator); g_DescriptorSetLayout = VK_NULL_HANDLE; } + if (g_PipelineLayout) { vkDestroyPipelineLayout(g_Device, g_PipelineLayout, g_Allocator); g_PipelineLayout = VK_NULL_HANDLE; } + if (g_Pipeline) { vkDestroyPipeline(g_Device, g_Pipeline, g_Allocator); g_Pipeline = VK_NULL_HANDLE; } +} + +bool ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, bool install_callbacks, ImGui_ImplGlfwVulkan_Init_Data *init_data) +{ + g_Allocator = init_data->allocator; + g_Gpu = init_data->gpu; + g_Device = init_data->device; + g_RenderPass = init_data->render_pass; + g_PipelineCache = init_data->pipeline_cache; + g_DescriptorPool = init_data->descriptor_pool; + g_CheckVkResult = init_data->check_vk_result; + + g_Window = window; + + ImGuiIO& io = ImGui::GetIO(); + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; + io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; + io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; + io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; + io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; + io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; + io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; + io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; + io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; + io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; + io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; + io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; + io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; + io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; + io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; + + io.RenderDrawListsFn = ImGui_ImplGlfwVulkan_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. + io.SetClipboardTextFn = ImGui_ImplGlfwVulkan_SetClipboardText; + io.GetClipboardTextFn = ImGui_ImplGlfwVulkan_GetClipboardText; + io.ClipboardUserData = g_Window; +#ifdef _WIN32 + io.ImeWindowHandle = glfwGetWin32Window(g_Window); +#endif + + if (install_callbacks) + { + glfwSetMouseButtonCallback(window, ImGui_ImplGlfwVulkan_MouseButtonCallback); + glfwSetScrollCallback(window, ImGui_ImplGlfwVulkan_ScrollCallback); + glfwSetKeyCallback(window, ImGui_ImplGlfwVulkan_KeyCallback); + glfwSetCharCallback(window, ImGui_ImplGlfwVulkan_CharCallback); + } + + ImGui_ImplGlfwVulkan_CreateDeviceObjects(); + + return true; +} + +void ImGui_ImplGlfwVulkan_Shutdown() +{ + ImGui_ImplGlfwVulkan_InvalidateDeviceObjects(); + ImGui::Shutdown(); +} + +void ImGui_ImplGlfwVulkan_NewFrame() +{ + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + glfwGetWindowSize(g_Window, &w, &h); + glfwGetFramebufferSize(g_Window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); + + // Setup time step + double current_time = glfwGetTime(); + io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); + g_Time = current_time; + + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) + if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) + { + double mouse_x, mouse_y; + glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.) + } + else + { + io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX); + } + + for (int i = 0; i < 3; i++) + { + io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + g_MousePressed[i] = false; + } + + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; + + // Hide OS mouse cursor if ImGui is drawing it + glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL); + + // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. + ImGui::NewFrame(); +} + +void ImGui_ImplGlfwVulkan_Render(VkCommandBuffer command_buffer) +{ + g_CommandBuffer = command_buffer; + ImGui::Render(); + g_CommandBuffer = VK_NULL_HANDLE; + g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.h b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.h new file mode 100644 index 0000000..4c19e9f --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/imgui_impl_glfw_vulkan.h @@ -0,0 +1,45 @@ +// ImGui GLFW binding with Vulkan + shaders +// FIXME: Changes of ImTextureID aren't supported by this binding! Please, someone add it! + +// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// If you use this binding you'll need to call 5 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXX_CreateFontsTexture(), ImGui_ImplXXXX_NewFrame(), ImGui_ImplXXXX_Render() and ImGui_ImplXXXX_Shutdown(). +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include + +#define GLFW_INCLUDE_VULKAN +#include + +#define IMGUI_VK_QUEUED_FRAMES 2 + +struct ImGui_ImplGlfwVulkan_Init_Data +{ + VkAllocationCallbacks* allocator; + VkPhysicalDevice gpu; + VkDevice device; + VkRenderPass render_pass; + VkPipelineCache pipeline_cache; + VkDescriptorPool descriptor_pool; + void (*check_vk_result)(VkResult err); +}; + +CIMGUI_API bool ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, bool install_callbacks, struct ImGui_ImplGlfwVulkan_Init_Data *init_data); +CIMGUI_API void ImGui_ImplGlfwVulkan_Shutdown(); +CIMGUI_API void ImGui_ImplGlfwVulkan_NewFrame(); +CIMGUI_API void ImGui_ImplGlfwVulkan_Render(VkCommandBuffer command_buffer); + +// Use if you want to reset your rendering device without losing ImGui state. +CIMGUI_API void ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects(); +CIMGUI_API void ImGui_ImplGlfwVulkan_InvalidateDeviceObjects(); +CIMGUI_API bool ImGui_ImplGlfwVulkan_CreateFontsTexture(VkCommandBuffer command_buffer); +CIMGUI_API bool ImGui_ImplGlfwVulkan_CreateDeviceObjects(); + +// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization) +// Provided here if you want to chain callbacks. +// You can also handle inputs yourself and use those as a reference. +CIMGUI_API void ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); +CIMGUI_API void ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); +CIMGUI_API void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); +CIMGUI_API void ImGui_ImplGlfwVulkan_CharCallback(GLFWwindow* window, unsigned int c); + diff --git a/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/main.cpp b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/main.cpp new file mode 100644 index 0000000..6c4ef33 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/examples/vulkan_example/main.cpp @@ -0,0 +1,744 @@ +// ImGui - standalone example application for Glfw + Vulkan, using programmable pipeline +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include + +#include // printf, fprintf +#include // abort +#define GLFW_INCLUDE_NONE +#define GLFW_INCLUDE_VULKAN +#include + +#include "imgui_impl_glfw_vulkan.h" + +#define IMGUI_MAX_POSSIBLE_BACK_BUFFERS 16 +#define IMGUI_UNLIMITED_FRAME_RATE +//#ifdef _DEBUG +//#define IMGUI_VULKAN_DEBUG_REPORT +//#endif + +static VkAllocationCallbacks* g_Allocator = NULL; +static VkInstance g_Instance = VK_NULL_HANDLE; +static VkSurfaceKHR g_Surface = VK_NULL_HANDLE; +static VkPhysicalDevice g_Gpu = VK_NULL_HANDLE; +static VkDevice g_Device = VK_NULL_HANDLE; +static VkSwapchainKHR g_Swapchain = VK_NULL_HANDLE; +static VkRenderPass g_RenderPass = VK_NULL_HANDLE; +static uint32_t g_QueueFamily = 0; +static VkQueue g_Queue = VK_NULL_HANDLE; +static VkDebugReportCallbackEXT g_Debug_Report = VK_NULL_HANDLE; + +static VkSurfaceFormatKHR g_SurfaceFormat; +static VkImageSubresourceRange g_ImageRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; +static VkPresentModeKHR g_PresentMode; + +static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE; +static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE; + +static int fb_width, fb_height; +static uint32_t g_BackbufferIndices[IMGUI_VK_QUEUED_FRAMES]; // keep track of recently rendered swapchain frame indices +static uint32_t g_BackBufferCount = 0; +static VkImage g_BackBuffer[IMGUI_MAX_POSSIBLE_BACK_BUFFERS] = {}; +static VkImageView g_BackBufferView[IMGUI_MAX_POSSIBLE_BACK_BUFFERS] = {}; +static VkFramebuffer g_Framebuffer[IMGUI_MAX_POSSIBLE_BACK_BUFFERS] = {}; + +static uint32_t g_FrameIndex = 0; +static VkCommandPool g_CommandPool[IMGUI_VK_QUEUED_FRAMES]; +static VkCommandBuffer g_CommandBuffer[IMGUI_VK_QUEUED_FRAMES]; +static VkFence g_Fence[IMGUI_VK_QUEUED_FRAMES]; +static VkSemaphore g_PresentCompleteSemaphore[IMGUI_VK_QUEUED_FRAMES]; +static VkSemaphore g_RenderCompleteSemaphore[IMGUI_VK_QUEUED_FRAMES]; + +static VkClearValue g_ClearValue = {}; + +static void check_vk_result(VkResult err) +{ + if (err == 0) return; + printf("VkResult %d\n", err); + if (err < 0) + abort(); +} + +static void resize_vulkan(GLFWwindow* /*window*/, int w, int h) +{ + VkResult err; + VkSwapchainKHR old_swapchain = g_Swapchain; + err = vkDeviceWaitIdle(g_Device); + check_vk_result(err); + + // Destroy old Framebuffer: + for (uint32_t i = 0; i < g_BackBufferCount; i++) + if (g_BackBufferView[i]) + vkDestroyImageView(g_Device, g_BackBufferView[i], g_Allocator); + for (uint32_t i = 0; i < g_BackBufferCount; i++) + if (g_Framebuffer[i]) + vkDestroyFramebuffer(g_Device, g_Framebuffer[i], g_Allocator); + if (g_RenderPass) + vkDestroyRenderPass(g_Device, g_RenderPass, g_Allocator); + + // Create Swapchain: + { + VkSwapchainCreateInfoKHR info = {}; + info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + info.surface = g_Surface; + info.imageFormat = g_SurfaceFormat.format; + info.imageColorSpace = g_SurfaceFormat.colorSpace; + info.imageArrayLayers = 1; + info.imageUsage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + info.presentMode = g_PresentMode; + info.clipped = VK_TRUE; + info.oldSwapchain = old_swapchain; + VkSurfaceCapabilitiesKHR cap; + err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_Gpu, g_Surface, &cap); + check_vk_result(err); + if (cap.maxImageCount > 0) + info.minImageCount = (cap.minImageCount + 2 < cap.maxImageCount) ? (cap.minImageCount + 2) : cap.maxImageCount; + else + info.minImageCount = cap.minImageCount + 2; + + if (cap.currentExtent.width == 0xffffffff) + { + fb_width = w; + fb_height = h; + info.imageExtent.width = fb_width; + info.imageExtent.height = fb_height; + } + else + { + fb_width = cap.currentExtent.width; + fb_height = cap.currentExtent.height; + info.imageExtent.width = fb_width; + info.imageExtent.height = fb_height; + } + err = vkCreateSwapchainKHR(g_Device, &info, g_Allocator, &g_Swapchain); + check_vk_result(err); + err = vkGetSwapchainImagesKHR(g_Device, g_Swapchain, &g_BackBufferCount, NULL); + check_vk_result(err); + err = vkGetSwapchainImagesKHR(g_Device, g_Swapchain, &g_BackBufferCount, g_BackBuffer); + check_vk_result(err); + } + if (old_swapchain) + vkDestroySwapchainKHR(g_Device, old_swapchain, g_Allocator); + + // Create the Render Pass: + { + VkAttachmentDescription attachment = {}; + attachment.format = g_SurfaceFormat.format; + attachment.samples = VK_SAMPLE_COUNT_1_BIT; + attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + VkAttachmentReference color_attachment = {}; + color_attachment.attachment = 0; + color_attachment.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + VkSubpassDescription subpass = {}; + subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + subpass.colorAttachmentCount = 1; + subpass.pColorAttachments = &color_attachment; + VkRenderPassCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + info.attachmentCount = 1; + info.pAttachments = &attachment; + info.subpassCount = 1; + info.pSubpasses = &subpass; + err = vkCreateRenderPass(g_Device, &info, g_Allocator, &g_RenderPass); + check_vk_result(err); + } + + // Create The Image Views + { + VkImageViewCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + info.viewType = VK_IMAGE_VIEW_TYPE_2D; + info.format = g_SurfaceFormat.format; + info.components.r = VK_COMPONENT_SWIZZLE_R; + info.components.g = VK_COMPONENT_SWIZZLE_G; + info.components.b = VK_COMPONENT_SWIZZLE_B; + info.components.a = VK_COMPONENT_SWIZZLE_A; + info.subresourceRange = g_ImageRange; + for (uint32_t i = 0; i < g_BackBufferCount; i++) + { + info.image = g_BackBuffer[i]; + err = vkCreateImageView(g_Device, &info, g_Allocator, &g_BackBufferView[i]); + check_vk_result(err); + } + } + + // Create Framebuffer: + { + VkImageView attachment[1]; + VkFramebufferCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + info.renderPass = g_RenderPass; + info.attachmentCount = 1; + info.pAttachments = attachment; + info.width = fb_width; + info.height = fb_height; + info.layers = 1; + for (uint32_t i = 0; i < g_BackBufferCount; i++) + { + attachment[0] = g_BackBufferView[i]; + err = vkCreateFramebuffer(g_Device, &info, g_Allocator, &g_Framebuffer[i]); + check_vk_result(err); + } + } +} + +#ifdef IMGUI_VULKAN_DEBUG_REPORT +static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report( + VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage, void* pUserData) +{ + printf("[vulkan] ObjectType: %i\nMessage: %s\n\n", objectType, pMessage ); + return VK_FALSE; +} +#endif // IMGUI_VULKAN_DEBUG_REPORT + +static void setup_vulkan(GLFWwindow* window) +{ + VkResult err; + + // Create Vulkan Instance + { + uint32_t extensions_count; + const char** glfw_extensions = glfwGetRequiredInstanceExtensions(&extensions_count); + + VkInstanceCreateInfo create_info = {}; + create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + create_info.enabledExtensionCount = extensions_count; + create_info.ppEnabledExtensionNames = glfw_extensions; + +#ifdef IMGUI_VULKAN_DEBUG_REPORT + // enabling multiple validation layers grouped as lunarg standard validation + const char* layers[] = {"VK_LAYER_LUNARG_standard_validation"}; + create_info.enabledLayerCount = 1; + create_info.ppEnabledLayerNames = layers; + + // need additional storage for char pointer to debug report extension + const char** extensions = (const char**)malloc(sizeof(const char*) * (extensions_count + 1)); + for (size_t i = 0; i < extensions_count; i++) + extensions[i] = glfw_extensions[i]; + extensions[ extensions_count ] = "VK_EXT_debug_report"; + create_info.enabledExtensionCount = extensions_count+1; + create_info.ppEnabledExtensionNames = extensions; +#endif // IMGUI_VULKAN_DEBUG_REPORT + + err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); + check_vk_result(err); + +#ifdef IMGUI_VULKAN_DEBUG_REPORT + free(extensions); + + // create the debug report callback + VkDebugReportCallbackCreateInfoEXT debug_report_ci ={}; + debug_report_ci.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT; + debug_report_ci.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; + debug_report_ci.pfnCallback = debug_report; + debug_report_ci.pUserData = NULL; + + // get the proc address of the function pointer, required for used extensions + PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT = + (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkCreateDebugReportCallbackEXT"); + + err = vkCreateDebugReportCallbackEXT( g_Instance, &debug_report_ci, g_Allocator, &g_Debug_Report ); + check_vk_result(err); +#endif // IMGUI_VULKAN_DEBUG_REPORT + } + + // Create Window Surface + { + err = glfwCreateWindowSurface(g_Instance, window, g_Allocator, &g_Surface); + check_vk_result(err); + } + + // Get GPU + { + uint32_t gpu_count; + err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, NULL); + check_vk_result(err); + + VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count); + err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus); + check_vk_result(err); + + // If a number >1 of GPUs got reported, you should find the best fit GPU for your purpose + // e.g. VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU if available, or with the greatest memory available, etc. + // for sake of simplicity we'll just take the first one, assuming it has a graphics queue family. + g_Gpu = gpus[0]; + free(gpus); + } + + // Get queue + { + uint32_t count; + vkGetPhysicalDeviceQueueFamilyProperties(g_Gpu, &count, NULL); + VkQueueFamilyProperties* queues = (VkQueueFamilyProperties*)malloc(sizeof(VkQueueFamilyProperties) * count); + vkGetPhysicalDeviceQueueFamilyProperties(g_Gpu, &count, queues); + for (uint32_t i = 0; i < count; i++) + { + if (queues[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) + { + g_QueueFamily = i; + break; + } + } + free(queues); + } + + // Check for WSI support + { + VkBool32 res; + vkGetPhysicalDeviceSurfaceSupportKHR(g_Gpu, g_QueueFamily, g_Surface, &res); + if (res != VK_TRUE) + { + fprintf(stderr, "Error no WSI support on physical device 0\n"); + exit(-1); + } + } + + // Get Surface Format + { + // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation + // Assuming that the default behavior is without setting this bit, there is no need for separate Spawchain image and image view format + // additionally several new color spaces were introduced with Vulkan Spec v1.0.40 + // hence we must make sure that a format with the mostly available color space, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, is found and used + uint32_t count; + vkGetPhysicalDeviceSurfaceFormatsKHR(g_Gpu, g_Surface, &count, NULL); + VkSurfaceFormatKHR *formats = (VkSurfaceFormatKHR*)malloc(sizeof(VkSurfaceFormatKHR) * count); + vkGetPhysicalDeviceSurfaceFormatsKHR(g_Gpu, g_Surface, &count, formats); + + // first check if only one format, VK_FORMAT_UNDEFINED, is available, which would imply that any format is available + if (count == 1) + { + if( formats[0].format == VK_FORMAT_UNDEFINED ) + { + g_SurfaceFormat.format = VK_FORMAT_B8G8R8A8_UNORM; + g_SurfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; + } + else + { // no point in searching another format + g_SurfaceFormat = formats[0]; + } + } + else + { + // request several formats, the first found will be used + VkFormat requestSurfaceImageFormat[] = {VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM}; + VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; + bool requestedFound = false; + for (size_t i = 0; i < sizeof(requestSurfaceImageFormat) / sizeof(requestSurfaceImageFormat[0]); i++) + { + if( requestedFound ) { + break; + } + for (uint32_t j = 0; j < count; j++) + { + if (formats[j].format == requestSurfaceImageFormat[i] && formats[j].colorSpace == requestSurfaceColorSpace) + { + g_SurfaceFormat = formats[j]; + requestedFound = true; + } + } + } + + // if none of the requested image formats could be found, use the first available + if (!requestedFound) + g_SurfaceFormat = formats[0]; + } + free(formats); + } + + + // Get Present Mode + { + // Requst a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory +#ifdef IMGUI_UNLIMITED_FRAME_RATE + g_PresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; +#else + g_PresentMode = VK_PRESENT_MODE_FIFO_KHR; +#endif + uint32_t count = 0; + vkGetPhysicalDeviceSurfacePresentModesKHR(g_Gpu, g_Surface, &count, nullptr); + VkPresentModeKHR* presentModes = (VkPresentModeKHR*)malloc(sizeof(VkQueueFamilyProperties) * count); + vkGetPhysicalDeviceSurfacePresentModesKHR(g_Gpu, g_Surface, &count, presentModes); + bool presentModeAvailable = false; + for (size_t i = 0; i < count; i++) + { + if (presentModes[i] == g_PresentMode) + { + presentModeAvailable = true; + break; + } + } + if( !presentModeAvailable ) + g_PresentMode = VK_PRESENT_MODE_FIFO_KHR; // always available + } + + + // Create Logical Device + { + int device_extension_count = 1; + const char* device_extensions[] = {"VK_KHR_swapchain"}; + const uint32_t queue_index = 0; + const uint32_t queue_count = 1; + const float queue_priority[] = {1.0f}; + VkDeviceQueueCreateInfo queue_info[1] = {}; + queue_info[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queue_info[0].queueFamilyIndex = g_QueueFamily; + queue_info[0].queueCount = queue_count; + queue_info[0].pQueuePriorities = queue_priority; + VkDeviceCreateInfo create_info = {}; + create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + create_info.queueCreateInfoCount = sizeof(queue_info)/sizeof(queue_info[0]); + create_info.pQueueCreateInfos = queue_info; + create_info.enabledExtensionCount = device_extension_count; + create_info.ppEnabledExtensionNames = device_extensions; + err = vkCreateDevice(g_Gpu, &create_info, g_Allocator, &g_Device); + check_vk_result(err); + vkGetDeviceQueue(g_Device, g_QueueFamily, queue_index, &g_Queue); + } + + // Create Framebuffers + { + int w, h; + glfwGetFramebufferSize(window, &w, &h); + resize_vulkan(window, w, h); + glfwSetFramebufferSizeCallback(window, resize_vulkan); + } + + // Create Command Buffers + for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++) + { + { + VkCommandPoolCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + info.queueFamilyIndex = g_QueueFamily; + err = vkCreateCommandPool(g_Device, &info, g_Allocator, &g_CommandPool[i]); + check_vk_result(err); + } + { + VkCommandBufferAllocateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + info.commandPool = g_CommandPool[i]; + info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + info.commandBufferCount = 1; + err = vkAllocateCommandBuffers(g_Device, &info, &g_CommandBuffer[i]); + check_vk_result(err); + } + { + VkFenceCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + info.flags = VK_FENCE_CREATE_SIGNALED_BIT; + err = vkCreateFence(g_Device, &info, g_Allocator, &g_Fence[i]); + check_vk_result(err); + } + { + VkSemaphoreCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + err = vkCreateSemaphore(g_Device, &info, g_Allocator, &g_PresentCompleteSemaphore[i]); + check_vk_result(err); + err = vkCreateSemaphore(g_Device, &info, g_Allocator, &g_RenderCompleteSemaphore[i]); + check_vk_result(err); + } + } + + // Create Descriptor Pool + { + VkDescriptorPoolSize pool_size[11] = + { + { VK_DESCRIPTOR_TYPE_SAMPLER, 1000 }, + { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000 }, + { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000 }, + { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000 }, + { VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000 }, + { VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000 }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000 }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000 }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000 }, + { VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000 } + }; + VkDescriptorPoolCreateInfo pool_info = {}; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; + pool_info.maxSets = 1000 * 11; + pool_info.poolSizeCount = 11; + pool_info.pPoolSizes = pool_size; + err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool); + check_vk_result(err); + } +} + +static void cleanup_vulkan() +{ + vkDestroyDescriptorPool(g_Device, g_DescriptorPool, g_Allocator); + for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++) + { + vkDestroyFence(g_Device, g_Fence[i], g_Allocator); + vkFreeCommandBuffers(g_Device, g_CommandPool[i], 1, &g_CommandBuffer[i]); + vkDestroyCommandPool(g_Device, g_CommandPool[i], g_Allocator); + vkDestroySemaphore(g_Device, g_PresentCompleteSemaphore[i], g_Allocator); + vkDestroySemaphore(g_Device, g_RenderCompleteSemaphore[i], g_Allocator); + } + for (uint32_t i = 0; i < g_BackBufferCount; i++) + { + vkDestroyImageView(g_Device, g_BackBufferView[i], g_Allocator); + vkDestroyFramebuffer(g_Device, g_Framebuffer[i], g_Allocator); + } + vkDestroyRenderPass(g_Device, g_RenderPass, g_Allocator); + vkDestroySwapchainKHR(g_Device, g_Swapchain, g_Allocator); + vkDestroySurfaceKHR(g_Instance, g_Surface, g_Allocator); + +#ifdef IMGUI_VULKAN_DEBUG_REPORT + // get the proc address of the function pointer, required for used extensions + auto vkDestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkDestroyDebugReportCallbackEXT"); + vkDestroyDebugReportCallbackEXT(g_Instance, g_Debug_Report, g_Allocator); +#endif // IMGUI_VULKAN_DEBUG_REPORT + + vkDestroyDevice(g_Device, g_Allocator); + vkDestroyInstance(g_Instance, g_Allocator); +} + +static void frame_begin() +{ + VkResult err; + while (true) + { + err = vkWaitForFences(g_Device, 1, &g_Fence[g_FrameIndex], VK_TRUE, 100); + if (err == VK_SUCCESS) break; + if (err == VK_TIMEOUT) continue; + check_vk_result(err); + } + { + err = vkAcquireNextImageKHR(g_Device, g_Swapchain, UINT64_MAX, g_PresentCompleteSemaphore[g_FrameIndex], VK_NULL_HANDLE, &g_BackbufferIndices[g_FrameIndex]); + check_vk_result(err); + } + { + err = vkResetCommandPool(g_Device, g_CommandPool[g_FrameIndex], 0); + check_vk_result(err); + VkCommandBufferBeginInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + err = vkBeginCommandBuffer(g_CommandBuffer[g_FrameIndex], &info); + check_vk_result(err); + } + { + VkRenderPassBeginInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + info.renderPass = g_RenderPass; + info.framebuffer = g_Framebuffer[g_BackbufferIndices[g_FrameIndex]]; + info.renderArea.extent.width = fb_width; + info.renderArea.extent.height = fb_height; + info.clearValueCount = 1; + info.pClearValues = &g_ClearValue; + vkCmdBeginRenderPass(g_CommandBuffer[g_FrameIndex], &info, VK_SUBPASS_CONTENTS_INLINE); + } +} + +static void frame_end() +{ + VkResult err; + vkCmdEndRenderPass(g_CommandBuffer[g_FrameIndex]); + { + VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; + VkSubmitInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + info.waitSemaphoreCount = 1; + info.pWaitSemaphores = &g_PresentCompleteSemaphore[g_FrameIndex]; + info.pWaitDstStageMask = &wait_stage; + info.commandBufferCount = 1; + info.pCommandBuffers = &g_CommandBuffer[g_FrameIndex]; + info.signalSemaphoreCount = 1; + info.pSignalSemaphores = &g_RenderCompleteSemaphore[g_FrameIndex]; + + err = vkEndCommandBuffer(g_CommandBuffer[g_FrameIndex]); + check_vk_result(err); + err = vkResetFences(g_Device, 1, &g_Fence[g_FrameIndex]); + check_vk_result(err); + err = vkQueueSubmit(g_Queue, 1, &info, g_Fence[g_FrameIndex]); + check_vk_result(err); + } +} + +static void frame_present() +{ + VkResult err; + // If IMGUI_UNLIMITED_FRAME_RATE is defined we present the latest but one frame. Otherwise we present the latest rendered frame +#ifdef IMGUI_UNLIMITED_FRAME_RATE + uint32_t PresentIndex = (g_FrameIndex + IMGUI_VK_QUEUED_FRAMES - 1) % IMGUI_VK_QUEUED_FRAMES; +#else + uint32_t PresentIndex = g_FrameIndex; +#endif // IMGUI_UNLIMITED_FRAME_RATE + + VkSwapchainKHR swapchains[1] = {g_Swapchain}; + uint32_t indices[1] = {g_BackbufferIndices[PresentIndex]}; + VkPresentInfoKHR info = {}; + info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + info.waitSemaphoreCount = 1; + info.pWaitSemaphores = &g_RenderCompleteSemaphore[PresentIndex]; + info.swapchainCount = 1; + info.pSwapchains = swapchains; + info.pImageIndices = indices; + err = vkQueuePresentKHR(g_Queue, &info); + check_vk_result(err); + + g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; +} + +static void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +int main(int, char**) +{ + // Setup window + glfwSetErrorCallback(error_callback); + if (!glfwInit()) + return 1; + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui Vulkan example", NULL, NULL); + + // Setup Vulkan + if (!glfwVulkanSupported()) + { + printf("GLFW: Vulkan Not Supported\n"); + return 1; + } + setup_vulkan(window); + + // Setup ImGui binding + ImGui_ImplGlfwVulkan_Init_Data init_data = {}; + init_data.allocator = g_Allocator; + init_data.gpu = g_Gpu; + init_data.device = g_Device; + init_data.render_pass = g_RenderPass; + init_data.pipeline_cache = g_PipelineCache; + init_data.descriptor_pool = g_DescriptorPool; + init_data.check_vk_result = check_vk_result; + ImGui_ImplGlfwVulkan_Init(window, true, &init_data); + + // Setup style + ImGui::StyleColorsClassic(); + //ImGui::StyleColorsDark(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'extra_fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //ImGuiIO& io = ImGui::GetIO(); + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + // Upload Fonts + { + VkResult err; + err = vkResetCommandPool(g_Device, g_CommandPool[g_FrameIndex], 0); + check_vk_result(err); + VkCommandBufferBeginInfo begin_info = {}; + begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + begin_info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + err = vkBeginCommandBuffer(g_CommandBuffer[g_FrameIndex], &begin_info); + check_vk_result(err); + + ImGui_ImplGlfwVulkan_CreateFontsTexture(g_CommandBuffer[g_FrameIndex]); + + VkSubmitInfo end_info = {}; + end_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + end_info.commandBufferCount = 1; + end_info.pCommandBuffers = &g_CommandBuffer[g_FrameIndex]; + err = vkEndCommandBuffer(g_CommandBuffer[g_FrameIndex]); + check_vk_result(err); + err = vkQueueSubmit(g_Queue, 1, &end_info, VK_NULL_HANDLE); + check_vk_result(err); + + err = vkDeviceWaitIdle(g_Device); + check_vk_result(err); + ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects(); + } + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before. + // Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop. + // This is also the reason why frame_end() is split into frame_end() and frame_present(), the later one not being called here. +#ifdef IMGUI_UNLIMITED_FRAME_RATE + ImGui_ImplGlfwVulkan_NewFrame(); + frame_begin(); + ImGui_ImplGlfwVulkan_Render(g_CommandBuffer[g_FrameIndex]); + frame_end(); + g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; +#endif // IMGUI_UNLIMITED_FRAME_RATE + + // Main loop + while (!glfwWindowShouldClose(window)) + { + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + glfwPollEvents(); + ImGui_ImplGlfwVulkan_NewFrame(); + + // 1. Show a simple window. + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". + { + static float f = 0.0f; + ImGui::Text("Hello, world!"); // Some text (you can use a format string too) + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color + if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. + show_demo_window ^= 1; + if (ImGui::Button("Another Window")) + show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + } + + // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello from another window!"); + ImGui::End(); + } + + // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). + if (show_demo_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowDemoWindow(&show_demo_window); + } + + memcpy(&g_ClearValue.color.float32[0], &clear_color, 4 * sizeof(float)); + frame_begin(); + ImGui_ImplGlfwVulkan_Render(g_CommandBuffer[g_FrameIndex]); + frame_end(); + frame_present(); + } + + // Cleanup + VkResult err = vkDeviceWaitIdle(g_Device); + check_vk_result(err); + ImGui_ImplGlfwVulkan_Shutdown(); + cleanup_vulkan(); + glfwTerminate(); + + return 0; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Cousine-Regular.ttf b/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Cousine-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..70a0bf902e1482724d7706f7a0f40d94fe51f4c3 GIT binary patch literal 43912 zcmb@uc|coLzBqo)x%Xx#xgiM&gph=gumlJY_AQqsArvTqLd#MLv_SVl3v{!#Si90y z?Wm*GR;`Xpou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KxaFv4YG}gOxNmxLY7~{-*t~WrA*vUW$z~?^%#O~;)DxqlBQvCKMliDXAQNu9 zXL52kJ<{0ZG^#lg8uu-$_t@k_2w5jRLn9-2b~M=J@V>pH6Cn?#jnG2nhK8pn@!iy( zp%6;hOL~bWun>Bwnib+_zx?r|FFrkCkUWsC@@tY&h>W4oRCQtD{{8#?L)y$Sj7iFm zO3}CfkHylkB2itgBvirm%QE*uQ2yqvLkFiuHDQ^a@sEf0BK=x99!Vl;B+&@khike8 z$^F9k>1C~Q1a`^_(5P?1Q>#+^=@Lle^~v0yo&f=$TpPqBIs@t0C#O>C`QFyGp3W(V zNfY|Wqa`TtEX|b2_UYzQbx#oWpt0u1FXv6%=cgtRXEI%bnhYk^(SPdf1)Qt6TB+fsL!n(`~+mapYNC(ir zPH-*6W4D|DtY9Kb0(Wl;_HG{L1#&PQ>$XhT!n3go%0)bHJ|+YoDqASmLM7OJtYBr} z9I1fkrV3(KgS~VuB0cL^0F&ZssO|=+!zQS|7IZ)xYsaH?uyuIIF8F?XF!QZv8_?Vv z;aS=YwCz@SKKjAiHNXZTre9*m*m3rC_Br-TaM_*(5AXf#arQ7cx_`=UVt2wkp|CUT z^XwLOnf-$6z~}J4ID(k*dIg~_e}%=(<#yZmTG^ibfi}3O-V^{RpjIZlphojmK~9y{gVsV zQK50DDtZ?TO-@+Gpy3w2k}{#7_XYZ!!!HN>ktQ!BHPQHW$uxx6=cqLf7QuT}zNB1z VEBwqml;Z2NCo|~pwK literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/DroidSans.ttf b/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/DroidSans.ttf new file mode 100644 index 0000000000000000000000000000000000000000..767c63ad000e3eea20f3cb7a43ba9f4154ed7a5d GIT binary patch literal 190044 zcmeFaX<$@Uwl=)?IaR0Ts#9|n2}vcDk%S~91QLd%2uTQGp2H9bn1q>t0TC5J5fK~_ z1Vuy|(MF}AKpRnUpl!to(6+s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heu~(*MwJ(Z^Wfx3GEaW3_*t&EQw*5SzoTY$QkMcKSHIPDklZHi%!N zU#Gk18Tu3Y1l>(t_RTlwP5RQ@+Ya2knIt+?^CVV`(v!x0A}-N#*UN@^(^rJE^>#RNhW1Zzq+v zlgiskMc2apesl1)tgFAQa+jV5uz$LdGK9~qQkqSGJ3OkVsJCO=IkqSGJ3OkVs zJCO=IkqSGJ3OkVsJCO=IkqSGJ3OkW1cQRG(WGe4uD(_?}?_?_PWGe4uD(_?}?_?_P aWGe4uD(_?}?_?_PWGe4uD(~cOqW=eI(CQrk literal 0 HcmV?d00001 diff --git a/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/README.txt b/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/README.txt new file mode 100644 index 0000000..2287f6e --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/README.txt @@ -0,0 +1,255 @@ + +The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' (by Tristan Grimmer) that is used by default. +We embed the font in source code so you can use Dear ImGui without any file system access. +You may also load external .TTF/.OTF files. +The files in this folder are suggested fonts, provided as a convenience. +(Note: .OTF support in stb_truetype.h currently doesn't appear to load every font) + +Fonts are rasterized in a single texture at the time of calling either of io.Fonts.GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). +Also read dear imgui FAQ in imgui.cpp! + +In this document: + +- Using Icons +- Fonts Loading Instructions +- FreeType rasterizer, Small font sizes +- Building Custom Glyph Ranges +- Remapping Codepoints +- Embedding Fonts in Source Code +- Credits/Licences for fonts included in this folder +- Links, Other fonts + + +--------------------------------------- + USING ICONS +--------------------------------------- + + Using an icon font (such as FontAwesome: http://fontawesome.io) is an easy and practical way to use icons in your ImGui application. + A common pattern is to merge the icon font within your main font, so you can embed icons directly from your strings without + having to change fonts back and forth. + + To refer to the icon UTF-8 codepoints from your C++ code, you may use those headers files created by Juliette Foucaut: + https://github.com/juliettef/IconFontCppHeaders + + The C++11 version of those files uses the u8"" utf-8 encoding syntax + \u + #define ICON_FA_SEARCH u8"\uf002" + The pre-C++11 version has the values directly encoded as utf-8: + #define ICON_FA_SEARCH "\xEF\x80\x82" + + Example: + + // Merge icons into default tool font + #include "IconsFontAwesome.h" + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->AddFontDefault(); + + ImFontConfig config; + config.MergeMode = true; + static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; + io.Fonts->AddFontFromFileTTF("fonts/fontawesome-webfont.ttf", 13.0f, &config, icon_ranges); + + // Usage, e.g. + ImGui::Text("%s Search", ICON_FA_SEARCH); + + See Links below for other icons fonts and related tools. + + +--------------------------------------- + FONTS LOADING INSTRUCTIONS +--------------------------------------- + + Load default font with: + + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->AddFontDefault(); + + Load .TTF/.OTF file with: + + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); + + For advanced options create a ImFontConfig structure and pass it to the AddFont function (it will be copied internally) + + ImFontConfig config; + config.OversampleH = 3; + config.OversampleV = 1; + config.GlyphExtraSpacing.x = 1.0f; + io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config); + + If you have very large number of glyphs or multiple fonts: + + - Mind the fact that some graphics drivers have texture size limitation. + - Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function). + - You may reduce oversampling, e.g. config.OversampleH = 2 or 1. + - Reduce glyphs ranges, consider calculating them based on your source data if this is possible. + + Combine two fonts into one: + + // Load a first font + io.Fonts->AddFontDefault(); + + // Add character ranges and merge into the previous font + // The ranges array is not copied by the AddFont* functions and is used lazily + // so ensure it is available for duration of font usage + static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope. + ImFontConfig config; + config.MergeMode = true; + io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 18.0f, &config, io.Fonts->GetGlyphRangesJapanese()); + io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges); + + Add a fourth parameter to bake specific font ranges only: + + // Basic Latin, Extended Latin + io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault()); + + // Include full set of about 21000 CJK Unified Ideographs + io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); + + // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs + io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesChinese()); + + Offset font vertically by altering the io.Font->DisplayOffset value: + + ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); + font->DisplayOffset.y += 1; // Render 1 pixel down + + +--------------------------------------- + FREETYPE RASTERIZER, SMALL FONT SIZES +--------------------------------------- + + Dear Imgui uses stb_truetype.h to rasterize fonts (with optional oversampling). + This technique and implementation are not ideal for fonts rendered at _small sizes_, which may appear a little blurry. + There is an implementation of the ImFontAtlas builder using FreeType that you can use: + + https://github.com/ocornut/imgui_club + + FreeType supports auto-hinting which tends to improve the readability of small fonts. + Note that this code currently creates textures that are unoptimally too large (could be fixed with some work) + + +--------------------------------------- + BUILDING CUSTOM GLYPH RANGES +--------------------------------------- + + You can use the ImFontAtlas::GlyphRangesBuilder helper to create glyph ranges based on text input. + For exemple: for a game where your script is known, if you can feed your entire script to it and only build the characters the game needs. + + ImVector ranges; + ImFontAtlas::GlyphRangesBuilder builder; + builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters) + builder.AddChar(0x7262); // Add a specific character + builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges + builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted) + io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, ranges.Data); + + +--------------------------------------- + REMAPPING CODEPOINTS +--------------------------------------- + + All your strings needs to use UTF-8 encoding. Specifying literal in your source code using a local code page (such as CP-923 for Japanese, or CP-1251 for Cyrillic) will NOT work! + In C++11 you can encode a string literal in UTF-8 by using the u8"hello" syntax. Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8. + e.g. + u8"hello" + u8"こんにちは" + You may also try to remap your local codepage characters to their Unicode codepoint using font->AddRemapChar(), but international users may have problems reading/editing your source code. + + +--------------------------------------- + EMBEDDING FONTS IN SOURCE CODE +--------------------------------------- + + Compile and use 'binary_to_compressed_c.cpp' to create a compressed C style array that you can embed in source code. + See the documentation in binary_to_compressed_c.cpp for instruction on how to use the tool. + You may find a precompiled version binary_to_compressed_c.exe for Windows instead of demo binaries package (see README). + The tool optionally used Base85 encoding to reduce the size of _source code_ but the read-only arrays will be about 20% bigger. + + Then load the font with: + + ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, ...); + + Or + + ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_base85, size_pixels, ...); + + +--------------------------------------- + CREDITS/LICENSES FOR FONTS INCLUDED IN THIS FOLDER +--------------------------------------- + + Roboto-Medium.ttf + Apache License 2.0 + by Christian Robertson + https://fonts.google.com/specimen/Roboto + + Cousine-Regular.ttf + by Steve Matteson + Digitized data copyright (c) 2010 Google Corporation. + Licensed under the SIL Open Font License, Version 1.1 + https://fonts.google.com/specimen/Cousine + + DroidSans.ttf + Copyright (c) Steve Matteson + Apache License, version 2.0 + https://www.fontsquirrel.com/fonts/droid-sans + + ProggyClean.ttf + Copyright (c) 2004, 2005 Tristan Grimmer + MIT License + recommended loading setting in ImGui: Size = 13.0, DisplayOffset.Y = +1 + http://www.proggyfonts.net/ + + ProggyTiny.ttf + Copyright (c) 2004, 2005 Tristan Grimmer + MIT License + recommended loading setting in ImGui: Size = 10.0, DisplayOffset.Y = +1 + http://www.proggyfonts.net/ + + Karla-Regular.ttf + Copyright (c) 2012, Jonathan Pinhorn + SIL OPEN FONT LICENSE Version 1.1 + + +--------------------------------------- + LINKS, OTHER FONTS +--------------------------------------- + + (Icons) Icon fonts + https://fortawesome.github.io/Font-Awesome/ + https://github.com/SamBrishes/kenney-icon-font + https://design.google.com/icons/ + You can use https://github.com/juliettef/IconFontCppHeaders for C/C++ header files with name #define to access icon codepoint in source code. + + (Icons) IcoMoon - Custom Icon font builder + https://icomoon.io/app + + (Regular) Open Sans Fonts + https://fonts.google.com/specimen/Open+Sans + + (Regular) Google Noto Fonts (worldwide languages) + https://www.google.com/get/noto/ + + (Monospace) Typefaces for source code beautification + https://github.com/chrissimpkins/codeface + + (Monospace) Programmation fonts + http://s9w.github.io/font_compare/ + + (Monospace) Proggy Programming Fonts + http://upperbounds.net + + (Monospace) Inconsolata + http://www.levien.com/type/myfonts/inconsolata.html + + (Monospace) Adobe Source Code Pro: Monospaced font family for user interface and coding environments + https://github.com/adobe-fonts/source-code-pro + + (Monospace) Monospace/Fixed Width Programmer's Fonts + http://www.lowing.org/fonts/ + + (Japanese) M+ fonts by Coji Morishita are free and include most useful Kanjis you would need. + http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html + + Or use Arial Unicode or other Unicode fonts provided with Windows for full characters coverage (not sure of their licensing). + diff --git a/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Roboto-Medium.ttf b/lib/cimgui-1.53.1/imgui-1.53/extra_fonts/Roboto-Medium.ttf new file mode 100644 index 0000000000000000000000000000000000000000..39c63d7461796094c0b8889ee8fe2706d344a99a GIT binary patch literal 162588 zcmbS!2S8Lu*Y?cZdv|Hd(h(FE5U?Q#0&3KtVndC+H|!NV*t;n95;ex&jeWgh?_CrX zdsjeBOro)%CMtXPf97rh^7?+?|Noe0&z-sV&YU@O=FFKhvl~JQAujk3iLQRLrY*;B z8#;$DyI%-t?^M5K>)MT1mdPfpTRI^n`ZjGD9=XnO&wfJaGQ5@8BdObvxR3_J2=N(6 zi0j23DI@gaPvsK`2|tSaZF&#slQi~ox9x<4RmM9<`*a&VgxC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_qL3#fr$WmVOQHu< z(WOvI#S@$g9dSA4mMd`dfrYUWv*^2^E2f*BII>X3fq9!nUz1Ua;AwleDO7fuWZuUg z^L{>{_hUKi0{j*+IF4a7!47HAJGFgS`BurZ@(HF$dRx_ShEP~MO`{*wUb!kx(@1M7 z&@*W(1tFn{FX>PRWn$!?~zs5707RHsAD?S}i7iP{ZV zf%#B?#pVmX8+P2pE~H&a%I0t<^X=x4*iv{>b19X2QyQgHe;Po8LSo_h#yxL~yC0A7 zDiMl=)MBLFL}&6`zJe>blIQXK=2!6iU@UeEnkQG_x?nEtkx#IE@*d6O^gWuFiE^8+ zKPuOaO*tgJOthPT0uy)-dFC<}xxH)Ov+vsv?1#4A?zJD;eKeE?(=ZxNL-^0Q XDz@2YO+x)8BOh4hvAddFontFromMemoryCompressedTTF() + +// Build with, e.g: +// # cl.exe binary_to_compressed_c.cpp +// # gcc binary_to_compressed_c.cpp +// You can also find a precompiled Windows binary in the binary/demo package available from https://github.com/ocornut/imgui + +// Usage: +// binary_to_compressed_c.exe [-base85] [-nocompress] +// Usage example: +// # binary_to_compressed_c.exe myfont.ttf MyFont > myfont.cpp +// # binary_to_compressed_c.exe -base85 myfont.ttf MyFont > myfont.cpp + +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include + +// stb_compress* from stb.h - declaration +typedef unsigned int stb_uint; +typedef unsigned char stb_uchar; +stb_uint stb_compress(stb_uchar *out,stb_uchar *in,stb_uint len); + +static bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression); + +int main(int argc, char** argv) +{ + if (argc < 3) + { + printf("Syntax: %s [-base85] [-nocompress] \n", argv[0]); + return 0; + } + + int argn = 1; + bool use_base85_encoding = false; + bool use_compression = true; + if (argv[argn][0] == '-') + { + if (strcmp(argv[argn], "-base85") == 0) { use_base85_encoding = true; argn++; } + else if (strcmp(argv[argn], "-nocompress") == 0) { use_compression = false; argn++; } + else + { + printf("Unknown argument: '%s'\n", argv[argn]); + return 1; + } + } + + return binary_to_compressed_c(argv[argn], argv[argn+1], use_base85_encoding, use_compression) ? 0 : 1; +} + +char Encode85Byte(unsigned int x) +{ + x = (x % 85) + 35; + return (x>='\\') ? x+1 : x; +} + +bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression) +{ + // Read file + FILE* f = fopen(filename, "rb"); + if (!f) return false; + int data_sz; + if (fseek(f, 0, SEEK_END) || (data_sz = (int)ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) { fclose(f); return false; } + char* data = new char[data_sz+4]; + if (fread(data, 1, data_sz, f) != (size_t)data_sz) { fclose(f); delete[] data; return false; } + memset((void *)(((char*)data) + data_sz), 0, 4); + fclose(f); + + // Compress + int maxlen = data_sz + 512 + (data_sz >> 2) + sizeof(int); // total guess + char* compressed = use_compression ? new char[maxlen] : data; + int compressed_sz = use_compression ? stb_compress((stb_uchar*)compressed, (stb_uchar*)data, data_sz) : data_sz; + if (use_compression) + memset(compressed + compressed_sz, 0, maxlen - compressed_sz); + + // Output as Base85 encoded + FILE* out = stdout; + fprintf(out, "// File: '%s' (%d bytes)\n", filename, (int)data_sz); + fprintf(out, "// Exported using binary_to_compressed_c.cpp\n"); + const char* compressed_str = use_compression ? "compressed_" : ""; + if (use_base85_encoding) + { + fprintf(out, "static const char %s_%sdata_base85[%d+1] =\n \"", symbol, compressed_str, (int)((compressed_sz+3)/4)*5); + char prev_c = 0; + for (int src_i = 0; src_i < compressed_sz; src_i += 4) + { + // This is made a little more complicated by the fact that ??X sequences are interpreted as trigraphs by old C/C++ compilers. So we need to escape pairs of ??. + unsigned int d = *(unsigned int*)(compressed + src_i); + for (unsigned int n5 = 0; n5 < 5; n5++, d /= 85) + { + char c = Encode85Byte(d); + fprintf(out, (c == '?' && prev_c == '?') ? "\\%c" : "%c", c); + prev_c = c; + } + if ((src_i % 112) == 112-4) + fprintf(out, "\"\n \""); + } + fprintf(out, "\";\n\n"); + } + else + { + fprintf(out, "static const unsigned int %s_%ssize = %d;\n", symbol, compressed_str, (int)compressed_sz); + fprintf(out, "static const unsigned int %s_%sdata[%d/4] =\n{", symbol, compressed_str, (int)((compressed_sz+3)/4)*4); + int column = 0; + for (int i = 0; i < compressed_sz; i += 4) + { + unsigned int d = *(unsigned int*)(compressed + i); + if ((column++ % 12) == 0) + fprintf(out, "\n 0x%08x, ", d); + else + fprintf(out, "0x%08x, ", d); + } + fprintf(out, "\n};\n\n"); + } + + // Cleanup + delete[] data; + if (use_compression) + delete[] compressed; + return true; +} + +// stb_compress* from stb.h - definition + +//////////////////// compressor /////////////////////// + +static stb_uint stb_adler32(stb_uint adler32, stb_uchar *buffer, stb_uint buflen) +{ + const unsigned long ADLER_MOD = 65521; + unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16; + unsigned long blocklen, i; + + blocklen = buflen % 5552; + while (buflen) { + for (i=0; i + 7 < blocklen; i += 8) { + s1 += buffer[0], s2 += s1; + s1 += buffer[1], s2 += s1; + s1 += buffer[2], s2 += s1; + s1 += buffer[3], s2 += s1; + s1 += buffer[4], s2 += s1; + s1 += buffer[5], s2 += s1; + s1 += buffer[6], s2 += s1; + s1 += buffer[7], s2 += s1; + + buffer += 8; + } + + for (; i < blocklen; ++i) + s1 += *buffer++, s2 += s1; + + s1 %= ADLER_MOD, s2 %= ADLER_MOD; + buflen -= blocklen; + blocklen = 5552; + } + return (s2 << 16) + s1; +} + +static unsigned int stb_matchlen(stb_uchar *m1, stb_uchar *m2, stb_uint maxlen) +{ + stb_uint i; + for (i=0; i < maxlen; ++i) + if (m1[i] != m2[i]) return i; + return i; +} + +// simple implementation that just takes the source data in a big block + +static stb_uchar *stb__out; +static FILE *stb__outfile; +static stb_uint stb__outbytes; + +static void stb__write(unsigned char v) +{ + fputc(v, stb__outfile); + ++stb__outbytes; +} + +//#define stb_out(v) (stb__out ? *stb__out++ = (stb_uchar) (v) : stb__write((stb_uchar) (v))) +#define stb_out(v) do { if (stb__out) *stb__out++ = (stb_uchar) (v); else stb__write((stb_uchar) (v)); } while (0) + +static void stb_out2(stb_uint v) { stb_out(v >> 8); stb_out(v); } +static void stb_out3(stb_uint v) { stb_out(v >> 16); stb_out(v >> 8); stb_out(v); } +static void stb_out4(stb_uint v) { stb_out(v >> 24); stb_out(v >> 16); stb_out(v >> 8 ); stb_out(v); } + +static void outliterals(stb_uchar *in, int numlit) +{ + while (numlit > 65536) { + outliterals(in,65536); + in += 65536; + numlit -= 65536; + } + + if (numlit == 0) ; + else if (numlit <= 32) stb_out (0x000020 + numlit-1); + else if (numlit <= 2048) stb_out2(0x000800 + numlit-1); + else /* numlit <= 65536) */ stb_out3(0x070000 + numlit-1); + + if (stb__out) { + memcpy(stb__out,in,numlit); + stb__out += numlit; + } else + fwrite(in, 1, numlit, stb__outfile); +} + +static int stb__window = 0x40000; // 256K + +static int stb_not_crap(int best, int dist) +{ + return ((best > 2 && dist <= 0x00100) + || (best > 5 && dist <= 0x04000) + || (best > 7 && dist <= 0x80000)); +} + +static stb_uint stb__hashsize = 32768; + +// note that you can play with the hashing functions all you +// want without needing to change the decompressor +#define stb__hc(q,h,c) (((h) << 7) + ((h) >> 25) + q[c]) +#define stb__hc2(q,h,c,d) (((h) << 14) + ((h) >> 18) + (q[c] << 7) + q[d]) +#define stb__hc3(q,c,d,e) ((q[c] << 14) + (q[d] << 7) + q[e]) + +static unsigned int stb__running_adler; + +static int stb_compress_chunk(stb_uchar *history, + stb_uchar *start, + stb_uchar *end, + int length, + int *pending_literals, + stb_uchar **chash, + stb_uint mask) +{ + (void)history; + int window = stb__window; + stb_uint match_max; + stb_uchar *lit_start = start - *pending_literals; + stb_uchar *q = start; + +#define STB__SCRAMBLE(h) (((h) + ((h) >> 16)) & mask) + + // stop short of the end so we don't scan off the end doing + // the hashing; this means we won't compress the last few bytes + // unless they were part of something longer + while (q < start+length && q+12 < end) { + int m; + stb_uint h1,h2,h3,h4, h; + stb_uchar *t; + int best = 2, dist=0; + + if (q+65536 > end) + match_max = end-q; + else + match_max = 65536; + +#define stb__nc(b,d) ((d) <= window && ((b) > 9 || stb_not_crap(b,d))) + +#define STB__TRY(t,p) /* avoid retrying a match we already tried */ \ + if (p ? dist != q-t : 1) \ + if ((m = stb_matchlen(t, q, match_max)) > best) \ + if (stb__nc(m,q-(t))) \ + best = m, dist = q - (t) + + // rather than search for all matches, only try 4 candidate locations, + // chosen based on 4 different hash functions of different lengths. + // this strategy is inspired by LZO; hashing is unrolled here using the + // 'hc' macro + h = stb__hc3(q,0, 1, 2); h1 = STB__SCRAMBLE(h); + t = chash[h1]; if (t) STB__TRY(t,0); + h = stb__hc2(q,h, 3, 4); h2 = STB__SCRAMBLE(h); + h = stb__hc2(q,h, 5, 6); t = chash[h2]; if (t) STB__TRY(t,1); + h = stb__hc2(q,h, 7, 8); h3 = STB__SCRAMBLE(h); + h = stb__hc2(q,h, 9,10); t = chash[h3]; if (t) STB__TRY(t,1); + h = stb__hc2(q,h,11,12); h4 = STB__SCRAMBLE(h); + t = chash[h4]; if (t) STB__TRY(t,1); + + // because we use a shared hash table, can only update it + // _after_ we've probed all of them + chash[h1] = chash[h2] = chash[h3] = chash[h4] = q; + + if (best > 2) + assert(dist > 0); + + // see if our best match qualifies + if (best < 3) { // fast path literals + ++q; + } else if (best > 2 && best <= 0x80 && dist <= 0x100) { + outliterals(lit_start, q-lit_start); lit_start = (q += best); + stb_out(0x80 + best-1); + stb_out(dist-1); + } else if (best > 5 && best <= 0x100 && dist <= 0x4000) { + outliterals(lit_start, q-lit_start); lit_start = (q += best); + stb_out2(0x4000 + dist-1); + stb_out(best-1); + } else if (best > 7 && best <= 0x100 && dist <= 0x80000) { + outliterals(lit_start, q-lit_start); lit_start = (q += best); + stb_out3(0x180000 + dist-1); + stb_out(best-1); + } else if (best > 8 && best <= 0x10000 && dist <= 0x80000) { + outliterals(lit_start, q-lit_start); lit_start = (q += best); + stb_out3(0x100000 + dist-1); + stb_out2(best-1); + } else if (best > 9 && dist <= 0x1000000) { + if (best > 65536) best = 65536; + outliterals(lit_start, q-lit_start); lit_start = (q += best); + if (best <= 0x100) { + stb_out(0x06); + stb_out3(dist-1); + stb_out(best-1); + } else { + stb_out(0x04); + stb_out3(dist-1); + stb_out2(best-1); + } + } else { // fallback literals if no match was a balanced tradeoff + ++q; + } + } + + // if we didn't get all the way, add the rest to literals + if (q-start < length) + q = start+length; + + // the literals are everything from lit_start to q + *pending_literals = (q - lit_start); + + stb__running_adler = stb_adler32(stb__running_adler, start, q - start); + return q - start; +} + +static int stb_compress_inner(stb_uchar *input, stb_uint length) +{ + int literals = 0; + stb_uint len,i; + + stb_uchar **chash; + chash = (stb_uchar**) malloc(stb__hashsize * sizeof(stb_uchar*)); + if (chash == NULL) return 0; // failure + for (i=0; i < stb__hashsize; ++i) + chash[i] = NULL; + + // stream signature + stb_out(0x57); stb_out(0xbc); + stb_out2(0); + + stb_out4(0); // 64-bit length requires 32-bit leading 0 + stb_out4(length); + stb_out4(stb__window); + + stb__running_adler = 1; + + len = stb_compress_chunk(input, input, input+length, length, &literals, chash, stb__hashsize-1); + assert(len == length); + + outliterals(input+length - literals, literals); + + free(chash); + + stb_out2(0x05fa); // end opcode + + stb_out4(stb__running_adler); + + return 1; // success +} + +stb_uint stb_compress(stb_uchar *out, stb_uchar *input, stb_uint length) +{ + stb__out = out; + stb__outfile = NULL; + + stb_compress_inner(input, length); + + return stb__out - out; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/imconfig.h b/lib/cimgui-1.53.1/imgui-1.53/imconfig.h new file mode 100644 index 0000000..824a81a --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/imconfig.h @@ -0,0 +1,61 @@ +//----------------------------------------------------------------------------- +// USER IMPLEMENTATION +// This file contains compile-time options for ImGui. +// Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO(). +//----------------------------------------------------------------------------- + +#pragma once + +//---- Define assertion handler. Defaults to calling assert(). +//#define IM_ASSERT(_EXPR) MyAssert(_EXPR) + +//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. +//#define IMGUI_API __declspec( dllexport ) +//#define IMGUI_API __declspec( dllimport ) + +//---- Don't define obsolete functions names. Consider enabling from time to time or when updating to reduce like hood of using already obsolete function/names +//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS + +//---- Include imgui_user.h at the end of imgui.h +//#define IMGUI_INCLUDE_IMGUI_USER_H + +//---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions) +//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS +//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS + +//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) +//---- It is very strongly recommended to NOT disable the demo windows. Please read the comment at the top of imgui_demo.cpp to learn why. +//#define IMGUI_DISABLE_DEMO_WINDOWS + +//---- Don't implement ImFormatString(), ImFormatStringV() so you can reimplement them yourself. +//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS + +//---- Pack colors to BGRA instead of RGBA (remove need to post process vertex buffer in back ends) +//#define IMGUI_USE_BGRA_PACKED_COLOR + +//---- Implement STB libraries in a namespace to avoid linkage conflicts +//#define IMGUI_STB_NAMESPACE ImGuiStb + +//---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. +/* +#define IM_VEC2_CLASS_EXTRA \ + ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ + operator MyVec2() const { return MyVec2(x,y); } + +#define IM_VEC4_CLASS_EXTRA \ + 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); } +*/ + +//---- Use 32-bit vertex indices (instead of default: 16-bit) to allow meshes with more than 64K vertices +//#define ImDrawIdx unsigned int + +//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. +//---- e.g. create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers. +/* +namespace ImGui +{ + void Value(const char* prefix, const MyMatrix44& v, const char* float_format = NULL); +} +*/ + diff --git a/lib/cimgui-1.53.1/imgui-1.53/imgui.cpp b/lib/cimgui-1.53.1/imgui-1.53/imgui.cpp new file mode 100644 index 0000000..075fb8c --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/imgui.cpp @@ -0,0 +1,11739 @@ +// dear imgui, v1.53 +// (main code and documentation) + +// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. +// Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase. +// Get latest version at https://github.com/ocornut/imgui +// Releases change-log at https://github.com/ocornut/imgui/releases +// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/1269 +// Developed by Omar Cornut and every direct or indirect contributors to the GitHub. +// This library is free but I need your support to sustain development and maintenance. +// If you work for a company, please consider financial support, see Readme. For individuals: https://www.patreon.com/imgui + +/* + + Index + - MISSION STATEMENT + - END-USER GUIDE + - PROGRAMMER GUIDE (read me!) + - Read first + - How to update to a newer version of Dear ImGui + - Getting started with integrating Dear ImGui in your code/engine + - API BREAKING CHANGES (read me when you update!) + - ISSUES & TODO LIST + - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS + - How can I help? + - What is ImTextureID and how do I display an image? + - I integrated Dear ImGui in my engine and the text or lines are blurry.. + - I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. + - How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on labels/IDs. + - How can I tell when Dear ImGui wants my mouse/keyboard inputs VS when I can pass them to my application? + - How can I load a different font than the default? + - How can I easily use icons in my application? + - How can I load multiple fonts? + - How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic? + - How can I preserve my Dear ImGui context across reloading a DLL? (loss of the global/static variables) + - How can I use the drawing facilities without an ImGui window? (using ImDrawList API) + - ISSUES & TODO-LIST + - CODE + + + MISSION STATEMENT + ================= + + - Easy to use to create code-driven and data-driven tools + - Easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools + - Easy to hack and improve + - Minimize screen real-estate usage + - Minimize setup and maintenance + - Minimize state storage on user side + - Portable, minimize dependencies, run on target (consoles, phones, etc.) + - Efficient runtime and memory consumption (NB- we do allocate when "growing" content e.g. creating a window, opening a tree node + for the first time, etc. but a typical frame won't allocate anything) + + Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes: + - Doesn't look fancy, doesn't animate + - Limited layout features, intricate layouts are typically crafted in code + + + END-USER GUIDE + ============== + + - Double-click on title bar to collapse window. + - Click upper right corner to close a window, available when 'bool* p_open' is passed to ImGui::Begin(). + - Click and drag on lower right corner to resize window (double-click to auto fit window to its contents). + - Click and drag on any empty space to move window. + - TAB/SHIFT+TAB to cycle through keyboard editable fields. + - CTRL+Click on a slider or drag box to input value as text. + - Use mouse wheel to scroll. + - Text editor: + - Hold SHIFT or use mouse to select text. + - CTRL+Left/Right to word jump. + - CTRL+Shift+Left/Right to select words. + - CTRL+A our Double-Click to select all. + - CTRL+X,CTRL+C,CTRL+V to use OS clipboard/ + - CTRL+Z,CTRL+Y to undo/redo. + - ESCAPE to revert text to its original value. + - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!) + - Controls are automatically adjusted for OSX to match standard OSX text editing operations. + + + PROGRAMMER GUIDE + ================ + + READ FIRST + + - Read the FAQ below this section! + - Your code creates the UI, if your code doesn't run the UI is gone! == very dynamic UI, no construction/destructions steps, less data retention + on your side, no state duplication, less sync, less bugs. + - Call and read ImGui::ShowDemoWindow() for demo code demonstrating most features. + - You can learn about immediate-mode gui principles at http://www.johno.se/book/imgui.html or watch http://mollyrocket.com/861 + + HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI + + - Overwrite all the sources files except for imconfig.h (if you have made modification to your copy of imconfig.h) + - Read the "API BREAKING CHANGES" section (below). This is where we list occasional API breaking changes. + If a function/type has been renamed / or marked obsolete, try to fix the name in your code before it is permanently removed from the public API. + If you have a problem with a missing function/symbols, search for its name in the code, there will likely be a comment about it. + Please report any issue to the GitHub page! + - Try to keep your copy of dear imgui reasonably up to date. + + GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE + + - Add the Dear ImGui source files to your projects, using your preferred build system. + It is recommended you build the .cpp files as part of your project and not as a library. + - You can later customize the imconfig.h file to tweak some compilation time behavior, such as integrating imgui types with your own maths types. + - See examples/ folder for standalone sample applications. + - You may be able to grab and copy a ready made imgui_impl_*** file from the examples/. + - When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them. + + - Init: retrieve the ImGuiIO structure with ImGui::GetIO() and fill the fields marked 'Settings': at minimum you need to set io.DisplaySize + (application resolution). Later on you will fill your keyboard mapping, clipboard handlers, and other advanced features but for a basic + integration you don't need to worry about it all. + - Init: call io.Fonts->GetTexDataAsRGBA32(...), it will build the font atlas texture, then load the texture pixels into graphics memory. + - Every frame: + - In your main loop as early a possible, fill the IO fields marked 'Input' (e.g. mouse position, buttons, keyboard info, etc.) + - Call ImGui::NewFrame() to begin the frame + - You can use any ImGui function you want between NewFrame() and Render() + - Call ImGui::Render() as late as you can to end the frame and finalize render data. it will call your io.RenderDrawListFn handler. + (Even if you don't render, call Render() and ignore the callback, or call EndFrame() instead. Otherwhise some features will break) + - All rendering information are stored into command-lists until ImGui::Render() is called. + - Dear ImGui never touches or knows about your GPU state. the only function that knows about GPU is the RenderDrawListFn handler that you provide. + - Effectively it means you can create widgets at any time in your code, regardless of considerations of being in "update" vs "render" phases + of your own application. + - Refer to the examples applications in the examples/ folder for instruction on how to setup your code. + - A minimal application skeleton may be: + + // Application init + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize.x = 1920.0f; + io.DisplaySize.y = 1280.0f; + io.RenderDrawListsFn = MyRenderFunction; // Setup a render function, or set to NULL and call GetDrawData() after Render() to access render data. + // TODO: Fill others settings of the io structure later. + + // Load texture atlas (there is a default font so you don't need to care about choosing a font yet) + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height); + // TODO: At this points you've got the texture data and you need to upload that your your graphic system: + MyTexture* texture = MyEngine::CreateTextureFromMemoryPixels(pixels, width, height, TEXTURE_TYPE_RGBA) + // TODO: Store your texture pointer/identifier (whatever your engine uses) in 'io.Fonts->TexID'. This will be passed back to your via the renderer. + io.Fonts->TexID = (void*)texture; + + // Application main loop + while (true) + { + // Setup low-level inputs (e.g. on Win32, GetKeyboardState(), or write to those fields from your Windows message loop handlers, etc.) + ImGuiIO& io = ImGui::GetIO(); + io.DeltaTime = 1.0f/60.0f; + io.MousePos = mouse_pos; + io.MouseDown[0] = mouse_button_0; + io.MouseDown[1] = mouse_button_1; + + // Call NewFrame(), after this point you can use ImGui::* functions anytime + ImGui::NewFrame(); + + // Most of your application code here + MyGameUpdate(); // may use any ImGui functions, e.g. ImGui::Begin("My window"); ImGui::Text("Hello, world!"); ImGui::End(); + MyGameRender(); // may use any ImGui functions as well! + + // Render & swap video buffers + ImGui::Render(); + SwapBuffers(); + } + + - A minimal render function skeleton may be: + + void void MyRenderFunction(ImDrawData* draw_data)(ImDrawData* draw_data) + { + // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled + // TODO: Setup viewport, orthographic projection matrix + // TODO: Setup shader: vertex { float2 pos, float2 uv, u32 color }, fragment shader sample color from 1 texture, multiply by vertex color. + for (int n = 0; n < draw_data->CmdListsCount; n++) + { + const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; // vertex buffer generated by ImGui + const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; // index buffer generated by ImGui + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + if (pcmd->UserCallback) + { + pcmd->UserCallback(cmd_list, pcmd); + } + else + { + // The texture for the draw call is specified by pcmd->TextureId. + // The vast majority of draw calls with use the imgui texture atlas, which value you have set yourself during initialization. + MyEngineBindTexture(pcmd->TextureId); + + // We are using scissoring to clip some objects. All low-level graphics API supports it. + // If your engine doesn't support scissoring yet, you will get some small glitches (some elements outside their bounds) which you can fix later. + MyEngineScissor((int)pcmd->ClipRect.x, (int)pcmd->ClipRect.y, (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); + + // Render 'pcmd->ElemCount/3' indexed triangles. + // By default the indices ImDrawIdx are 16-bits, you can change them to 32-bits if your engine doesn't support 16-bits indices. + MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer, vtx_buffer); + } + idx_buffer += pcmd->ElemCount; + } + } + } + + - The examples/ folders contains many functional implementation of the pseudo-code above. + - When calling NewFrame(), the 'io.WantCaptureMouse'/'io.WantCaptureKeyboard'/'io.WantTextInput' flags are updated. + They tell you if ImGui intends to use your inputs. So for example, if 'io.WantCaptureMouse' is set you would typically want to hide + mouse inputs from the rest of your application. Read the FAQ below for more information about those flags. + + + + API BREAKING CHANGES + ==================== + + Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix. + Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. + Also read releases logs https://github.com/ocornut/imgui/releases for more details. + + - 2017/12/24 (1.53) - renamed the emblematic ShowTestWindow() function to ShowDemoWindow(). Kept redirection function (will obsolete). + - 2017/12/21 (1.53) - ImDrawList: renamed style.AntiAliasedShapes to style.AntiAliasedFill for consistency and as a way to explicitly break code that manipulate those flag at runtime. You can now manipulate ImDrawList::Flags + - 2017/12/21 (1.53) - ImDrawList: removed 'bool anti_aliased = true' final parameter of ImDrawList::AddPolyline() and ImDrawList::AddConvexPolyFilled(). Prefer manipulating ImDrawList::Flags if you need to toggle them during the frame. + - 2017/12/14 (1.53) - using the ImGuiWindowFlags_NoScrollWithMouse flag on a child window forwards the mouse wheel event to the parent window, unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set. + - 2017/12/13 (1.53) - renamed GetItemsLineHeightWithSpacing() to GetFrameHeightWithSpacing(). Kept redirection function (will obsolete). + - 2017/12/13 (1.53) - obsoleted IsRootWindowFocused() in favor of using IsWindowFocused(ImGuiFocusedFlags_RootWindow). Kept redirection function (will obsolete). + - obsoleted IsRootWindowOrAnyChildFocused() in favor of using IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows). Kept redirection function (will obsolete). + - 2017/12/12 (1.53) - renamed ImGuiTreeNodeFlags_AllowOverlapMode to ImGuiTreeNodeFlags_AllowItemOverlap. Kept redirection enum (will obsolete). + - 2017/12/10 (1.53) - removed SetNextWindowContentWidth(), prefer using SetNextWindowContentSize(). Kept redirection function (will obsolete). + - 2017/11/27 (1.53) - renamed ImGuiTextBuffer::append() helper to appendf(), appendv() to appendfv(). If you copied the 'Log' demo in your code, it uses appendv() so that needs to be renamed. + - 2017/11/18 (1.53) - Style, Begin: removed ImGuiWindowFlags_ShowBorders window flag. Borders are now fully set up in the ImGuiStyle structure (see e.g. style.FrameBorderSize, style.WindowBorderSize). Use ImGui::ShowStyleEditor() to look them up. + Please note that the style system will keep evolving (hopefully stabilizing in Q1 2018), and so custom styles will probably subtly break over time. It is recommended you use the StyleColorsClassic(), StyleColorsDark(), StyleColorsLight() functions. + - 2017/11/18 (1.53) - Style: removed ImGuiCol_ComboBg in favor of combo boxes using ImGuiCol_PopupBg for consistency. + - 2017/11/18 (1.53) - Style: renamed ImGuiCol_ChildWindowBg to ImGuiCol_ChildBg. + - 2017/11/18 (1.53) - Style: renamed style.ChildWindowRounding to style.ChildRounding, ImGuiStyleVar_ChildWindowRounding to ImGuiStyleVar_ChildRounding. + - 2017/11/02 (1.53) - obsoleted IsRootWindowOrAnyChildHovered() in favor of using IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); + - 2017/10/24 (1.52) - renamed IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS/IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS to IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS/IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS for consistency. + - 2017/10/20 (1.52) - changed IsWindowHovered() default parameters behavior to return false if an item is active in another window (e.g. click-dragging item from another window to this window). You can use the newly introduced IsWindowHovered() flags to requests this specific behavior if you need it. + - 2017/10/20 (1.52) - marked IsItemHoveredRect()/IsMouseHoveringWindow() as obsolete, in favor of using the newly introduced flags for IsItemHovered() and IsWindowHovered(). See https://github.com/ocornut/imgui/issues/1382 for details. + removed the IsItemRectHovered()/IsWindowRectHovered() names introduced in 1.51 since they were merely more consistent names for the two functions we are now obsoleting. + - 2017/10/17 (1.52) - marked the old 5-parameters version of Begin() as obsolete (still available). Use SetNextWindowSize()+Begin() instead! + - 2017/10/11 (1.52) - renamed AlignFirstTextHeightToWidgets() to AlignTextToFramePadding(). Kept inline redirection function (will obsolete). + - 2017/09/25 (1.52) - removed SetNextWindowPosCenter() because SetNextWindowPos() now has the optional pivot information to do the same and more. Kept redirection function (will obsolete). + - 2017/08/25 (1.52) - io.MousePos needs to be set to ImVec2(-FLT_MAX,-FLT_MAX) when mouse is unavailable/missing. Previously ImVec2(-1,-1) was enough but we now accept negative mouse coordinates. In your binding if you need to support unavailable mouse, make sure to replace "io.MousePos = ImVec2(-1,-1)" with "io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX)". + - 2017/08/22 (1.51) - renamed IsItemHoveredRect() to IsItemRectHovered(). Kept inline redirection function (will obsolete). -> (1.52) use IsItemHovered(ImGuiHoveredFlags_RectOnly)! + - renamed IsMouseHoveringAnyWindow() to IsAnyWindowHovered() for consistency. Kept inline redirection function (will obsolete). + - renamed IsMouseHoveringWindow() to IsWindowRectHovered() for consistency. Kept inline redirection function (will obsolete). + - 2017/08/20 (1.51) - renamed GetStyleColName() to GetStyleColorName() for consistency. + - 2017/08/20 (1.51) - added PushStyleColor(ImGuiCol idx, ImU32 col) overload, which _might_ cause an "ambiguous call" compilation error if you are using ImColor() with implicit cast. Cast to ImU32 or ImVec4 explicily to fix. + - 2017/08/15 (1.51) - marked the weird IMGUI_ONCE_UPON_A_FRAME helper macro as obsolete. prefer using the more explicit ImGuiOnceUponAFrame. + - 2017/08/15 (1.51) - changed parameter order for BeginPopupContextWindow() from (const char*,int buttons,bool also_over_items) to (const char*,int buttons,bool also_over_items). Note that most calls relied on default parameters completely. + - 2017/08/13 (1.51) - renamed ImGuiCol_Columns*** to ImGuiCol_Separator***. Kept redirection enums (will obsolete). + - 2017/08/11 (1.51) - renamed ImGuiSetCond_*** types and flags to ImGuiCond_***. Kept redirection enums (will obsolete). + - 2017/08/09 (1.51) - removed ValueColor() helpers, they are equivalent to calling Text(label) + SameLine() + ColorButton(). + - 2017/08/08 (1.51) - removed ColorEditMode() and ImGuiColorEditMode in favor of ImGuiColorEditFlags and parameters to the various Color*() functions. The SetColorEditOptions() allows to initialize default but the user can still change them with right-click context menu. + - changed prototype of 'ColorEdit4(const char* label, float col[4], bool show_alpha = true)' to 'ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0)', where passing flags = 0x01 is a safe no-op (hello dodgy backward compatibility!). - check and run the demo window, under "Color/Picker Widgets", to understand the various new options. + - changed prototype of rarely used 'ColorButton(ImVec4 col, bool small_height = false, bool outline_border = true)' to 'ColorButton(const char* desc_id, ImVec4 col, ImGuiColorEditFlags flags = 0, ImVec2 size = ImVec2(0,0))' + - 2017/07/20 (1.51) - removed IsPosHoveringAnyWindow(ImVec2), which was partly broken and misleading. ASSERT + redirect user to io.WantCaptureMouse + - 2017/05/26 (1.50) - removed ImFontConfig::MergeGlyphCenterV in favor of a more multipurpose ImFontConfig::GlyphOffset. + - 2017/05/01 (1.50) - renamed ImDrawList::PathFill() (rarely used directly) to ImDrawList::PathFillConvex() for clarity. + - 2016/11/06 (1.50) - BeginChild(const char*) now applies the stack id to the provided label, consistently with other functions as it should always have been. It shouldn't affect you unless (extremely unlikely) you were appending multiple times to a same child from different locations of the stack id. If that's the case, generate an id with GetId() and use it instead of passing string to BeginChild(). + - 2016/10/15 (1.50) - avoid 'void* user_data' parameter to io.SetClipboardTextFn/io.GetClipboardTextFn pointers. We pass io.ClipboardUserData to it. + - 2016/09/25 (1.50) - style.WindowTitleAlign is now a ImVec2 (ImGuiAlign enum was removed). set to (0.5f,0.5f) for horizontal+vertical centering, (0.0f,0.0f) for upper-left, etc. + - 2016/07/30 (1.50) - SameLine(x) with x>0.0f is now relative to left of column/group if any, and not always to left of window. This was sort of always the intent and hopefully breakage should be minimal. + - 2016/05/12 (1.49) - title bar (using ImGuiCol_TitleBg/ImGuiCol_TitleBgActive colors) isn't rendered over a window background (ImGuiCol_WindowBg color) anymore. + If your TitleBg/TitleBgActive alpha was 1.0f or you are using the default theme it will not affect you. + However if your TitleBg/TitleBgActive alpha was <1.0f you need to tweak your custom theme to readjust for the fact that we don't draw a WindowBg background behind the title bar. + This helper function will convert an old TitleBg/TitleBgActive color into a new one with the same visual output, given the OLD color and the OLD WindowBg color. + ImVec4 ConvertTitleBgCol(const ImVec4& win_bg_col, const ImVec4& title_bg_col) + { + float new_a = 1.0f - ((1.0f - win_bg_col.w) * (1.0f - title_bg_col.w)), k = title_bg_col.w / new_a; + return ImVec4((win_bg_col.x * win_bg_col.w + title_bg_col.x) * k, (win_bg_col.y * win_bg_col.w + title_bg_col.y) * k, (win_bg_col.z * win_bg_col.w + title_bg_col.z) * k, new_a); + } + If this is confusing, pick the RGB value from title bar from an old screenshot and apply this as TitleBg/TitleBgActive. Or you may just create TitleBgActive from a tweaked TitleBg color. + - 2016/05/07 (1.49) - removed confusing set of GetInternalState(), GetInternalStateSize(), SetInternalState() functions. Now using CreateContext(), DestroyContext(), GetCurrentContext(), SetCurrentContext(). + - 2016/05/02 (1.49) - renamed SetNextTreeNodeOpened() to SetNextTreeNodeOpen(), no redirection. + - 2016/05/01 (1.49) - obsoleted old signature of CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false) as extra parameters were badly designed and rarely used. You can replace the "default_open = true" flag in new API with CollapsingHeader(label, ImGuiTreeNodeFlags_DefaultOpen). + - 2016/04/26 (1.49) - changed ImDrawList::PushClipRect(ImVec4 rect) to ImDraw::PushClipRect(Imvec2 min,ImVec2 max,bool intersect_with_current_clip_rect=false). Note that higher-level ImGui::PushClipRect() is preferable because it will clip at logic/widget level, whereas ImDrawList::PushClipRect() only affect your renderer. + - 2016/04/03 (1.48) - removed style.WindowFillAlphaDefault setting which was redundant. Bake default BG alpha inside style.Colors[ImGuiCol_WindowBg] and all other Bg color values. (ref github issue #337). + - 2016/04/03 (1.48) - renamed ImGuiCol_TooltipBg to ImGuiCol_PopupBg, used by popups/menus and tooltips. popups/menus were previously using ImGuiCol_WindowBg. (ref github issue #337) + - 2016/03/21 (1.48) - renamed GetWindowFont() to GetFont(), GetWindowFontSize() to GetFontSize(). Kept inline redirection function (will obsolete). + - 2016/03/02 (1.48) - InputText() completion/history/always callbacks: if you modify the text buffer manually (without using DeleteChars()/InsertChars() helper) you need to maintain the BufTextLen field. added an assert. + - 2016/01/23 (1.48) - fixed not honoring exact width passed to PushItemWidth(), previously it would add extra FramePadding.x*2 over that width. if you had manual pixel-perfect alignment in place it might affect you. + - 2015/12/27 (1.48) - fixed ImDrawList::AddRect() which used to render a rectangle 1 px too large on each axis. + - 2015/12/04 (1.47) - renamed Color() helpers to ValueColor() - dangerously named, rarely used and probably to be made obsolete. + - 2015/08/29 (1.45) - with the addition of horizontal scrollbar we made various fixes to inconsistencies with dealing with cursor position. + GetCursorPos()/SetCursorPos() functions now include the scrolled amount. It shouldn't affect the majority of users, but take note that SetCursorPosX(100.0f) puts you at +100 from the starting x position which may include scrolling, not at +100 from the window left side. + GetContentRegionMax()/GetWindowContentRegionMin()/GetWindowContentRegionMax() functions allow include the scrolled amount. Typically those were used in cases where no scrolling would happen so it may not be a problem, but watch out! + - 2015/08/29 (1.45) - renamed style.ScrollbarWidth to style.ScrollbarSize + - 2015/08/05 (1.44) - split imgui.cpp into extra files: imgui_demo.cpp imgui_draw.cpp imgui_internal.h that you need to add to your project. + - 2015/07/18 (1.44) - fixed angles in ImDrawList::PathArcTo(), PathArcToFast() (introduced in 1.43) being off by an extra PI for no justifiable reason + - 2015/07/14 (1.43) - add new ImFontAtlas::AddFont() API. For the old AddFont***, moved the 'font_no' parameter of ImFontAtlas::AddFont** functions to the ImFontConfig structure. + you need to render your textured triangles with bilinear filtering to benefit from sub-pixel positioning of text. + - 2015/07/08 (1.43) - switched rendering data to use indexed rendering. this is saving a fair amount of CPU/GPU and enables us to get anti-aliasing for a marginal cost. + this necessary change will break your rendering function! the fix should be very easy. sorry for that :( + - if you are using a vanilla copy of one of the imgui_impl_XXXX.cpp provided in the example, you just need to update your copy and you can ignore the rest. + - the signature of the io.RenderDrawListsFn handler has changed! + ImGui_XXXX_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) + became: + ImGui_XXXX_RenderDrawLists(ImDrawData* draw_data). + argument 'cmd_lists' -> 'draw_data->CmdLists' + argument 'cmd_lists_count' -> 'draw_data->CmdListsCount' + ImDrawList 'commands' -> 'CmdBuffer' + ImDrawList 'vtx_buffer' -> 'VtxBuffer' + ImDrawList n/a -> 'IdxBuffer' (new) + ImDrawCmd 'vtx_count' -> 'ElemCount' + ImDrawCmd 'clip_rect' -> 'ClipRect' + ImDrawCmd 'user_callback' -> 'UserCallback' + ImDrawCmd 'texture_id' -> 'TextureId' + - each ImDrawList now contains both a vertex buffer and an index buffer. For each command, render ElemCount/3 triangles using indices from the index buffer. + - if you REALLY cannot render indexed primitives, you can call the draw_data->DeIndexAllBuffers() method to de-index the buffers. This is slow and a waste of CPU/GPU. Prefer using indexed rendering! + - refer to code in the examples/ folder or ask on the GitHub if you are unsure of how to upgrade. please upgrade! + - 2015/07/10 (1.43) - changed SameLine() parameters from int to float. + - 2015/07/02 (1.42) - renamed SetScrollPosHere() to SetScrollFromCursorPos(). Kept inline redirection function (will obsolete). + - 2015/07/02 (1.42) - renamed GetScrollPosY() to GetScrollY(). Necessary to reduce confusion along with other scrolling functions, because positions (e.g. cursor position) are not equivalent to scrolling amount. + - 2015/06/14 (1.41) - changed ImageButton() default bg_col parameter from (0,0,0,1) (black) to (0,0,0,0) (transparent) - makes a difference when texture have transparence + - 2015/06/14 (1.41) - changed Selectable() API from (label, selected, size) to (label, selected, flags, size). Size override should have been rarely be used. Sorry! + - 2015/05/31 (1.40) - renamed GetWindowCollapsed() to IsWindowCollapsed() for consistency. Kept inline redirection function (will obsolete). + - 2015/05/31 (1.40) - renamed IsRectClipped() to IsRectVisible() for consistency. Note that return value is opposite! Kept inline redirection function (will obsolete). + - 2015/05/27 (1.40) - removed the third 'repeat_if_held' parameter from Button() - sorry! it was rarely used and inconsistent. Use PushButtonRepeat(true) / PopButtonRepeat() to enable repeat on desired buttons. + - 2015/05/11 (1.40) - changed BeginPopup() API, takes a string identifier instead of a bool. ImGui needs to manage the open/closed state of popups. Call OpenPopup() to actually set the "open" state of a popup. BeginPopup() returns true if the popup is opened. + - 2015/05/03 (1.40) - removed style.AutoFitPadding, using style.WindowPadding makes more sense (the default values were already the same). + - 2015/04/13 (1.38) - renamed IsClipped() to IsRectClipped(). Kept inline redirection function until 1.50. + - 2015/04/09 (1.38) - renamed ImDrawList::AddArc() to ImDrawList::AddArcFast() for compatibility with future API + - 2015/04/03 (1.38) - removed ImGuiCol_CheckHovered, ImGuiCol_CheckActive, replaced with the more general ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive. + - 2014/04/03 (1.38) - removed support for passing -FLT_MAX..+FLT_MAX as the range for a SliderFloat(). Use DragFloat() or Inputfloat() instead. + - 2015/03/17 (1.36) - renamed GetItemBoxMin()/GetItemBoxMax()/IsMouseHoveringBox() to GetItemRectMin()/GetItemRectMax()/IsMouseHoveringRect(). Kept inline redirection function until 1.50. + - 2015/03/15 (1.36) - renamed style.TreeNodeSpacing to style.IndentSpacing, ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing + - 2015/03/13 (1.36) - renamed GetWindowIsFocused() to IsWindowFocused(). Kept inline redirection function until 1.50. + - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth (casing) + - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond). Kept inline redirection function until 1.50. + - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once. + - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now. + - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior + - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing() + - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused) + - 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions. + - 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader. + (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels. + this sequence: + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + // + became: + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + // + io.Fonts->TexID = (your_texture_identifier); + you now have much more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs. + it is now recommended that you sample the font texture with bilinear interpolation. + (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID. + (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix) + (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets + - 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver) + - 2014/11/28 (1.17) - moved IO.Font*** options to inside the IO.Font-> structure (FontYOffset, FontTexUvForWhite, FontBaseScale, FontFallbackGlyph) + - 2014/11/26 (1.17) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility + - 2014/11/07 (1.15) - renamed IsHovered() to IsItemHovered() + - 2014/10/02 (1.14) - renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user.cpp to imgui_user.inl (more IDE friendly) + - 2014/09/25 (1.13) - removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity) + - 2014/09/24 (1.12) - renamed SetFontScale() to SetWindowFontScale() + - 2014/09/24 (1.12) - moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn + - 2014/08/30 (1.09) - removed IO.FontHeight (now computed automatically) + - 2014/08/30 (1.09) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite + - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes + + + ISSUES & TODO-LIST + ================== + See TODO.txt + + + FREQUENTLY ASKED QUESTIONS (FAQ), TIPS + ====================================== + + Q: How can I help? + A: - If you are experienced enough with Dear ImGui and with C/C++, look at the todo list and see how you want/can help! + - Become a Patron/donate! Convince your company to become a Patron or provide serious funding for development time! See http://www.patreon.com/imgui + + Q: What is ImTextureID and how do I display an image? + A: ImTextureID is a void* used to pass renderer-agnostic texture references around until it hits your render function. + Dear ImGui knows nothing about what those bits represent, it just passes them around. It is up to you to decide what you want the void* to carry! + It could be an identifier to your OpenGL texture (cast GLuint to void*), a pointer to your custom engine material (cast MyMaterial* to void*), etc. + At the end of the chain, your renderer takes this void* to cast it back into whatever it needs to select a current texture to render. + Refer to examples applications, where each renderer (in a imgui_impl_xxxx.cpp file) is treating ImTextureID as a different thing. + (c++ tip: OpenGL uses integers to identify textures. You can safely store an integer into a void*, just cast it to void*, don't take it's address!) + To display a custom image/texture within an ImGui window, you may use ImGui::Image(), ImGui::ImageButton(), ImDrawList::AddImage() functions. + Dear ImGui will generate the geometry and draw calls using the ImTextureID that you passed and which your renderer can use. + It is your responsibility to get textures uploaded to your GPU. + + Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. + A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f). + Also make sure your orthographic projection matrix and io.DisplaySize matches your actual framebuffer dimension. + + Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. + A: You are probably mishandling the clipping rectangles in your render function. + Rectangles provided by ImGui are defined as (x1=left,y1=top,x2=right,y2=bottom) and NOT as (x1,y1,width,height). + + Q: Can I have multiple widgets with the same label? Can I have widget without a label? + A: Yes. A primer on the use of labels/IDs in Dear ImGui.. + + - Elements that are not clickable, such as Text() items don't need an ID. + + - Interactive widgets require state to be carried over multiple frames (most typically Dear ImGui often needs to remember what is + the "active" widget). to do so they need a unique ID. unique ID are typically derived from a string label, an integer index or a pointer. + + Button("OK"); // Label = "OK", ID = hash of "OK" + Button("Cancel"); // Label = "Cancel", ID = hash of "Cancel" + + - ID are uniquely scoped within windows, tree nodes, etc. so no conflict can happen if you have two buttons called "OK" + in two different windows or in two different locations of a tree. + + - If you have a same ID twice in the same location, you'll have a conflict: + + Button("OK"); + Button("OK"); // ID collision! Both buttons will be treated as the same. + + Fear not! this is easy to solve and there are many ways to solve it! + + - When passing a label you can optionally specify extra unique ID information within string itself. + This helps solving the simpler collision cases. Use "##" to pass a complement to the ID that won't be visible to the end-user: + + Button("Play"); // Label = "Play", ID = hash of "Play" + Button("Play##foo1"); // Label = "Play", ID = hash of "Play##foo1" (different from above) + Button("Play##foo2"); // Label = "Play", ID = hash of "Play##foo2" (different from above) + + - If you want to completely hide the label, but still need an ID: + + Checkbox("##On", &b); // Label = "", ID = hash of "##On" (no label!) + + - Occasionally/rarely you might want change a label while preserving a constant ID. This allows you to animate labels. + For example you may want to include varying information in a window title bar (and windows are uniquely identified by their ID.. obviously) + Use "###" to pass a label that isn't part of ID: + + Button("Hello###ID"; // Label = "Hello", ID = hash of "ID" + Button("World###ID"; // Label = "World", ID = hash of "ID" (same as above) + + sprintf(buf, "My game (%f FPS)###MyGame"); + Begin(buf); // Variable label, ID = hash of "MyGame" + + - Use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window. + This is the most convenient way of distinguishing ID if you are iterating and creating many UI elements. + You can push a pointer, a string or an integer value. Remember that ID are formed from the concatenation of everything in the ID stack! + + for (int i = 0; i < 100; i++) + { + PushID(i); + Button("Click"); // Label = "Click", ID = hash of integer + "label" (unique) + PopID(); + } + + for (int i = 0; i < 100; i++) + { + MyObject* obj = Objects[i]; + PushID(obj); + Button("Click"); // Label = "Click", ID = hash of pointer + "label" (unique) + PopID(); + } + + for (int i = 0; i < 100; i++) + { + MyObject* obj = Objects[i]; + PushID(obj->Name); + Button("Click"); // Label = "Click", ID = hash of string + "label" (unique) + PopID(); + } + + - More example showing that you can stack multiple prefixes into the ID stack: + + Button("Click"); // Label = "Click", ID = hash of "Click" + PushID("node"); + Button("Click"); // Label = "Click", ID = hash of "node" + "Click" + PushID(my_ptr); + Button("Click"); // Label = "Click", ID = hash of "node" + ptr + "Click" + PopID(); + PopID(); + + - Tree nodes implicitly creates a scope for you by calling PushID(). + + Button("Click"); // Label = "Click", ID = hash of "Click" + if (TreeNode("node")) + { + Button("Click"); // Label = "Click", ID = hash of "node" + "Click" + TreePop(); + } + + - When working with trees, ID are used to preserve the open/close state of each tree node. + Depending on your use cases you may want to use strings, indices or pointers as ID. + e.g. when displaying a single object that may change over time (dynamic 1-1 relationship), using a static string as ID will preserve your + node open/closed state when the targeted object change. + e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. + experiment and see what makes more sense! + + Q: How can I tell when Dear ImGui wants my mouse/keyboard inputs VS when I can pass them to my application? + A: You can read the 'io.WantCaptureMouse'/'io.WantCaptureKeyboard'/'ioWantTextInput' flags from the ImGuiIO structure. + - When 'io.WantCaptureMouse' or 'io.WantCaptureKeyboard' flags are set you may want to discard/hide the inputs from the rest of your application. + - When 'io.WantTextInput' is set to may want to notify your OS to popup an on-screen keyboard, if available (e.g. on a mobile phone, or console OS). + Preferably read the flags after calling ImGui::NewFrame() to avoid them lagging by one frame. But reading those flags before calling NewFrame() is + also generally ok, as the bool toggles fairly rarely and you don't generally expect to interact with either Dear ImGui or your application during + the same frame when that transition occurs. Dear ImGui is tracking dragging and widget activity that may occur outside the boundary of a window, + so 'io.WantCaptureMouse' is more accurate and correct than checking if a window is hovered. + (Advanced note: text input releases focus on Return 'KeyDown', so the following Return 'KeyUp' event that your application receive will typically + have 'io.WantCaptureKeyboard=false'. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs + were for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) + + Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13) + A: Use the font atlas to load the TTF/OTF file you want: + + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); + io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() + + Q: How can I easily use icons in my application? + A: The most convenient and practical way is to merge an icon font such as FontAwesome inside you main font. Then you can refer to icons within your + strings. Read 'How can I load multiple fonts?' and the file 'extra_fonts/README.txt' for instructions and useful header files. + + Q: How can I load multiple fonts? + A: Use the font atlas to pack them into a single texture: + (Read extra_fonts/README.txt and the code in ImFontAtlas for more details.) + + ImGuiIO& io = ImGui::GetIO(); + ImFont* font0 = io.Fonts->AddFontDefault(); + ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); + ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels); + io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() + // the first loaded font gets used by default + // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime + + // Options + ImFontConfig config; + config.OversampleH = 3; + config.OversampleV = 1; + config.GlyphOffset.y -= 2.0f; // Move everything by 2 pixels up + config.GlyphExtraSpacing.x = 1.0f; // Increase spacing between characters + io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, &config); + + // Combine multiple fonts into one (e.g. for icon fonts) + ImWchar ranges[] = { 0xf000, 0xf3ff, 0 }; + ImFontConfig config; + config.MergeMode = true; + io.Fonts->AddFontDefault(); + io.Fonts->LoadFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); // Merge icon font + io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs + + Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? + A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. + + // Add default Japanese ranges + io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); + + // Or create your own custom ranges (e.g. for a game you can feed your entire game script and only build the characters the game need) + ImVector ranges; + ImFontAtlas::GlyphRangesBuilder builder; + builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters) + builder.AddChar(0x7262); // Add a specific character + builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges + builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted) + io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, ranges.Data); + + All your strings needs to use UTF-8 encoding. In C++11 you can encode a string literal in UTF-8 by using the u8"hello" syntax. + Specifying literal in your source code using a local code page (such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! + Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8. + + Text input: it is up to your application to pass the right character code to io.AddInputCharacter(). The applications in examples/ are doing that. + For languages using IME, on Windows you can copy the Hwnd of your application to io.ImeWindowHandle. + The default implementation of io.ImeSetInputScreenPosFn() on Windows will set your IME position correctly. + + Q: How can I preserve my Dear ImGui context across reloading a DLL? (loss of the global/static variables) + A: Create your own context 'ctx = CreateContext()' + 'SetCurrentContext(ctx)' and your own font atlas 'ctx->GetIO().Fonts = new ImFontAtlas()' + so you don't rely on the default globals. + + Q: How can I use the drawing facilities without an ImGui window? (using ImDrawList API) + A: The easiest way is to create a dummy window. Call Begin() with NoTitleBar|NoResize|NoMove|NoScrollbar|NoSavedSettings|NoInputs flag, + zero background alpha, then retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. + You can also perfectly create a standalone ImDrawList instance _but_ you need ImGui to be initialized because ImDrawList pulls from ImGui + data to retrieve the coordinates of the white pixel. + + - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window. + this is also useful to set yourself in the context of another window (to get/set other settings) + - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug". + - tip: the ImGuiOnceUponAFrame helper will allow run the block of code only once a frame. You can use it to quickly add custom UI in the middle + of a deep nested inner loop in your code. + - tip: you can call Render() multiple times (e.g for VR renders). + - tip: call and read the ShowDemoWindow() code in imgui_demo.cpp for more example of how to use ImGui! + +*/ + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include "imgui.h" +#define IMGUI_DEFINE_MATH_OPERATORS +#include "imgui_internal.h" + +#include // toupper, isprint +#include // NULL, malloc, free, qsort, atoi +#include // vsnprintf, sscanf, printf +#include // INT_MIN, INT_MAX +#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier +#include // intptr_t +#else +#include // intptr_t +#endif + +#ifdef _MSC_VER +#pragma warning (disable: 4127) // condition expression is constant +#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#endif + +// Clang warnings with -Weverything +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning : unknown warning group '-Wformat-pedantic *' // not all warnings are known by all clang versions.. so ignoring warnings triggers new warnings on some configuration. great! +#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse. +#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants (typically 0.0f) is ok. +#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code. +#pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals. +#pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. +#pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // +#pragma clang diagnostic ignored "-Wformat-pedantic" // warning : format specifies type 'void *' but the argument has type 'xxxx *' // unreasonable, would lead to casting every %p arg to void*. probably enabled by -pedantic. +#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int' // +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size +#pragma GCC diagnostic ignored "-Wformat" // warning: format '%p' expects argument of type 'void*', but argument 6 has type 'ImGuiWindow*' +#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function +#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value +#pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'xxxx' to type 'xxxx' casts away qualifiers +#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked +#endif + +//------------------------------------------------------------------------- +// Forward Declarations +//------------------------------------------------------------------------- + +static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); + +static ImFont* GetDefaultFont(); +static void SetCurrentFont(ImFont* font); +static void SetCurrentWindow(ImGuiWindow* window); +static void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y); +static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond); +static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond); +static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond); +static ImGuiWindow* FindHoveredWindow(ImVec2 pos); +static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags); +static void ClearSetNextWindowData(); +static void CheckStacksSize(ImGuiWindow* window, bool write); +static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window); + +static void AddDrawListToRenderList(ImVector& out_render_list, ImDrawList* draw_list); +static void AddWindowToRenderList(ImVector& out_render_list, ImGuiWindow* window); +static void AddWindowToSortedBuffer(ImVector& out_sorted_windows, ImGuiWindow* window); + +static ImGuiWindowSettings* AddWindowSettings(const char* name); + +static void LoadIniSettingsFromDisk(const char* ini_filename); +static void LoadIniSettingsFromMemory(const char* buf); +static void SaveIniSettingsToDisk(const char* ini_filename); +static void SaveIniSettingsToMemory(ImVector& out_buf); +static void MarkIniSettingsDirty(ImGuiWindow* window); + +static ImRect GetVisibleRect(); + +static void CloseInactivePopups(ImGuiWindow* ref_window); +static void ClosePopupToLevel(int remaining); +static ImGuiWindow* GetFrontMostModalRootWindow(); + +static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data); +static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end); +static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false); + +static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, const char* display_format, char* buf, int buf_size); +static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, int decimal_precision, char* buf, int buf_size); +static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* value1, const void* value2); +static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* scalar_format); + +namespace ImGui +{ +static void FocusPreviousWindow(); +} + +//----------------------------------------------------------------------------- +// Platform dependent default implementations +//----------------------------------------------------------------------------- + +static const char* GetClipboardTextFn_DefaultImpl(void* user_data); +static void SetClipboardTextFn_DefaultImpl(void* user_data, const char* text); +static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y); + +//----------------------------------------------------------------------------- +// Context +//----------------------------------------------------------------------------- + +// Default font atlas storage. +// New contexts always point by default to this font atlas. It can be changed by reassigning the GetIO().Fonts variable. +static ImFontAtlas GImDefaultFontAtlas; + +// Default context storage + current context pointer. +// Implicitely used by all ImGui functions. Always assumed to be != NULL. Change to a different context by calling ImGui::SetCurrentContext() +// If you are hot-reloading this code in a DLL you will lose the static/global variables. Create your own context+font atlas instead of relying on those default (see FAQ entry "How can I preserve my ImGui context across reloading a DLL?"). +// ImGui is currently not thread-safe because of this variable. If you want thread-safety to allow N threads to access N different contexts, you might work around it by: +// - Having multiple instances of the ImGui code compiled inside different namespace (easiest/safest, if you have a finite number of contexts) +// - or: Changing this variable to be TLS. You may #define GImGui in imconfig.h for further custom hackery. Future development aim to make this context pointer explicit to all calls. Also read https://github.com/ocornut/imgui/issues/586 +#ifndef GImGui +static ImGuiContext GImDefaultContext; +ImGuiContext* GImGui = &GImDefaultContext; +#endif + +//----------------------------------------------------------------------------- +// User facing structures +//----------------------------------------------------------------------------- + +ImGuiStyle::ImGuiStyle() +{ + Alpha = 1.0f; // Global alpha applies to everything in ImGui + WindowPadding = ImVec2(8,8); // Padding within a window + WindowRounding = 7.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + WindowBorderSize = 0.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested. + WindowMinSize = ImVec2(32,32); // Minimum window size + WindowTitleAlign = ImVec2(0.0f,0.5f);// Alignment for title bar text + ChildRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular child windows + ChildBorderSize = 1.0f; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested. + PopupRounding = 0.0f; // Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows + PopupBorderSize = 1.0f; // Thickness of border around popup or tooltip windows. Generally set to 0.0f or 1.0f. Other values not well tested. + FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets) + FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets). + FrameBorderSize = 0.0f; // Thickness of border around frames. Generally set to 0.0f or 1.0f. Other values not well tested. + ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines + ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) + TouchExtraPadding = ImVec2(0,0); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much! + IndentSpacing = 21.0f; // Horizontal spacing when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2). + ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns + ScrollbarSize = 16.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar + ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar + GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar + GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs. + ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text. + DisplayWindowPadding = ImVec2(22,22); // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows. + DisplaySafeAreaPadding = ImVec2(4,4); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. + AntiAliasedLines = true; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU. + AntiAliasedFill = true; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) + CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. + + ImGui::StyleColorsClassic(this); +} + +// To scale your entire UI (e.g. if you want your app to use High DPI or generally be DPI aware) you may use this helper function. Scaling the fonts is done separately and is up to you. +// Important: This operation is lossy because we round all sizes to integer. If you need to change your scale multiples, call this over a freshly initialized ImGuiStyle structure rather than scaling multiple times. +void ImGuiStyle::ScaleAllSizes(float scale_factor) +{ + WindowPadding = ImFloor(WindowPadding * scale_factor); + WindowRounding = ImFloor(WindowRounding * scale_factor); + WindowMinSize = ImFloor(WindowMinSize * scale_factor); + ChildRounding = ImFloor(ChildRounding * scale_factor); + PopupRounding = ImFloor(PopupRounding * scale_factor); + FramePadding = ImFloor(FramePadding * scale_factor); + FrameRounding = ImFloor(FrameRounding * scale_factor); + ItemSpacing = ImFloor(ItemSpacing * scale_factor); + ItemInnerSpacing = ImFloor(ItemInnerSpacing * scale_factor); + TouchExtraPadding = ImFloor(TouchExtraPadding * scale_factor); + IndentSpacing = ImFloor(IndentSpacing * scale_factor); + ColumnsMinSpacing = ImFloor(ColumnsMinSpacing * scale_factor); + ScrollbarSize = ImFloor(ScrollbarSize * scale_factor); + ScrollbarRounding = ImFloor(ScrollbarRounding * scale_factor); + GrabMinSize = ImFloor(GrabMinSize * scale_factor); + GrabRounding = ImFloor(GrabRounding * scale_factor); + DisplayWindowPadding = ImFloor(DisplayWindowPadding * scale_factor); + DisplaySafeAreaPadding = ImFloor(DisplaySafeAreaPadding * scale_factor); +} + +ImGuiIO::ImGuiIO() +{ + // Most fields are initialized with zero + memset(this, 0, sizeof(*this)); + + // Settings + DisplaySize = ImVec2(-1.0f, -1.0f); + DeltaTime = 1.0f/60.0f; + IniSavingRate = 5.0f; + IniFilename = "imgui.ini"; + LogFilename = "imgui_log.txt"; + MouseDoubleClickTime = 0.30f; + MouseDoubleClickMaxDist = 6.0f; + for (int i = 0; i < ImGuiKey_COUNT; i++) + KeyMap[i] = -1; + KeyRepeatDelay = 0.250f; + KeyRepeatRate = 0.050f; + UserData = NULL; + + Fonts = &GImDefaultFontAtlas; + FontGlobalScale = 1.0f; + FontDefault = NULL; + FontAllowUserScaling = false; + DisplayFramebufferScale = ImVec2(1.0f, 1.0f); + DisplayVisibleMin = DisplayVisibleMax = ImVec2(0.0f, 0.0f); + + // Advanced/subtle behaviors +#ifdef __APPLE__ + OptMacOSXBehaviors = true; // Set Mac OS X style defaults based on __APPLE__ compile time flag +#else + OptMacOSXBehaviors = false; +#endif + OptCursorBlink = true; + + // Settings (User Functions) + RenderDrawListsFn = NULL; + MemAllocFn = malloc; + MemFreeFn = free; + GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations + SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; + ClipboardUserData = NULL; + ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl; + ImeWindowHandle = NULL; + + // Input (NB: we already have memset zero the entire structure) + MousePos = ImVec2(-FLT_MAX, -FLT_MAX); + MousePosPrev = ImVec2(-FLT_MAX, -FLT_MAX); + MouseDragThreshold = 6.0f; + for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f; + for (int i = 0; i < IM_ARRAYSIZE(KeysDownDuration); i++) KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f; +} + +// Pass in translated ASCII characters for text input. +// - with glfw you can get those from the callback set in glfwSetCharCallback() +// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message +void ImGuiIO::AddInputCharacter(ImWchar c) +{ + const int n = ImStrlenW(InputCharacters); + if (n + 1 < IM_ARRAYSIZE(InputCharacters)) + { + InputCharacters[n] = c; + InputCharacters[n+1] = '\0'; + } +} + +void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) +{ + // We can't pass more wchars than ImGuiIO::InputCharacters[] can hold so don't convert more + const int wchars_buf_len = sizeof(ImGuiIO::InputCharacters) / sizeof(ImWchar); + ImWchar wchars[wchars_buf_len]; + ImTextStrFromUtf8(wchars, wchars_buf_len, utf8_chars, NULL); + for (int i = 0; i < wchars_buf_len && wchars[i] != 0; i++) + AddInputCharacter(wchars[i]); +} + +//----------------------------------------------------------------------------- +// HELPERS +//----------------------------------------------------------------------------- + +#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose +#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 + +// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n. +#ifdef _WIN32 +#define IM_NEWLINE "\r\n" +#else +#define IM_NEWLINE "\n" +#endif + +ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p) +{ + ImVec2 ap = p - a; + ImVec2 ab_dir = b - a; + float ab_len = sqrtf(ab_dir.x * ab_dir.x + ab_dir.y * ab_dir.y); + ab_dir *= 1.0f / ab_len; + float dot = ap.x * ab_dir.x + ap.y * ab_dir.y; + if (dot < 0.0f) + return a; + if (dot > ab_len) + return b; + return a + ab_dir * dot; +} + +bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p) +{ + bool b1 = ((p.x - b.x) * (a.y - b.y) - (p.y - b.y) * (a.x - b.x)) < 0.0f; + bool b2 = ((p.x - c.x) * (b.y - c.y) - (p.y - c.y) * (b.x - c.x)) < 0.0f; + bool b3 = ((p.x - a.x) * (c.y - a.y) - (p.y - a.y) * (c.x - a.x)) < 0.0f; + return ((b1 == b2) && (b2 == b3)); +} + +void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w) +{ + ImVec2 v0 = b - a; + ImVec2 v1 = c - a; + ImVec2 v2 = p - a; + const float denom = v0.x * v1.y - v1.x * v0.y; + out_v = (v2.x * v1.y - v1.x * v2.y) / denom; + out_w = (v0.x * v2.y - v2.x * v0.y) / denom; + out_u = 1.0f - out_v - out_w; +} + +ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p) +{ + ImVec2 proj_ab = ImLineClosestPoint(a, b, p); + ImVec2 proj_bc = ImLineClosestPoint(b, c, p); + ImVec2 proj_ca = ImLineClosestPoint(c, a, p); + float dist2_ab = ImLengthSqr(p - proj_ab); + float dist2_bc = ImLengthSqr(p - proj_bc); + float dist2_ca = ImLengthSqr(p - proj_ca); + float m = ImMin(dist2_ab, ImMin(dist2_bc, dist2_ca)); + if (m == dist2_ab) + return proj_ab; + if (m == dist2_bc) + return proj_bc; + return proj_ca; +} + +int ImStricmp(const char* str1, const char* str2) +{ + int d; + while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } + return d; +} + +int ImStrnicmp(const char* str1, const char* str2, size_t count) +{ + int d = 0; + while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; } + return d; +} + +void ImStrncpy(char* dst, const char* src, size_t count) +{ + if (count < 1) return; + strncpy(dst, src, count); + dst[count-1] = 0; +} + +char* ImStrdup(const char *str) +{ + size_t len = strlen(str) + 1; + void* buf = ImGui::MemAlloc(len); + return (char*)memcpy(buf, (const void*)str, len); +} + +char* ImStrchrRange(const char* str, const char* str_end, char c) +{ + for ( ; str < str_end; str++) + if (*str == c) + return (char*)str; + return NULL; +} + +int ImStrlenW(const ImWchar* str) +{ + int n = 0; + while (*str++) n++; + return n; +} + +const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin) // find beginning-of-line +{ + while (buf_mid_line > buf_begin && buf_mid_line[-1] != '\n') + buf_mid_line--; + return buf_mid_line; +} + +const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end) +{ + if (!needle_end) + needle_end = needle + strlen(needle); + + const char un0 = (char)toupper(*needle); + while ((!haystack_end && *haystack) || (haystack_end && haystack < haystack_end)) + { + if (toupper(*haystack) == un0) + { + const char* b = needle + 1; + for (const char* a = haystack + 1; b < needle_end; a++, b++) + if (toupper(*a) != toupper(*b)) + break; + if (b == needle_end) + return haystack; + } + haystack++; + } + return NULL; +} + +static const char* ImAtoi(const char* src, int* output) +{ + int negative = 0; + if (*src == '-') { negative = 1; src++; } + if (*src == '+') { src++; } + int v = 0; + while (*src >= '0' && *src <= '9') + v = (v * 10) + (*src++ - '0'); + *output = negative ? -v : v; + return src; +} + +// A) MSVC version appears to return -1 on overflow, whereas glibc appears to return total count (which may be >= buf_size). +// Ideally we would test for only one of those limits at runtime depending on the behavior the vsnprintf(), but trying to deduct it at compile time sounds like a pandora can of worm. +// B) When buf==NULL vsnprintf() will return the output size. +#ifndef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS +int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + int w = vsnprintf(buf, buf_size, fmt, args); + va_end(args); + if (buf == NULL) + return w; + if (w == -1 || w >= (int)buf_size) + w = (int)buf_size - 1; + buf[w] = 0; + return w; +} + +int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) +{ + int w = vsnprintf(buf, buf_size, fmt, args); + if (buf == NULL) + return w; + if (w == -1 || w >= (int)buf_size) + w = (int)buf_size - 1; + buf[w] = 0; + return w; +} +#endif // #ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS + +// Pass data_size==0 for zero-terminated strings +// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. +ImU32 ImHash(const void* data, int data_size, ImU32 seed) +{ + static ImU32 crc32_lut[256] = { 0 }; + if (!crc32_lut[1]) + { + const ImU32 polynomial = 0xEDB88320; + for (ImU32 i = 0; i < 256; i++) + { + ImU32 crc = i; + for (ImU32 j = 0; j < 8; j++) + crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial); + crc32_lut[i] = crc; + } + } + + seed = ~seed; + ImU32 crc = seed; + const unsigned char* current = (const unsigned char*)data; + + if (data_size > 0) + { + // Known size + while (data_size--) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; + } + else + { + // Zero-terminated string + while (unsigned char c = *current++) + { + // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed. + // Because this syntax is rarely used we are optimizing for the common case. + // - If we reach ### in the string we discard the hash so far and reset to the seed. + // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller. + if (c == '#' && current[0] == '#' && current[1] == '#') + crc = seed; + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; + } + } + return ~crc; +} + +//----------------------------------------------------------------------------- +// ImText* helpers +//----------------------------------------------------------------------------- + +// Convert UTF-8 to 32-bits character, process single character input. +// Based on stb_from_utf8() from github.com/nothings/stb/ +// We handle UTF-8 decoding error by skipping forward. +int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end) +{ + unsigned int c = (unsigned int)-1; + const unsigned char* str = (const unsigned char*)in_text; + if (!(*str & 0x80)) + { + c = (unsigned int)(*str++); + *out_char = c; + return 1; + } + if ((*str & 0xe0) == 0xc0) + { + *out_char = 0xFFFD; // will be invalid but not end of string + if (in_text_end && in_text_end - (const char*)str < 2) return 1; + if (*str < 0xc2) return 2; + c = (unsigned int)((*str++ & 0x1f) << 6); + if ((*str & 0xc0) != 0x80) return 2; + c += (*str++ & 0x3f); + *out_char = c; + return 2; + } + if ((*str & 0xf0) == 0xe0) + { + *out_char = 0xFFFD; // will be invalid but not end of string + if (in_text_end && in_text_end - (const char*)str < 3) return 1; + if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 3; + if (*str == 0xed && str[1] > 0x9f) return 3; // str[1] < 0x80 is checked below + c = (unsigned int)((*str++ & 0x0f) << 12); + if ((*str & 0xc0) != 0x80) return 3; + c += (unsigned int)((*str++ & 0x3f) << 6); + if ((*str & 0xc0) != 0x80) return 3; + c += (*str++ & 0x3f); + *out_char = c; + return 3; + } + if ((*str & 0xf8) == 0xf0) + { + *out_char = 0xFFFD; // will be invalid but not end of string + if (in_text_end && in_text_end - (const char*)str < 4) return 1; + if (*str > 0xf4) return 4; + if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 4; + if (*str == 0xf4 && str[1] > 0x8f) return 4; // str[1] < 0x80 is checked below + c = (unsigned int)((*str++ & 0x07) << 18); + if ((*str & 0xc0) != 0x80) return 4; + c += (unsigned int)((*str++ & 0x3f) << 12); + if ((*str & 0xc0) != 0x80) return 4; + c += (unsigned int)((*str++ & 0x3f) << 6); + if ((*str & 0xc0) != 0x80) return 4; + c += (*str++ & 0x3f); + // utf-8 encodings of values used in surrogate pairs are invalid + if ((c & 0xFFFFF800) == 0xD800) return 4; + *out_char = c; + return 4; + } + *out_char = 0; + return 0; +} + +int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining) +{ + ImWchar* buf_out = buf; + ImWchar* buf_end = buf + buf_size; + while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text) + { + unsigned int c; + in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); + if (c == 0) + break; + if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes + *buf_out++ = (ImWchar)c; + } + *buf_out = 0; + if (in_text_remaining) + *in_text_remaining = in_text; + return (int)(buf_out - buf); +} + +int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end) +{ + int char_count = 0; + while ((!in_text_end || in_text < in_text_end) && *in_text) + { + unsigned int c; + in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); + if (c == 0) + break; + if (c < 0x10000) + char_count++; + } + return char_count; +} + +// Based on stb_to_utf8() from github.com/nothings/stb/ +static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c) +{ + if (c < 0x80) + { + buf[0] = (char)c; + return 1; + } + if (c < 0x800) + { + if (buf_size < 2) return 0; + buf[0] = (char)(0xc0 + (c >> 6)); + buf[1] = (char)(0x80 + (c & 0x3f)); + return 2; + } + if (c >= 0xdc00 && c < 0xe000) + { + return 0; + } + if (c >= 0xd800 && c < 0xdc00) + { + if (buf_size < 4) return 0; + buf[0] = (char)(0xf0 + (c >> 18)); + buf[1] = (char)(0x80 + ((c >> 12) & 0x3f)); + buf[2] = (char)(0x80 + ((c >> 6) & 0x3f)); + buf[3] = (char)(0x80 + ((c ) & 0x3f)); + return 4; + } + //else if (c < 0x10000) + { + if (buf_size < 3) return 0; + buf[0] = (char)(0xe0 + (c >> 12)); + buf[1] = (char)(0x80 + ((c>> 6) & 0x3f)); + buf[2] = (char)(0x80 + ((c ) & 0x3f)); + return 3; + } +} + +static inline int ImTextCountUtf8BytesFromChar(unsigned int c) +{ + if (c < 0x80) return 1; + if (c < 0x800) return 2; + if (c >= 0xdc00 && c < 0xe000) return 0; + if (c >= 0xd800 && c < 0xdc00) return 4; + return 3; +} + +int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end) +{ + char* buf_out = buf; + const char* buf_end = buf + buf_size; + while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text) + { + unsigned int c = (unsigned int)(*in_text++); + if (c < 0x80) + *buf_out++ = (char)c; + else + buf_out += ImTextCharToUtf8(buf_out, (int)(buf_end-buf_out-1), c); + } + *buf_out = 0; + return (int)(buf_out - buf); +} + +int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end) +{ + int bytes_count = 0; + while ((!in_text_end || in_text < in_text_end) && *in_text) + { + unsigned int c = (unsigned int)(*in_text++); + if (c < 0x80) + bytes_count++; + else + bytes_count += ImTextCountUtf8BytesFromChar(c); + } + return bytes_count; +} + +ImVec4 ImGui::ColorConvertU32ToFloat4(ImU32 in) +{ + float s = 1.0f/255.0f; + return ImVec4( + ((in >> IM_COL32_R_SHIFT) & 0xFF) * s, + ((in >> IM_COL32_G_SHIFT) & 0xFF) * s, + ((in >> IM_COL32_B_SHIFT) & 0xFF) * s, + ((in >> IM_COL32_A_SHIFT) & 0xFF) * s); +} + +ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in) +{ + ImU32 out; + out = ((ImU32)IM_F32_TO_INT8_SAT(in.x)) << IM_COL32_R_SHIFT; + out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << IM_COL32_G_SHIFT; + out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << IM_COL32_B_SHIFT; + out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << IM_COL32_A_SHIFT; + return out; +} + +ImU32 ImGui::GetColorU32(ImGuiCol idx, float alpha_mul) +{ + ImGuiStyle& style = GImGui->Style; + ImVec4 c = style.Colors[idx]; + c.w *= style.Alpha * alpha_mul; + return ColorConvertFloat4ToU32(c); +} + +ImU32 ImGui::GetColorU32(const ImVec4& col) +{ + ImGuiStyle& style = GImGui->Style; + ImVec4 c = col; + c.w *= style.Alpha; + return ColorConvertFloat4ToU32(c); +} + +const ImVec4& ImGui::GetStyleColorVec4(ImGuiCol idx) +{ + ImGuiStyle& style = GImGui->Style; + return style.Colors[idx]; +} + +ImU32 ImGui::GetColorU32(ImU32 col) +{ + float style_alpha = GImGui->Style.Alpha; + if (style_alpha >= 1.0f) + return col; + int a = (col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT; + a = (int)(a * style_alpha); // We don't need to clamp 0..255 because Style.Alpha is in 0..1 range. + return (col & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT); +} + +// Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592 +// Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv +void ImGui::ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v) +{ + float K = 0.f; + if (g < b) + { + ImSwap(g, b); + K = -1.f; + } + if (r < g) + { + ImSwap(r, g); + K = -2.f / 6.f - K; + } + + const float chroma = r - (g < b ? g : b); + out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f)); + out_s = chroma / (r + 1e-20f); + out_v = r; +} + +// Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593 +// also http://en.wikipedia.org/wiki/HSL_and_HSV +void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b) +{ + if (s == 0.0f) + { + // gray + out_r = out_g = out_b = v; + return; + } + + h = fmodf(h, 1.0f) / (60.0f/360.0f); + int i = (int)h; + float f = h - (float)i; + float p = v * (1.0f - s); + float q = v * (1.0f - s * f); + float t = v * (1.0f - s * (1.0f - f)); + + switch (i) + { + case 0: out_r = v; out_g = t; out_b = p; break; + case 1: out_r = q; out_g = v; out_b = p; break; + case 2: out_r = p; out_g = v; out_b = t; break; + case 3: out_r = p; out_g = q; out_b = v; break; + case 4: out_r = t; out_g = p; out_b = v; break; + case 5: default: out_r = v; out_g = p; out_b = q; break; + } +} + +FILE* ImFileOpen(const char* filename, const char* mode) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can) + const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1; + const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1; + ImVector buf; + buf.resize(filename_wsize + mode_wsize); + ImTextStrFromUtf8(&buf[0], filename_wsize, filename, NULL); + ImTextStrFromUtf8(&buf[filename_wsize], mode_wsize, mode, NULL); + return _wfopen((wchar_t*)&buf[0], (wchar_t*)&buf[filename_wsize]); +#else + return fopen(filename, mode); +#endif +} + +// Load file content into memory +// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree() +void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, int* out_file_size, int padding_bytes) +{ + IM_ASSERT(filename && file_open_mode); + if (out_file_size) + *out_file_size = 0; + + FILE* f; + if ((f = ImFileOpen(filename, file_open_mode)) == NULL) + return NULL; + + long file_size_signed; + if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) + { + fclose(f); + return NULL; + } + + int file_size = (int)file_size_signed; + void* file_data = ImGui::MemAlloc(file_size + padding_bytes); + if (file_data == NULL) + { + fclose(f); + return NULL; + } + if (fread(file_data, 1, (size_t)file_size, f) != (size_t)file_size) + { + fclose(f); + ImGui::MemFree(file_data); + return NULL; + } + if (padding_bytes > 0) + memset((void *)(((char*)file_data) + file_size), 0, padding_bytes); + + fclose(f); + if (out_file_size) + *out_file_size = file_size; + + return file_data; +} + +//----------------------------------------------------------------------------- +// ImGuiStorage +// Helper: Key->value storage +//----------------------------------------------------------------------------- + +// std::lower_bound but without the bullshit +static ImVector::iterator LowerBound(ImVector& data, ImGuiID key) +{ + ImVector::iterator first = data.begin(); + ImVector::iterator last = data.end(); + size_t count = (size_t)(last - first); + while (count > 0) + { + size_t count2 = count >> 1; + ImVector::iterator mid = first + count2; + if (mid->key < key) + { + first = ++mid; + count -= count2 + 1; + } + else + { + count = count2; + } + } + return first; +} + +// For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once. +void ImGuiStorage::BuildSortByKey() +{ + struct StaticFunc + { + static int PairCompareByID(const void* lhs, const void* rhs) + { + // We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that. + if (((const Pair*)lhs)->key > ((const Pair*)rhs)->key) return +1; + if (((const Pair*)lhs)->key < ((const Pair*)rhs)->key) return -1; + return 0; + } + }; + if (Data.Size > 1) + qsort(Data.Data, (size_t)Data.Size, sizeof(Pair), StaticFunc::PairCompareByID); +} + +int ImGuiStorage::GetInt(ImGuiID key, int default_val) const +{ + ImVector::iterator it = LowerBound(const_cast&>(Data), key); + if (it == Data.end() || it->key != key) + return default_val; + return it->val_i; +} + +bool ImGuiStorage::GetBool(ImGuiID key, bool default_val) const +{ + return GetInt(key, default_val ? 1 : 0) != 0; +} + +float ImGuiStorage::GetFloat(ImGuiID key, float default_val) const +{ + ImVector::iterator it = LowerBound(const_cast&>(Data), key); + if (it == Data.end() || it->key != key) + return default_val; + return it->val_f; +} + +void* ImGuiStorage::GetVoidPtr(ImGuiID key) const +{ + ImVector::iterator it = LowerBound(const_cast&>(Data), key); + if (it == Data.end() || it->key != key) + return NULL; + return it->val_p; +} + +// References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer. +int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + it = Data.insert(it, Pair(key, default_val)); + return &it->val_i; +} + +bool* ImGuiStorage::GetBoolRef(ImGuiID key, bool default_val) +{ + return (bool*)GetIntRef(key, default_val ? 1 : 0); +} + +float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + it = Data.insert(it, Pair(key, default_val)); + return &it->val_f; +} + +void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + it = Data.insert(it, Pair(key, default_val)); + return &it->val_p; +} + +// FIXME-OPT: Need a way to reuse the result of lower_bound when doing GetInt()/SetInt() - not too bad because it only happens on explicit interaction (maximum one a frame) +void ImGuiStorage::SetInt(ImGuiID key, int val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + { + Data.insert(it, Pair(key, val)); + return; + } + it->val_i = val; +} + +void ImGuiStorage::SetBool(ImGuiID key, bool val) +{ + SetInt(key, val ? 1 : 0); +} + +void ImGuiStorage::SetFloat(ImGuiID key, float val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + { + Data.insert(it, Pair(key, val)); + return; + } + it->val_f = val; +} + +void ImGuiStorage::SetVoidPtr(ImGuiID key, void* val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + { + Data.insert(it, Pair(key, val)); + return; + } + it->val_p = val; +} + +void ImGuiStorage::SetAllInt(int v) +{ + for (int i = 0; i < Data.Size; i++) + Data[i].val_i = v; +} + +//----------------------------------------------------------------------------- +// ImGuiTextFilter +//----------------------------------------------------------------------------- + +// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" +ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) +{ + if (default_filter) + { + ImStrncpy(InputBuf, default_filter, IM_ARRAYSIZE(InputBuf)); + Build(); + } + else + { + InputBuf[0] = 0; + CountGrep = 0; + } +} + +bool ImGuiTextFilter::Draw(const char* label, float width) +{ + if (width != 0.0f) + ImGui::PushItemWidth(width); + bool value_changed = ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf)); + if (width != 0.0f) + ImGui::PopItemWidth(); + if (value_changed) + Build(); + return value_changed; +} + +void ImGuiTextFilter::TextRange::split(char separator, ImVector& out) +{ + out.resize(0); + const char* wb = b; + const char* we = wb; + while (we < e) + { + if (*we == separator) + { + out.push_back(TextRange(wb, we)); + wb = we + 1; + } + we++; + } + if (wb != we) + out.push_back(TextRange(wb, we)); +} + +void ImGuiTextFilter::Build() +{ + Filters.resize(0); + TextRange input_range(InputBuf, InputBuf+strlen(InputBuf)); + input_range.split(',', Filters); + + CountGrep = 0; + for (int i = 0; i != Filters.Size; i++) + { + Filters[i].trim_blanks(); + if (Filters[i].empty()) + continue; + if (Filters[i].front() != '-') + CountGrep += 1; + } +} + +bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const +{ + if (Filters.empty()) + return true; + + if (text == NULL) + text = ""; + + for (int i = 0; i != Filters.Size; i++) + { + const TextRange& f = Filters[i]; + if (f.empty()) + continue; + if (f.front() == '-') + { + // Subtract + if (ImStristr(text, text_end, f.begin()+1, f.end()) != NULL) + return false; + } + else + { + // Grep + if (ImStristr(text, text_end, f.begin(), f.end()) != NULL) + return true; + } + } + + // Implicit * grep + if (CountGrep == 0) + return true; + + return false; +} + +//----------------------------------------------------------------------------- +// ImGuiTextBuffer +//----------------------------------------------------------------------------- + +// On some platform vsnprintf() takes va_list by reference and modifies it. +// va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it. +#ifndef va_copy +#define va_copy(dest, src) (dest = src) +#endif + +// Helper: Text buffer for logging/accumulating text +void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) +{ + va_list args_copy; + va_copy(args_copy, args); + + int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. + if (len <= 0) + return; + + const int write_off = Buf.Size; + const int needed_sz = write_off + len; + if (write_off + len >= Buf.Capacity) + { + int double_capacity = Buf.Capacity * 2; + Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity); + } + + Buf.resize(needed_sz); + ImFormatStringV(&Buf[write_off - 1], len + 1, fmt, args_copy); +} + +void ImGuiTextBuffer::appendf(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + appendfv(fmt, args); + va_end(args); +} + +//----------------------------------------------------------------------------- +// ImGuiSimpleColumns (internal use only) +//----------------------------------------------------------------------------- + +ImGuiSimpleColumns::ImGuiSimpleColumns() +{ + Count = 0; + Spacing = Width = NextWidth = 0.0f; + memset(Pos, 0, sizeof(Pos)); + memset(NextWidths, 0, sizeof(NextWidths)); +} + +void ImGuiSimpleColumns::Update(int count, float spacing, bool clear) +{ + IM_ASSERT(Count <= IM_ARRAYSIZE(Pos)); + Count = count; + Width = NextWidth = 0.0f; + Spacing = spacing; + if (clear) memset(NextWidths, 0, sizeof(NextWidths)); + for (int i = 0; i < Count; i++) + { + if (i > 0 && NextWidths[i] > 0.0f) + Width += Spacing; + Pos[i] = (float)(int)Width; + Width += NextWidths[i]; + NextWidths[i] = 0.0f; + } +} + +float ImGuiSimpleColumns::DeclColumns(float w0, float w1, float w2) // not using va_arg because they promote float to double +{ + NextWidth = 0.0f; + NextWidths[0] = ImMax(NextWidths[0], w0); + NextWidths[1] = ImMax(NextWidths[1], w1); + NextWidths[2] = ImMax(NextWidths[2], w2); + for (int i = 0; i < 3; i++) + NextWidth += NextWidths[i] + ((i > 0 && NextWidths[i] > 0.0f) ? Spacing : 0.0f); + return ImMax(Width, NextWidth); +} + +float ImGuiSimpleColumns::CalcExtraSpace(float avail_w) +{ + return ImMax(0.0f, avail_w - Width); +} + +//----------------------------------------------------------------------------- +// ImGuiListClipper +//----------------------------------------------------------------------------- + +static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height) +{ + // Set cursor position and a few other things so that SetScrollHere() and Columns() can work when seeking cursor. + // FIXME: It is problematic that we have to do that here, because custom/equivalent end-user code would stumble on the same issue. Consider moving within SetCursorXXX functions? + ImGui::SetCursorPosY(pos_y); + ImGuiWindow* window = ImGui::GetCurrentWindow(); + window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHere() can properly function after the end of our clipper usage. + window->DC.PrevLineHeight = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list. + if (window->DC.ColumnsSet) + window->DC.ColumnsSet->CellMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly +} + +// Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1 +// Use case B: Begin() called from constructor with items_height>0 +// FIXME-LEGACY: Ideally we should remove the Begin/End functions but they are part of the legacy API we still support. This is why some of the code in Step() calling Begin() and reassign some fields, spaghetti style. +void ImGuiListClipper::Begin(int count, float items_height) +{ + StartPosY = ImGui::GetCursorPosY(); + ItemsHeight = items_height; + ItemsCount = count; + StepNo = 0; + DisplayEnd = DisplayStart = -1; + if (ItemsHeight > 0.0f) + { + ImGui::CalcListClipping(ItemsCount, ItemsHeight, &DisplayStart, &DisplayEnd); // calculate how many to clip/display + if (DisplayStart > 0) + SetCursorPosYAndSetupDummyPrevLine(StartPosY + DisplayStart * ItemsHeight, ItemsHeight); // advance cursor + StepNo = 2; + } +} + +void ImGuiListClipper::End() +{ + if (ItemsCount < 0) + return; + // In theory here we should assert that ImGui::GetCursorPosY() == StartPosY + DisplayEnd * ItemsHeight, but it feels saner to just seek at the end and not assert/crash the user. + if (ItemsCount < INT_MAX) + SetCursorPosYAndSetupDummyPrevLine(StartPosY + ItemsCount * ItemsHeight, ItemsHeight); // advance cursor + ItemsCount = -1; + StepNo = 3; +} + +bool ImGuiListClipper::Step() +{ + if (ItemsCount == 0 || ImGui::GetCurrentWindowRead()->SkipItems) + { + ItemsCount = -1; + return false; + } + if (StepNo == 0) // Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height. + { + DisplayStart = 0; + DisplayEnd = 1; + StartPosY = ImGui::GetCursorPosY(); + StepNo = 1; + return true; + } + if (StepNo == 1) // Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element. + { + if (ItemsCount == 1) { ItemsCount = -1; return false; } + float items_height = ImGui::GetCursorPosY() - StartPosY; + IM_ASSERT(items_height > 0.0f); // If this triggers, it means Item 0 hasn't moved the cursor vertically + Begin(ItemsCount-1, items_height); + DisplayStart++; + DisplayEnd++; + StepNo = 3; + return true; + } + if (StepNo == 2) // Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user still call Step(). Does nothing and switch to Step 3. + { + IM_ASSERT(DisplayStart >= 0 && DisplayEnd >= 0); + StepNo = 3; + return true; + } + if (StepNo == 3) // Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop. + End(); + return false; +} + +//----------------------------------------------------------------------------- +// ImGuiWindow +//----------------------------------------------------------------------------- + +ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) +{ + Name = ImStrdup(name); + ID = ImHash(name, 0); + IDStack.push_back(ID); + Flags = 0; + PosFloat = Pos = ImVec2(0.0f, 0.0f); + Size = SizeFull = ImVec2(0.0f, 0.0f); + SizeContents = SizeContentsExplicit = ImVec2(0.0f, 0.0f); + WindowPadding = ImVec2(0.0f, 0.0f); + WindowRounding = 0.0f; + WindowBorderSize = 0.0f; + MoveId = GetID("#MOVE"); + Scroll = ImVec2(0.0f, 0.0f); + ScrollTarget = ImVec2(FLT_MAX, FLT_MAX); + ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f); + ScrollbarX = ScrollbarY = false; + ScrollbarSizes = ImVec2(0.0f, 0.0f); + Active = WasActive = false; + WriteAccessed = false; + Collapsed = false; + SkipItems = false; + Appearing = false; + CloseButton = false; + BeginOrderWithinParent = -1; + BeginOrderWithinContext = -1; + BeginCount = 0; + PopupId = 0; + AutoFitFramesX = AutoFitFramesY = -1; + AutoFitOnlyGrows = false; + AutoFitChildAxises = 0x00; + AutoPosLastDirection = ImGuiDir_None; + HiddenFrames = 0; + SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; + SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX); + + LastFrameActive = -1; + ItemWidthDefault = 0.0f; + FontWindowScale = 1.0f; + + DrawList = IM_NEW(ImDrawList)(&context->DrawListSharedData); + DrawList->_OwnerName = Name; + ParentWindow = NULL; + RootWindow = NULL; + RootNonPopupWindow = NULL; + + FocusIdxAllCounter = FocusIdxTabCounter = -1; + FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = INT_MAX; + FocusIdxAllRequestNext = FocusIdxTabRequestNext = INT_MAX; +} + +ImGuiWindow::~ImGuiWindow() +{ + IM_DELETE(DrawList); + IM_DELETE(Name); +} + +ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end) +{ + ImGuiID seed = IDStack.back(); + ImGuiID id = ImHash(str, str_end ? (int)(str_end - str) : 0, seed); + ImGui::KeepAliveID(id); + return id; +} + +ImGuiID ImGuiWindow::GetID(const void* ptr) +{ + ImGuiID seed = IDStack.back(); + ImGuiID id = ImHash(&ptr, sizeof(void*), seed); + ImGui::KeepAliveID(id); + return id; +} + +ImGuiID ImGuiWindow::GetIDNoKeepAlive(const char* str, const char* str_end) +{ + ImGuiID seed = IDStack.back(); + return ImHash(str, str_end ? (int)(str_end - str) : 0, seed); +} + +// This is only used in rare/specific situations to manufacture an ID out of nowhere. +ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs) +{ + ImGuiID seed = IDStack.back(); + const int r_rel[4] = { (int)(r_abs.Min.x - Pos.x), (int)(r_abs.Min.y - Pos.y), (int)(r_abs.Max.x - Pos.x), (int)(r_abs.Max.y - Pos.y) }; + ImGuiID id = ImHash(&r_rel, sizeof(r_rel), seed); + ImGui::KeepAliveID(id); + return id; +} + +//----------------------------------------------------------------------------- +// Internal API exposed in imgui_internal.h +//----------------------------------------------------------------------------- + +static void SetCurrentWindow(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + g.CurrentWindow = window; + if (window) + g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); +} + +void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + g.ActiveIdIsJustActivated = (g.ActiveId != id); + if (g.ActiveIdIsJustActivated) + g.ActiveIdTimer = 0.0f; + g.ActiveId = id; + g.ActiveIdAllowOverlap = false; + g.ActiveIdIsAlive |= (id != 0); + g.ActiveIdWindow = window; +} + +void ImGui::ClearActiveID() +{ + SetActiveID(0, NULL); +} + +void ImGui::SetHoveredID(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + g.HoveredId = id; + g.HoveredIdAllowOverlap = false; + g.HoveredIdTimer = (id != 0 && g.HoveredIdPreviousFrame == id) ? (g.HoveredIdTimer + g.IO.DeltaTime) : 0.0f; +} + +void ImGui::KeepAliveID(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + if (g.ActiveId == id) + g.ActiveIdIsAlive = true; +} + +static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flags) +{ + // An active popup disable hovering on other windows (apart from its own children) + // FIXME-OPT: This could be cached/stored within the window. + ImGuiContext& g = *GImGui; + if (g.NavWindow) + if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) + if (focused_root_window->WasActive && focused_root_window != window->RootWindow) + { + // For the purpose of those flags we differentiate "standard popup" from "modal popup" + // NB: The order of those two tests is important because Modal windows are also Popups. + if (focused_root_window->Flags & ImGuiWindowFlags_Modal) + return false; + if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + return false; + } + + return true; +} + +// Advance cursor given item size for layout. +void ImGui::ItemSize(const ImVec2& size, float text_offset_y) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + if (window->SkipItems) + return; + + // Always align ourselves on pixel boundaries + const float line_height = ImMax(window->DC.CurrentLineHeight, size.y); + const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y); + //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] + window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y); + window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y)); + window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); + //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] + + window->DC.PrevLineHeight = line_height; + window->DC.PrevLineTextBaseOffset = text_base_offset; + window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f; + + // Horizontal layout mode + if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) + SameLine(); +} + +void ImGui::ItemSize(const ImRect& bb, float text_offset_y) +{ + ItemSize(bb.GetSize(), text_offset_y); +} + +// Declare item bounding box for clipping and interaction. +// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface +// declares their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd(). +bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + const bool is_clipped = IsClippedEx(bb, id, false); + window->DC.LastItemId = id; + window->DC.LastItemRect = bb; + window->DC.LastItemRectHoveredRect = false; + if (is_clipped) + return false; + //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG] + + // We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them) + window->DC.LastItemRectHoveredRect = IsMouseHoveringRect(bb.Min, bb.Max); + return true; +} + +// This is roughly matching the behavior of internal-facing ItemHoverable() +// - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered() +// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId +bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + // Test for bounding box overlap, as updated as ItemAdd() + if (!window->DC.LastItemRectHoveredRect) + return false; + IM_ASSERT((flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows)) == 0); // Flags not supported by this function + + // Test if we are hovering the right window (our window could be behind another window) + // [2017/10/16] Reverted commit 344d48be3 and testing RootWindow instead. I believe it is correct to NOT test for RootWindow but this leaves us unable to use IsItemHovered() after EndChild() itself. + // Until a solution is found I believe reverting to the test from 2017/09/27 is safe since this was the test that has been running for a long while. + //if (g.HoveredWindow != window) + // return false; + if (g.HoveredRootWindow != window->RootWindow && !(flags & ImGuiHoveredFlags_AllowWhenOverlapped)) + return false; + + // Test if another item is active (e.g. being dragged) + if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + if (g.ActiveId != 0 && g.ActiveId != window->DC.LastItemId && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId) + return false; + + // Test if interactions on this window are blocked by an active popup or modal + if (!IsWindowContentHoverable(window, flags)) + return false; + + // Test if the item is disabled + if (window->DC.ItemFlags & ImGuiItemFlags_Disabled) + return false; + + // Special handling for the 1st item after Begin() which represent the title bar. When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect tht case. + if (window->DC.LastItemId == window->MoveId && window->WriteAccessed) + return false; + return true; +} + +// Internal facing ItemHoverable() used when submitting widgets. Differs slightly from IsItemHovered(). +bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) +{ + ImGuiContext& g = *GImGui; + if (g.HoveredId != 0 && g.HoveredId != id && !g.HoveredIdAllowOverlap) + return false; + + ImGuiWindow* window = g.CurrentWindow; + if (g.HoveredWindow != window) + return false; + if (g.ActiveId != 0 && g.ActiveId != id && !g.ActiveIdAllowOverlap) + return false; + if (!IsMouseHoveringRect(bb.Min, bb.Max)) + return false; + if (!IsWindowContentHoverable(window, ImGuiHoveredFlags_Default)) + return false; + if (window->DC.ItemFlags & ImGuiItemFlags_Disabled) + return false; + + SetHoveredID(id); + return true; +} + +bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + if (!bb.Overlaps(window->ClipRect)) + if (id == 0 || id != g.ActiveId) + if (clip_even_when_logged || !g.LogEnabled) + return true; + return false; +} + +bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop) +{ + ImGuiContext& g = *GImGui; + + const bool allow_keyboard_focus = (window->DC.ItemFlags & (ImGuiItemFlags_AllowKeyboardFocus | ImGuiItemFlags_Disabled)) == ImGuiItemFlags_AllowKeyboardFocus; + window->FocusIdxAllCounter++; + if (allow_keyboard_focus) + window->FocusIdxTabCounter++; + + // Process keyboard input at this point: TAB/Shift-TAB to tab out of the currently focused item. + // Note that we can always TAB out of a widget that doesn't allow tabbing in. + if (tab_stop && (g.ActiveId == id) && window->FocusIdxAllRequestNext == INT_MAX && window->FocusIdxTabRequestNext == INT_MAX && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab)) + window->FocusIdxTabRequestNext = window->FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items. + + if (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent) + return true; + + if (allow_keyboard_focus) + if (window->FocusIdxTabCounter == window->FocusIdxTabRequestCurrent) + return true; + + return false; +} + +void ImGui::FocusableItemUnregister(ImGuiWindow* window) +{ + window->FocusIdxAllCounter--; + window->FocusIdxTabCounter--; +} + +ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_x, float default_y) +{ + ImGuiContext& g = *GImGui; + ImVec2 content_max; + if (size.x < 0.0f || size.y < 0.0f) + content_max = g.CurrentWindow->Pos + GetContentRegionMax(); + if (size.x <= 0.0f) + size.x = (size.x == 0.0f) ? default_x : ImMax(content_max.x - g.CurrentWindow->DC.CursorPos.x, 4.0f) + size.x; + if (size.y <= 0.0f) + size.y = (size.y == 0.0f) ? default_y : ImMax(content_max.y - g.CurrentWindow->DC.CursorPos.y, 4.0f) + size.y; + return size; +} + +float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x) +{ + if (wrap_pos_x < 0.0f) + return 0.0f; + + ImGuiWindow* window = GetCurrentWindowRead(); + if (wrap_pos_x == 0.0f) + wrap_pos_x = GetContentRegionMax().x + window->Pos.x; + else if (wrap_pos_x > 0.0f) + wrap_pos_x += window->Pos.x - window->Scroll.x; // wrap_pos_x is provided is window local space + + return ImMax(wrap_pos_x - pos.x, 1.0f); +} + +//----------------------------------------------------------------------------- + +void* ImGui::MemAlloc(size_t sz) +{ + GImGui->IO.MetricsAllocs++; + return GImGui->IO.MemAllocFn(sz); +} + +void ImGui::MemFree(void* ptr) +{ + if (ptr) GImGui->IO.MetricsAllocs--; + return GImGui->IO.MemFreeFn(ptr); +} + +const char* ImGui::GetClipboardText() +{ + return GImGui->IO.GetClipboardTextFn ? GImGui->IO.GetClipboardTextFn(GImGui->IO.ClipboardUserData) : ""; +} + +void ImGui::SetClipboardText(const char* text) +{ + if (GImGui->IO.SetClipboardTextFn) + GImGui->IO.SetClipboardTextFn(GImGui->IO.ClipboardUserData, text); +} + +const char* ImGui::GetVersion() +{ + return IMGUI_VERSION; +} + +// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself +// Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module +ImGuiContext* ImGui::GetCurrentContext() +{ + return GImGui; +} + +void ImGui::SetCurrentContext(ImGuiContext* ctx) +{ +#ifdef IMGUI_SET_CURRENT_CONTEXT_FUNC + IMGUI_SET_CURRENT_CONTEXT_FUNC(ctx); // For custom thread-based hackery you may want to have control over this. +#else + GImGui = ctx; +#endif +} + +ImGuiContext* ImGui::CreateContext(void* (*malloc_fn)(size_t), void (*free_fn)(void*)) +{ + if (!malloc_fn) malloc_fn = malloc; + ImGuiContext* ctx = (ImGuiContext*)malloc_fn(sizeof(ImGuiContext)); + IM_PLACEMENT_NEW(ctx) ImGuiContext(); + ctx->IO.MemAllocFn = malloc_fn; + ctx->IO.MemFreeFn = free_fn ? free_fn : free; + return ctx; +} + +void ImGui::DestroyContext(ImGuiContext* ctx) +{ + void (*free_fn)(void*) = ctx->IO.MemFreeFn; + ctx->~ImGuiContext(); + free_fn(ctx); + if (GImGui == ctx) + SetCurrentContext(NULL); +} + +ImGuiIO& ImGui::GetIO() +{ + return GImGui->IO; +} + +ImGuiStyle& ImGui::GetStyle() +{ + return GImGui->Style; +} + +// Same value as passed to your RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame() +ImDrawData* ImGui::GetDrawData() +{ + return GImGui->RenderDrawData.Valid ? &GImGui->RenderDrawData : NULL; +} + +float ImGui::GetTime() +{ + return GImGui->Time; +} + +int ImGui::GetFrameCount() +{ + return GImGui->FrameCount; +} + +ImDrawList* ImGui::GetOverlayDrawList() +{ + return &GImGui->OverlayDrawList; +} + +ImDrawListSharedData* ImGui::GetDrawListSharedData() +{ + return &GImGui->DrawListSharedData; +} + +void ImGui::NewFrame() +{ + ImGuiContext& g = *GImGui; + + // Check user data + // (We pass an error message in the assert expression as a trick to get it visible to programmers who are not using a debugger, as most assert handlers display their argument) + IM_ASSERT(g.IO.DeltaTime >= 0.0f && "Need a positive DeltaTime (zero is tolerated but will cause some timing issues)"); + IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value"); + IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?"); + IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?"); + IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting"); + IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)"); + IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?"); + + // Initialize on first frame + if (!g.Initialized) + Initialize(); + + SetCurrentFont(GetDefaultFont()); + IM_ASSERT(g.Font->IsLoaded()); + g.DrawListSharedData.ClipRectFullscreen = ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); + g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; + + g.Time += g.IO.DeltaTime; + g.FrameCount += 1; + g.TooltipOverrideCount = 0; + g.WindowsActiveCount = 0; + g.OverlayDrawList.Clear(); + g.OverlayDrawList.PushTextureID(g.IO.Fonts->TexID); + g.OverlayDrawList.PushClipRectFullScreen(); + g.OverlayDrawList.Flags = (g.Style.AntiAliasedLines ? ImDrawListFlags_AntiAliasedLines : 0) | (g.Style.AntiAliasedFill ? ImDrawListFlags_AntiAliasedFill : 0); + + // Mark rendering data as invalid to prevent user who may have a handle on it to use it + g.RenderDrawData.Valid = false; + g.RenderDrawData.CmdLists = NULL; + g.RenderDrawData.CmdListsCount = g.RenderDrawData.TotalVtxCount = g.RenderDrawData.TotalIdxCount = 0; + + // Clear reference to active widget if the widget isn't alive anymore + if (!g.HoveredIdPreviousFrame) + g.HoveredIdTimer = 0.0f; + g.HoveredIdPreviousFrame = g.HoveredId; + g.HoveredId = 0; + g.HoveredIdAllowOverlap = false; + if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) + ClearActiveID(); + if (g.ActiveId) + g.ActiveIdTimer += g.IO.DeltaTime; + g.ActiveIdPreviousFrame = g.ActiveId; + g.ActiveIdIsAlive = false; + g.ActiveIdIsJustActivated = false; + if (g.ScalarAsInputTextId && g.ActiveId != g.ScalarAsInputTextId) + g.ScalarAsInputTextId = 0; + + // Elapse drag & drop payload + if (g.DragDropActive && g.DragDropPayload.DataFrameCount + 1 < g.FrameCount) + { + ClearDragDrop(); + g.DragDropPayloadBufHeap.clear(); + memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal)); + } + g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr; + g.DragDropAcceptIdCurr = 0; + g.DragDropAcceptIdCurrRectSurface = FLT_MAX; + + // Update keyboard input state + memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration)); + for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) + g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f; + + // Update mouse input state + // If mouse just appeared or disappeared (usually denoted by -FLT_MAX component, but in reality we test for -256000.0f) we cancel out movement in MouseDelta + if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev)) + g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev; + else + g.IO.MouseDelta = ImVec2(0.0f, 0.0f); + g.IO.MousePosPrev = g.IO.MousePos; + for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++) + { + g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f; + g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f; + g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i]; + g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f; + g.IO.MouseDoubleClicked[i] = false; + if (g.IO.MouseClicked[i]) + { + if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime) + { + if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist) + g.IO.MouseDoubleClicked[i] = true; + g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click + } + else + { + g.IO.MouseClickedTime[i] = g.Time; + } + g.IO.MouseClickedPos[i] = g.IO.MousePos; + g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); + g.IO.MouseDragMaxDistanceSqr[i] = 0.0f; + } + else if (g.IO.MouseDown[i]) + { + ImVec2 mouse_delta = g.IO.MousePos - g.IO.MouseClickedPos[i]; + g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, mouse_delta.x < 0.0f ? -mouse_delta.x : mouse_delta.x); + g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, mouse_delta.y < 0.0f ? -mouse_delta.y : mouse_delta.y); + g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(mouse_delta)); + } + } + + // Calculate frame-rate for the user, as a purely luxurious feature + g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx]; + g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime; + g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame); + g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame)); + + // Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows. + if (g.MovingWindowMoveId && g.MovingWindowMoveId == g.ActiveId) + { + KeepAliveID(g.MovingWindowMoveId); + IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow); + IM_ASSERT(g.MovingWindow->MoveId == g.MovingWindowMoveId); + if (g.IO.MouseDown[0]) + { + ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset; + if (g.MovingWindow->RootWindow->PosFloat.x != pos.x || g.MovingWindow->RootWindow->PosFloat.y != pos.y) + MarkIniSettingsDirty(g.MovingWindow->RootWindow); + g.MovingWindow->RootWindow->PosFloat = pos; + FocusWindow(g.MovingWindow); + } + else + { + ClearActiveID(); + g.MovingWindow = NULL; + g.MovingWindowMoveId = 0; + } + } + else + { + g.MovingWindow = NULL; + g.MovingWindowMoveId = 0; + } + + // Delay saving settings so we don't spam disk too much + if (g.SettingsDirtyTimer > 0.0f) + { + g.SettingsDirtyTimer -= g.IO.DeltaTime; + if (g.SettingsDirtyTimer <= 0.0f) + SaveIniSettingsToDisk(g.IO.IniFilename); + } + + // Find the window we are hovering + // - Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow. + // - When moving a window we can skip the search, which also conveniently bypasses the fact that window->WindowRectClipped is lagging as this point. + // - We also support the moved window toggling the NoInputs flag after moving has started in order to be able to detect windows below it, which is useful for e.g. docking mechanisms. + g.HoveredWindow = (g.MovingWindow && !(g.MovingWindow->Flags & ImGuiWindowFlags_NoInputs)) ? g.MovingWindow : FindHoveredWindow(g.IO.MousePos); + g.HoveredRootWindow = g.HoveredWindow ? g.HoveredWindow->RootWindow : NULL; + + ImGuiWindow* modal_window = GetFrontMostModalRootWindow(); + if (modal_window != NULL) + { + g.ModalWindowDarkeningRatio = ImMin(g.ModalWindowDarkeningRatio + g.IO.DeltaTime * 6.0f, 1.0f); + if (g.HoveredRootWindow && !IsWindowChildOf(g.HoveredRootWindow, modal_window)) + g.HoveredRootWindow = g.HoveredWindow = NULL; + } + else + { + g.ModalWindowDarkeningRatio = 0.0f; + } + + // Update the WantCaptureMouse/WantCAptureKeyboard flags, so user can capture/discard the inputs away from the rest of their application. + // When clicking outside of a window we assume the click is owned by the application and won't request capture. We need to track click ownership. + int mouse_earliest_button_down = -1; + bool mouse_any_down = false; + for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++) + { + if (g.IO.MouseClicked[i]) + g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL) || (!g.OpenPopupStack.empty()); + mouse_any_down |= g.IO.MouseDown[i]; + if (g.IO.MouseDown[i]) + if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[i] < g.IO.MouseClickedTime[mouse_earliest_button_down]) + mouse_earliest_button_down = i; + } + bool mouse_avail_to_imgui = (mouse_earliest_button_down == -1) || g.IO.MouseDownOwned[mouse_earliest_button_down]; + if (g.WantCaptureMouseNextFrame != -1) + g.IO.WantCaptureMouse = (g.WantCaptureMouseNextFrame != 0); + else + g.IO.WantCaptureMouse = (mouse_avail_to_imgui && (g.HoveredWindow != NULL || mouse_any_down)) || (!g.OpenPopupStack.empty()); + if (g.WantCaptureKeyboardNextFrame != -1) + g.IO.WantCaptureKeyboard = (g.WantCaptureKeyboardNextFrame != 0); + else + g.IO.WantCaptureKeyboard = (g.ActiveId != 0) || (modal_window != NULL); + g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : 0; + g.MouseCursor = ImGuiMouseCursor_Arrow; + g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1; + g.OsImePosRequest = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default + + // If mouse was first clicked outside of ImGui bounds we also cancel out hovering. + // FIXME: For patterns of drag and drop across OS windows, we may need to rework/remove this test (first committed 311c0ca9 on 2015/02) + bool mouse_dragging_extern_payload = g.DragDropActive && (g.DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern) != 0; + if (!mouse_avail_to_imgui && !mouse_dragging_extern_payload) + g.HoveredWindow = g.HoveredRootWindow = NULL; + + // Scale & Scrolling + if (g.HoveredWindow && g.IO.MouseWheel != 0.0f && !g.HoveredWindow->Collapsed) + { + ImGuiWindow* window = g.HoveredWindow; + if (g.IO.KeyCtrl && g.IO.FontAllowUserScaling) + { + // Zoom / Scale window + const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); + const float scale = new_font_scale / window->FontWindowScale; + window->FontWindowScale = new_font_scale; + + const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; + window->Pos += offset; + window->PosFloat += offset; + window->Size *= scale; + window->SizeFull *= scale; + } + else if (!g.IO.KeyCtrl) + { + // Mouse wheel Scrolling + // If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent (unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set). + ImGuiWindow* scroll_window = window; + while ((scroll_window->Flags & ImGuiWindowFlags_ChildWindow) && (scroll_window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(scroll_window->Flags & ImGuiWindowFlags_NoScrollbar) && !(scroll_window->Flags & ImGuiWindowFlags_NoInputs) && scroll_window->ParentWindow) + scroll_window = scroll_window->ParentWindow; + + if (!(scroll_window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(scroll_window->Flags & ImGuiWindowFlags_NoInputs)) + { + float scroll_amount = 5 * scroll_window->CalcFontSize(); + scroll_amount = (float)(int)ImMin(scroll_amount, (scroll_window->ContentsRegionRect.GetHeight() + scroll_window->WindowPadding.y * 2.0f) * 0.67f); + SetWindowScrollY(scroll_window, scroll_window->Scroll.y - g.IO.MouseWheel * scroll_amount); + } + } + } + + // Pressing TAB activate widget focus + if (g.ActiveId == 0 && g.NavWindow != NULL && g.NavWindow->Active && IsKeyPressedMap(ImGuiKey_Tab, false)) + g.NavWindow->FocusIdxTabRequestNext = 0; + + // Mark all windows as not visible + for (int i = 0; i != g.Windows.Size; i++) + { + ImGuiWindow* window = g.Windows[i]; + window->WasActive = window->Active; + window->Active = false; + window->WriteAccessed = false; + } + + // Closing the focused window restore focus to the first active root window in descending z-order + if (g.NavWindow && !g.NavWindow->WasActive) + FocusPreviousWindow(); + + // No window should be open at the beginning of the frame. + // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear. + g.CurrentWindowStack.resize(0); + g.CurrentPopupStack.resize(0); + CloseInactivePopups(g.NavWindow); + + // Create implicit window - we will only render it if the user has added something to it. + // We don't use "Debug" to avoid colliding with user trying to create a "Debug" window with custom flags. + SetNextWindowSize(ImVec2(400,400), ImGuiCond_FirstUseEver); + Begin("Debug##Default"); +} + +static void* SettingsHandlerWindow_ReadOpen(ImGuiContext&, const char* name) +{ + ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHash(name, 0)); + if (!settings) + settings = AddWindowSettings(name); + return (void*)settings; +} + +static void SettingsHandlerWindow_ReadLine(ImGuiContext&, void* entry, const char* line) +{ + ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry; + float x, y; + int i; + if (sscanf(line, "Pos=%f,%f", &x, &y) == 2) settings->Pos = ImVec2(x, y); + else if (sscanf(line, "Size=%f,%f", &x, &y) == 2) settings->Size = ImMax(ImVec2(x, y), GImGui->Style.WindowMinSize); + else if (sscanf(line, "Collapsed=%d", &i) == 1) settings->Collapsed = (i != 0); +} + +static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf) +{ + // Gather data from windows that were active during this session + for (int i = 0; i != g.Windows.Size; i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Flags & ImGuiWindowFlags_NoSavedSettings) + continue; + ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); + if (!settings) + settings = AddWindowSettings(window->Name); + settings->Pos = window->Pos; + settings->Size = window->SizeFull; + settings->Collapsed = window->Collapsed; + } + + // Write a buffer + // If a window wasn't opened in this session we preserve its settings + buf->reserve(buf->size() + g.SettingsWindows.Size * 96); // ballpark reserve + for (int i = 0; i != g.SettingsWindows.Size; i++) + { + const ImGuiWindowSettings* settings = &g.SettingsWindows[i]; + if (settings->Pos.x == FLT_MAX) + continue; + const char* name = settings->Name; + if (const char* p = strstr(name, "###")) // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID() + name = p; + buf->appendf("[Window][%s]\n", name); + buf->appendf("Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y); + buf->appendf("Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y); + buf->appendf("Collapsed=%d\n", settings->Collapsed); + buf->appendf("\n"); + } +} + +void ImGui::Initialize() +{ + ImGuiContext& g = *GImGui; + g.LogClipboard = IM_NEW(ImGuiTextBuffer)(); + + // Add .ini handle for ImGuiWindow type + ImGuiSettingsHandler ini_handler; + ini_handler.TypeName = "Window"; + ini_handler.TypeHash = ImHash("Window", 0, 0); + ini_handler.ReadOpenFn = SettingsHandlerWindow_ReadOpen; + ini_handler.ReadLineFn = SettingsHandlerWindow_ReadLine; + ini_handler.WriteAllFn = SettingsHandlerWindow_WriteAll; + g.SettingsHandlers.push_front(ini_handler); + + // Load .ini file + IM_ASSERT(g.SettingsWindows.empty()); + LoadIniSettingsFromDisk(g.IO.IniFilename); + g.Initialized = true; +} + +// This function is merely here to free heap allocations. +void ImGui::Shutdown() +{ + ImGuiContext& g = *GImGui; + + // The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame) + if (g.IO.Fonts) // Testing for NULL to allow user to NULLify in case of running Shutdown() on multiple contexts. Bit hacky. + g.IO.Fonts->Clear(); + + // Cleanup of other data are conditional on actually having initialize ImGui. + if (!g.Initialized) + return; + + SaveIniSettingsToDisk(g.IO.IniFilename); + + for (int i = 0; i < g.Windows.Size; i++) + IM_DELETE(g.Windows[i]); + g.Windows.clear(); + g.WindowsSortBuffer.clear(); + g.CurrentWindow = NULL; + g.CurrentWindowStack.clear(); + g.WindowsById.Clear(); + g.NavWindow = NULL; + g.HoveredWindow = NULL; + g.HoveredRootWindow = NULL; + g.ActiveIdWindow = NULL; + g.MovingWindow = NULL; + for (int i = 0; i < g.SettingsWindows.Size; i++) + IM_DELETE(g.SettingsWindows[i].Name); + g.ColorModifiers.clear(); + g.StyleModifiers.clear(); + g.FontStack.clear(); + g.OpenPopupStack.clear(); + g.CurrentPopupStack.clear(); + g.SetNextWindowSizeConstraintCallback = NULL; + g.SetNextWindowSizeConstraintCallbackUserData = NULL; + for (int i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + g.RenderDrawLists[i].clear(); + g.OverlayDrawList.ClearFreeMemory(); + g.PrivateClipboard.clear(); + g.InputTextState.Text.clear(); + g.InputTextState.InitialText.clear(); + g.InputTextState.TempTextBuffer.clear(); + + g.SettingsWindows.clear(); + g.SettingsHandlers.clear(); + + if (g.LogFile && g.LogFile != stdout) + { + fclose(g.LogFile); + g.LogFile = NULL; + } + if (g.LogClipboard) + IM_DELETE(g.LogClipboard); + + g.Initialized = false; +} + +ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + for (int i = 0; i != g.SettingsWindows.Size; i++) + if (g.SettingsWindows[i].Id == id) + return &g.SettingsWindows[i]; + return NULL; +} + +static ImGuiWindowSettings* AddWindowSettings(const char* name) +{ + ImGuiContext& g = *GImGui; + g.SettingsWindows.push_back(ImGuiWindowSettings()); + ImGuiWindowSettings* settings = &g.SettingsWindows.back(); + settings->Name = ImStrdup(name); + settings->Id = ImHash(name, 0); + return settings; +} + +static void LoadIniSettingsFromDisk(const char* ini_filename) +{ + if (!ini_filename) + return; + char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", NULL, +1); + if (!file_data) + return; + LoadIniSettingsFromMemory(file_data); + ImGui::MemFree(file_data); +} + +ImGuiSettingsHandler* ImGui::FindSettingsHandler(ImGuiID type_hash) +{ + ImGuiContext& g = *GImGui; + for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++) + if (g.SettingsHandlers[handler_n].TypeHash == type_hash) + return &g.SettingsHandlers[handler_n]; + return NULL; +} + +// Zero-tolerance, no error reporting, cheap .ini parsing +static void LoadIniSettingsFromMemory(const char* buf_readonly) +{ + // For convenience and to make the code simpler, we'll write zero terminators inside the buffer. So let's create a writable copy. + char* buf = ImStrdup(buf_readonly); + char* buf_end = buf + strlen(buf); + + ImGuiContext& g = *GImGui; + void* entry_data = NULL; + const ImGuiSettingsHandler* entry_handler = NULL; + + char* line_end = NULL; + for (char* line = buf; line < buf_end; line = line_end + 1) + { + // Skip new lines markers, then find end of the line + while (*line == '\n' || *line == '\r') + line++; + line_end = line; + while (line_end < buf_end && *line_end != '\n' && *line_end != '\r') + line_end++; + line_end[0] = 0; + + if (line[0] == '[' && line_end > line && line_end[-1] == ']') + { + // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code. + line_end[-1] = 0; + const char* name_end = line_end - 1; + const char* type_start = line + 1; + char* type_end = ImStrchrRange(type_start, name_end, ']'); + const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL; + if (!type_end || !name_start) + { + name_start = type_start; // Import legacy entries that have no type + type_start = "Window"; + } + else + { + *type_end = 0; // Overwrite first ']' + name_start++; // Skip second '[' + } + const ImGuiID type_hash = ImHash(type_start, 0, 0); + entry_handler = ImGui::FindSettingsHandler(type_hash); + entry_data = entry_handler ? entry_handler->ReadOpenFn(g, name_start) : NULL; + } + else if (entry_handler != NULL && entry_data != NULL) + { + // Let type handler parse the line + entry_handler->ReadLineFn(g, entry_data, line); + } + } + ImGui::MemFree(buf); +} + +static void SaveIniSettingsToDisk(const char* ini_filename) +{ + ImGuiContext& g = *GImGui; + g.SettingsDirtyTimer = 0.0f; + if (!ini_filename) + return; + + ImVector buf; + SaveIniSettingsToMemory(buf); + + FILE* f = ImFileOpen(ini_filename, "wt"); + if (!f) + return; + fwrite(buf.Data, sizeof(char), (size_t)buf.Size, f); + fclose(f); +} + +static void SaveIniSettingsToMemory(ImVector& out_buf) +{ + ImGuiContext& g = *GImGui; + g.SettingsDirtyTimer = 0.0f; + + ImGuiTextBuffer buf; + for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++) + g.SettingsHandlers[handler_n].WriteAllFn(g, &buf); + + buf.Buf.pop_back(); // Remove extra zero-terminator used by ImGuiTextBuffer + out_buf.swap(buf.Buf); +} + +void ImGui::MarkIniSettingsDirty() +{ + ImGuiContext& g = *GImGui; + if (g.SettingsDirtyTimer <= 0.0f) + g.SettingsDirtyTimer = g.IO.IniSavingRate; +} + +static void MarkIniSettingsDirty(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + if (g.SettingsDirtyTimer <= 0.0f) + g.SettingsDirtyTimer = g.IO.IniSavingRate; +} + +// FIXME: Add a more explicit sort order in the window structure. +static int ChildWindowComparer(const void* lhs, const void* rhs) +{ + const ImGuiWindow* a = *(const ImGuiWindow**)lhs; + const ImGuiWindow* b = *(const ImGuiWindow**)rhs; + if (int d = (a->Flags & ImGuiWindowFlags_Popup) - (b->Flags & ImGuiWindowFlags_Popup)) + return d; + if (int d = (a->Flags & ImGuiWindowFlags_Tooltip) - (b->Flags & ImGuiWindowFlags_Tooltip)) + return d; + return (a->BeginOrderWithinParent - b->BeginOrderWithinParent); +} + +static void AddWindowToSortedBuffer(ImVector& out_sorted_windows, ImGuiWindow* window) +{ + out_sorted_windows.push_back(window); + if (window->Active) + { + int count = window->DC.ChildWindows.Size; + if (count > 1) + qsort(window->DC.ChildWindows.begin(), (size_t)count, sizeof(ImGuiWindow*), ChildWindowComparer); + for (int i = 0; i < count; i++) + { + ImGuiWindow* child = window->DC.ChildWindows[i]; + if (child->Active) + AddWindowToSortedBuffer(out_sorted_windows, child); + } + } +} + +static void AddDrawListToRenderList(ImVector& out_render_list, ImDrawList* draw_list) +{ + if (draw_list->CmdBuffer.empty()) + return; + + // Remove trailing command if unused + ImDrawCmd& last_cmd = draw_list->CmdBuffer.back(); + if (last_cmd.ElemCount == 0 && last_cmd.UserCallback == NULL) + { + draw_list->CmdBuffer.pop_back(); + if (draw_list->CmdBuffer.empty()) + return; + } + + // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. May trigger for you if you are using PrimXXX functions incorrectly. + IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size); + IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size); + IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); + + // Check that draw_list doesn't use more vertices than indexable in a single draw call (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window) + // If this assert triggers because you are drawing lots of stuff manually: + // A) Make sure you are coarse clipping, because ImDrawList let all your vertices pass. You can use thre Metrics window to inspect draw list contents. + // B) If you need/want meshes with more than 64K vertices, uncomment the '#define ImDrawIdx unsigned int' line in imconfig.h to set the index size to 4 bytes. + // You'll need to handle the 4-bytes indices to your renderer. For example, the OpenGL example code detect index size at compile-time by doing: + // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); + // Your own engine or render API may use different parameters or function calls to specify index sizes. 2 and 4 bytes indices are generally supported by most API. + // C) If for some reason you cannot use 4 bytes indices or don't want to, a workaround is to call BeginChild()/EndChild() before reaching the 64K limit to split your draw commands in multiple draw lists. + if (sizeof(ImDrawIdx) == 2) + IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above"); + + out_render_list.push_back(draw_list); + GImGui->IO.MetricsRenderVertices += draw_list->VtxBuffer.Size; + GImGui->IO.MetricsRenderIndices += draw_list->IdxBuffer.Size; +} + +static void AddWindowToRenderList(ImVector& out_render_list, ImGuiWindow* window) +{ + AddDrawListToRenderList(out_render_list, window->DrawList); + for (int i = 0; i < window->DC.ChildWindows.Size; i++) + { + ImGuiWindow* child = window->DC.ChildWindows[i]; + if (!child->Active) // clipped children may have been marked not active + continue; + if ((child->Flags & ImGuiWindowFlags_Popup) && child->HiddenFrames > 0) + continue; + AddWindowToRenderList(out_render_list, child); + } +} + +static void AddWindowToRenderListSelectLayer(ImGuiWindow* window) +{ + // FIXME: Generalize this with a proper layering system so e.g. user can draw in specific layers, below text, .. + ImGuiContext& g = *GImGui; + g.IO.MetricsActiveWindows++; + if (window->Flags & ImGuiWindowFlags_Popup) + AddWindowToRenderList(g.RenderDrawLists[1], window); + else if (window->Flags & ImGuiWindowFlags_Tooltip) + AddWindowToRenderList(g.RenderDrawLists[2], window); + else + AddWindowToRenderList(g.RenderDrawLists[0], window); +} + +// When using this function it is sane to ensure that float are perfectly rounded to integer values, to that e.g. (int)(max.x-min.x) in user's render produce correct result. +void ImGui::PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DrawList->PushClipRect(clip_rect_min, clip_rect_max, intersect_with_current_clip_rect); + window->ClipRect = window->DrawList->_ClipRectStack.back(); +} + +void ImGui::PopClipRect() +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DrawList->PopClipRect(); + window->ClipRect = window->DrawList->_ClipRectStack.back(); +} + +// This is normally called by Render(). You may want to call it directly if you want to avoid calling Render() but the gain will be very minimal. +void ImGui::EndFrame() +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() + if (g.FrameCountEnded == g.FrameCount) // Don't process EndFrame() multiple times. + return; + + // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) + if (g.IO.ImeSetInputScreenPosFn && ImLengthSqr(g.OsImePosRequest - g.OsImePosSet) > 0.0001f) + { + g.IO.ImeSetInputScreenPosFn((int)g.OsImePosRequest.x, (int)g.OsImePosRequest.y); + g.OsImePosSet = g.OsImePosRequest; + } + + // Hide implicit "Debug" window if it hasn't been used + IM_ASSERT(g.CurrentWindowStack.Size == 1); // Mismatched Begin()/End() calls + if (g.CurrentWindow && !g.CurrentWindow->WriteAccessed) + g.CurrentWindow->Active = false; + ImGui::End(); + + if (g.ActiveId == 0 && g.HoveredId == 0) + { + if (!g.NavWindow || !g.NavWindow->Appearing) // Unless we just made a window/popup appear + { + // Click to focus window and start moving (after we're done with all our widgets) + if (g.IO.MouseClicked[0]) + { + if (g.HoveredRootWindow != NULL) + { + FocusWindow(g.HoveredWindow); + if (!(g.HoveredWindow->Flags & ImGuiWindowFlags_NoMove) && !(g.HoveredRootWindow->Flags & ImGuiWindowFlags_NoMove)) + { + g.MovingWindow = g.HoveredWindow; + g.MovingWindowMoveId = g.MovingWindow->MoveId; + SetActiveID(g.MovingWindowMoveId, g.HoveredRootWindow); + g.ActiveIdClickOffset = g.IO.MousePos - g.MovingWindow->RootWindow->Pos; + } + } + else if (g.NavWindow != NULL && GetFrontMostModalRootWindow() == NULL) + { + // Clicking on void disable focus + FocusWindow(NULL); + } + } + + // With right mouse button we close popups without changing focus + // (The left mouse button path calls FocusWindow which will lead NewFrame->CloseInactivePopups to trigger) + if (g.IO.MouseClicked[1]) + { + // Find the top-most window between HoveredWindow and the front most Modal Window. + // This is where we can trim the popup stack. + ImGuiWindow* modal = GetFrontMostModalRootWindow(); + bool hovered_window_above_modal = false; + if (modal == NULL) + hovered_window_above_modal = true; + for (int i = g.Windows.Size - 1; i >= 0 && hovered_window_above_modal == false; i--) + { + ImGuiWindow* window = g.Windows[i]; + if (window == modal) + break; + if (window == g.HoveredWindow) + hovered_window_above_modal = true; + } + CloseInactivePopups(hovered_window_above_modal ? g.HoveredWindow : modal); + } + } + } + + // Sort the window list so that all child windows are after their parent + // We cannot do that on FocusWindow() because childs may not exist yet + g.WindowsSortBuffer.resize(0); + g.WindowsSortBuffer.reserve(g.Windows.Size); + for (int i = 0; i != g.Windows.Size; i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Active && (window->Flags & ImGuiWindowFlags_ChildWindow)) // if a child is active its parent will add it + continue; + AddWindowToSortedBuffer(g.WindowsSortBuffer, window); + } + + IM_ASSERT(g.Windows.Size == g.WindowsSortBuffer.Size); // we done something wrong + g.Windows.swap(g.WindowsSortBuffer); + + // Clear Input data for next frame + g.IO.MouseWheel = 0.0f; + memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); + + g.FrameCountEnded = g.FrameCount; +} + +void ImGui::Render() +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() + + if (g.FrameCountEnded != g.FrameCount) + ImGui::EndFrame(); + g.FrameCountRendered = g.FrameCount; + + // Skip render altogether if alpha is 0.0 + // Note that vertex buffers have been created and are wasted, so it is best practice that you don't create windows in the first place, or consistently respond to Begin() returning false. + if (g.Style.Alpha > 0.0f) + { + // Gather windows to render + g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsActiveWindows = 0; + for (int i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + g.RenderDrawLists[i].resize(0); + for (int i = 0; i != g.Windows.Size; i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Active && window->HiddenFrames <= 0 && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0) + AddWindowToRenderListSelectLayer(window); + } + + // Flatten layers + int n = g.RenderDrawLists[0].Size; + int flattened_size = n; + for (int i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + flattened_size += g.RenderDrawLists[i].Size; + g.RenderDrawLists[0].resize(flattened_size); + for (int i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + { + ImVector& layer = g.RenderDrawLists[i]; + if (layer.empty()) + continue; + memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.Size * sizeof(ImDrawList*)); + n += layer.Size; + } + + // Draw software mouse cursor if requested + if (g.IO.MouseDrawCursor) + { + const ImGuiMouseCursorData& cursor_data = g.MouseCursorData[g.MouseCursor]; + const ImVec2 pos = g.IO.MousePos - cursor_data.HotOffset; + const ImVec2 size = cursor_data.Size; + const ImTextureID tex_id = g.IO.Fonts->TexID; + g.OverlayDrawList.PushTextureID(tex_id); + g.OverlayDrawList.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], IM_COL32(0,0,0,48)); // Shadow + g.OverlayDrawList.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], IM_COL32(0,0,0,48)); // Shadow + g.OverlayDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], IM_COL32(0,0,0,255)); // Black border + g.OverlayDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[0], cursor_data.TexUvMax[0], IM_COL32(255,255,255,255)); // White fill + g.OverlayDrawList.PopTextureID(); + } + if (!g.OverlayDrawList.VtxBuffer.empty()) + AddDrawListToRenderList(g.RenderDrawLists[0], &g.OverlayDrawList); + + // Setup draw data + g.RenderDrawData.Valid = true; + g.RenderDrawData.CmdLists = (g.RenderDrawLists[0].Size > 0) ? &g.RenderDrawLists[0][0] : NULL; + g.RenderDrawData.CmdListsCount = g.RenderDrawLists[0].Size; + g.RenderDrawData.TotalVtxCount = g.IO.MetricsRenderVertices; + g.RenderDrawData.TotalIdxCount = g.IO.MetricsRenderIndices; + + // Render. If user hasn't set a callback then they may retrieve the draw data via GetDrawData() + if (g.RenderDrawData.CmdListsCount > 0 && g.IO.RenderDrawListsFn != NULL) + g.IO.RenderDrawListsFn(&g.RenderDrawData); + } +} + +const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end) +{ + const char* text_display_end = text; + if (!text_end) + text_end = (const char*)-1; + + while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) + text_display_end++; + return text_display_end; +} + +// Pass text data straight to log (without being displayed) +void ImGui::LogText(const char* fmt, ...) +{ + ImGuiContext& g = *GImGui; + if (!g.LogEnabled) + return; + + va_list args; + va_start(args, fmt); + if (g.LogFile) + { + vfprintf(g.LogFile, fmt, args); + } + else + { + g.LogClipboard->appendfv(fmt, args); + } + va_end(args); +} + +// Internal version that takes a position to decide on newline placement and pad items according to their depth. +// We split text into individual lines to add current tree level padding +static void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + if (!text_end) + text_end = ImGui::FindRenderedTextEnd(text, text_end); + + const bool log_new_line = ref_pos && (ref_pos->y > window->DC.LogLinePosY + 1); + if (ref_pos) + window->DC.LogLinePosY = ref_pos->y; + + const char* text_remaining = text; + if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth + g.LogStartDepth = window->DC.TreeDepth; + const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth); + for (;;) + { + // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry. + const char* line_end = text_remaining; + while (line_end < text_end) + if (*line_end == '\n') + break; + else + line_end++; + if (line_end >= text_end) + line_end = NULL; + + const bool is_first_line = (text == text_remaining); + bool is_last_line = false; + if (line_end == NULL) + { + is_last_line = true; + line_end = text_end; + } + if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0)) + { + const int char_count = (int)(line_end - text_remaining); + if (log_new_line || !is_first_line) + ImGui::LogText(IM_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining); + else + ImGui::LogText(" %.*s", char_count, text_remaining); + } + + if (is_last_line) + break; + text_remaining = line_end + 1; + } +} + +// Internal ImGui functions to render text +// RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText() +void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + // Hide anything after a '##' string + const char* text_display_end; + if (hide_text_after_hash) + { + text_display_end = FindRenderedTextEnd(text, text_end); + } + else + { + if (!text_end) + text_end = text + strlen(text); // FIXME-OPT + text_display_end = text_end; + } + + const int text_len = (int)(text_display_end - text); + if (text_len > 0) + { + window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_display_end); + if (g.LogEnabled) + LogRenderedText(&pos, text, text_display_end); + } +} + +void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + if (!text_end) + text_end = text + strlen(text); // FIXME-OPT + + const int text_len = (int)(text_end - text); + if (text_len > 0) + { + window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_end, wrap_width); + if (g.LogEnabled) + LogRenderedText(&pos, text, text_end); + } +} + +// Default clip_rect uses (pos_min,pos_max) +// Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges) +void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align, const ImRect* clip_rect) +{ + // Hide anything after a '##' string + const char* text_display_end = FindRenderedTextEnd(text, text_end); + const int text_len = (int)(text_display_end - text); + if (text_len == 0) + return; + + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + // Perform CPU side clipping for single clipped element to avoid using scissor state + ImVec2 pos = pos_min; + const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f); + + const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min; + const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max; + bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y); + if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min + need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y); + + // Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment. + if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x); + if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y); + + // Render + if (need_clipping) + { + ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y); + window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, &fine_clip_rect); + } + else + { + window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, NULL); + } + if (g.LogEnabled) + LogRenderedText(&pos, text, text_display_end); +} + +// Render a rectangle shaped with optional rounding and borders +void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding); + const float border_size = g.Style.FrameBorderSize; + if (border && border_size > 0.0f) + { + window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), GetColorU32(ImGuiCol_BorderShadow), rounding, ImDrawCornerFlags_All, border_size); + window->DrawList->AddRect(p_min, p_max, GetColorU32(ImGuiCol_Border), rounding, ImDrawCornerFlags_All, border_size); + } +} + +void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + const float border_size = g.Style.FrameBorderSize; + if (border_size > 0.0f) + { + window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), GetColorU32(ImGuiCol_BorderShadow), rounding, ImDrawCornerFlags_All, border_size); + window->DrawList->AddRect(p_min, p_max, GetColorU32(ImGuiCol_Border), rounding, ImDrawCornerFlags_All, border_size); + } +} + +// Render a triangle to denote expanded/collapsed state +void ImGui::RenderTriangle(ImVec2 p_min, ImGuiDir dir, float scale) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + const float h = g.FontSize * 1.00f; + float r = h * 0.40f * scale; + ImVec2 center = p_min + ImVec2(h * 0.50f, h * 0.50f * scale); + + ImVec2 a, b, c; + switch (dir) + { + case ImGuiDir_Up: + case ImGuiDir_Down: + if (dir == ImGuiDir_Up) r = -r; + center.y -= r * 0.25f; + a = ImVec2(0,1) * r; + b = ImVec2(-0.866f,-0.5f) * r; + c = ImVec2(+0.866f,-0.5f) * r; + break; + case ImGuiDir_Left: + case ImGuiDir_Right: + if (dir == ImGuiDir_Left) r = -r; + center.x -= r * 0.25f; + a = ImVec2(1,0) * r; + b = ImVec2(-0.500f,+0.866f) * r; + c = ImVec2(-0.500f,-0.866f) * r; + break; + case ImGuiDir_None: + case ImGuiDir_Count_: + IM_ASSERT(0); + break; + } + + window->DrawList->AddTriangleFilled(center + a, center + b, center + c, GetColorU32(ImGuiCol_Text)); +} + +void ImGui::RenderBullet(ImVec2 pos) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->DrawList->AddCircleFilled(pos, GImGui->FontSize*0.20f, GetColorU32(ImGuiCol_Text), 8); +} + +void ImGui::RenderCheckMark(ImVec2 pos, ImU32 col, float sz) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + float thickness = ImMax(sz / 5.0f, 1.0f); + sz -= thickness*0.5f; + pos += ImVec2(thickness*0.25f, thickness*0.25f); + + float third = sz / 3.0f; + float bx = pos.x + third; + float by = pos.y + sz - third*0.5f; + window->DrawList->PathLineTo(ImVec2(bx - third, by - third)); + window->DrawList->PathLineTo(ImVec2(bx, by)); + window->DrawList->PathLineTo(ImVec2(bx + third*2, by - third*2)); + window->DrawList->PathStroke(col, false, thickness); +} + +// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker. +// CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize) +ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) +{ + ImGuiContext& g = *GImGui; + + const char* text_display_end; + if (hide_text_after_double_hash) + text_display_end = FindRenderedTextEnd(text, text_end); // Hide anything after a '##' string + else + text_display_end = text_end; + + ImFont* font = g.Font; + const float font_size = g.FontSize; + if (text == text_display_end) + return ImVec2(0.0f, font_size); + ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL); + + // Cancel out character spacing for the last character of a line (it is baked into glyph->AdvanceX field) + const float font_scale = font_size / font->FontSize; + const float character_spacing_x = 1.0f * font_scale; + if (text_size.x > 0.0f) + text_size.x -= character_spacing_x; + text_size.x = (float)(int)(text_size.x + 0.95f); + + return text_size; +} + +// Helper to calculate coarse clipping of large list of evenly sized items. +// NB: Prefer using the ImGuiListClipper higher-level helper if you can! Read comments and instructions there on how those use this sort of pattern. +// NB: 'items_count' is only used to clamp the result, if you don't know your count you can use INT_MAX +void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + if (g.LogEnabled) + { + // If logging is active, do not perform any clipping + *out_items_display_start = 0; + *out_items_display_end = items_count; + return; + } + if (window->SkipItems) + { + *out_items_display_start = *out_items_display_end = 0; + return; + } + + const ImVec2 pos = window->DC.CursorPos; + int start = (int)((window->ClipRect.Min.y - pos.y) / items_height); + int end = (int)((window->ClipRect.Max.y - pos.y) / items_height); + start = ImClamp(start, 0, items_count); + end = ImClamp(end + 1, start, items_count); + *out_items_display_start = start; + *out_items_display_end = end; +} + +// Find window given position, search front-to-back +// FIXME: Note that we have a lag here because WindowRectClipped is updated in Begin() so windows moved by user via SetWindowPos() and not SetNextWindowPos() will have that rectangle lagging by a frame at the time FindHoveredWindow() is called, aka before the next Begin(). Moving window thankfully isn't affected. +static ImGuiWindow* FindHoveredWindow(ImVec2 pos) +{ + ImGuiContext& g = *GImGui; + for (int i = g.Windows.Size - 1; i >= 0; i--) + { + ImGuiWindow* window = g.Windows[i]; + if (!window->Active) + continue; + if (window->Flags & ImGuiWindowFlags_NoInputs) + continue; + + // Using the clipped AABB, a child window will typically be clipped by its parent (not always) + ImRect bb(window->WindowRectClipped.Min - g.Style.TouchExtraPadding, window->WindowRectClipped.Max + g.Style.TouchExtraPadding); + if (bb.Contains(pos)) + return window; + } + return NULL; +} + +// Test if mouse cursor is hovering given rectangle +// NB- Rectangle is clipped by our current clip setting +// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) +bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + // Clip + ImRect rect_clipped(r_min, r_max); + if (clip) + rect_clipped.ClipWith(window->ClipRect); + + // Expand for touch input + const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); + return rect_for_touch.Contains(g.IO.MousePos); +} + +bool ImGui::IsAnyWindowHovered() +{ + ImGuiContext& g = *GImGui; + return g.HoveredWindow != NULL; +} + +bool ImGui::IsAnyWindowFocused() +{ + ImGuiContext& g = *GImGui; + return g.NavWindow != NULL; +} + +static bool IsKeyPressedMap(ImGuiKey key, bool repeat) +{ + const int key_index = GImGui->IO.KeyMap[key]; + return (key_index >= 0) ? ImGui::IsKeyPressed(key_index, repeat) : false; +} + +int ImGui::GetKeyIndex(ImGuiKey imgui_key) +{ + IM_ASSERT(imgui_key >= 0 && imgui_key < ImGuiKey_COUNT); + return GImGui->IO.KeyMap[imgui_key]; +} + +// Note that imgui doesn't know the semantic of each entry of io.KeyDown[]. Use your own indices/enums according to how your backend/engine stored them into KeyDown[]! +bool ImGui::IsKeyDown(int user_key_index) +{ + if (user_key_index < 0) return false; + IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(GImGui->IO.KeysDown)); + return GImGui->IO.KeysDown[user_key_index]; +} + +int ImGui::CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate) +{ + if (t == 0.0f) + return 1; + if (t <= repeat_delay || repeat_rate <= 0.0f) + return 0; + const int count = (int)((t - repeat_delay) / repeat_rate) - (int)((t_prev - repeat_delay) / repeat_rate); + return (count > 0) ? count : 0; +} + +int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_rate) +{ + ImGuiContext& g = *GImGui; + if (key_index < 0) return false; + IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); + const float t = g.IO.KeysDownDuration[key_index]; + return CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, repeat_delay, repeat_rate); +} + +bool ImGui::IsKeyPressed(int user_key_index, bool repeat) +{ + ImGuiContext& g = *GImGui; + if (user_key_index < 0) return false; + IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown)); + const float t = g.IO.KeysDownDuration[user_key_index]; + if (t == 0.0f) + return true; + if (repeat && t > g.IO.KeyRepeatDelay) + return GetKeyPressedAmount(user_key_index, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; + return false; +} + +bool ImGui::IsKeyReleased(int user_key_index) +{ + ImGuiContext& g = *GImGui; + if (user_key_index < 0) return false; + IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown)); + if (g.IO.KeysDownDurationPrev[user_key_index] >= 0.0f && !g.IO.KeysDown[user_key_index]) + return true; + return false; +} + +bool ImGui::IsMouseDown(int button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDown[button]; +} + +bool ImGui::IsMouseClicked(int button, bool repeat) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + const float t = g.IO.MouseDownDuration[button]; + if (t == 0.0f) + return true; + + if (repeat && t > g.IO.KeyRepeatDelay) + { + float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate; + if ((fmodf(t - delay, rate) > rate*0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f)) + return true; + } + + return false; +} + +bool ImGui::IsMouseReleased(int button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseReleased[button]; +} + +bool ImGui::IsMouseDoubleClicked(int button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDoubleClicked[button]; +} + +bool ImGui::IsMouseDragging(int button, float lock_threshold) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (!g.IO.MouseDown[button]) + return false; + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; +} + +ImVec2 ImGui::GetMousePos() +{ + return GImGui->IO.MousePos; +} + +// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed! +ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup() +{ + ImGuiContext& g = *GImGui; + if (g.CurrentPopupStack.Size > 0) + return g.OpenPopupStack[g.CurrentPopupStack.Size-1].MousePosOnOpen; + return g.IO.MousePos; +} + +// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position +bool ImGui::IsMousePosValid(const ImVec2* mouse_pos) +{ + if (mouse_pos == NULL) + mouse_pos = &GImGui->IO.MousePos; + const float MOUSE_INVALID = -256000.0f; + return mouse_pos->x >= MOUSE_INVALID && mouse_pos->y >= MOUSE_INVALID; +} + +ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + if (g.IO.MouseDown[button]) + if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold) + return g.IO.MousePos - g.IO.MouseClickedPos[button]; // Assume we can only get active with left-mouse button (at the moment). + return ImVec2(0.0f, 0.0f); +} + +void ImGui::ResetMouseDragDelta(int button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr + g.IO.MouseClickedPos[button] = g.IO.MousePos; +} + +ImGuiMouseCursor ImGui::GetMouseCursor() +{ + return GImGui->MouseCursor; +} + +void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type) +{ + GImGui->MouseCursor = cursor_type; +} + +void ImGui::CaptureKeyboardFromApp(bool capture) +{ + GImGui->WantCaptureKeyboardNextFrame = capture ? 1 : 0; +} + +void ImGui::CaptureMouseFromApp(bool capture) +{ + GImGui->WantCaptureMouseNextFrame = capture ? 1 : 0; +} + +bool ImGui::IsItemActive() +{ + ImGuiContext& g = *GImGui; + if (g.ActiveId) + { + ImGuiWindow* window = g.CurrentWindow; + return g.ActiveId == window->DC.LastItemId; + } + return false; +} + +bool ImGui::IsItemClicked(int mouse_button) +{ + return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_Default); +} + +bool ImGui::IsAnyItemHovered() +{ + ImGuiContext& g = *GImGui; + return g.HoveredId != 0 || g.HoveredIdPreviousFrame != 0; +} + +bool ImGui::IsAnyItemActive() +{ + return GImGui->ActiveId != 0; +} + +bool ImGui::IsItemVisible() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->ClipRect.Overlaps(window->DC.LastItemRect); +} + +// Allow last item to be overlapped by a subsequent item. Both may be activated during the same frame before the later one takes priority. +void ImGui::SetItemAllowOverlap() +{ + ImGuiContext& g = *GImGui; + if (g.HoveredId == g.CurrentWindow->DC.LastItemId) + g.HoveredIdAllowOverlap = true; + if (g.ActiveId == g.CurrentWindow->DC.LastItemId) + g.ActiveIdAllowOverlap = true; +} + +ImVec2 ImGui::GetItemRectMin() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.LastItemRect.Min; +} + +ImVec2 ImGui::GetItemRectMax() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.LastItemRect.Max; +} + +ImVec2 ImGui::GetItemRectSize() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.LastItemRect.GetSize(); +} + +ImVec2 ImGui::CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge, float outward) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + ImRect rect = window->DC.LastItemRect; + rect.Expand(outward); + return rect.GetClosestPoint(pos, on_edge); +} + +static ImRect GetVisibleRect() +{ + ImGuiContext& g = *GImGui; + if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y) + return ImRect(g.IO.DisplayVisibleMin, g.IO.DisplayVisibleMax); + return ImRect(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); +} + +// Not exposed publicly as BeginTooltip() because bool parameters are evil. Let's see if other needs arise first. +void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip) +{ + ImGuiContext& g = *GImGui; + char window_name[16]; + ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", g.TooltipOverrideCount); + if (override_previous_tooltip) + if (ImGuiWindow* window = FindWindowByName(window_name)) + if (window->Active) + { + // Hide previous tooltips. We can't easily "reset" the content of a window so we create a new one. + window->HiddenFrames = 1; + ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", ++g.TooltipOverrideCount); + } + ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize; + Begin(window_name, NULL, flags | extra_flags); +} + +void ImGui::SetTooltipV(const char* fmt, va_list args) +{ + BeginTooltipEx(0, true); + TextV(fmt, args); + EndTooltip(); +} + +void ImGui::SetTooltip(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + SetTooltipV(fmt, args); + va_end(args); +} + +void ImGui::BeginTooltip() +{ + BeginTooltipEx(0, false); +} + +void ImGui::EndTooltip() +{ + IM_ASSERT(GetCurrentWindowRead()->Flags & ImGuiWindowFlags_Tooltip); // Mismatched BeginTooltip()/EndTooltip() calls + ImGui::End(); +} + +// Mark popup as open (toggle toward open state). +// Popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. +// Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). +// One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL) +void ImGui::OpenPopupEx(ImGuiID id, bool reopen_existing) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* parent_window = g.CurrentWindow; + int current_stack_size = g.CurrentPopupStack.Size; + ImGuiPopupRef popup_ref = ImGuiPopupRef(id, parent_window, parent_window->GetID("##Menus"), g.IO.MousePos); // Tagged as new ref because constructor sets Window to NULL. + if (g.OpenPopupStack.Size < current_stack_size + 1) + g.OpenPopupStack.push_back(popup_ref); + else if (reopen_existing || g.OpenPopupStack[current_stack_size].PopupId != id) + { + g.OpenPopupStack.resize(current_stack_size+1); + g.OpenPopupStack[current_stack_size] = popup_ref; + + // When reopening a popup we first refocus its parent, otherwise if its parent is itself a popup it would get closed by CloseInactivePopups(). + // This is equivalent to what ClosePopupToLevel() does. + if (g.OpenPopupStack[current_stack_size].PopupId == id) + FocusWindow(parent_window); + } +} + +void ImGui::OpenPopup(const char* str_id) +{ + ImGuiContext& g = *GImGui; + OpenPopupEx(g.CurrentWindow->GetID(str_id), false); +} + +static void CloseInactivePopups(ImGuiWindow* ref_window) +{ + ImGuiContext& g = *GImGui; + if (g.OpenPopupStack.empty()) + return; + + // When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it. + // Don't close our own child popup windows. + int n = 0; + if (ref_window) + { + for (n = 0; n < g.OpenPopupStack.Size; n++) + { + ImGuiPopupRef& popup = g.OpenPopupStack[n]; + if (!popup.Window) + continue; + IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0); + if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow) + continue; + + // Trim the stack if popups are not direct descendant of the reference window (which is often the NavWindow) + bool has_focus = false; + for (int m = n; m < g.OpenPopupStack.Size && !has_focus; m++) + has_focus = (g.OpenPopupStack[m].Window && g.OpenPopupStack[m].Window->RootWindow == ref_window->RootWindow); + if (!has_focus) + break; + } + } + if (n < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the block below + ClosePopupToLevel(n); +} + +static ImGuiWindow* GetFrontMostModalRootWindow() +{ + ImGuiContext& g = *GImGui; + for (int n = g.OpenPopupStack.Size-1; n >= 0; n--) + if (ImGuiWindow* popup = g.OpenPopupStack.Data[n].Window) + if (popup->Flags & ImGuiWindowFlags_Modal) + return popup; + return NULL; +} + +static void ClosePopupToLevel(int remaining) +{ + ImGuiContext& g = *GImGui; + if (remaining > 0) + ImGui::FocusWindow(g.OpenPopupStack[remaining-1].Window); + else + ImGui::FocusWindow(g.OpenPopupStack[0].ParentWindow); + g.OpenPopupStack.resize(remaining); +} + +void ImGui::ClosePopup(ImGuiID id) +{ + if (!IsPopupOpen(id)) + return; + ImGuiContext& g = *GImGui; + ClosePopupToLevel(g.OpenPopupStack.Size - 1); +} + +// Close the popup we have begin-ed into. +void ImGui::CloseCurrentPopup() +{ + ImGuiContext& g = *GImGui; + int popup_idx = g.CurrentPopupStack.Size - 1; + if (popup_idx < 0 || popup_idx >= g.OpenPopupStack.Size || g.CurrentPopupStack[popup_idx].PopupId != g.OpenPopupStack[popup_idx].PopupId) + return; + while (popup_idx > 0 && g.OpenPopupStack[popup_idx].Window && (g.OpenPopupStack[popup_idx].Window->Flags & ImGuiWindowFlags_ChildMenu)) + popup_idx--; + ClosePopupToLevel(popup_idx); +} + +static inline void ClearSetNextWindowData() +{ + // FIXME-OPT + ImGuiContext& g = *GImGui; + g.SetNextWindowPosCond = g.SetNextWindowSizeCond = g.SetNextWindowContentSizeCond = g.SetNextWindowCollapsedCond = 0; + g.SetNextWindowSizeConstraint = g.SetNextWindowFocus = false; +} + +bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags) +{ + ImGuiContext& g = *GImGui; + if (!IsPopupOpen(id)) + { + ClearSetNextWindowData(); // We behave like Begin() and need to consume those values + return false; + } + + char name[20]; + if (extra_flags & ImGuiWindowFlags_ChildMenu) + ImFormatString(name, IM_ARRAYSIZE(name), "##Menu_%02d", g.CurrentPopupStack.Size); // Recycle windows based on depth + else + ImFormatString(name, IM_ARRAYSIZE(name), "##Popup_%08x", id); // Not recycling, so we can close/open during the same frame + + bool is_open = Begin(name, NULL, extra_flags | ImGuiWindowFlags_Popup); + if (!is_open) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display) + EndPopup(); + + return is_open; +} + +bool ImGui::BeginPopup(const char* str_id) +{ + ImGuiContext& g = *GImGui; + if (g.OpenPopupStack.Size <= g.CurrentPopupStack.Size) // Early out for performance + { + ClearSetNextWindowData(); // We behave like Begin() and need to consume those values + return false; + } + return BeginPopupEx(g.CurrentWindow->GetID(str_id), ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); +} + +bool ImGui::IsPopupOpen(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + return g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].PopupId == id; +} + +bool ImGui::IsPopupOpen(const char* str_id) +{ + ImGuiContext& g = *GImGui; + return g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].PopupId == g.CurrentWindow->GetID(str_id); +} + +bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags extra_flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + const ImGuiID id = window->GetID(name); + if (!IsPopupOpen(id)) + { + ClearSetNextWindowData(); // We behave like Begin() and need to consume those values + return false; + } + + // Center modal windows by default + if ((window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) == 0) + SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + + ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings; + bool is_open = Begin(name, p_open, flags); + if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display) + { + EndPopup(); + if (is_open) + ClosePopup(id); + return false; + } + + return is_open; +} + +void ImGui::EndPopup() +{ + ImGuiContext& g = *GImGui; (void)g; + IM_ASSERT(g.CurrentWindow->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginPopup()/EndPopup() calls + IM_ASSERT(g.CurrentPopupStack.Size > 0); + End(); +} + +bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button) +{ + ImGuiWindow* window = GImGui->CurrentWindow; + if (IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + { + ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict! + IM_ASSERT(id != 0); // However, you cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item) + OpenPopupEx(id, true); + return true; + } + return false; +} + +// This is a helper to handle the simplest case of associating one named popup to one given widget. +// You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters). +// You can pass a NULL str_id to use the identifier of the last item. +bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button) +{ + ImGuiWindow* window = GImGui->CurrentWindow; + ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict! + IM_ASSERT(id != 0); // However, you cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item) + if (IsMouseClicked(mouse_button)) + if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + OpenPopupEx(id, true); + return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); +} + +bool ImGui::BeginPopupContextWindow(const char* str_id, int mouse_button, bool also_over_items) +{ + if (!str_id) + str_id = "window_context"; + ImGuiID id = GImGui->CurrentWindow->GetID(str_id); + if (IsMouseClicked(mouse_button)) + if (IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + if (also_over_items || !IsAnyItemHovered()) + OpenPopupEx(id, true); + return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); +} + +bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button) +{ + if (!str_id) + str_id = "void_context"; + ImGuiID id = GImGui->CurrentWindow->GetID(str_id); + if (!IsAnyWindowHovered() && IsMouseClicked(mouse_button)) + OpenPopupEx(id, true); + return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); +} + +static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* parent_window = ImGui::GetCurrentWindow(); + ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow; + flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag + + const ImVec2 content_avail = ImGui::GetContentRegionAvail(); + ImVec2 size = ImFloor(size_arg); + const int auto_fit_axises = ((size.x == 0.0f) ? (1 << ImGuiAxis_X) : 0x00) | ((size.y == 0.0f) ? (1 << ImGuiAxis_Y) : 0x00); + if (size.x <= 0.0f) + size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too much issues) + if (size.y <= 0.0f) + size.y = ImMax(content_avail.y + size.y, 4.0f); + + const float backup_border_size = g.Style.ChildBorderSize; + if (!border) + g.Style.ChildBorderSize = 0.0f; + flags |= extra_flags; + + char title[256]; + if (name) + ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s_%08X", parent_window->Name, name, id); + else + ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", parent_window->Name, id); + + ImGui::SetNextWindowSize(size); + bool ret = ImGui::Begin(title, NULL, flags); + ImGuiWindow* child_window = ImGui::GetCurrentWindow(); + child_window->AutoFitChildAxises = auto_fit_axises; + g.Style.ChildBorderSize = backup_border_size; + + return ret; +} + +bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + return BeginChildEx(str_id, window->GetID(str_id), size_arg, border, extra_flags); +} + +bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +{ + return BeginChildEx(NULL, id, size_arg, border, extra_flags); +} + +void ImGui::EndChild() +{ + ImGuiWindow* window = GetCurrentWindow(); + + IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() callss + if (window->BeginCount > 1) + { + ImGui::End(); + } + else + { + // When using auto-filling child window, we don't provide full width/height to ItemSize so that it doesn't feed back into automatic size-fitting. + ImVec2 sz = GetWindowSize(); + if (window->AutoFitChildAxises & (1 << ImGuiAxis_X)) // Arbitrary minimum zero-ish child size of 4.0f causes less trouble than a 0.0f + sz.x = ImMax(4.0f, sz.x); + if (window->AutoFitChildAxises & (1 << ImGuiAxis_Y)) + sz.y = ImMax(4.0f, sz.y); + ImGui::End(); + + ImGuiWindow* parent_window = GetCurrentWindow(); + ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz); + ItemSize(sz); + ItemAdd(bb, 0); + } +} + +// Helper to create a child window / scrolling region that looks like a normal widget frame. +bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags extra_flags) +{ + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]); + PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding); + PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize); + PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding); + return BeginChild(id, size, true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags); +} + +void ImGui::EndChildFrame() +{ + EndChild(); + PopStyleVar(3); + PopStyleColor(); +} + +// Save and compare stack sizes on Begin()/End() to detect usage errors +static void CheckStacksSize(ImGuiWindow* window, bool write) +{ + // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) + ImGuiContext& g = *GImGui; + int* p_backup = &window->DC.StackSizesBackup[0]; + { int current = window->IDStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushID/PopID or TreeNode/TreePop Mismatch!"); p_backup++; } // Too few or too many PopID()/TreePop() + { int current = window->DC.GroupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "BeginGroup/EndGroup Mismatch!"); p_backup++; } // Too few or too many EndGroup() + { int current = g.CurrentPopupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch"); p_backup++;}// Too few or too many EndMenu()/EndPopup() + { int current = g.ColorModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushStyleColor/PopStyleColor Mismatch!"); p_backup++; } // Too few or too many PopStyleColor() + { int current = g.StyleModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushStyleVar/PopStyleVar Mismatch!"); p_backup++; } // Too few or too many PopStyleVar() + { int current = g.FontStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushFont/PopFont Mismatch!"); p_backup++; } // Too few or too many PopFont() + IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); +} + +enum ImGuiPopupPositionPolicy +{ + ImGuiPopupPositionPolicy_Default, + ImGuiPopupPositionPolicy_ComboBox +}; + +static ImVec2 FindBestWindowPosForPopup(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy = ImGuiPopupPositionPolicy_Default) +{ + const ImGuiStyle& style = GImGui->Style; + + // r_avoid = the rectangle to avoid (e.g. for tooltip it is a rectangle around the mouse cursor which we want to avoid. for popups it's a small point around the cursor.) + // r_outer = the visible area rectangle, minus safe area padding. If our popup size won't fit because of safe area padding we ignore it. + ImVec2 safe_padding = style.DisplaySafeAreaPadding; + ImRect r_outer(GetVisibleRect()); + r_outer.Expand(ImVec2((size.x - r_outer.GetWidth() > safe_padding.x*2) ? -safe_padding.x : 0.0f, (size.y - r_outer.GetHeight() > safe_padding.y*2) ? -safe_padding.y : 0.0f)); + ImVec2 base_pos_clamped = ImClamp(ref_pos, r_outer.Min, r_outer.Max - size); + //GImGui->OverlayDrawList.AddRect(r_avoid.Min, r_avoid.Max, IM_COL32(255,0,0,255)); + //GImGui->OverlayDrawList.AddRect(r_outer.Min, r_outer.Max, IM_COL32(0,255,0,255)); + + // Combo Box policy (we want a connecting edge) + if (policy == ImGuiPopupPositionPolicy_ComboBox) + { + const ImGuiDir dir_prefered_order[ImGuiDir_Count_] = { ImGuiDir_Down, ImGuiDir_Right, ImGuiDir_Left, ImGuiDir_Up }; + for (int n = (*last_dir != ImGuiDir_None) ? -1 : 0; n < ImGuiDir_Count_; n++) + { + const ImGuiDir dir = (n == -1) ? *last_dir : dir_prefered_order[n]; + if (n != -1 && dir == *last_dir) // Already tried this direction? + continue; + ImVec2 pos; + if (dir == ImGuiDir_Down) pos = ImVec2(r_avoid.Min.x, r_avoid.Max.y); // Below, Toward Right (default) + if (dir == ImGuiDir_Right) pos = ImVec2(r_avoid.Min.x, r_avoid.Min.y - size.y); // Above, Toward Right + if (dir == ImGuiDir_Left) pos = ImVec2(r_avoid.Max.x - size.x, r_avoid.Max.y); // Below, Toward Left + if (dir == ImGuiDir_Up) pos = ImVec2(r_avoid.Max.x - size.x, r_avoid.Min.y - size.y); // Above, Toward Left + if (!r_outer.Contains(ImRect(pos, pos + size))) + continue; + *last_dir = dir; + return pos; + } + } + + // Default popup policy + const ImGuiDir dir_prefered_order[ImGuiDir_Count_] = { ImGuiDir_Right, ImGuiDir_Down, ImGuiDir_Up, ImGuiDir_Left }; + for (int n = (*last_dir != ImGuiDir_None) ? -1 : 0; n < ImGuiDir_Count_; n++) + { + const ImGuiDir dir = (n == -1) ? *last_dir : dir_prefered_order[n]; + if (n != -1 && dir == *last_dir) // Already tried this direction? + continue; + float avail_w = (dir == ImGuiDir_Left ? r_avoid.Min.x : r_outer.Max.x) - (dir == ImGuiDir_Right ? r_avoid.Max.x : r_outer.Min.x); + float avail_h = (dir == ImGuiDir_Up ? r_avoid.Min.y : r_outer.Max.y) - (dir == ImGuiDir_Down ? r_avoid.Max.y : r_outer.Min.y); + if (avail_w < size.x || avail_h < size.y) + continue; + ImVec2 pos; + pos.x = (dir == ImGuiDir_Left) ? r_avoid.Min.x - size.x : (dir == ImGuiDir_Right) ? r_avoid.Max.x : base_pos_clamped.x; + pos.y = (dir == ImGuiDir_Up) ? r_avoid.Min.y - size.y : (dir == ImGuiDir_Down) ? r_avoid.Max.y : base_pos_clamped.y; + *last_dir = dir; + return pos; + } + + // Fallback, try to keep within display + *last_dir = ImGuiDir_None; + ImVec2 pos = ref_pos; + pos.x = ImMax(ImMin(pos.x + size.x, r_outer.Max.x) - size.x, r_outer.Min.x); + pos.y = ImMax(ImMin(pos.y + size.y, r_outer.Max.y) - size.y, r_outer.Min.y); + return pos; +} + +static void SetWindowConditionAllowFlags(ImGuiWindow* window, ImGuiCond flags, bool enabled) +{ + window->SetWindowPosAllowFlags = enabled ? (window->SetWindowPosAllowFlags | flags) : (window->SetWindowPosAllowFlags & ~flags); + window->SetWindowSizeAllowFlags = enabled ? (window->SetWindowSizeAllowFlags | flags) : (window->SetWindowSizeAllowFlags & ~flags); + window->SetWindowCollapsedAllowFlags = enabled ? (window->SetWindowCollapsedAllowFlags | flags) : (window->SetWindowCollapsedAllowFlags & ~flags); +} + +ImGuiWindow* ImGui::FindWindowByName(const char* name) +{ + ImGuiContext& g = *GImGui; + ImGuiID id = ImHash(name, 0); + return (ImGuiWindow*)g.WindowsById.GetVoidPtr(id); +} + +static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags) +{ + ImGuiContext& g = *GImGui; + + // Create window the first time + ImGuiWindow* window = IM_NEW(ImGuiWindow)(&g, name); + window->Flags = flags; + g.WindowsById.SetVoidPtr(window->ID, window); + + // User can disable loading and saving of settings. Tooltip and child windows also don't store settings. + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) + { + // Retrieve settings from .ini file + // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. + window->PosFloat = ImVec2(60, 60); + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + + if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) + { + SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); + window->PosFloat = settings->Pos; + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + window->Collapsed = settings->Collapsed; + if (ImLengthSqr(settings->Size) > 0.00001f) + size = settings->Size; + } + } + window->Size = window->SizeFull = window->SizeFullAtLastBegin = size; + + if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) + { + window->AutoFitFramesX = window->AutoFitFramesY = 2; + window->AutoFitOnlyGrows = false; + } + else + { + if (window->Size.x <= 0.0f) + window->AutoFitFramesX = 2; + if (window->Size.y <= 0.0f) + window->AutoFitFramesY = 2; + window->AutoFitOnlyGrows = (window->AutoFitFramesX > 0) || (window->AutoFitFramesY > 0); + } + + if (flags & ImGuiWindowFlags_NoBringToFrontOnFocus) + g.Windows.insert(g.Windows.begin(), window); // Quite slow but rare and only once + else + g.Windows.push_back(window); + return window; +} + +static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) +{ + ImGuiContext& g = *GImGui; + if (g.SetNextWindowSizeConstraint) + { + // Using -1,-1 on either X/Y axis to preserve the current size. + ImRect cr = g.SetNextWindowSizeConstraintRect; + new_size.x = (cr.Min.x >= 0 && cr.Max.x >= 0) ? ImClamp(new_size.x, cr.Min.x, cr.Max.x) : window->SizeFull.x; + new_size.y = (cr.Min.y >= 0 && cr.Max.y >= 0) ? ImClamp(new_size.y, cr.Min.y, cr.Max.y) : window->SizeFull.y; + if (g.SetNextWindowSizeConstraintCallback) + { + ImGuiSizeConstraintCallbackData data; + data.UserData = g.SetNextWindowSizeConstraintCallbackUserData; + data.Pos = window->Pos; + data.CurrentSize = window->SizeFull; + data.DesiredSize = new_size; + g.SetNextWindowSizeConstraintCallback(&data); + new_size = data.DesiredSize; + } + } + + // Minimum size + if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize))) + { + new_size = ImMax(new_size, g.Style.WindowMinSize); + new_size.y = ImMax(new_size.y, window->TitleBarHeight() + window->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f)); // Reduce artifacts with very small windows + } + return new_size; +} + +static ImVec2 CalcSizeContents(ImGuiWindow* window) +{ + ImVec2 sz; + sz.x = (float)(int)((window->SizeContentsExplicit.x != 0.0f) ? window->SizeContentsExplicit.x : (window->DC.CursorMaxPos.x - window->Pos.x + window->Scroll.x)); + sz.y = (float)(int)((window->SizeContentsExplicit.y != 0.0f) ? window->SizeContentsExplicit.y : (window->DC.CursorMaxPos.y - window->Pos.y + window->Scroll.y)); + return sz + window->WindowPadding; +} + +static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents) +{ + ImGuiContext& g = *GImGui; + ImGuiStyle& style = g.Style; + ImGuiWindowFlags flags = window->Flags; + ImVec2 size_auto_fit; + if ((flags & ImGuiWindowFlags_Tooltip) != 0) + { + // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose. + size_auto_fit = size_contents; + } + else + { + // When the window cannot fit all contents (either because of constraints, either because screen is too small): we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than DisplaySize-WindowPadding. + size_auto_fit = ImClamp(size_contents, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - g.Style.DisplaySafeAreaPadding)); + ImVec2 size_auto_fit_after_constraint = CalcSizeAfterConstraint(window, size_auto_fit); + if (size_auto_fit_after_constraint.x < size_contents.x && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar)) + size_auto_fit.y += style.ScrollbarSize; + if (size_auto_fit_after_constraint.y < size_contents.y && !(flags & ImGuiWindowFlags_NoScrollbar)) + size_auto_fit.x += style.ScrollbarSize; + } + return size_auto_fit; +} + +static float GetScrollMaxX(ImGuiWindow* window) +{ + return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x)); +} + +static float GetScrollMaxY(ImGuiWindow* window) +{ + return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y)); +} + +static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window) +{ + ImVec2 scroll = window->Scroll; + float cr_x = window->ScrollTargetCenterRatio.x; + float cr_y = window->ScrollTargetCenterRatio.y; + if (window->ScrollTarget.x < FLT_MAX) + scroll.x = window->ScrollTarget.x - cr_x * (window->SizeFull.x - window->ScrollbarSizes.x); + if (window->ScrollTarget.y < FLT_MAX) + scroll.y = window->ScrollTarget.y - (1.0f - cr_y) * (window->TitleBarHeight() + window->MenuBarHeight()) - cr_y * (window->SizeFull.y - window->ScrollbarSizes.y); + scroll = ImMax(scroll, ImVec2(0.0f, 0.0f)); + if (!window->Collapsed && !window->SkipItems) + { + scroll.x = ImMin(scroll.x, GetScrollMaxX(window)); + scroll.y = ImMin(scroll.y, GetScrollMaxY(window)); + } + return scroll; +} + +static ImGuiCol GetWindowBgColorIdxFromFlags(ImGuiWindowFlags flags) +{ + if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) + return ImGuiCol_PopupBg; + if (flags & ImGuiWindowFlags_ChildWindow) + return ImGuiCol_ChildBg; + return ImGuiCol_WindowBg; +} + +static void CalcResizePosSizeFromAnyCorner(ImGuiWindow* window, const ImVec2& corner_target, const ImVec2& corner_norm, ImVec2* out_pos, ImVec2* out_size) +{ + ImVec2 pos_min = ImLerp(corner_target, window->Pos, corner_norm); // Expected window upper-left + ImVec2 pos_max = ImLerp(window->Pos + window->Size, corner_target, corner_norm); // Expected window lower-right + ImVec2 size_expected = pos_max - pos_min; + ImVec2 size_constrained = CalcSizeAfterConstraint(window, size_expected); + *out_pos = pos_min; + if (corner_norm.x == 0.0f) + out_pos->x -= (size_constrained.x - size_expected.x); + if (corner_norm.y == 0.0f) + out_pos->y -= (size_constrained.y - size_expected.y); + *out_size = size_constrained; +} + +struct ImGuiResizeGripDef +{ + ImVec2 CornerPos; + ImVec2 InnerDir; + int AngleMin12, AngleMax12; +}; + +const ImGuiResizeGripDef resize_grip_def[4] = +{ + { ImVec2(1,1), ImVec2(-1,-1), 0, 3 }, // Lower right + { ImVec2(0,1), ImVec2(+1,-1), 3, 6 }, // Lower left + { ImVec2(0,0), ImVec2(+1,+1), 6, 9 }, // Upper left + { ImVec2(1,0), ImVec2(-1,+1), 9,12 }, // Upper right +}; + +static ImRect GetBorderRect(ImGuiWindow* window, int border_n, float perp_padding, float thickness) +{ + ImRect rect = window->Rect(); + if (thickness == 0.0f) rect.Max -= ImVec2(1,1); + if (border_n == 0) return ImRect(rect.Min.x + perp_padding, rect.Min.y, rect.Max.x - perp_padding, rect.Min.y + thickness); + if (border_n == 1) return ImRect(rect.Max.x - thickness, rect.Min.y + perp_padding, rect.Max.x, rect.Max.y - perp_padding); + if (border_n == 2) return ImRect(rect.Min.x + perp_padding, rect.Max.y - thickness, rect.Max.x - perp_padding, rect.Max.y); + if (border_n == 3) return ImRect(rect.Min.x, rect.Min.y + perp_padding, rect.Min.x + thickness, rect.Max.y - perp_padding); + IM_ASSERT(0); + return ImRect(); +} + +// Push a new ImGui window to add widgets to. +// - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair. +// - Begin/End can be called multiple times during the frame with the same window name to append content. +// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). +// You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file. +// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned. +// - Passing 'bool* p_open' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. +bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) +{ + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + IM_ASSERT(name != NULL); // Window name required + IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() + IM_ASSERT(g.FrameCountEnded != g.FrameCount); // Called ImGui::Render() or ImGui::EndFrame() and haven't called ImGui::NewFrame() again yet + + if (flags & ImGuiWindowFlags_NoInputs) + flags |= ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize; + + // Find or create + ImGuiWindow* window = FindWindowByName(name); + if (!window) + { + ImVec2 size_on_first_use = (g.SetNextWindowSizeCond != 0) ? g.SetNextWindowSizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here. + window = CreateNewWindow(name, size_on_first_use, flags); + } + + const int current_frame = g.FrameCount; + const bool first_begin_of_the_frame = (window->LastFrameActive != current_frame); + if (first_begin_of_the_frame) + window->Flags = (ImGuiWindowFlags)flags; + else + flags = window->Flags; + + // Update the Appearing flag + bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on + const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFrames == 1); + if (flags & ImGuiWindowFlags_Popup) + { + ImGuiPopupRef& popup_ref = g.OpenPopupStack[g.CurrentPopupStack.Size]; + window_just_activated_by_user |= (window->PopupId != popup_ref.PopupId); // We recycle popups so treat window as activated if popup id changed + window_just_activated_by_user |= (window != popup_ref.Window); + } + window->Appearing = (window_just_activated_by_user || window_just_appearing_after_hidden_for_resize); + window->CloseButton = (p_open != NULL); + if (window->Appearing) + SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); + + // Parent window is latched only on the first call to Begin() of the frame, so further append-calls can be done from a different window stack + ImGuiWindow* parent_window_in_stack = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); + ImGuiWindow* parent_window = first_begin_of_the_frame ? ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)) ? parent_window_in_stack : NULL) : window->ParentWindow; + IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow)); + + // Add to stack + g.CurrentWindowStack.push_back(window); + SetCurrentWindow(window); + CheckStacksSize(window, true); + if (flags & ImGuiWindowFlags_Popup) + { + ImGuiPopupRef& popup_ref = g.OpenPopupStack[g.CurrentPopupStack.Size]; + popup_ref.Window = window; + g.CurrentPopupStack.push_back(popup_ref); + window->PopupId = popup_ref.PopupId; + } + + // Process SetNextWindow***() calls + bool window_pos_set_by_api = false; + bool window_size_x_set_by_api = false, window_size_y_set_by_api = false; + if (g.SetNextWindowPosCond) + { + window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) != 0; + if (window_pos_set_by_api && ImLengthSqr(g.SetNextWindowPosPivot) > 0.00001f) + { + // May be processed on the next frame if this is our first frame and we are measuring size + // FIXME: Look into removing the branch so everything can go through this same code path for consistency. + window->SetWindowPosVal = g.SetNextWindowPosVal; + window->SetWindowPosPivot = g.SetNextWindowPosPivot; + window->SetWindowPosAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); + } + else + { + SetWindowPos(window, g.SetNextWindowPosVal, g.SetNextWindowPosCond); + } + g.SetNextWindowPosCond = 0; + } + if (g.SetNextWindowSizeCond) + { + window_size_x_set_by_api = (window->SetWindowSizeAllowFlags & g.SetNextWindowSizeCond) != 0 && (g.SetNextWindowSizeVal.x > 0.0f); + window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.SetNextWindowSizeCond) != 0 && (g.SetNextWindowSizeVal.y > 0.0f); + SetWindowSize(window, g.SetNextWindowSizeVal, g.SetNextWindowSizeCond); + g.SetNextWindowSizeCond = 0; + } + if (g.SetNextWindowContentSizeCond) + { + // Adjust passed "client size" to become a "window size" + window->SizeContentsExplicit = g.SetNextWindowContentSizeVal; + window->SizeContentsExplicit.y += window->TitleBarHeight() + window->MenuBarHeight(); + g.SetNextWindowContentSizeCond = 0; + } + else if (first_begin_of_the_frame) + { + window->SizeContentsExplicit = ImVec2(0.0f, 0.0f); + } + if (g.SetNextWindowCollapsedCond) + { + SetWindowCollapsed(window, g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond); + g.SetNextWindowCollapsedCond = 0; + } + if (g.SetNextWindowFocus) + { + SetWindowFocus(); + g.SetNextWindowFocus = false; + } + if (window->Appearing) + SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false); + + // When reusing window again multiple times a frame, just append content (don't need to setup again) + if (first_begin_of_the_frame) + { + // Initialize + window->ParentWindow = parent_window; + window->RootWindow = window->RootNonPopupWindow = window; + if (parent_window && (flags & ImGuiWindowFlags_ChildWindow)) + window->RootWindow = parent_window->RootWindow; + if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) + window->RootNonPopupWindow = parent_window->RootNonPopupWindow; + //window->RootNavWindow = window; + //while (window->RootNavWindow->Flags & ImGuiWindowFlags_NavFlattened) + // window->RootNavWindow = window->RootNavWindow->ParentWindow; + + window->Active = true; + window->BeginOrderWithinParent = 0; + window->BeginOrderWithinContext = g.WindowsActiveCount++; + window->BeginCount = 0; + window->ClipRect = ImVec4(-FLT_MAX,-FLT_MAX,+FLT_MAX,+FLT_MAX); + window->LastFrameActive = current_frame; + window->IDStack.resize(1); + + // Setup draw list and outer clipping rectangle + window->DrawList->Clear(); + window->DrawList->Flags = (g.Style.AntiAliasedLines ? ImDrawListFlags_AntiAliasedLines : 0) | (g.Style.AntiAliasedFill ? ImDrawListFlags_AntiAliasedFill : 0); + window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); + ImRect fullscreen_rect(GetVisibleRect()); + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup)) + PushClipRect(parent_window->ClipRect.Min, parent_window->ClipRect.Max, true); + else + PushClipRect(fullscreen_rect.Min, fullscreen_rect.Max, true); + + if (window_just_activated_by_user) + { + // Popup first latch mouse position, will position itself when it appears next frame + window->AutoPosLastDirection = ImGuiDir_None; + if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api) + window->PosFloat = g.IO.MousePos; + } + + // Collapse window by double-clicking on title bar + // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing + if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse)) + { + ImRect title_bar_rect = window->TitleBarRect(); + if (g.HoveredWindow == window && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max) && g.IO.MouseDoubleClicked[0]) + { + window->Collapsed = !window->Collapsed; + MarkIniSettingsDirty(window); + FocusWindow(window); + } + } + else + { + window->Collapsed = false; + } + + // SIZE + + // Update contents size from last frame for auto-fitting (unless explicitly specified) + window->SizeContents = CalcSizeContents(window); + + // Hide popup/tooltip window when re-opening while we measure size (because we recycle the windows) + if (window->HiddenFrames > 0) + window->HiddenFrames--; + if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) != 0 && window_just_activated_by_user) + { + window->HiddenFrames = 1; + if (flags & ImGuiWindowFlags_AlwaysAutoResize) + { + if (!window_size_x_set_by_api) + window->Size.x = window->SizeFull.x = 0.f; + if (!window_size_y_set_by_api) + window->Size.y = window->SizeFull.y = 0.f; + window->SizeContents = ImVec2(0.f, 0.f); + } + } + + // Lock window rounding, border size and rounding so that altering the border sizes for children doesn't have side-effects. + window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; + window->WindowBorderSize = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildBorderSize : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupBorderSize : style.WindowBorderSize; + window->WindowPadding = style.WindowPadding; + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f) + window->WindowPadding = ImVec2(0.0f, (flags & ImGuiWindowFlags_MenuBar) ? style.WindowPadding.y : 0.0f); + const float window_rounding = window->WindowRounding; + const float window_border_size = window->WindowBorderSize; + + // Calculate auto-fit size, handle automatic resize + const ImVec2 size_auto_fit = CalcSizeAutoFit(window, window->SizeContents); + ImVec2 size_full_modified(FLT_MAX, FLT_MAX); + if (flags & ImGuiWindowFlags_AlwaysAutoResize && !window->Collapsed) + { + // Using SetNextWindowSize() overrides ImGuiWindowFlags_AlwaysAutoResize, so it can be used on tooltips/popups, etc. + if (!window_size_x_set_by_api) + window->SizeFull.x = size_full_modified.x = size_auto_fit.x; + if (!window_size_y_set_by_api) + window->SizeFull.y = size_full_modified.y = size_auto_fit.y; + } + else if (window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) + { + // Auto-fit only grows during the first few frames + // We still process initial auto-fit on collapsed windows to get a window width, but otherwise don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed. + if (!window_size_x_set_by_api && window->AutoFitFramesX > 0) + window->SizeFull.x = size_full_modified.x = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.x, size_auto_fit.x) : size_auto_fit.x; + if (!window_size_y_set_by_api && window->AutoFitFramesY > 0) + window->SizeFull.y = size_full_modified.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y; + if (!window->Collapsed) + MarkIniSettingsDirty(window); + } + + // Apply minimum/maximum window size constraints and final size + window->SizeFull = CalcSizeAfterConstraint(window, window->SizeFull); + window->Size = window->Collapsed ? window->TitleBarRect().GetSize() : window->SizeFull; + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup)) + { + IM_ASSERT(window_size_x_set_by_api && window_size_y_set_by_api); // Submitted by BeginChild() + window->Size = window->SizeFull; + } + + // SCROLLBAR STATUS + + // Update scrollbar status (based on the Size that was effective during last frame or the auto-resized Size). + if (!window->Collapsed) + { + // When reading the current size we need to read it after size constraints have been applied + float size_x_for_scrollbars = size_full_modified.x != FLT_MAX ? window->SizeFull.x : window->SizeFullAtLastBegin.x; + float size_y_for_scrollbars = size_full_modified.y != FLT_MAX ? window->SizeFull.y : window->SizeFullAtLastBegin.y; + window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((window->SizeContents.y > size_y_for_scrollbars) && !(flags & ImGuiWindowFlags_NoScrollbar)); + window->ScrollbarX = (flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar) || ((window->SizeContents.x > size_x_for_scrollbars - (window->ScrollbarY ? style.ScrollbarSize : 0.0f) - window->WindowPadding.x) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar)); + if (window->ScrollbarX && !window->ScrollbarY) + window->ScrollbarY = (window->SizeContents.y > size_y_for_scrollbars + style.ScrollbarSize) && !(flags & ImGuiWindowFlags_NoScrollbar); + window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f); + } + + // POSITION + + // Position child window + if (flags & ImGuiWindowFlags_ChildWindow) + { + window->BeginOrderWithinParent = parent_window->DC.ChildWindows.Size; + parent_window->DC.ChildWindows.push_back(window); + } + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_pos_set_by_api) + window->Pos = window->PosFloat = parent_window->DC.CursorPos; + + const bool window_pos_with_pivot = (window->SetWindowPosVal.x != FLT_MAX && window->HiddenFrames == 0); + if (window_pos_with_pivot) + { + // Position given a pivot (e.g. for centering) + SetWindowPos(window, ImMax(style.DisplaySafeAreaPadding, window->SetWindowPosVal - window->SizeFull * window->SetWindowPosPivot), 0); + } + else if (flags & ImGuiWindowFlags_ChildMenu) + { + // Child menus typically request _any_ position within the parent menu item, and then our FindBestPopupWindowPos() function will move the new menu outside the parent bounds. + // This is how we end up with child menus appearing (most-commonly) on the right of the parent menu. + IM_ASSERT(window_pos_set_by_api); + float horizontal_overlap = style.ItemSpacing.x; // We want some overlap to convey the relative depth of each popup (currently the amount of overlap it is hard-coded to style.ItemSpacing.x, may need to introduce another style value). + ImGuiWindow* parent_menu = parent_window_in_stack; + ImRect rect_to_avoid; + if (parent_menu->DC.MenuBarAppending) + rect_to_avoid = ImRect(-FLT_MAX, parent_menu->Pos.y + parent_menu->TitleBarHeight(), FLT_MAX, parent_menu->Pos.y + parent_menu->TitleBarHeight() + parent_menu->MenuBarHeight()); + else + rect_to_avoid = ImRect(parent_menu->Pos.x + horizontal_overlap, -FLT_MAX, parent_menu->Pos.x + parent_menu->Size.x - horizontal_overlap - parent_menu->ScrollbarSizes.x, FLT_MAX); + window->PosFloat = FindBestWindowPosForPopup(window->PosFloat, window->Size, &window->AutoPosLastDirection, rect_to_avoid); + } + else if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api && window_just_appearing_after_hidden_for_resize) + { + ImRect rect_to_avoid(window->PosFloat.x - 1, window->PosFloat.y - 1, window->PosFloat.x + 1, window->PosFloat.y + 1); + window->PosFloat = FindBestWindowPosForPopup(window->PosFloat, window->Size, &window->AutoPosLastDirection, rect_to_avoid); + } + + // Position tooltip (always follows mouse) + if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api) + { + ImVec2 ref_pos = g.IO.MousePos; + ImRect rect_to_avoid(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 24, ref_pos.y + 24); // FIXME: Completely hard-coded. Store boxes in mouse cursor data? Scale? Center on cursor hit-point? + window->PosFloat = FindBestWindowPosForPopup(ref_pos, window->Size, &window->AutoPosLastDirection, rect_to_avoid); + if (window->AutoPosLastDirection == ImGuiDir_None) + window->PosFloat = ref_pos + ImVec2(2,2); // If there's not enough room, for tooltip we prefer avoiding the cursor at all cost even if it means that part of the tooltip won't be visible. + } + + // Clamp position so it stays visible + if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip)) + { + if (!window_pos_set_by_api && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. + { + ImVec2 padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); + window->PosFloat = ImMax(window->PosFloat + window->Size, padding) - window->Size; + window->PosFloat = ImMin(window->PosFloat, g.IO.DisplaySize - padding); + } + } + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + + // Default item width. Make it proportional to window size if window manually resizes + if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize)) + window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f); + else + window->ItemWidthDefault = (float)(int)(g.FontSize * 16.0f); + + // Prepare for focus requests + window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext == INT_MAX || window->FocusIdxAllCounter == -1) ? INT_MAX : (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1); + window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext == INT_MAX || window->FocusIdxTabCounter == -1) ? INT_MAX : (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1); + window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1; + window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = INT_MAX; + + // Apply scrolling + window->Scroll = CalcNextScrollFromScrollTargetAndClamp(window); + window->ScrollTarget = ImVec2(FLT_MAX, FLT_MAX); + + // Apply focus, new windows appears in front + bool want_focus = false; + if (window_just_activated_by_user && !(flags & ImGuiWindowFlags_NoFocusOnAppearing)) + if (!(flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) || (flags & ImGuiWindowFlags_Popup)) + want_focus = true; + + // Draw modal window background (darkens what is behind them) + if ((flags & ImGuiWindowFlags_Modal) != 0 && window == GetFrontMostModalRootWindow()) + window->DrawList->AddRectFilled(fullscreen_rect.Min, fullscreen_rect.Max, GetColorU32(ImGuiCol_ModalWindowDarkening, g.ModalWindowDarkeningRatio)); + + // Draw window + handle manual resize + ImRect title_bar_rect = window->TitleBarRect(); + if (window->Collapsed) + { + // Title bar only + float backup_border_size = style.FrameBorderSize; + g.Style.FrameBorderSize = window->WindowBorderSize; + RenderFrame(title_bar_rect.Min, title_bar_rect.Max, GetColorU32(ImGuiCol_TitleBgCollapsed), true, window_rounding); + g.Style.FrameBorderSize = backup_border_size; + } + else + { + // Handle resize for: Resize Grips, Borders, Gamepad + int border_held = -1; + ImU32 resize_grip_col[4] = { 0 }; + const int resize_grip_count = (flags & ImGuiWindowFlags_ResizeFromAnySide) ? 2 : 1; // 4 + const int resize_border_count = (flags & ImGuiWindowFlags_ResizeFromAnySide) ? 4 : 0; + + const float grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window_rounding + 1.0f + g.FontSize * 0.2f); + const float grip_hover_size = (float)(int)(grip_draw_size * 0.75f); + if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && !(flags & ImGuiWindowFlags_NoResize)) + { + ImVec2 pos_target(FLT_MAX, FLT_MAX); + ImVec2 size_target(FLT_MAX, FLT_MAX); + + // Manual resize grips + PushID("#RESIZE"); + for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) + { + const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n]; + const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPos); + + // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window + ImRect resize_rect(corner, corner + grip.InnerDir * grip_hover_size); + resize_rect.FixInverted(); + bool hovered, held; + ButtonBehavior(resize_rect, window->GetID((void*)(intptr_t)resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren); + if (hovered || held) + g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; + + if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0] && resize_grip_n == 0) + { + // Manual auto-fit when double-clicking + size_target = CalcSizeAfterConstraint(window, size_auto_fit); + ClearActiveID(); + } + else if (held) + { + // Resize from any of the four corners + // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position + ImVec2 corner_target = g.IO.MousePos - g.ActiveIdClickOffset + resize_rect.GetSize() * grip.CornerPos; // Corner of the window corresponding to our corner grip + CalcResizePosSizeFromAnyCorner(window, corner_target, grip.CornerPos, &pos_target, &size_target); + } + if (resize_grip_n == 0 || held || hovered) + resize_grip_col[resize_grip_n] = GetColorU32(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); + } + for (int border_n = 0; border_n < resize_border_count; border_n++) + { + const float BORDER_SIZE = 5.0f; // FIXME: Only works _inside_ window because of HoveredWindow check. + const float BORDER_APPEAR_TIMER = 0.05f; // Reduce visual noise + bool hovered, held; + ImRect border_rect = GetBorderRect(window, border_n, grip_hover_size, BORDER_SIZE); + ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n+4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren); + if ((hovered && g.HoveredIdTimer > BORDER_APPEAR_TIMER) || held) + { + g.MouseCursor = (border_n & 1) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS; + if (held) border_held = border_n; + } + if (held) + { + ImVec2 border_target = window->Pos; + ImVec2 border_posn; + if (border_n == 0) { border_posn = ImVec2(0, 0); border_target.y = (g.IO.MousePos.y - g.ActiveIdClickOffset.y); } + if (border_n == 1) { border_posn = ImVec2(1, 0); border_target.x = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + BORDER_SIZE); } + if (border_n == 2) { border_posn = ImVec2(0, 1); border_target.y = (g.IO.MousePos.y - g.ActiveIdClickOffset.y + BORDER_SIZE); } + if (border_n == 3) { border_posn = ImVec2(0, 0); border_target.x = (g.IO.MousePos.x - g.ActiveIdClickOffset.x); } + CalcResizePosSizeFromAnyCorner(window, border_target, border_posn, &pos_target, &size_target); + } + } + PopID(); + + // Apply back modified position/size to window + if (size_target.x != FLT_MAX) + { + window->SizeFull = size_target; + MarkIniSettingsDirty(window); + } + if (pos_target.x != FLT_MAX) + { + window->Pos = window->PosFloat = ImVec2((float)(int)pos_target.x, (float)(int)pos_target.y); + MarkIniSettingsDirty(window); + } + + window->Size = window->SizeFull; + title_bar_rect = window->TitleBarRect(); + } + + // Window background, Default Alpha + ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags)); + window->DrawList->AddRectFilled(window->Pos+ImVec2(0,window->TitleBarHeight()), window->Pos+window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot); + + // Title bar + const bool window_is_focused = want_focus || (g.NavWindow && window->RootNonPopupWindow == g.NavWindow->RootNonPopupWindow); + if (!(flags & ImGuiWindowFlags_NoTitleBar)) + window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, GetColorU32(window_is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, ImDrawCornerFlags_Top); + + // Menu bar + if (flags & ImGuiWindowFlags_MenuBar) + { + ImRect menu_bar_rect = window->MenuBarRect(); + menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them. + window->DrawList->AddRectFilled(menu_bar_rect.Min, menu_bar_rect.Max, GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top); + if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y) + window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize); + } + + // Scrollbars + if (window->ScrollbarX) + Scrollbar(ImGuiLayoutType_Horizontal); + if (window->ScrollbarY) + Scrollbar(ImGuiLayoutType_Vertical); + + // Render resize grips (after their input handling so we don't have a frame of latency) + if (!(flags & ImGuiWindowFlags_NoResize)) + { + for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) + { + const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n]; + const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPos); + window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, grip_draw_size) : ImVec2(grip_draw_size, window_border_size))); + window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(grip_draw_size, window_border_size) : ImVec2(window_border_size, grip_draw_size))); + window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12); + window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]); + } + } + + // Borders + if (window_border_size > 0.0f) + window->DrawList->AddRect(window->Pos, window->Pos+window->Size, GetColorU32(ImGuiCol_Border), window_rounding, ImDrawCornerFlags_All, window_border_size); + if (border_held != -1) + { + ImRect border = GetBorderRect(window, border_held, grip_draw_size, 0.0f); + window->DrawList->AddLine(border.Min, border.Max, GetColorU32(ImGuiCol_SeparatorActive), ImMax(1.0f, window_border_size)); + } + if (style.FrameBorderSize > 0 && !(flags & ImGuiWindowFlags_NoTitleBar)) + window->DrawList->AddLine(title_bar_rect.GetBL() + ImVec2(style.WindowBorderSize, -1), title_bar_rect.GetBR() + ImVec2(-style.WindowBorderSize,-1), GetColorU32(ImGuiCol_Border), style.FrameBorderSize); + } + + // Store a backup of SizeFull which we will use next frame to decide if we need scrollbars. + window->SizeFullAtLastBegin = window->SizeFull; + + // Update ContentsRegionMax. All the variable it depends on are set above in this function. + window->ContentsRegionRect.Min.x = -window->Scroll.x + window->WindowPadding.x; + window->ContentsRegionRect.Min.y = -window->Scroll.y + window->WindowPadding.y + window->TitleBarHeight() + window->MenuBarHeight(); + window->ContentsRegionRect.Max.x = -window->Scroll.x - window->WindowPadding.x + (window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : (window->Size.x - window->ScrollbarSizes.x)); + window->ContentsRegionRect.Max.y = -window->Scroll.y - window->WindowPadding.y + (window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : (window->Size.y - window->ScrollbarSizes.y)); + + // Setup drawing context + // (NB: That term "drawing context / DC" lost its meaning a long time ago. Initially was meant to hold transient data only. Nowadays difference between window-> and window->DC-> is dubious.) + window->DC.IndentX = 0.0f + window->WindowPadding.x - window->Scroll.x; + window->DC.GroupOffsetX = 0.0f; + window->DC.ColumnsOffsetX = 0.0f; + window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.IndentX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->MenuBarHeight() + window->WindowPadding.y - window->Scroll.y); + window->DC.CursorPos = window->DC.CursorStartPos; + window->DC.CursorPosPrevLine = window->DC.CursorPos; + window->DC.CursorMaxPos = window->DC.CursorStartPos; + window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f; + window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f; + window->DC.MenuBarAppending = false; + window->DC.MenuBarOffsetX = ImMax(window->WindowPadding.x, style.ItemSpacing.x); + window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; + window->DC.ChildWindows.resize(0); + window->DC.LayoutType = ImGuiLayoutType_Vertical; + window->DC.ItemFlags = ImGuiItemFlags_Default_; + window->DC.ItemWidth = window->ItemWidthDefault; + window->DC.TextWrapPos = -1.0f; // disabled + window->DC.ItemFlagsStack.resize(0); + window->DC.ItemWidthStack.resize(0); + window->DC.TextWrapPosStack.resize(0); + window->DC.ColumnsSet = NULL; + window->DC.TreeDepth = 0; + window->DC.StateStorage = &window->StateStorage; + window->DC.GroupStack.resize(0); + window->MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user); + + if ((flags & ImGuiWindowFlags_ChildWindow) && (window->DC.ItemFlags != parent_window->DC.ItemFlags)) + { + window->DC.ItemFlags = parent_window->DC.ItemFlags; + window->DC.ItemFlagsStack.push_back(window->DC.ItemFlags); + } + + if (window->AutoFitFramesX > 0) + window->AutoFitFramesX--; + if (window->AutoFitFramesY > 0) + window->AutoFitFramesY--; + + // Apply focus (we need to call FocusWindow() AFTER setting DC.CursorStartPos so our initial navigation reference rectangle can start around there) + if (want_focus) + FocusWindow(window); + + // Title bar + if (!(flags & ImGuiWindowFlags_NoTitleBar)) + { + // Collapse button + if (!(flags & ImGuiWindowFlags_NoCollapse)) + { + RenderTriangle(window->Pos + style.FramePadding, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f); + } + + // Close button + if (p_open != NULL) + { + const float PAD = 2.0f; + const float rad = (window->TitleBarHeight() - PAD*2.0f) * 0.5f; + if (CloseButton(window->GetID("#CLOSE"), window->Rect().GetTR() + ImVec2(-PAD - rad, PAD + rad), rad)) + *p_open = false; + } + + // Title text (FIXME: refactor text alignment facilities along with RenderText helpers) + const ImVec2 text_size = CalcTextSize(name, NULL, true); + ImVec2 text_min = window->Pos; + ImVec2 text_max = window->Pos + ImVec2(window->Size.x, style.FramePadding.y*2 + text_size.y); + ImRect clip_rect; + clip_rect.Max = ImVec2(window->Pos.x + window->Size.x - (p_open ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton() + float pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0 ? (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x) : style.FramePadding.x; + float pad_right = (p_open != NULL) ? (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x) : style.FramePadding.x; + if (style.WindowTitleAlign.x > 0.0f) pad_right = ImLerp(pad_right, pad_left, style.WindowTitleAlign.x); + text_min.x += pad_left; + text_max.x -= pad_right; + clip_rect.Min = ImVec2(text_min.x, window->Pos.y); + RenderTextClipped(text_min, text_max, name, NULL, &text_size, style.WindowTitleAlign, &clip_rect); + } + + // Save clipped aabb so we can access it in constant-time in FindHoveredWindow() + window->WindowRectClipped = window->Rect(); + window->WindowRectClipped.ClipWith(window->ClipRect); + + // Pressing CTRL+C while holding on a window copy its content to the clipboard + // This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope. + // Maybe we can support CTRL+C on every element? + /* + if (g.ActiveId == move_id) + if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C)) + ImGui::LogToClipboard(); + */ + + // Inner rectangle + // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame + // Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior. + window->InnerRect.Min.x = title_bar_rect.Min.x + window->WindowBorderSize; + window->InnerRect.Min.y = title_bar_rect.Max.y + window->MenuBarHeight() + (((flags & ImGuiWindowFlags_MenuBar) || !(flags & ImGuiWindowFlags_NoTitleBar)) ? style.FrameBorderSize : window->WindowBorderSize); + window->InnerRect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x - window->WindowBorderSize; + window->InnerRect.Max.y = window->Pos.y + window->Size.y - window->ScrollbarSizes.y - window->WindowBorderSize; + //window->DrawList->AddRect(window->InnerRect.Min, window->InnerRect.Max, IM_COL32_WHITE); + + // After Begin() we fill the last item / hovered data using the title bar data. Make that a standard behavior (to allow usage of context menus on title bar only, etc.). + window->DC.LastItemId = window->MoveId; + window->DC.LastItemRect = title_bar_rect; + window->DC.LastItemRectHoveredRect = IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false); + } + + // Inner clipping rectangle + // Force round operator last to ensure that e.g. (int)(max.x-min.x) in user's render code produce correct result. + const float border_size = window->WindowBorderSize; + ImRect clip_rect; + clip_rect.Min.x = ImFloor(0.5f + window->InnerRect.Min.x + ImMax(0.0f, ImFloor(window->WindowPadding.x*0.5f - border_size))); + clip_rect.Min.y = ImFloor(0.5f + window->InnerRect.Min.y); + clip_rect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(0.0f, ImFloor(window->WindowPadding.x*0.5f - border_size))); + clip_rect.Max.y = ImFloor(0.5f + window->InnerRect.Max.y); + PushClipRect(clip_rect.Min, clip_rect.Max, true); + + // Clear 'accessed' flag last thing (After PushClipRect which will set the flag. We want the flag to stay false when the default "Debug" window is unused) + if (first_begin_of_the_frame) + window->WriteAccessed = false; + + window->BeginCount++; + g.SetNextWindowSizeConstraint = false; + + // Child window can be out of sight and have "negative" clip windows. + // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar). + if (flags & ImGuiWindowFlags_ChildWindow) + { + IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0); + window->Collapsed = parent_window && parent_window->Collapsed; + + if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) + window->Collapsed |= (window->WindowRectClipped.Min.x >= window->WindowRectClipped.Max.x || window->WindowRectClipped.Min.y >= window->WindowRectClipped.Max.y); + + // We also hide the window from rendering because we've already added its border to the command list. + // (we could perform the check earlier in the function but it is simpler at this point) + if (window->Collapsed) + window->Active = false; + } + if (style.Alpha <= 0.0f) + window->Active = false; + + // Return false if we don't intend to display anything to allow user to perform an early out optimization + window->SkipItems = (window->Collapsed || !window->Active) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0; + return !window->SkipItems; +} + +// Old Begin() API with 5 parameters, avoid calling this version directly! Use SetNextWindowSize()+Begin() instead. +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS +bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override, ImGuiWindowFlags flags) +{ + // Old API feature: we could pass the initial window size as a parameter, however this was very misleading because in most cases it would only affect the window when it didn't have storage in the .ini file. + if (size_on_first_use.x != 0.0f || size_on_first_use.y != 0.0f) + SetNextWindowSize(size_on_first_use, ImGuiCond_FirstUseEver); + + // Old API feature: we could override the window background alpha with a parameter. This is actually tricky to reproduce manually because: + // (1) there are multiple variants of WindowBg (popup, tooltip, etc.) and (2) you can't call PushStyleColor before Begin and PopStyleColor just after Begin() because of how CheckStackSizes() behave. + // The user-side solution is to do backup = GetStyleColorVec4(ImGuiCol_xxxBG), PushStyleColor(ImGuiCol_xxxBg), Begin, PushStyleColor(ImGuiCol_xxxBg, backup), [...], PopStyleColor(), End(); PopStyleColor() - which is super awkward. + // The alpha override was rarely used but for now we'll leave the Begin() variant around for a bit. We may either lift the constraint on CheckStackSizes() either add a SetNextWindowBgAlpha() helper that does it magically. + ImGuiContext& g = *GImGui; + const ImGuiCol bg_color_idx = GetWindowBgColorIdxFromFlags(flags); + const ImVec4 bg_color_backup = g.Style.Colors[bg_color_idx]; + if (bg_alpha_override >= 0.0f) + g.Style.Colors[bg_color_idx].w = bg_alpha_override; + + bool ret = Begin(name, p_open, flags); + + if (bg_alpha_override >= 0.0f) + g.Style.Colors[bg_color_idx] = bg_color_backup; + return ret; +} +#endif // IMGUI_DISABLE_OBSOLETE_FUNCTIONS + +void ImGui::End() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + if (window->DC.ColumnsSet != NULL) + EndColumns(); + PopClipRect(); // inner window clip rectangle + + // Stop logging + if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging + LogFinish(); + + // Pop + // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin(). + g.CurrentWindowStack.pop_back(); + if (window->Flags & ImGuiWindowFlags_Popup) + g.CurrentPopupStack.pop_back(); + CheckStacksSize(window, false); + SetCurrentWindow(g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back()); +} + +// Vertical scrollbar +// The entire piece of code below is rather confusing because: +// - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab) +// - We store values as normalized ratio and in a form that allows the window content to change while we are holding on a scrollbar +// - We handle both horizontal and vertical scrollbars, which makes the terminology not ideal. +void ImGui::Scrollbar(ImGuiLayoutType direction) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + const bool horizontal = (direction == ImGuiLayoutType_Horizontal); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(horizontal ? "#SCROLLX" : "#SCROLLY"); + + // Render background + bool other_scrollbar = (horizontal ? window->ScrollbarY : window->ScrollbarX); + float other_scrollbar_size_w = other_scrollbar ? style.ScrollbarSize : 0.0f; + const ImRect window_rect = window->Rect(); + const float border_size = window->WindowBorderSize; + ImRect bb = horizontal + ? ImRect(window->Pos.x + border_size, window_rect.Max.y - style.ScrollbarSize, window_rect.Max.x - other_scrollbar_size_w - border_size, window_rect.Max.y - border_size) + : ImRect(window_rect.Max.x - style.ScrollbarSize, window->Pos.y + border_size, window_rect.Max.x - border_size, window_rect.Max.y - other_scrollbar_size_w - border_size); + if (!horizontal) + bb.Min.y += window->TitleBarHeight() + ((window->Flags & ImGuiWindowFlags_MenuBar) ? window->MenuBarHeight() : 0.0f); + if (bb.GetWidth() <= 0.0f || bb.GetHeight() <= 0.0f) + return; + + int window_rounding_corners; + if (horizontal) + window_rounding_corners = ImDrawCornerFlags_BotLeft | (other_scrollbar ? 0 : ImDrawCornerFlags_BotRight); + else + window_rounding_corners = (((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? ImDrawCornerFlags_TopRight : 0) | (other_scrollbar ? 0 : ImDrawCornerFlags_BotRight); + window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_ScrollbarBg), window->WindowRounding, window_rounding_corners); + bb.Expand(ImVec2(-ImClamp((float)(int)((bb.Max.x - bb.Min.x - 2.0f) * 0.5f), 0.0f, 3.0f), -ImClamp((float)(int)((bb.Max.y - bb.Min.y - 2.0f) * 0.5f), 0.0f, 3.0f))); + + // V denote the main, longer axis of the scrollbar (= height for a vertical scrollbar) + float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight(); + float scroll_v = horizontal ? window->Scroll.x : window->Scroll.y; + float win_size_avail_v = (horizontal ? window->SizeFull.x : window->SizeFull.y) - other_scrollbar_size_w; + float win_size_contents_v = horizontal ? window->SizeContents.x : window->SizeContents.y; + + // Calculate the height of our grabbable box. It generally represent the amount visible (vs the total scrollable amount) + // But we maintain a minimum size in pixel to allow for the user to still aim inside. + IM_ASSERT(ImMax(win_size_contents_v, win_size_avail_v) > 0.0f); // Adding this assert to check if the ImMax(XXX,1.0f) is still needed. PLEASE CONTACT ME if this triggers. + const float win_size_v = ImMax(ImMax(win_size_contents_v, win_size_avail_v), 1.0f); + const float grab_h_pixels = ImClamp(scrollbar_size_v * (win_size_avail_v / win_size_v), style.GrabMinSize, scrollbar_size_v); + const float grab_h_norm = grab_h_pixels / scrollbar_size_v; + + // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar(). + bool held = false; + bool hovered = false; + const bool previously_held = (g.ActiveId == id); + ButtonBehavior(bb, id, &hovered, &held); + + float scroll_max = ImMax(1.0f, win_size_contents_v - win_size_avail_v); + float scroll_ratio = ImSaturate(scroll_v / scroll_max); + float grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v; + if (held && grab_h_norm < 1.0f) + { + float scrollbar_pos_v = horizontal ? bb.Min.x : bb.Min.y; + float mouse_pos_v = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y; + float* click_delta_to_grab_center_v = horizontal ? &g.ScrollbarClickDeltaToGrabCenter.x : &g.ScrollbarClickDeltaToGrabCenter.y; + + // Click position in scrollbar normalized space (0.0f->1.0f) + const float clicked_v_norm = ImSaturate((mouse_pos_v - scrollbar_pos_v) / scrollbar_size_v); + SetHoveredID(id); + + bool seek_absolute = false; + if (!previously_held) + { + // On initial click calculate the distance between mouse and the center of the grab + if (clicked_v_norm >= grab_v_norm && clicked_v_norm <= grab_v_norm + grab_h_norm) + { + *click_delta_to_grab_center_v = clicked_v_norm - grab_v_norm - grab_h_norm*0.5f; + } + else + { + seek_absolute = true; + *click_delta_to_grab_center_v = 0.0f; + } + } + + // Apply scroll + // It is ok to modify Scroll here because we are being called in Begin() after the calculation of SizeContents and before setting up our starting position + const float scroll_v_norm = ImSaturate((clicked_v_norm - *click_delta_to_grab_center_v - grab_h_norm*0.5f) / (1.0f - grab_h_norm)); + scroll_v = (float)(int)(0.5f + scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v)); + if (horizontal) + window->Scroll.x = scroll_v; + else + window->Scroll.y = scroll_v; + + // Update values for rendering + scroll_ratio = ImSaturate(scroll_v / scroll_max); + grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v; + + // Update distance to grab now that we have seeked and saturated + if (seek_absolute) + *click_delta_to_grab_center_v = clicked_v_norm - grab_v_norm - grab_h_norm*0.5f; + } + + // Render + const ImU32 grab_col = GetColorU32(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); + ImRect grab_rect; + if (horizontal) + grab_rect = ImRect(ImLerp(bb.Min.x, bb.Max.x, grab_v_norm), bb.Min.y, ImMin(ImLerp(bb.Min.x, bb.Max.x, grab_v_norm) + grab_h_pixels, window_rect.Max.x), bb.Max.y); + else + grab_rect = ImRect(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_v_norm), bb.Max.x, ImMin(ImLerp(bb.Min.y, bb.Max.y, grab_v_norm) + grab_h_pixels, window_rect.Max.y)); + window->DrawList->AddRectFilled(grab_rect.Min, grab_rect.Max, grab_col, style.ScrollbarRounding); +} + +void ImGui::BringWindowToFront(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (g.Windows.back() == window) + return; + for (int i = 0; i < g.Windows.Size; i++) + if (g.Windows[i] == window) + { + g.Windows.erase(g.Windows.begin() + i); + g.Windows.push_back(window); + break; + } +} + +void ImGui::BringWindowToBack(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (g.Windows[0] == window) + return; + for (int i = 0; i < g.Windows.Size; i++) + if (g.Windows[i] == window) + { + memmove(&g.Windows[1], &g.Windows[0], (size_t)i * sizeof(ImGuiWindow*)); + g.Windows[0] = window; + break; + } +} + +// Moving window to front of display and set focus (which happens to be back of our sorted list) +void ImGui::FocusWindow(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + + // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing. + g.NavWindow = window; + + // Passing NULL allow to disable keyboard focus + if (!window) + return; + + // Move the root window to the top of the pile + if (window->RootWindow) + window = window->RootWindow; + + // Steal focus on active widgets + if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it.. + if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window) + ClearActiveID(); + + // Bring to front + if (!(window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) + BringWindowToFront(window); +} + +void ImGui::FocusPreviousWindow() +{ + ImGuiContext& g = *GImGui; + for (int i = g.Windows.Size - 1; i >= 0; i--) + if (g.Windows[i]->WasActive && !(g.Windows[i]->Flags & ImGuiWindowFlags_ChildWindow)) + { + FocusWindow(g.Windows[i]); + return; + } +} + +void ImGui::PushItemWidth(float item_width) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ItemWidth = (item_width == 0.0f ? window->ItemWidthDefault : item_width); + window->DC.ItemWidthStack.push_back(window->DC.ItemWidth); +} + +void ImGui::PushMultiItemsWidths(int components, float w_full) +{ + ImGuiWindow* window = GetCurrentWindow(); + const ImGuiStyle& style = GImGui->Style; + if (w_full <= 0.0f) + w_full = CalcItemWidth(); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); + window->DC.ItemWidthStack.push_back(w_item_last); + for (int i = 0; i < components-1; i++) + window->DC.ItemWidthStack.push_back(w_item_one); + window->DC.ItemWidth = window->DC.ItemWidthStack.back(); +} + +void ImGui::PopItemWidth() +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ItemWidthStack.pop_back(); + window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back(); +} + +float ImGui::CalcItemWidth() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + float w = window->DC.ItemWidth; + if (w < 0.0f) + { + // Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well. + float width_to_right_edge = GetContentRegionAvail().x; + w = ImMax(1.0f, width_to_right_edge + w); + } + w = (float)(int)w; + return w; +} + +static ImFont* GetDefaultFont() +{ + ImGuiContext& g = *GImGui; + return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; +} + +static void SetCurrentFont(ImFont* font) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(font && font->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ? + IM_ASSERT(font->Scale > 0.0f); + g.Font = font; + g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale; + g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f; + + ImFontAtlas* atlas = g.Font->ContainerAtlas; + g.DrawListSharedData.TexUvWhitePixel = atlas->TexUvWhitePixel; + g.DrawListSharedData.Font = g.Font; + g.DrawListSharedData.FontSize = g.FontSize; +} + +void ImGui::PushFont(ImFont* font) +{ + ImGuiContext& g = *GImGui; + if (!font) + font = GetDefaultFont(); + SetCurrentFont(font); + g.FontStack.push_back(font); + g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID); +} + +void ImGui::PopFont() +{ + ImGuiContext& g = *GImGui; + g.CurrentWindow->DrawList->PopTextureID(); + g.FontStack.pop_back(); + SetCurrentFont(g.FontStack.empty() ? GetDefaultFont() : g.FontStack.back()); +} + +void ImGui::PushItemFlag(ImGuiItemFlags option, bool enabled) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (enabled) + window->DC.ItemFlags |= option; + else + window->DC.ItemFlags &= ~option; + window->DC.ItemFlagsStack.push_back(window->DC.ItemFlags); +} + +void ImGui::PopItemFlag() +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ItemFlagsStack.pop_back(); + window->DC.ItemFlags = window->DC.ItemFlagsStack.empty() ? ImGuiItemFlags_Default_ : window->DC.ItemFlagsStack.back(); +} + +void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus) +{ + PushItemFlag(ImGuiItemFlags_AllowKeyboardFocus, allow_keyboard_focus); +} + +void ImGui::PopAllowKeyboardFocus() +{ + PopItemFlag(); +} + +void ImGui::PushButtonRepeat(bool repeat) +{ + PushItemFlag(ImGuiItemFlags_ButtonRepeat, repeat); +} + +void ImGui::PopButtonRepeat() +{ + PopItemFlag(); +} + +void ImGui::PushTextWrapPos(float wrap_pos_x) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.TextWrapPos = wrap_pos_x; + window->DC.TextWrapPosStack.push_back(wrap_pos_x); +} + +void ImGui::PopTextWrapPos() +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.TextWrapPosStack.pop_back(); + window->DC.TextWrapPos = window->DC.TextWrapPosStack.empty() ? -1.0f : window->DC.TextWrapPosStack.back(); +} + +// FIXME: This may incur a round-trip (if the end user got their data from a float4) but eventually we aim to store the in-flight colors as ImU32 +void ImGui::PushStyleColor(ImGuiCol idx, ImU32 col) +{ + ImGuiContext& g = *GImGui; + ImGuiColMod backup; + backup.Col = idx; + backup.BackupValue = g.Style.Colors[idx]; + g.ColorModifiers.push_back(backup); + g.Style.Colors[idx] = ColorConvertU32ToFloat4(col); +} + +void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col) +{ + ImGuiContext& g = *GImGui; + ImGuiColMod backup; + backup.Col = idx; + backup.BackupValue = g.Style.Colors[idx]; + g.ColorModifiers.push_back(backup); + g.Style.Colors[idx] = col; +} + +void ImGui::PopStyleColor(int count) +{ + ImGuiContext& g = *GImGui; + while (count > 0) + { + ImGuiColMod& backup = g.ColorModifiers.back(); + g.Style.Colors[backup.Col] = backup.BackupValue; + g.ColorModifiers.pop_back(); + count--; + } +} + +struct ImGuiStyleVarInfo +{ + ImGuiDataType Type; + ImU32 Offset; + void* GetVarPtr(ImGuiStyle* style) const { return (void*)((unsigned char*)style + Offset); } +}; + +static const ImGuiStyleVarInfo GStyleVarInfo[ImGuiStyleVar_Count_] = +{ + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha + { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowPadding) }, // ImGuiStyleVar_WindowPadding + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowRounding) }, // ImGuiStyleVar_WindowRounding + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowBorderSize) }, // ImGuiStyleVar_WindowBorderSize + { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowMinSize) }, // ImGuiStyleVar_WindowMinSize + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildRounding) }, // ImGuiStyleVar_ChildRounding + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildBorderSize) }, // ImGuiStyleVar_ChildBorderSize + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupRounding) }, // ImGuiStyleVar_PopupRounding + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupBorderSize) }, // ImGuiStyleVar_PopupBorderSize + { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, FramePadding) }, // ImGuiStyleVar_FramePadding + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameRounding) }, // ImGuiStyleVar_FrameRounding + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameBorderSize) }, // ImGuiStyleVar_FrameBorderSize + { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemSpacing) }, // ImGuiStyleVar_ItemSpacing + { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemInnerSpacing) }, // ImGuiStyleVar_ItemInnerSpacing + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, IndentSpacing) }, // ImGuiStyleVar_IndentSpacing + { ImGuiDataType_Float, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize + { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign +}; + +static const ImGuiStyleVarInfo* GetStyleVarInfo(ImGuiStyleVar idx) +{ + IM_ASSERT(idx >= 0 && idx < ImGuiStyleVar_Count_); + return &GStyleVarInfo[idx]; +} + +void ImGui::PushStyleVar(ImGuiStyleVar idx, float val) +{ + const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); + if (var_info->Type == ImGuiDataType_Float) + { + ImGuiContext& g = *GImGui; + float* pvar = (float*)var_info->GetVarPtr(&g.Style); + g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); + *pvar = val; + return; + } + IM_ASSERT(0); // Called function with wrong-type? Variable is not a float. +} + +void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val) +{ + const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); + if (var_info->Type == ImGuiDataType_Float2) + { + ImGuiContext& g = *GImGui; + ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(&g.Style); + g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); + *pvar = val; + return; + } + IM_ASSERT(0); // Called function with wrong-type? Variable is not a ImVec2. +} + +void ImGui::PopStyleVar(int count) +{ + ImGuiContext& g = *GImGui; + while (count > 0) + { + ImGuiStyleMod& backup = g.StyleModifiers.back(); + const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx); + if (info->Type == ImGuiDataType_Float) (*(float*)info->GetVarPtr(&g.Style)) = backup.BackupFloat[0]; + else if (info->Type == ImGuiDataType_Float2) (*(ImVec2*)info->GetVarPtr(&g.Style)) = ImVec2(backup.BackupFloat[0], backup.BackupFloat[1]); + else if (info->Type == ImGuiDataType_Int) (*(int*)info->GetVarPtr(&g.Style)) = backup.BackupInt[0]; + g.StyleModifiers.pop_back(); + count--; + } +} + +const char* ImGui::GetStyleColorName(ImGuiCol idx) +{ + // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1"; + switch (idx) + { + case ImGuiCol_Text: return "Text"; + case ImGuiCol_TextDisabled: return "TextDisabled"; + case ImGuiCol_WindowBg: return "WindowBg"; + case ImGuiCol_ChildBg: return "ChildBg"; + case ImGuiCol_PopupBg: return "PopupBg"; + case ImGuiCol_Border: return "Border"; + case ImGuiCol_BorderShadow: return "BorderShadow"; + case ImGuiCol_FrameBg: return "FrameBg"; + case ImGuiCol_FrameBgHovered: return "FrameBgHovered"; + case ImGuiCol_FrameBgActive: return "FrameBgActive"; + case ImGuiCol_TitleBg: return "TitleBg"; + case ImGuiCol_TitleBgActive: return "TitleBgActive"; + case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed"; + case ImGuiCol_MenuBarBg: return "MenuBarBg"; + case ImGuiCol_ScrollbarBg: return "ScrollbarBg"; + case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab"; + case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; + case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; + case ImGuiCol_CheckMark: return "CheckMark"; + case ImGuiCol_SliderGrab: return "SliderGrab"; + case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; + case ImGuiCol_Button: return "Button"; + case ImGuiCol_ButtonHovered: return "ButtonHovered"; + case ImGuiCol_ButtonActive: return "ButtonActive"; + case ImGuiCol_Header: return "Header"; + case ImGuiCol_HeaderHovered: return "HeaderHovered"; + case ImGuiCol_HeaderActive: return "HeaderActive"; + case ImGuiCol_Separator: return "Separator"; + case ImGuiCol_SeparatorHovered: return "SeparatorHovered"; + case ImGuiCol_SeparatorActive: return "SeparatorActive"; + case ImGuiCol_ResizeGrip: return "ResizeGrip"; + case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered"; + case ImGuiCol_ResizeGripActive: return "ResizeGripActive"; + case ImGuiCol_CloseButton: return "CloseButton"; + case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered"; + case ImGuiCol_CloseButtonActive: return "CloseButtonActive"; + case ImGuiCol_PlotLines: return "PlotLines"; + case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; + case ImGuiCol_PlotHistogram: return "PlotHistogram"; + case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered"; + case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; + case ImGuiCol_ModalWindowDarkening: return "ModalWindowDarkening"; + case ImGuiCol_DragDropTarget: return "DragDropTarget"; + } + IM_ASSERT(0); + return "Unknown"; +} + +bool ImGui::IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent) +{ + if (window->RootWindow == potential_parent) + return true; + while (window != NULL) + { + if (window == potential_parent) + return true; + window = window->ParentWindow; + } + return false; +} + +bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags) +{ + IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function + ImGuiContext& g = *GImGui; + switch (flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows)) + { + case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows: + if (g.HoveredRootWindow != g.CurrentWindow->RootWindow) + return false; + break; + case ImGuiHoveredFlags_RootWindow: + if (g.HoveredWindow != g.CurrentWindow->RootWindow) + return false; + break; + case ImGuiHoveredFlags_ChildWindows: + if (g.HoveredWindow == NULL || !IsWindowChildOf(g.HoveredWindow, g.CurrentWindow)) + return false; + break; + default: + if (g.HoveredWindow != g.CurrentWindow) + return false; + break; + } + + if (!IsWindowContentHoverable(g.HoveredRootWindow, flags)) + return false; + if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + if (g.ActiveId != 0 && !g.ActiveIdAllowOverlap && g.ActiveId != g.HoveredWindow->MoveId) + return false; + return true; +} + +bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.CurrentWindow); // Not inside a Begin()/End() + + switch (flags & (ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows)) + { + case ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows: + return g.NavWindow && g.CurrentWindow->RootWindow == g.NavWindow->RootWindow; + case ImGuiFocusedFlags_RootWindow: + return g.CurrentWindow->RootWindow == g.NavWindow; + case ImGuiFocusedFlags_ChildWindows: + return g.NavWindow && IsWindowChildOf(g.NavWindow, g.CurrentWindow); + default: + return g.CurrentWindow == g.NavWindow; + } +} + +float ImGui::GetWindowWidth() +{ + ImGuiWindow* window = GImGui->CurrentWindow; + return window->Size.x; +} + +float ImGui::GetWindowHeight() +{ + ImGuiWindow* window = GImGui->CurrentWindow; + return window->Size.y; +} + +ImVec2 ImGui::GetWindowPos() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + return window->Pos; +} + +static void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y) +{ + window->DC.CursorMaxPos.y += window->Scroll.y; // SizeContents is generally computed based on CursorMaxPos which is affected by scroll position, so we need to apply our change to it. + window->Scroll.y = new_scroll_y; + window->DC.CursorMaxPos.y -= window->Scroll.y; +} + +static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond) +{ + // Test condition (NB: bit 0 is always true) and clear flags for next time + if (cond && (window->SetWindowPosAllowFlags & cond) == 0) + return; + window->SetWindowPosAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); + window->SetWindowPosVal = ImVec2(FLT_MAX, FLT_MAX); + + // Set + const ImVec2 old_pos = window->Pos; + window->PosFloat = pos; + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor + window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected. +} + +void ImGui::SetWindowPos(const ImVec2& pos, ImGuiCond cond) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + SetWindowPos(window, pos, cond); +} + +void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiCond cond) +{ + if (ImGuiWindow* window = FindWindowByName(name)) + SetWindowPos(window, pos, cond); +} + +ImVec2 ImGui::GetWindowSize() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->Size; +} + +static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond) +{ + // Test condition (NB: bit 0 is always true) and clear flags for next time + if (cond && (window->SetWindowSizeAllowFlags & cond) == 0) + return; + window->SetWindowSizeAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); + + // Set + if (size.x > 0.0f) + { + window->AutoFitFramesX = 0; + window->SizeFull.x = size.x; + } + else + { + window->AutoFitFramesX = 2; + window->AutoFitOnlyGrows = false; + } + if (size.y > 0.0f) + { + window->AutoFitFramesY = 0; + window->SizeFull.y = size.y; + } + else + { + window->AutoFitFramesY = 2; + window->AutoFitOnlyGrows = false; + } +} + +void ImGui::SetWindowSize(const ImVec2& size, ImGuiCond cond) +{ + SetWindowSize(GImGui->CurrentWindow, size, cond); +} + +void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiCond cond) +{ + if (ImGuiWindow* window = FindWindowByName(name)) + SetWindowSize(window, size, cond); +} + +static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond) +{ + // Test condition (NB: bit 0 is always true) and clear flags for next time + if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0) + return; + window->SetWindowCollapsedAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); + + // Set + window->Collapsed = collapsed; +} + +void ImGui::SetWindowCollapsed(bool collapsed, ImGuiCond cond) +{ + SetWindowCollapsed(GImGui->CurrentWindow, collapsed, cond); +} + +bool ImGui::IsWindowCollapsed() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->Collapsed; +} + +bool ImGui::IsWindowAppearing() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->Appearing; +} + +void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond) +{ + if (ImGuiWindow* window = FindWindowByName(name)) + SetWindowCollapsed(window, collapsed, cond); +} + +void ImGui::SetWindowFocus() +{ + FocusWindow(GImGui->CurrentWindow); +} + +void ImGui::SetWindowFocus(const char* name) +{ + if (name) + { + if (ImGuiWindow* window = FindWindowByName(name)) + FocusWindow(window); + } + else + { + FocusWindow(NULL); + } +} + +void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pivot) +{ + ImGuiContext& g = *GImGui; + g.SetNextWindowPosVal = pos; + g.SetNextWindowPosPivot = pivot; + g.SetNextWindowPosCond = cond ? cond : ImGuiCond_Always; +} + +void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond) +{ + ImGuiContext& g = *GImGui; + g.SetNextWindowSizeVal = size; + g.SetNextWindowSizeCond = cond ? cond : ImGuiCond_Always; +} + +void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data) +{ + ImGuiContext& g = *GImGui; + g.SetNextWindowSizeConstraint = true; + g.SetNextWindowSizeConstraintRect = ImRect(size_min, size_max); + g.SetNextWindowSizeConstraintCallback = custom_callback; + g.SetNextWindowSizeConstraintCallbackUserData = custom_callback_user_data; +} + +void ImGui::SetNextWindowContentSize(const ImVec2& size) +{ + ImGuiContext& g = *GImGui; + g.SetNextWindowContentSizeVal = size; // In Begin() we will add the size of window decorations (title bar, menu etc.) to that to form a SizeContents value. + g.SetNextWindowContentSizeCond = ImGuiCond_Always; +} + +void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond) +{ + ImGuiContext& g = *GImGui; + g.SetNextWindowCollapsedVal = collapsed; + g.SetNextWindowCollapsedCond = cond ? cond : ImGuiCond_Always; +} + +void ImGui::SetNextWindowFocus() +{ + ImGuiContext& g = *GImGui; + g.SetNextWindowFocus = true; +} + +// In window space (not screen space!) +ImVec2 ImGui::GetContentRegionMax() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + ImVec2 mx = window->ContentsRegionRect.Max; + if (window->DC.ColumnsSet) + mx.x = GetColumnOffset(window->DC.ColumnsSet->Current + 1) - window->WindowPadding.x; + return mx; +} + +ImVec2 ImGui::GetContentRegionAvail() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return GetContentRegionMax() - (window->DC.CursorPos - window->Pos); +} + +float ImGui::GetContentRegionAvailWidth() +{ + return GetContentRegionAvail().x; +} + +// In window space (not screen space!) +ImVec2 ImGui::GetWindowContentRegionMin() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->ContentsRegionRect.Min; +} + +ImVec2 ImGui::GetWindowContentRegionMax() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->ContentsRegionRect.Max; +} + +float ImGui::GetWindowContentRegionWidth() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->ContentsRegionRect.Max.x - window->ContentsRegionRect.Min.x; +} + +float ImGui::GetTextLineHeight() +{ + ImGuiContext& g = *GImGui; + return g.FontSize; +} + +float ImGui::GetTextLineHeightWithSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + g.Style.ItemSpacing.y; +} + +float ImGui::GetFrameHeight() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + g.Style.FramePadding.y * 2.0f; +} + +float ImGui::GetFrameHeightWithSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y; +} + +ImDrawList* ImGui::GetWindowDrawList() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DrawList; +} + +ImFont* ImGui::GetFont() +{ + return GImGui->Font; +} + +float ImGui::GetFontSize() +{ + return GImGui->FontSize; +} + +ImVec2 ImGui::GetFontTexUvWhitePixel() +{ + return GImGui->DrawListSharedData.TexUvWhitePixel; +} + +void ImGui::SetWindowFontScale(float scale) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->FontWindowScale = scale; + g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); +} + +// User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient. +// Conversion happens as we pass the value to user, but it makes our naming convention confusing because GetCursorPos() == (DC.CursorPos - window.Pos). May want to rename 'DC.CursorPos'. +ImVec2 ImGui::GetCursorPos() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos - window->Pos + window->Scroll; +} + +float ImGui::GetCursorPosX() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos.x - window->Pos.x + window->Scroll.x; +} + +float ImGui::GetCursorPosY() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos.y - window->Pos.y + window->Scroll.y; +} + +void ImGui::SetCursorPos(const ImVec2& local_pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = window->Pos - window->Scroll + local_pos; + window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); +} + +void ImGui::SetCursorPosX(float x) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + x; + window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x); +} + +void ImGui::SetCursorPosY(float y) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos.y = window->Pos.y - window->Scroll.y + y; + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); +} + +ImVec2 ImGui::GetCursorStartPos() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorStartPos - window->Pos; +} + +ImVec2 ImGui::GetCursorScreenPos() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos; +} + +void ImGui::SetCursorScreenPos(const ImVec2& screen_pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = screen_pos; + window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); +} + +float ImGui::GetScrollX() +{ + return GImGui->CurrentWindow->Scroll.x; +} + +float ImGui::GetScrollY() +{ + return GImGui->CurrentWindow->Scroll.y; +} + +float ImGui::GetScrollMaxX() +{ + return GetScrollMaxX(GImGui->CurrentWindow); +} + +float ImGui::GetScrollMaxY() +{ + return GetScrollMaxY(GImGui->CurrentWindow); +} + +void ImGui::SetScrollX(float scroll_x) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->ScrollTarget.x = scroll_x; + window->ScrollTargetCenterRatio.x = 0.0f; +} + +void ImGui::SetScrollY(float scroll_y) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->ScrollTarget.y = scroll_y + window->TitleBarHeight() + window->MenuBarHeight(); // title bar height canceled out when using ScrollTargetRelY + window->ScrollTargetCenterRatio.y = 0.0f; +} + +void ImGui::SetScrollFromPosY(float pos_y, float center_y_ratio) +{ + // We store a target position so centering can occur on the next frame when we are guaranteed to have a known window size + ImGuiWindow* window = GetCurrentWindow(); + IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f); + window->ScrollTarget.y = (float)(int)(pos_y + window->Scroll.y); + window->ScrollTargetCenterRatio.y = center_y_ratio; + + // Minor hack to to make scrolling to top/bottom of window take account of WindowPadding, it looks more right to the user this way + if (center_y_ratio <= 0.0f && window->ScrollTarget.y <= window->WindowPadding.y) + window->ScrollTarget.y = 0.0f; + else if (center_y_ratio >= 1.0f && window->ScrollTarget.y >= window->SizeContents.y - window->WindowPadding.y + GImGui->Style.ItemSpacing.y) + window->ScrollTarget.y = window->SizeContents.y; +} + +// center_y_ratio: 0.0f top of last item, 0.5f vertical center of last item, 1.0f bottom of last item. +void ImGui::SetScrollHere(float center_y_ratio) +{ + ImGuiWindow* window = GetCurrentWindow(); + float target_y = window->DC.CursorPosPrevLine.y - window->Pos.y; // Top of last item, in window space + target_y += (window->DC.PrevLineHeight * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line. + SetScrollFromPosY(target_y, center_y_ratio); +} + +// FIXME-NAV: This function is a placeholder for the upcoming Navigation branch + Focusing features. +// In the current branch this function will only set the scrolling, in the navigation branch it will also set your navigation cursor. +// Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHere()" when applicable. +void ImGui::SetItemDefaultFocus() +{ + if (IsWindowAppearing()) + SetScrollHere(); +} + +void ImGui::SetKeyboardFocusHere(int offset) +{ + IM_ASSERT(offset >= -1); // -1 is allowed but not below + ImGuiWindow* window = GetCurrentWindow(); + window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset; + window->FocusIdxTabRequestNext = INT_MAX; +} + +void ImGui::SetStateStorage(ImGuiStorage* tree) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.StateStorage = tree ? tree : &window->StateStorage; +} + +ImGuiStorage* ImGui::GetStateStorage() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.StateStorage; +} + +void ImGui::TextV(const char* fmt, va_list args) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + TextUnformatted(g.TempBuffer, text_end); +} + +void ImGui::Text(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + TextV(fmt, args); + va_end(args); +} + +void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args) +{ + PushStyleColor(ImGuiCol_Text, col); + TextV(fmt, args); + PopStyleColor(); +} + +void ImGui::TextColored(const ImVec4& col, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + TextColoredV(col, fmt, args); + va_end(args); +} + +void ImGui::TextDisabledV(const char* fmt, va_list args) +{ + PushStyleColor(ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled]); + TextV(fmt, args); + PopStyleColor(); +} + +void ImGui::TextDisabled(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + TextDisabledV(fmt, args); + va_end(args); +} + +void ImGui::TextWrappedV(const char* fmt, va_list args) +{ + bool need_wrap = (GImGui->CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position is one ia already set + if (need_wrap) PushTextWrapPos(0.0f); + TextV(fmt, args); + if (need_wrap) PopTextWrapPos(); +} + +void ImGui::TextWrapped(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + TextWrappedV(fmt, args); + va_end(args); +} + +void ImGui::TextUnformatted(const char* text, const char* text_end) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + IM_ASSERT(text != NULL); + const char* text_begin = text; + if (text_end == NULL) + text_end = text + strlen(text); // FIXME-OPT + + const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrentLineTextBaseOffset); + const float wrap_pos_x = window->DC.TextWrapPos; + const bool wrap_enabled = wrap_pos_x >= 0.0f; + if (text_end - text > 2000 && !wrap_enabled) + { + // Long text! + // Perform manual coarse clipping to optimize for long multi-line text + // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled. + // We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line. + const char* line = text; + const float line_height = GetTextLineHeight(); + const ImRect clip_rect = window->ClipRect; + ImVec2 text_size(0,0); + + if (text_pos.y <= clip_rect.Max.y) + { + ImVec2 pos = text_pos; + + // Lines to skip (can't skip when logging text) + if (!g.LogEnabled) + { + int lines_skippable = (int)((clip_rect.Min.y - text_pos.y) / line_height); + if (lines_skippable > 0) + { + int lines_skipped = 0; + while (line < text_end && lines_skipped < lines_skippable) + { + const char* line_end = strchr(line, '\n'); + if (!line_end) + line_end = text_end; + line = line_end + 1; + lines_skipped++; + } + pos.y += lines_skipped * line_height; + } + } + + // Lines to render + if (line < text_end) + { + ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height)); + while (line < text_end) + { + const char* line_end = strchr(line, '\n'); + if (IsClippedEx(line_rect, 0, false)) + break; + + const ImVec2 line_size = CalcTextSize(line, line_end, false); + text_size.x = ImMax(text_size.x, line_size.x); + RenderText(pos, line, line_end, false); + if (!line_end) + line_end = text_end; + line = line_end + 1; + line_rect.Min.y += line_height; + line_rect.Max.y += line_height; + pos.y += line_height; + } + + // Count remaining lines + int lines_skipped = 0; + while (line < text_end) + { + const char* line_end = strchr(line, '\n'); + if (!line_end) + line_end = text_end; + line = line_end + 1; + lines_skipped++; + } + pos.y += lines_skipped * line_height; + } + + text_size.y += (pos - text_pos).y; + } + + ImRect bb(text_pos, text_pos + text_size); + ItemSize(bb); + ItemAdd(bb, 0); + } + else + { + const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f; + const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width); + + // Account of baseline offset + ImRect bb(text_pos, text_pos + text_size); + ItemSize(text_size); + if (!ItemAdd(bb, 0)) + return; + + // Render (we don't hide text after ## in this end-user function) + RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width); + } +} + +void ImGui::AlignTextToFramePadding() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + window->DC.CurrentLineHeight = ImMax(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y * 2); + window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); +} + +// Add a label+text combo aligned to other label+value widgets +void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const float w = CalcItemWidth(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2)); + const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, 0)) + return; + + // Render + const char* value_text_begin = &g.TempBuffer[0]; + const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + RenderTextClipped(value_bb.Min, value_bb.Max, value_text_begin, value_text_end, NULL, ImVec2(0.0f,0.5f)); + if (label_size.x > 0.0f) + RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y + style.FramePadding.y), label); +} + +void ImGui::LabelText(const char* label, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + LabelTextV(label, fmt, args); + va_end(args); +} + +bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + + if (flags & ImGuiButtonFlags_Disabled) + { + if (out_hovered) *out_hovered = false; + if (out_held) *out_held = false; + if (g.ActiveId == id) ClearActiveID(); + return false; + } + + // Default behavior requires click+release on same spot + if ((flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick)) == 0) + flags |= ImGuiButtonFlags_PressedOnClickRelease; + + ImGuiWindow* backup_hovered_window = g.HoveredWindow; + if ((flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredRootWindow == window) + g.HoveredWindow = window; + + bool pressed = false; + bool hovered = ItemHoverable(bb, id); + + // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button + if ((flags & ImGuiButtonFlags_PressedOnDragDropHold) && g.DragDropActive && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) + if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + { + hovered = true; + SetHoveredID(id); + if (CalcTypematicPressedRepeatAmount(g.HoveredIdTimer + 0.0001f, g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, 0.01f, 0.70f)) // FIXME: Our formula for CalcTypematicPressedRepeatAmount() is fishy + { + pressed = true; + FocusWindow(window); + } + } + + if ((flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredRootWindow == window) + g.HoveredWindow = backup_hovered_window; + + // AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one. + if (hovered && (flags & ImGuiButtonFlags_AllowItemOverlap) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0)) + hovered = false; + + if (hovered) + { + if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) + { + // | CLICKING | HOLDING with ImGuiButtonFlags_Repeat + // PressedOnClickRelease | * | .. (NOT on release) <-- MOST COMMON! (*) only if both click/release were over bounds + // PressedOnClick | | .. + // PressedOnRelease | | .. (NOT on release) + // PressedOnDoubleClick | | .. + if ((flags & ImGuiButtonFlags_PressedOnClickRelease) && g.IO.MouseClicked[0]) + { + SetActiveID(id, window); // Hold on ID + FocusWindow(window); + g.ActiveIdClickOffset = g.IO.MousePos - bb.Min; + } + if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) + { + pressed = true; + if (flags & ImGuiButtonFlags_NoHoldingActiveID) + { + ClearActiveID(); + } + else + { + SetActiveID(id, window); // Hold on ID + g.ActiveIdClickOffset = g.IO.MousePos - bb.Min; + } + FocusWindow(window); + } + if ((flags & ImGuiButtonFlags_PressedOnRelease) && g.IO.MouseReleased[0]) + { + if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps + pressed = true; + ClearActiveID(); + } + + // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). + // Relies on repeat logic of IsMouseClicked() but we may as well do it ourselves if we end up exposing finer RepeatDelay/RepeatRate settings. + if ((flags & ImGuiButtonFlags_Repeat) && g.ActiveId == id && g.IO.MouseDownDuration[0] > 0.0f && IsMouseClicked(0, true)) + pressed = true; + } + } + + bool held = false; + if (g.ActiveId == id) + { + if (g.IO.MouseDown[0]) + { + held = true; + } + else + { + if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease)) + if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps + if (!g.DragDropActive) + pressed = true; + ClearActiveID(); + } + } + + if (out_hovered) *out_hovered = hovered; + if (out_held) *out_held = held; + + return pressed; +} + +bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + ImVec2 pos = window->DC.CursorPos; + if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrentLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag) + pos.y += window->DC.CurrentLineTextBaseOffset - style.FramePadding.y; + ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f); + + const ImRect bb(pos, pos + size); + ItemSize(bb, style.FramePadding.y); + if (!ItemAdd(bb, id)) + return false; + + if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat) flags |= ImGuiButtonFlags_Repeat; + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); + + // Render + const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); + RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb); + + // Automatically close popups + //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup)) + // CloseCurrentPopup(); + + return pressed; +} + +bool ImGui::Button(const char* label, const ImVec2& size_arg) +{ + return ButtonEx(label, size_arg, 0); +} + +// Small buttons fits within text without additional vertical spacing. +bool ImGui::SmallButton(const char* label) +{ + ImGuiContext& g = *GImGui; + float backup_padding_y = g.Style.FramePadding.y; + g.Style.FramePadding.y = 0.0f; + bool pressed = ButtonEx(label, ImVec2(0,0), ImGuiButtonFlags_AlignTextBaseLine); + g.Style.FramePadding.y = backup_padding_y; + return pressed; +} + +// Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack. +// Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id) +bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiID id = window->GetID(str_id); + ImVec2 size = CalcItemSize(size_arg, 0.0f, 0.0f); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + ItemSize(bb); + if (!ItemAdd(bb, id)) + return false; + + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held); + + return pressed; +} + +// Upper-right button to close a window. +bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos, float radius) +{ + ImGuiWindow* window = GetCurrentWindow(); + + const ImRect bb(pos - ImVec2(radius,radius), pos + ImVec2(radius,radius)); + + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held); + + // Render + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); + const ImVec2 center = bb.GetCenter(); + window->DrawList->AddCircleFilled(center, ImMax(2.0f, radius), col, 12); + + const float cross_extent = (radius * 0.7071f) - 1.0f; + if (hovered) + { + window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), GetColorU32(ImGuiCol_Text)); + window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), GetColorU32(ImGuiCol_Text)); + } + + return pressed; +} + +// [Internal] +bool ImGui::ArrowButton(ImGuiID id, ImGuiDir dir, ImVec2 padding, ImGuiButtonFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize + padding.x * 2.0f, g.FontSize + padding.y * 2.0f)); + ItemSize(bb, style.FramePadding.y); + if (!ItemAdd(bb, id)) + return false; + + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); + + const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); +#ifdef IMGUI_HAS_NAV + RenderNavHighlight(bb, id); +#endif + RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); + RenderTriangle(bb.Min + padding, dir, 1.0f); + + return pressed; +} + +void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + if (border_col.w > 0.0f) + bb.Max += ImVec2(2,2); + ItemSize(bb); + if (!ItemAdd(bb, 0)) + return; + + if (border_col.w > 0.0f) + { + window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(border_col), 0.0f); + window->DrawList->AddImage(user_texture_id, bb.Min+ImVec2(1,1), bb.Max-ImVec2(1,1), uv0, uv1, GetColorU32(tint_col)); + } + else + { + window->DrawList->AddImage(user_texture_id, bb.Min, bb.Max, uv0, uv1, GetColorU32(tint_col)); + } +} + +// frame_padding < 0: uses FramePadding from style (default) +// frame_padding = 0: no framing +// frame_padding > 0: set framing size +// The color used are the button colors. +bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + // Default to using texture ID as ID. User can still push string/integer prefixes. + // We could hash the size/uv to create a unique ID but that would prevent the user from animating UV. + PushID((void *)user_texture_id); + const ImGuiID id = window->GetID("#image"); + PopID(); + + const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding; + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2); + const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size); + ItemSize(bb); + if (!ItemAdd(bb, id)) + return false; + + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held); + + // Render + const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, style.FrameRounding)); + if (bg_col.w > 0.0f) + window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, GetColorU32(bg_col)); + window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1, GetColorU32(tint_col)); + + return pressed; +} + +// Start logging ImGui output to TTY +void ImGui::LogToTTY(int max_depth) +{ + ImGuiContext& g = *GImGui; + if (g.LogEnabled) + return; + ImGuiWindow* window = g.CurrentWindow; + + g.LogEnabled = true; + g.LogFile = stdout; + g.LogStartDepth = window->DC.TreeDepth; + if (max_depth >= 0) + g.LogAutoExpandMaxDepth = max_depth; +} + +// Start logging ImGui output to given file +void ImGui::LogToFile(int max_depth, const char* filename) +{ + ImGuiContext& g = *GImGui; + if (g.LogEnabled) + return; + ImGuiWindow* window = g.CurrentWindow; + + if (!filename) + { + filename = g.IO.LogFilename; + if (!filename) + return; + } + + g.LogFile = ImFileOpen(filename, "ab"); + if (!g.LogFile) + { + IM_ASSERT(g.LogFile != NULL); // Consider this an error + return; + } + g.LogEnabled = true; + g.LogStartDepth = window->DC.TreeDepth; + if (max_depth >= 0) + g.LogAutoExpandMaxDepth = max_depth; +} + +// Start logging ImGui output to clipboard +void ImGui::LogToClipboard(int max_depth) +{ + ImGuiContext& g = *GImGui; + if (g.LogEnabled) + return; + ImGuiWindow* window = g.CurrentWindow; + + g.LogEnabled = true; + g.LogFile = NULL; + g.LogStartDepth = window->DC.TreeDepth; + if (max_depth >= 0) + g.LogAutoExpandMaxDepth = max_depth; +} + +void ImGui::LogFinish() +{ + ImGuiContext& g = *GImGui; + if (!g.LogEnabled) + return; + + LogText(IM_NEWLINE); + g.LogEnabled = false; + if (g.LogFile != NULL) + { + if (g.LogFile == stdout) + fflush(g.LogFile); + else + fclose(g.LogFile); + g.LogFile = NULL; + } + if (g.LogClipboard->size() > 1) + { + SetClipboardText(g.LogClipboard->begin()); + g.LogClipboard->clear(); + } +} + +// Helper to display logging buttons +void ImGui::LogButtons() +{ + ImGuiContext& g = *GImGui; + + PushID("LogButtons"); + const bool log_to_tty = Button("Log To TTY"); SameLine(); + const bool log_to_file = Button("Log To File"); SameLine(); + const bool log_to_clipboard = Button("Log To Clipboard"); SameLine(); + PushItemWidth(80.0f); + PushAllowKeyboardFocus(false); + SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL); + PopAllowKeyboardFocus(); + PopItemWidth(); + PopID(); + + // Start logging at the end of the function so that the buttons don't appear in the log + if (log_to_tty) + LogToTTY(g.LogAutoExpandMaxDepth); + if (log_to_file) + LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename); + if (log_to_clipboard) + LogToClipboard(g.LogAutoExpandMaxDepth); +} + +bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) +{ + if (flags & ImGuiTreeNodeFlags_Leaf) + return true; + + // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions) + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiStorage* storage = window->DC.StateStorage; + + bool is_open; + if (g.SetNextTreeNodeOpenCond != 0) + { + if (g.SetNextTreeNodeOpenCond & ImGuiCond_Always) + { + is_open = g.SetNextTreeNodeOpenVal; + storage->SetInt(id, is_open); + } + else + { + // We treat ImGuiCond_Once and ImGuiCond_FirstUseEver the same because tree node state are not saved persistently. + const int stored_value = storage->GetInt(id, -1); + if (stored_value == -1) + { + is_open = g.SetNextTreeNodeOpenVal; + storage->SetInt(id, is_open); + } + else + { + is_open = stored_value != 0; + } + } + g.SetNextTreeNodeOpenCond = 0; + } + else + { + is_open = storage->GetInt(id, (flags & ImGuiTreeNodeFlags_DefaultOpen) ? 1 : 0) != 0; + } + + // When logging is enabled, we automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior). + // NB- If we are above max depth we still allow manually opened nodes to be logged. + if (g.LogEnabled && !(flags & ImGuiTreeNodeFlags_NoAutoOpenOnLog) && window->DC.TreeDepth < g.LogAutoExpandMaxDepth) + is_open = true; + + return is_open; +} + +bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const bool display_frame = (flags & ImGuiTreeNodeFlags_Framed) != 0; + const ImVec2 padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding)) ? style.FramePadding : ImVec2(style.FramePadding.x, 0.0f); + + if (!label_end) + label_end = FindRenderedTextEnd(label); + const ImVec2 label_size = CalcTextSize(label, label_end, false); + + // We vertically grow up to current line height up the typical widget height. + const float text_base_offset_y = ImMax(padding.y, window->DC.CurrentLineTextBaseOffset); // Latch before ItemSize changes it + const float frame_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + style.FramePadding.y*2), label_size.y + padding.y*2); + ImRect bb = ImRect(window->DC.CursorPos, ImVec2(window->Pos.x + GetContentRegionMax().x, window->DC.CursorPos.y + frame_height)); + if (display_frame) + { + // Framed header expand a little outside the default padding + bb.Min.x -= (float)(int)(window->WindowPadding.x*0.5f) - 1; + bb.Max.x += (float)(int)(window->WindowPadding.x*0.5f) - 1; + } + + const float text_offset_x = (g.FontSize + (display_frame ? padding.x*3 : padding.x*2)); // Collapser arrow width + Spacing + const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x*2 : 0.0f); // Include collapser + ItemSize(ImVec2(text_width, frame_height), text_base_offset_y); + + // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing + // (Ideally we'd want to add a flag for the user to specify if we want the hit test to be done up to the right side of the content or not) + const ImRect interact_bb = display_frame ? bb : ImRect(bb.Min.x, bb.Min.y, bb.Min.x + text_width + style.ItemSpacing.x*2, bb.Max.y); + bool is_open = TreeNodeBehaviorIsOpen(id, flags); + if (!ItemAdd(interact_bb, id)) + { + if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) + TreePushRawID(id); + return is_open; + } + + // Flags that affects opening behavior: + // - 0(default) ..................... single-click anywhere to open + // - OpenOnDoubleClick .............. double-click anywhere to open + // - OpenOnArrow .................... single-click on arrow to open + // - OpenOnDoubleClick|OpenOnArrow .. single-click on arrow or double-click anywhere to open + ImGuiButtonFlags button_flags = ImGuiButtonFlags_NoKeyModifiers | ((flags & ImGuiTreeNodeFlags_AllowItemOverlap) ? ImGuiButtonFlags_AllowItemOverlap : 0); + button_flags |= ImGuiButtonFlags_PressedOnDragDropHold; + if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) + button_flags |= ImGuiButtonFlags_PressedOnDoubleClick | ((flags & ImGuiTreeNodeFlags_OpenOnArrow) ? ImGuiButtonFlags_PressedOnClickRelease : 0); + + bool hovered, held, pressed = ButtonBehavior(interact_bb, id, &hovered, &held, button_flags); + if (pressed && !(flags & ImGuiTreeNodeFlags_Leaf)) + { + bool toggled = !(flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)); + if (flags & ImGuiTreeNodeFlags_OpenOnArrow) + toggled |= IsMouseHoveringRect(interact_bb.Min, ImVec2(interact_bb.Min.x + text_offset_x, interact_bb.Max.y)); + if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) + toggled |= g.IO.MouseDoubleClicked[0]; + if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. + toggled = false; + if (toggled) + { + is_open = !is_open; + window->DC.StateStorage->SetInt(id, is_open); + } + } + if (flags & ImGuiTreeNodeFlags_AllowItemOverlap) + SetItemAllowOverlap(); + + // Render + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); + const ImVec2 text_pos = bb.Min + ImVec2(text_offset_x, text_base_offset_y); + if (display_frame) + { + // Framed type + RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); + RenderTriangle(bb.Min + ImVec2(padding.x, text_base_offset_y), is_open ? ImGuiDir_Down : ImGuiDir_Right, 1.0f); + if (g.LogEnabled) + { + // NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here. + const char log_prefix[] = "\n##"; + const char log_suffix[] = "##"; + LogRenderedText(&text_pos, log_prefix, log_prefix+3); + RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size); + LogRenderedText(&text_pos, log_suffix+1, log_suffix+3); + } + else + { + RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size); + } + } + else + { + // Unframed typed for tree nodes + if (hovered || (flags & ImGuiTreeNodeFlags_Selected)) + RenderFrame(bb.Min, bb.Max, col, false); + + if (flags & ImGuiTreeNodeFlags_Bullet) + RenderBullet(bb.Min + ImVec2(text_offset_x * 0.5f, g.FontSize*0.50f + text_base_offset_y)); + else if (!(flags & ImGuiTreeNodeFlags_Leaf)) + RenderTriangle(bb.Min + ImVec2(padding.x, g.FontSize*0.15f + text_base_offset_y), is_open ? ImGuiDir_Down : ImGuiDir_Right, 0.70f); + if (g.LogEnabled) + LogRenderedText(&text_pos, ">"); + RenderText(text_pos, label, label_end, false); + } + + if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) + TreePushRawID(id); + return is_open; +} + +// CollapsingHeader returns true when opened but do not indent nor push into the ID stack (because of the ImGuiTreeNodeFlags_NoTreePushOnOpen flag). +// This is basically the same as calling TreeNodeEx(label, ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_NoTreePushOnOpen). You can remove the _NoTreePushOnOpen flag if you want behavior closer to normal TreeNode(). +bool ImGui::CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + return TreeNodeBehavior(window->GetID(label), flags | ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_NoTreePushOnOpen, label); +} + +bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + if (p_open && !*p_open) + return false; + + ImGuiID id = window->GetID(label); + bool is_open = TreeNodeBehavior(id, flags | ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_NoTreePushOnOpen | (p_open ? ImGuiTreeNodeFlags_AllowItemOverlap : 0), label); + if (p_open) + { + // Create a small overlapping close button // FIXME: We can evolve this into user accessible helpers to add extra buttons on title bars, headers, etc. + ImGuiContext& g = *GImGui; + float button_sz = g.FontSize * 0.5f; + ImGuiItemHoveredDataBackup last_item_backup; + if (CloseButton(window->GetID((void*)(intptr_t)(id+1)), ImVec2(ImMin(window->DC.LastItemRect.Max.x, window->ClipRect.Max.x) - g.Style.FramePadding.x - button_sz, window->DC.LastItemRect.Min.y + g.Style.FramePadding.y + button_sz), button_sz)) + *p_open = false; + last_item_backup.Restore(); + } + + return is_open; +} + +bool ImGui::TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + return TreeNodeBehavior(window->GetID(label), flags, label, NULL); +} + +bool ImGui::TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const char* label_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + return TreeNodeBehavior(window->GetID(str_id), flags, g.TempBuffer, label_end); +} + +bool ImGui::TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const char* label_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + return TreeNodeBehavior(window->GetID(ptr_id), flags, g.TempBuffer, label_end); +} + +bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args) +{ + return TreeNodeExV(str_id, 0, fmt, args); +} + +bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args) +{ + return TreeNodeExV(ptr_id, 0, fmt, args); +} + +bool ImGui::TreeNodeEx(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool is_open = TreeNodeExV(str_id, flags, fmt, args); + va_end(args); + return is_open; +} + +bool ImGui::TreeNodeEx(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool is_open = TreeNodeExV(ptr_id, flags, fmt, args); + va_end(args); + return is_open; +} + +bool ImGui::TreeNode(const char* str_id, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool is_open = TreeNodeExV(str_id, 0, fmt, args); + va_end(args); + return is_open; +} + +bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + bool is_open = TreeNodeExV(ptr_id, 0, fmt, args); + va_end(args); + return is_open; +} + +bool ImGui::TreeNode(const char* label) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + return TreeNodeBehavior(window->GetID(label), 0, label, NULL); +} + +void ImGui::TreeAdvanceToLabelPos() +{ + ImGuiContext& g = *GImGui; + g.CurrentWindow->DC.CursorPos.x += GetTreeNodeToLabelSpacing(); +} + +// Horizontal distance preceding label when using TreeNode() or Bullet() +float ImGui::GetTreeNodeToLabelSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + (g.Style.FramePadding.x * 2.0f); +} + +void ImGui::SetNextTreeNodeOpen(bool is_open, ImGuiCond cond) +{ + ImGuiContext& g = *GImGui; + if (g.CurrentWindow->SkipItems) + return; + g.SetNextTreeNodeOpenVal = is_open; + g.SetNextTreeNodeOpenCond = cond ? cond : ImGuiCond_Always; +} + +void ImGui::PushID(const char* str_id) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + window->IDStack.push_back(window->GetID(str_id)); +} + +void ImGui::PushID(const char* str_id_begin, const char* str_id_end) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + window->IDStack.push_back(window->GetID(str_id_begin, str_id_end)); +} + +void ImGui::PushID(const void* ptr_id) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + window->IDStack.push_back(window->GetID(ptr_id)); +} + +void ImGui::PushID(int int_id) +{ + const void* ptr_id = (void*)(intptr_t)int_id; + ImGuiWindow* window = GetCurrentWindowRead(); + window->IDStack.push_back(window->GetID(ptr_id)); +} + +void ImGui::PopID() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + window->IDStack.pop_back(); +} + +ImGuiID ImGui::GetID(const char* str_id) +{ + return GImGui->CurrentWindow->GetID(str_id); +} + +ImGuiID ImGui::GetID(const char* str_id_begin, const char* str_id_end) +{ + return GImGui->CurrentWindow->GetID(str_id_begin, str_id_end); +} + +ImGuiID ImGui::GetID(const void* ptr_id) +{ + return GImGui->CurrentWindow->GetID(ptr_id); +} + +void ImGui::Bullet() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const float line_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), g.FontSize); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize, line_height)); + ItemSize(bb); + if (!ItemAdd(bb, 0)) + { + SameLine(0, style.FramePadding.x*2); + return; + } + + // Render and stay on same line + RenderBullet(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f)); + SameLine(0, style.FramePadding.x*2); +} + +// Text with a little bullet aligned to the typical tree node. +void ImGui::BulletTextV(const char* fmt, va_list args) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + const char* text_begin = g.TempBuffer; + const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + const ImVec2 label_size = CalcTextSize(text_begin, text_end, false); + const float text_base_offset_y = ImMax(0.0f, window->DC.CurrentLineTextBaseOffset); // Latch before ItemSize changes it + const float line_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), g.FontSize); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x*2) : 0.0f), ImMax(line_height, label_size.y))); // Empty text doesn't add padding + ItemSize(bb); + if (!ItemAdd(bb, 0)) + return; + + // Render + RenderBullet(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f)); + RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2, text_base_offset_y), text_begin, text_end, false); +} + +void ImGui::BulletText(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + BulletTextV(fmt, args); + va_end(args); +} + +static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, const char* display_format, char* buf, int buf_size) +{ + if (data_type == ImGuiDataType_Int) + ImFormatString(buf, buf_size, display_format, *(int*)data_ptr); + else if (data_type == ImGuiDataType_Float) + ImFormatString(buf, buf_size, display_format, *(float*)data_ptr); +} + +static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, int decimal_precision, char* buf, int buf_size) +{ + if (data_type == ImGuiDataType_Int) + { + if (decimal_precision < 0) + ImFormatString(buf, buf_size, "%d", *(int*)data_ptr); + else + ImFormatString(buf, buf_size, "%.*d", decimal_precision, *(int*)data_ptr); + } + else if (data_type == ImGuiDataType_Float) + { + if (decimal_precision < 0) + ImFormatString(buf, buf_size, "%f", *(float*)data_ptr); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits? + else + ImFormatString(buf, buf_size, "%.*f", decimal_precision, *(float*)data_ptr); + } +} + +static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* value1, const void* value2)// Store into value1 +{ + if (data_type == ImGuiDataType_Int) + { + if (op == '+') + *(int*)value1 = *(int*)value1 + *(const int*)value2; + else if (op == '-') + *(int*)value1 = *(int*)value1 - *(const int*)value2; + } + else if (data_type == ImGuiDataType_Float) + { + if (op == '+') + *(float*)value1 = *(float*)value1 + *(const float*)value2; + else if (op == '-') + *(float*)value1 = *(float*)value1 - *(const float*)value2; + } +} + +// User can input math operators (e.g. +100) to edit a numerical values. +static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* scalar_format) +{ + while (ImCharIsSpace(*buf)) + buf++; + + // We don't support '-' op because it would conflict with inputing negative value. + // Instead you can use +-100 to subtract from an existing value + char op = buf[0]; + if (op == '+' || op == '*' || op == '/') + { + buf++; + while (ImCharIsSpace(*buf)) + buf++; + } + else + { + op = 0; + } + if (!buf[0]) + return false; + + if (data_type == ImGuiDataType_Int) + { + if (!scalar_format) + scalar_format = "%d"; + int* v = (int*)data_ptr; + const int old_v = *v; + int arg0i = *v; + if (op && sscanf(initial_value_buf, scalar_format, &arg0i) < 1) + return false; + + // Store operand in a float so we can use fractional value for multipliers (*1.1), but constant always parsed as integer so we can fit big integers (e.g. 2000000003) past float precision + float arg1f = 0.0f; + if (op == '+') { if (sscanf(buf, "%f", &arg1f) == 1) *v = (int)(arg0i + arg1f); } // Add (use "+-" to subtract) + else if (op == '*') { if (sscanf(buf, "%f", &arg1f) == 1) *v = (int)(arg0i * arg1f); } // Multiply + else if (op == '/') { if (sscanf(buf, "%f", &arg1f) == 1 && arg1f != 0.0f) *v = (int)(arg0i / arg1f); }// Divide + else { if (sscanf(buf, scalar_format, &arg0i) == 1) *v = arg0i; } // Assign constant (read as integer so big values are not lossy) + return (old_v != *v); + } + else if (data_type == ImGuiDataType_Float) + { + // For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in + scalar_format = "%f"; + float* v = (float*)data_ptr; + const float old_v = *v; + float arg0f = *v; + if (op && sscanf(initial_value_buf, scalar_format, &arg0f) < 1) + return false; + + float arg1f = 0.0f; + if (sscanf(buf, scalar_format, &arg1f) < 1) + return false; + if (op == '+') { *v = arg0f + arg1f; } // Add (use "+-" to subtract) + else if (op == '*') { *v = arg0f * arg1f; } // Multiply + else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide + else { *v = arg1f; } // Assign constant + return (old_v != *v); + } + + return false; +} + +// Create text input in place of a slider (when CTRL+Clicking on slider) +// FIXME: Logic is messy and confusing. +bool ImGui::InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + + // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen) + // On the first frame, g.ScalarAsInputTextId == 0, then on subsequent frames it becomes == id + SetActiveID(g.ScalarAsInputTextId, window); + SetHoveredID(0); + FocusableItemUnregister(window); + + char buf[32]; + DataTypeFormatString(data_type, data_ptr, decimal_precision, buf, IM_ARRAYSIZE(buf)); + bool text_value_changed = InputTextEx(label, buf, IM_ARRAYSIZE(buf), aabb.GetSize(), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll); + if (g.ScalarAsInputTextId == 0) // First frame we started displaying the InputText widget + { + IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible) + g.ScalarAsInputTextId = g.ActiveId; + SetHoveredID(id); + } + if (text_value_changed) + return DataTypeApplyOpFromText(buf, GImGui->InputTextState.InitialText.begin(), data_type, data_ptr, NULL); + return false; +} + +// Parse display precision back from the display format string +int ImGui::ParseFormatPrecision(const char* fmt, int default_precision) +{ + int precision = default_precision; + while ((fmt = strchr(fmt, '%')) != NULL) + { + fmt++; + if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%" + while (*fmt >= '0' && *fmt <= '9') + fmt++; + if (*fmt == '.') + { + fmt = ImAtoi(fmt + 1, &precision); + if (precision < 0 || precision > 10) + precision = default_precision; + } + if (*fmt == 'e' || *fmt == 'E') // Maximum precision with scientific notation + precision = -1; + break; + } + return precision; +} + +static float GetMinimumStepAtDecimalPrecision(int decimal_precision) +{ + static const float min_steps[10] = { 1.0f, 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, 0.000000001f }; + return (decimal_precision >= 0 && decimal_precision < 10) ? min_steps[decimal_precision] : powf(10.0f, (float)-decimal_precision); +} + +float ImGui::RoundScalar(float value, int decimal_precision) +{ + // Round past decimal precision + // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 + // FIXME: Investigate better rounding methods + if (decimal_precision < 0) + return value; + const float min_step = GetMinimumStepAtDecimalPrecision(decimal_precision); + bool negative = value < 0.0f; + value = fabsf(value); + float remainder = fmodf(value, min_step); + if (remainder <= min_step*0.5f) + value -= remainder; + else + value += (min_step - remainder); + return negative ? -value : value; +} + +static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos) +{ + if (v_min == v_max) + return 0.0f; + + const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f); + const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min); + if (is_non_linear) + { + if (v_clamped < 0.0f) + { + const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min); + return (1.0f - powf(f, 1.0f/power)) * linear_zero_pos; + } + else + { + const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min)); + return linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos); + } + } + + // Linear slider + return (v_clamped - v_min) / (v_max - v_min); +} + +bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + const ImGuiStyle& style = g.Style; + + // Draw frame + RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); + + const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f); + const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0; + + const float grab_padding = 2.0f; + const float slider_sz = is_horizontal ? (frame_bb.GetWidth() - grab_padding * 2.0f) : (frame_bb.GetHeight() - grab_padding * 2.0f); + float grab_sz; + if (decimal_precision != 0) + grab_sz = ImMin(style.GrabMinSize, slider_sz); + else + grab_sz = ImMin(ImMax(1.0f * (slider_sz / ((v_min < v_max ? v_max - v_min : v_min - v_max) + 1.0f)), style.GrabMinSize), slider_sz); // Integer sliders, if possible have the grab size represent 1 unit + const float slider_usable_sz = slider_sz - grab_sz; + const float slider_usable_pos_min = (is_horizontal ? frame_bb.Min.x : frame_bb.Min.y) + grab_padding + grab_sz*0.5f; + const float slider_usable_pos_max = (is_horizontal ? frame_bb.Max.x : frame_bb.Max.y) - grab_padding - grab_sz*0.5f; + + // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f + float linear_zero_pos = 0.0f; // 0.0->1.0f + if (v_min * v_max < 0.0f) + { + // Different sign + const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power); + const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power); + linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0); + } + else + { + // Same sign + linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f; + } + + // Process clicking on the slider + bool value_changed = false; + if (g.ActiveId == id) + { + bool set_new_value = false; + float clicked_t = 0.0f; + if (g.IO.MouseDown[0]) + { + const float mouse_abs_pos = is_horizontal ? g.IO.MousePos.x : g.IO.MousePos.y; + clicked_t = (slider_usable_sz > 0.0f) ? ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f) : 0.0f; + if (!is_horizontal) + clicked_t = 1.0f - clicked_t; + set_new_value = true; + } + else + { + ClearActiveID(); + } + + if (set_new_value) + { + float new_value; + if (is_non_linear) + { + // Account for logarithmic scale on both sides of the zero + if (clicked_t < linear_zero_pos) + { + // Negative: rescale to the negative range before powering + float a = 1.0f - (clicked_t / linear_zero_pos); + a = powf(a, power); + new_value = ImLerp(ImMin(v_max,0.0f), v_min, a); + } + else + { + // Positive: rescale to the positive range before powering + float a; + if (fabsf(linear_zero_pos - 1.0f) > 1.e-6f) + a = (clicked_t - linear_zero_pos) / (1.0f - linear_zero_pos); + else + a = clicked_t; + a = powf(a, power); + new_value = ImLerp(ImMax(v_min,0.0f), v_max, a); + } + } + else + { + // Linear slider + new_value = ImLerp(v_min, v_max, clicked_t); + } + + // Round past decimal precision + new_value = RoundScalar(new_value, decimal_precision); + if (*v != new_value) + { + *v = new_value; + value_changed = true; + } + } + } + + // Draw + float grab_t = SliderBehaviorCalcRatioFromValue(*v, v_min, v_max, power, linear_zero_pos); + if (!is_horizontal) + grab_t = 1.0f - grab_t; + const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t); + ImRect grab_bb; + if (is_horizontal) + grab_bb = ImRect(ImVec2(grab_pos - grab_sz*0.5f, frame_bb.Min.y + grab_padding), ImVec2(grab_pos + grab_sz*0.5f, frame_bb.Max.y - grab_padding)); + else + grab_bb = ImRect(ImVec2(frame_bb.Min.x + grab_padding, grab_pos - grab_sz*0.5f), ImVec2(frame_bb.Max.x - grab_padding, grab_pos + grab_sz*0.5f)); + window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, GetColorU32(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); + + return value_changed; +} + +// Use power!=1.0 for logarithmic sliders. +// Adjust display_format to decorate the value with a prefix or a suffix. +// "%.3f" 1.234 +// "%5.2f secs" 01.23 secs +// "Gold: %.0f" Gold: 1 +bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w = CalcItemWidth(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f)); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + + // NB- we don't call ItemSize() yet because we may turn into a text edit box below + if (!ItemAdd(total_bb, id)) + { + ItemSize(total_bb, style.FramePadding.y); + return false; + } + const bool hovered = ItemHoverable(frame_bb, id); + + if (!display_format) + display_format = "%.3f"; + int decimal_precision = ParseFormatPrecision(display_format, 3); + + // Tabbing or CTRL-clicking on Slider turns it into an input box + bool start_text_input = false; + const bool tab_focus_requested = FocusableItemRegister(window, id); + if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) + { + SetActiveID(id, window); + FocusWindow(window); + if (tab_focus_requested || g.IO.KeyCtrl) + { + start_text_input = true; + g.ScalarAsInputTextId = 0; + } + } + if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) + return InputScalarAsWidgetReplacement(frame_bb, label, ImGuiDataType_Float, v, id, decimal_precision); + + // Actual slider behavior + render grab + ItemSize(total_bb, style.FramePadding.y); + const bool value_changed = SliderBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision); + + // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. + char value_buf[64]; + const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.5f)); + + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + + return value_changed; +} + +bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size); + const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + + ItemSize(bb, style.FramePadding.y); + if (!ItemAdd(frame_bb, id)) + return false; + const bool hovered = ItemHoverable(frame_bb, id); + + if (!display_format) + display_format = "%.3f"; + int decimal_precision = ParseFormatPrecision(display_format, 3); + + if (hovered && g.IO.MouseClicked[0]) + { + SetActiveID(id, window); + FocusWindow(window); + } + + // Actual slider behavior + render grab + bool value_changed = SliderBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, ImGuiSliderFlags_Vertical); + + // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. + // For the vertical slider we allow centered text to overlap the frame padding + char value_buf[64]; + char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.0f)); + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + + return value_changed; +} + +bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, float v_degrees_max) +{ + float v_deg = (*v_rad) * 360.0f / (2*IM_PI); + bool value_changed = SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f); + *v_rad = v_deg * (2*IM_PI) / 360.0f; + return value_changed; +} + +bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format) +{ + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + *v = (int)v_f; + return value_changed; +} + +bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format) +{ + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool value_changed = VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + *v = (int)v_f; + return value_changed; +} + +// Add multiple sliders on 1 line for compact edition of multiple components +bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + bool value_changed = false; + BeginGroup(); + PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + PushID(i); + value_changed |= SliderFloat("##v", &v[i], v_min, v_max, display_format, power); + SameLine(0, g.Style.ItemInnerSpacing.x); + PopID(); + PopItemWidth(); + } + PopID(); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + + return value_changed; +} + +bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power) +{ + return SliderFloatN(label, v, 2, v_min, v_max, display_format, power); +} + +bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power) +{ + return SliderFloatN(label, v, 3, v_min, v_max, display_format, power); +} + +bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power) +{ + return SliderFloatN(label, v, 4, v_min, v_max, display_format, power); +} + +bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + bool value_changed = false; + BeginGroup(); + PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + PushID(i); + value_changed |= SliderInt("##v", &v[i], v_min, v_max, display_format); + SameLine(0, g.Style.ItemInnerSpacing.x); + PopID(); + PopItemWidth(); + } + PopID(); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + + return value_changed; +} + +bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format) +{ + return SliderIntN(label, v, 2, v_min, v_max, display_format); +} + +bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format) +{ + return SliderIntN(label, v, 3, v_min, v_max, display_format); +} + +bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format) +{ + return SliderIntN(label, v, 4, v_min, v_max, display_format); +} + +bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power) +{ + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + // Draw frame + const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); + RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding); + + bool value_changed = false; + + // Process clicking on the drag + if (g.ActiveId == id) + { + if (g.IO.MouseDown[0]) + { + if (g.ActiveIdIsJustActivated) + { + // Lock current value on click + g.DragCurrentValue = *v; + g.DragLastMouseDelta = ImVec2(0.f, 0.f); + } + + if (v_speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX) + v_speed = (v_max - v_min) * g.DragSpeedDefaultRatio; + + float v_cur = g.DragCurrentValue; + const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f); + float adjust_delta = 0.0f; + //if (g.ActiveIdSource == ImGuiInputSource_Mouse) + { + adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x; + if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f) + adjust_delta *= g.DragSpeedScaleFast; + if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) + adjust_delta *= g.DragSpeedScaleSlow; + } + adjust_delta *= v_speed; + g.DragLastMouseDelta.x = mouse_drag_delta.x; + + if (fabsf(adjust_delta) > 0.0f) + { + if (fabsf(power - 1.0f) > 0.001f) + { + // Logarithmic curve on both side of 0.0 + float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur; + float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f; + float v1 = powf(v0_abs, 1.0f / power) + (adjust_delta * v0_sign); + float v1_abs = v1 >= 0.0f ? v1 : -v1; + float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line + v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign + } + else + { + v_cur += adjust_delta; + } + + // Clamp + if (v_min < v_max) + v_cur = ImClamp(v_cur, v_min, v_max); + g.DragCurrentValue = v_cur; + } + + // Round to user desired precision, then apply + v_cur = RoundScalar(v_cur, decimal_precision); + if (*v != v_cur) + { + *v = v_cur; + value_changed = true; + } + } + else + { + ClearActiveID(); + } + } + + return value_changed; +} + +bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w = CalcItemWidth(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f)); + const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + + // NB- we don't call ItemSize() yet because we may turn into a text edit box below + if (!ItemAdd(total_bb, id)) + { + ItemSize(total_bb, style.FramePadding.y); + return false; + } + const bool hovered = ItemHoverable(frame_bb, id); + + if (!display_format) + display_format = "%.3f"; + int decimal_precision = ParseFormatPrecision(display_format, 3); + + // Tabbing or CTRL-clicking on Drag turns it into an input box + bool start_text_input = false; + const bool tab_focus_requested = FocusableItemRegister(window, id); + if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0]))) + { + SetActiveID(id, window); + FocusWindow(window); + if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0]) + { + start_text_input = true; + g.ScalarAsInputTextId = 0; + } + } + if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) + return InputScalarAsWidgetReplacement(frame_bb, label, ImGuiDataType_Float, v, id, decimal_precision); + + // Actual drag behavior + ItemSize(total_bb, style.FramePadding.y); + const bool value_changed = DragBehavior(frame_bb, id, v, v_speed, v_min, v_max, decimal_precision, power); + + // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. + char value_buf[64]; + const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.5f)); + + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); + + return value_changed; +} + +bool ImGui::DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + bool value_changed = false; + BeginGroup(); + PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + PushID(i); + value_changed |= DragFloat("##v", &v[i], v_speed, v_min, v_max, display_format, power); + SameLine(0, g.Style.ItemInnerSpacing.x); + PopID(); + PopItemWidth(); + } + PopID(); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + + return value_changed; +} + +bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + return DragFloatN(label, v, 2, v_speed, v_min, v_max, display_format, power); +} + +bool ImGui::DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + return DragFloatN(label, v, 3, v_speed, v_min, v_max, display_format, power); +} + +bool ImGui::DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power); +} + +bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed, float v_min, float v_max, const char* display_format, const char* display_format_max, float power) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + PushID(label); + BeginGroup(); + PushMultiItemsWidths(2); + + bool value_changed = DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format, power); + PopItemWidth(); + SameLine(0, g.Style.ItemInnerSpacing.x); + value_changed |= DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, display_format_max ? display_format_max : display_format, power); + PopItemWidth(); + SameLine(0, g.Style.ItemInnerSpacing.x); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + PopID(); + + return value_changed; +} + +// NB: v_speed is float to allow adjusting the drag speed with more precision +bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format) +{ + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool value_changed = DragFloat(label, &v_f, v_speed, (float)v_min, (float)v_max, display_format); + *v = (int)v_f; + return value_changed; +} + +bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + bool value_changed = false; + BeginGroup(); + PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + PushID(i); + value_changed |= DragInt("##v", &v[i], v_speed, v_min, v_max, display_format); + SameLine(0, g.Style.ItemInnerSpacing.x); + PopID(); + PopItemWidth(); + } + PopID(); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + + return value_changed; +} + +bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* display_format) +{ + return DragIntN(label, v, 2, v_speed, v_min, v_max, display_format); +} + +bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* display_format) +{ + return DragIntN(label, v, 3, v_speed, v_min, v_max, display_format); +} + +bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* display_format) +{ + return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format); +} + +bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed, int v_min, int v_max, const char* display_format, const char* display_format_max) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + PushID(label); + BeginGroup(); + PushMultiItemsWidths(2); + + bool value_changed = DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format); + PopItemWidth(); + SameLine(0, g.Style.ItemInnerSpacing.x); + value_changed |= DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? INT_MAX : v_max, display_format_max ? display_format_max : display_format); + PopItemWidth(); + SameLine(0, g.Style.ItemInnerSpacing.x); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + PopID(); + + return value_changed; +} + +void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + if (graph_size.x == 0.0f) + graph_size.x = CalcItemWidth(); + if (graph_size.y == 0.0f) + graph_size.y = label_size.y + (style.FramePadding.y * 2); + + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y)); + const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, 0)) + return; + const bool hovered = ItemHoverable(inner_bb, 0); + + // Determine scale from values if not specified + if (scale_min == FLT_MAX || scale_max == FLT_MAX) + { + float v_min = FLT_MAX; + float v_max = -FLT_MAX; + for (int i = 0; i < values_count; i++) + { + const float v = values_getter(data, i); + v_min = ImMin(v_min, v); + v_max = ImMax(v_max, v); + } + if (scale_min == FLT_MAX) + scale_min = v_min; + if (scale_max == FLT_MAX) + scale_max = v_max; + } + + RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); + + if (values_count > 0) + { + int res_w = ImMin((int)graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); + int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); + + // Tooltip on hover + int v_hovered = -1; + if (hovered) + { + const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); + const int v_idx = (int)(t * item_count); + IM_ASSERT(v_idx >= 0 && v_idx < values_count); + + const float v0 = values_getter(data, (v_idx + values_offset) % values_count); + const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count); + if (plot_type == ImGuiPlotType_Lines) + SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1); + else if (plot_type == ImGuiPlotType_Histogram) + SetTooltip("%d: %8.4g", v_idx, v0); + v_hovered = v_idx; + } + + const float t_step = 1.0f / (float)res_w; + + float v0 = values_getter(data, (0 + values_offset) % values_count); + float t0 = 0.0f; + ImVec2 tp0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) ); // Point in the normalized space of our target rectangle + float histogram_zero_line_t = (scale_min * scale_max < 0.0f) ? (-scale_min / (scale_max - scale_min)) : (scale_min < 0.0f ? 0.0f : 1.0f); // Where does the zero line stands + + const ImU32 col_base = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram); + const ImU32 col_hovered = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered); + + for (int n = 0; n < res_w; n++) + { + const float t1 = t0 + t_step; + const int v1_idx = (int)(t0 * item_count + 0.5f); + IM_ASSERT(v1_idx >= 0 && v1_idx < values_count); + const float v1 = values_getter(data, (v1_idx + values_offset + 1) % values_count); + const ImVec2 tp1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) ); + + // NB: Draw calls are merged together by the DrawList system. Still, we should render our batch are lower level to save a bit of CPU. + ImVec2 pos0 = ImLerp(inner_bb.Min, inner_bb.Max, tp0); + ImVec2 pos1 = ImLerp(inner_bb.Min, inner_bb.Max, (plot_type == ImGuiPlotType_Lines) ? tp1 : ImVec2(tp1.x, histogram_zero_line_t)); + if (plot_type == ImGuiPlotType_Lines) + { + window->DrawList->AddLine(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base); + } + else if (plot_type == ImGuiPlotType_Histogram) + { + if (pos1.x >= pos0.x + 2.0f) + pos1.x -= 1.0f; + window->DrawList->AddRectFilled(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base); + } + + t0 = t1; + tp0 = tp1; + } + } + + // Text overlay + if (overlay_text) + RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, overlay_text, NULL, NULL, ImVec2(0.5f,0.0f)); + + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); +} + +struct ImGuiPlotArrayGetterData +{ + const float* Values; + int Stride; + + ImGuiPlotArrayGetterData(const float* values, int stride) { Values = values; Stride = stride; } +}; + +static float Plot_ArrayGetter(void* data, int idx) +{ + ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data; + const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride); + return v; +} + +void ImGui::PlotLines(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride) +{ + ImGuiPlotArrayGetterData data(values, stride); + PlotEx(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); +} + +void ImGui::PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size) +{ + PlotEx(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); +} + +void ImGui::PlotHistogram(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride) +{ + ImGuiPlotArrayGetterData data(values, stride); + PlotEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); +} + +void ImGui::PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size) +{ + PlotEx(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); +} + +// size_arg (for each axis) < 0.0f: align to end, 0.0f: auto, > 0.0f: specified size +void ImGui::ProgressBar(float fraction, const ImVec2& size_arg, const char* overlay) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + ImVec2 pos = window->DC.CursorPos; + ImRect bb(pos, pos + CalcItemSize(size_arg, CalcItemWidth(), g.FontSize + style.FramePadding.y*2.0f)); + ItemSize(bb, style.FramePadding.y); + if (!ItemAdd(bb, 0)) + return; + + // Render + fraction = ImSaturate(fraction); + RenderFrame(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); + bb.Expand(ImVec2(-style.FrameBorderSize, -style.FrameBorderSize)); + const ImVec2 fill_br = ImVec2(ImLerp(bb.Min.x, bb.Max.x, fraction), bb.Max.y); + RenderRectFilledRangeH(window->DrawList, bb, GetColorU32(ImGuiCol_PlotHistogram), 0.0f, fraction, style.FrameRounding); + + // Default displaying the fraction as percentage string, but user can override it + char overlay_buf[32]; + if (!overlay) + { + ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%.0f%%", fraction*100+0.01f); + overlay = overlay_buf; + } + + ImVec2 overlay_size = CalcTextSize(overlay, NULL); + if (overlay_size.x > 0.0f) + RenderTextClipped(ImVec2(ImClamp(fill_br.x + style.ItemSpacing.x, bb.Min.x, bb.Max.x - overlay_size.x - style.ItemInnerSpacing.x), bb.Min.y), bb.Max, overlay, NULL, &overlay_size, ImVec2(0.0f,0.5f), &bb); +} + +bool ImGui::Checkbox(const char* label, bool* v) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2)); // We want a square shape to we use Y twice + ItemSize(check_bb, style.FramePadding.y); + + ImRect total_bb = check_bb; + if (label_size.x > 0) + SameLine(0, style.ItemInnerSpacing.x); + const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size); + if (label_size.x > 0) + { + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y); + total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + } + + if (!ItemAdd(total_bb, id)) + return false; + + bool hovered, held; + bool pressed = ButtonBehavior(total_bb, id, &hovered, &held); + if (pressed) + *v = !(*v); + + RenderFrame(check_bb.Min, check_bb.Max, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding); + if (*v) + { + const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); + const float pad = ImMax(1.0f, (float)(int)(check_sz / 6.0f)); + RenderCheckMark(check_bb.Min + ImVec2(pad,pad), GetColorU32(ImGuiCol_CheckMark), check_bb.GetWidth() - pad*2.0f); + } + + if (g.LogEnabled) + LogRenderedText(&text_bb.Min, *v ? "[x]" : "[ ]"); + if (label_size.x > 0.0f) + RenderText(text_bb.Min, label); + + return pressed; +} + +bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) +{ + bool v = ((*flags & flags_value) == flags_value); + bool pressed = Checkbox(label, &v); + if (pressed) + { + if (v) + *flags |= flags_value; + else + *flags &= ~flags_value; + } + + return pressed; +} + +bool ImGui::RadioButton(const char* label, bool active) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1)); + ItemSize(check_bb, style.FramePadding.y); + + ImRect total_bb = check_bb; + if (label_size.x > 0) + SameLine(0, style.ItemInnerSpacing.x); + const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size); + if (label_size.x > 0) + { + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y); + total_bb.Add(text_bb); + } + + if (!ItemAdd(total_bb, id)) + return false; + + ImVec2 center = check_bb.GetCenter(); + center.x = (float)(int)center.x + 0.5f; + center.y = (float)(int)center.y + 0.5f; + const float radius = check_bb.GetHeight() * 0.5f; + + bool hovered, held; + bool pressed = ButtonBehavior(total_bb, id, &hovered, &held); + + window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16); + if (active) + { + const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); + const float pad = ImMax(1.0f, (float)(int)(check_sz / 6.0f)); + window->DrawList->AddCircleFilled(center, radius-pad, GetColorU32(ImGuiCol_CheckMark), 16); + } + + if (style.FrameBorderSize > 0.0f) + { + window->DrawList->AddCircle(center+ImVec2(1,1), radius, GetColorU32(ImGuiCol_BorderShadow), 16, style.FrameBorderSize); + window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize); + } + + if (g.LogEnabled) + LogRenderedText(&text_bb.Min, active ? "(x)" : "( )"); + if (label_size.x > 0.0f) + RenderText(text_bb.Min, label); + + return pressed; +} + +bool ImGui::RadioButton(const char* label, int* v, int v_button) +{ + const bool pressed = RadioButton(label, *v == v_button); + if (pressed) + { + *v = v_button; + } + return pressed; +} + +static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end) +{ + int line_count = 0; + const char* s = text_begin; + while (char c = *s++) // We are only matching for \n so we can ignore UTF-8 decoding + if (c == '\n') + line_count++; + s--; + if (s[0] != '\n' && s[0] != '\r') + line_count++; + *out_text_end = s; + return line_count; +} + +static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining, ImVec2* out_offset, bool stop_on_new_line) +{ + ImFont* font = GImGui->Font; + const float line_height = GImGui->FontSize; + const float scale = line_height / font->FontSize; + + ImVec2 text_size = ImVec2(0,0); + float line_width = 0.0f; + + const ImWchar* s = text_begin; + while (s < text_end) + { + unsigned int c = (unsigned int)(*s++); + if (c == '\n') + { + text_size.x = ImMax(text_size.x, line_width); + text_size.y += line_height; + line_width = 0.0f; + if (stop_on_new_line) + break; + continue; + } + if (c == '\r') + continue; + + const float char_width = font->GetCharAdvance((unsigned short)c) * scale; + line_width += char_width; + } + + if (text_size.x < line_width) + text_size.x = line_width; + + if (out_offset) + *out_offset = ImVec2(line_width, text_size.y + line_height); // offset allow for the possibility of sitting after a trailing \n + + if (line_width > 0 || text_size.y == 0.0f) // whereas size.y will ignore the trailing \n + text_size.y += line_height; + + if (remaining) + *remaining = s; + + return text_size; +} + +// Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, wchar characters. InputText converts between UTF-8 and wchar) +namespace ImGuiStb +{ + +static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return obj->CurLenW; } +static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; } +static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { ImWchar c = obj->Text[line_start_idx+char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; return GImGui->Font->GetCharAdvance(c) * (GImGui->FontSize / GImGui->Font->FontSize); } +static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; } +static ImWchar STB_TEXTEDIT_NEWLINE = '\n'; +static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx) +{ + const ImWchar* text = obj->Text.Data; + const ImWchar* text_remaining = NULL; + const ImVec2 size = InputTextCalcTextSizeW(text + line_start_idx, text + obj->CurLenW, &text_remaining, NULL, true); + r->x0 = 0.0f; + r->x1 = size.x; + r->baseline_y_delta = size.y; + r->ymin = 0.0f; + r->ymax = size.y; + r->num_chars = (int)(text_remaining - (text + line_start_idx)); +} + +static bool is_separator(unsigned int c) { return ImCharIsSpace(c) || c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; } +static int is_word_boundary_from_right(STB_TEXTEDIT_STRING* obj, int idx) { return idx > 0 ? (is_separator( obj->Text[idx-1] ) && !is_separator( obj->Text[idx] ) ) : 1; } +static int STB_TEXTEDIT_MOVEWORDLEFT_IMPL(STB_TEXTEDIT_STRING* obj, int idx) { idx--; while (idx >= 0 && !is_word_boundary_from_right(obj, idx)) idx--; return idx < 0 ? 0 : idx; } +#ifdef __APPLE__ // FIXME: Move setting to IO structure +static int is_word_boundary_from_left(STB_TEXTEDIT_STRING* obj, int idx) { return idx > 0 ? (!is_separator( obj->Text[idx-1] ) && is_separator( obj->Text[idx] ) ) : 1; } +static int STB_TEXTEDIT_MOVEWORDRIGHT_IMPL(STB_TEXTEDIT_STRING* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_left(obj, idx)) idx++; return idx > len ? len : idx; } +#else +static int STB_TEXTEDIT_MOVEWORDRIGHT_IMPL(STB_TEXTEDIT_STRING* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_right(obj, idx)) idx++; return idx > len ? len : idx; } +#endif +#define STB_TEXTEDIT_MOVEWORDLEFT STB_TEXTEDIT_MOVEWORDLEFT_IMPL // They need to be #define for stb_textedit.h +#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_IMPL + +static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) +{ + ImWchar* dst = obj->Text.Data + pos; + + // We maintain our buffer length in both UTF-8 and wchar formats + obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n); + obj->CurLenW -= n; + + // Offset remaining text + const ImWchar* src = obj->Text.Data + pos + n; + while (ImWchar c = *src++) + *dst++ = c; + *dst = '\0'; +} + +static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len) +{ + const int text_len = obj->CurLenW; + IM_ASSERT(pos <= text_len); + if (new_text_len + text_len + 1 > obj->Text.Size) + return false; + + const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len); + if (new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA) + return false; + + ImWchar* text = obj->Text.Data; + if (pos != text_len) + memmove(text + pos + new_text_len, text + pos, (size_t)(text_len - pos) * sizeof(ImWchar)); + memcpy(text + pos, new_text, (size_t)new_text_len * sizeof(ImWchar)); + + obj->CurLenW += new_text_len; + obj->CurLenA += new_text_len_utf8; + obj->Text[obj->CurLenW] = '\0'; + + return true; +} + +// We don't use an enum so we can build even with conflicting symbols (if another user of stb_textedit.h leak their STB_TEXTEDIT_K_* symbols) +#define STB_TEXTEDIT_K_LEFT 0x10000 // keyboard input to move cursor left +#define STB_TEXTEDIT_K_RIGHT 0x10001 // keyboard input to move cursor right +#define STB_TEXTEDIT_K_UP 0x10002 // keyboard input to move cursor up +#define STB_TEXTEDIT_K_DOWN 0x10003 // keyboard input to move cursor down +#define STB_TEXTEDIT_K_LINESTART 0x10004 // keyboard input to move cursor to start of line +#define STB_TEXTEDIT_K_LINEEND 0x10005 // keyboard input to move cursor to end of line +#define STB_TEXTEDIT_K_TEXTSTART 0x10006 // keyboard input to move cursor to start of text +#define STB_TEXTEDIT_K_TEXTEND 0x10007 // keyboard input to move cursor to end of text +#define STB_TEXTEDIT_K_DELETE 0x10008 // keyboard input to delete selection or character under cursor +#define STB_TEXTEDIT_K_BACKSPACE 0x10009 // keyboard input to delete selection or character left of cursor +#define STB_TEXTEDIT_K_UNDO 0x1000A // keyboard input to perform undo +#define STB_TEXTEDIT_K_REDO 0x1000B // keyboard input to perform redo +#define STB_TEXTEDIT_K_WORDLEFT 0x1000C // keyboard input to move cursor left one word +#define STB_TEXTEDIT_K_WORDRIGHT 0x1000D // keyboard input to move cursor right one word +#define STB_TEXTEDIT_K_SHIFT 0x20000 + +#define STB_TEXTEDIT_IMPLEMENTATION +#include "stb_textedit.h" + +} + +void ImGuiTextEditState::OnKeyPressed(int key) +{ + stb_textedit_key(this, &StbState, key); + CursorFollow = true; + CursorAnimReset(); +} + +// Public API to manipulate UTF-8 text +// We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar) +// FIXME: The existence of this rarely exercised code path is a bit of a nuisance. +void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count) +{ + IM_ASSERT(pos + bytes_count <= BufTextLen); + char* dst = Buf + pos; + const char* src = Buf + pos + bytes_count; + while (char c = *src++) + *dst++ = c; + *dst = '\0'; + + if (CursorPos + bytes_count >= pos) + CursorPos -= bytes_count; + else if (CursorPos >= pos) + CursorPos = pos; + SelectionStart = SelectionEnd = CursorPos; + BufDirty = true; + BufTextLen -= bytes_count; +} + +void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end) +{ + const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)strlen(new_text); + if (new_text_len + BufTextLen + 1 >= BufSize) + return; + + if (BufTextLen != pos) + memmove(Buf + pos + new_text_len, Buf + pos, (size_t)(BufTextLen - pos)); + memcpy(Buf + pos, new_text, (size_t)new_text_len * sizeof(char)); + Buf[BufTextLen + new_text_len] = '\0'; + + if (CursorPos >= pos) + CursorPos += new_text_len; + SelectionStart = SelectionEnd = CursorPos; + BufDirty = true; + BufTextLen += new_text_len; +} + +// Return false to discard a character. +static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) +{ + unsigned int c = *p_char; + + if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) + { + bool pass = false; + pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); + pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput)); + if (!pass) + return false; + } + + if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys. + return false; + + if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank)) + { + if (flags & ImGuiInputTextFlags_CharsDecimal) + if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) + return false; + + if (flags & ImGuiInputTextFlags_CharsHexadecimal) + if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) + return false; + + if (flags & ImGuiInputTextFlags_CharsUppercase) + if (c >= 'a' && c <= 'z') + *p_char = (c += (unsigned int)('A'-'a')); + + if (flags & ImGuiInputTextFlags_CharsNoBlank) + if (ImCharIsSpace(c)) + return false; + } + + if (flags & ImGuiInputTextFlags_CallbackCharFilter) + { + ImGuiTextEditCallbackData callback_data; + memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData)); + callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; + callback_data.EventChar = (ImWchar)c; + callback_data.Flags = flags; + callback_data.UserData = user_data; + if (callback(&callback_data) != 0) + return false; + *p_char = callback_data.EventChar; + if (!callback_data.EventChar) + return false; + } + + return true; +} + +// Edit a string of text +// NB: when active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while active has no effect. +// FIXME: Rather messy function partly because we are doing UTF8 > u16 > UTF8 conversions on the go to more easily handle stb_textedit calls. Ideally we should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188 +bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys) + IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key) + + ImGuiContext& g = *GImGui; + const ImGuiIO& io = g.IO; + const ImGuiStyle& style = g.Style; + + const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0; + const bool is_editable = (flags & ImGuiInputTextFlags_ReadOnly) == 0; + const bool is_password = (flags & ImGuiInputTextFlags_Password) != 0; + const bool is_undoable = (flags & ImGuiInputTextFlags_NoUndoRedo) == 0; + + if (is_multiline) // Open group before calling GetID() because groups tracks id created during their spawn + BeginGroup(); + const ImGuiID id = window->GetID(label); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? GetTextLineHeight() * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f)); + + ImGuiWindow* draw_window = window; + if (is_multiline) + { + if (!BeginChildFrame(id, frame_bb.GetSize())) + { + EndChildFrame(); + EndGroup(); + return false; + } + draw_window = GetCurrentWindow(); + size.x -= draw_window->ScrollbarSizes.x; + } + else + { + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, id)) + return false; + } + const bool hovered = ItemHoverable(frame_bb, id); + if (hovered) + g.MouseCursor = ImGuiMouseCursor_TextInput; + + // Password pushes a temporary font with only a fallback glyph + if (is_password) + { + const ImFontGlyph* glyph = g.Font->FindGlyph('*'); + ImFont* password_font = &g.InputTextPasswordFont; + password_font->FontSize = g.Font->FontSize; + password_font->Scale = g.Font->Scale; + password_font->DisplayOffset = g.Font->DisplayOffset; + password_font->Ascent = g.Font->Ascent; + password_font->Descent = g.Font->Descent; + password_font->ContainerAtlas = g.Font->ContainerAtlas; + password_font->FallbackGlyph = glyph; + password_font->FallbackAdvanceX = glyph->AdvanceX; + IM_ASSERT(password_font->Glyphs.empty() && password_font->IndexAdvanceX.empty() && password_font->IndexLookup.empty()); + PushFont(password_font); + } + + // NB: we are only allowed to access 'edit_state' if we are the active widget. + ImGuiTextEditState& edit_state = g.InputTextState; + + const bool focus_requested = FocusableItemRegister(window, id, (flags & (ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_AllowTabInput)) == 0); // Using completion callback disable keyboard tabbing + const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent); + const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code; + + const bool user_clicked = hovered && io.MouseClicked[0]; + const bool user_scrolled = is_multiline && g.ActiveId == 0 && edit_state.Id == id && g.ActiveIdPreviousFrame == draw_window->GetIDNoKeepAlive("#SCROLLY"); + + bool clear_active_id = false; + + bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0; + if (focus_requested || user_clicked || user_scrolled) + { + if (g.ActiveId != id) + { + // Start edition + // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar) + // From the moment we focused we are ignoring the content of 'buf' (unless we are in read-only mode) + const int prev_len_w = edit_state.CurLenW; + edit_state.Text.resize(buf_size+1); // wchar count <= UTF-8 count. we use +1 to make sure that .Data isn't NULL so it doesn't crash. + edit_state.InitialText.resize(buf_size+1); // UTF-8. we use +1 to make sure that .Data isn't NULL so it doesn't crash. + ImStrncpy(edit_state.InitialText.Data, buf, edit_state.InitialText.Size); + const char* buf_end = NULL; + edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.Data, edit_state.Text.Size, buf, NULL, &buf_end); + edit_state.CurLenA = (int)(buf_end - buf); // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. + edit_state.CursorAnimReset(); + + // Preserve cursor position and undo/redo stack if we come back to same widget + // FIXME: We should probably compare the whole buffer to be on the safety side. Comparing buf (utf8) and edit_state.Text (wchar). + const bool recycle_state = (edit_state.Id == id) && (prev_len_w == edit_state.CurLenW); + if (recycle_state) + { + // Recycle existing cursor/selection/undo stack but clamp position + // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler. + edit_state.CursorClamp(); + } + else + { + edit_state.Id = id; + edit_state.ScrollX = 0.0f; + stb_textedit_initialize_state(&edit_state.StbState, !is_multiline); + if (!is_multiline && focus_requested_by_code) + select_all = true; + } + if (flags & ImGuiInputTextFlags_AlwaysInsertMode) + edit_state.StbState.insert_mode = true; + if (!is_multiline && (focus_requested_by_tab || (user_clicked && io.KeyCtrl))) + select_all = true; + } + SetActiveID(id, window); + FocusWindow(window); + } + else if (io.MouseClicked[0]) + { + // Release focus when we click outside + clear_active_id = true; + } + + bool value_changed = false; + bool enter_pressed = false; + + if (g.ActiveId == id) + { + if (!is_editable && !g.ActiveIdIsJustActivated) + { + // When read-only we always use the live data passed to the function + edit_state.Text.resize(buf_size+1); + const char* buf_end = NULL; + edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.Data, edit_state.Text.Size, buf, NULL, &buf_end); + edit_state.CurLenA = (int)(buf_end - buf); + edit_state.CursorClamp(); + } + + edit_state.BufSizeA = buf_size; + + // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget. + // Down the line we should have a cleaner library-wide concept of Selected vs Active. + g.ActiveIdAllowOverlap = !io.MouseDown[0]; + g.WantTextInputNextFrame = 1; + + // Edit in progress + const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + edit_state.ScrollX; + const float mouse_y = (is_multiline ? (io.MousePos.y - draw_window->DC.CursorPos.y - style.FramePadding.y) : (g.FontSize*0.5f)); + + const bool osx_double_click_selects_words = io.OptMacOSXBehaviors; // OS X style: Double click selects by word instead of selecting whole text + if (select_all || (hovered && !osx_double_click_selects_words && io.MouseDoubleClicked[0])) + { + edit_state.SelectAll(); + edit_state.SelectedAllMouseLock = true; + } + else if (hovered && osx_double_click_selects_words && io.MouseDoubleClicked[0]) + { + // Select a word only, OS X style (by simulating keystrokes) + edit_state.OnKeyPressed(STB_TEXTEDIT_K_WORDLEFT); + edit_state.OnKeyPressed(STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT); + } + else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock) + { + stb_textedit_click(&edit_state, &edit_state.StbState, mouse_x, mouse_y); + edit_state.CursorAnimReset(); + } + else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock && (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)) + { + stb_textedit_drag(&edit_state, &edit_state.StbState, mouse_x, mouse_y); + edit_state.CursorAnimReset(); + edit_state.CursorFollow = true; + } + if (edit_state.SelectedAllMouseLock && !io.MouseDown[0]) + edit_state.SelectedAllMouseLock = false; + + if (io.InputCharacters[0]) + { + // Process text input (before we check for Return because using some IME will effectively send a Return?) + // We ignore CTRL inputs, but need to allow CTRL+ALT as some keyboards (e.g. German) use AltGR - which is Alt+Ctrl - to input certain characters. + if (!(io.KeyCtrl && !io.KeyAlt) && is_editable) + { + for (int n = 0; n < IM_ARRAYSIZE(io.InputCharacters) && io.InputCharacters[n]; n++) + if (unsigned int c = (unsigned int)io.InputCharacters[n]) + { + // Insert character if they pass filtering + if (!InputTextFilterCharacter(&c, flags, callback, user_data)) + continue; + edit_state.OnKeyPressed((int)c); + } + } + + // Consume characters + memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); + } + } + + bool cancel_edit = false; + if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id) + { + // Handle key-presses + const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0); + const bool is_shortcut_key_only = (io.OptMacOSXBehaviors ? (io.KeySuper && !io.KeyCtrl) : (io.KeyCtrl && !io.KeySuper)) && !io.KeyAlt && !io.KeyShift; // OS X style: Shortcuts using Cmd/Super instead of Ctrl + const bool is_wordmove_key_down = io.OptMacOSXBehaviors ? io.KeyAlt : io.KeyCtrl; // OS X style: Text editing cursor movement using Alt instead of Ctrl + const bool is_startend_key_down = io.OptMacOSXBehaviors && io.KeySuper && !io.KeyCtrl && !io.KeyAlt; // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End + + if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_UpArrow) && is_multiline) { if (io.KeyCtrl) SetWindowScrollY(draw_window, ImMax(draw_window->Scroll.y - g.FontSize, 0.0f)); else edit_state.OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTSTART : STB_TEXTEDIT_K_UP) | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_DownArrow) && is_multiline) { if (io.KeyCtrl) SetWindowScrollY(draw_window, ImMin(draw_window->Scroll.y + g.FontSize, GetScrollMaxY())); else edit_state.OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTEND : STB_TEXTEDIT_K_DOWN) | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_Delete) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); } + else if (IsKeyPressedMap(ImGuiKey_Backspace) && is_editable) + { + if (!edit_state.HasSelection()) + { + if (is_wordmove_key_down) edit_state.OnKeyPressed(STB_TEXTEDIT_K_WORDLEFT|STB_TEXTEDIT_K_SHIFT); + else if (io.OptMacOSXBehaviors && io.KeySuper && !io.KeyAlt && !io.KeyCtrl) edit_state.OnKeyPressed(STB_TEXTEDIT_K_LINESTART|STB_TEXTEDIT_K_SHIFT); + } + edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); + } + else if (IsKeyPressedMap(ImGuiKey_Enter)) + { + bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; + if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) + { + enter_pressed = clear_active_id = true; + } + else if (is_editable) + { + unsigned int c = '\n'; // Insert new line + if (InputTextFilterCharacter(&c, flags, callback, user_data)) + edit_state.OnKeyPressed((int)c); + } + } + else if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !io.KeyCtrl && !io.KeyShift && !io.KeyAlt && is_editable) + { + unsigned int c = '\t'; // Insert TAB + if (InputTextFilterCharacter(&c, flags, callback, user_data)) + edit_state.OnKeyPressed((int)c); + } + else if (IsKeyPressedMap(ImGuiKey_Escape)) { clear_active_id = cancel_edit = true; } + else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Z) && is_editable && is_undoable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); edit_state.ClearSelection(); } + else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Y) && is_editable && is_undoable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); edit_state.ClearSelection(); } + else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); edit_state.CursorFollow = true; } + else if (is_shortcut_key_only && !is_password && ((IsKeyPressedMap(ImGuiKey_X) && is_editable) || IsKeyPressedMap(ImGuiKey_C)) && (!is_multiline || edit_state.HasSelection())) + { + // Cut, Copy + const bool cut = IsKeyPressedMap(ImGuiKey_X); + if (cut && !edit_state.HasSelection()) + edit_state.SelectAll(); + + if (io.SetClipboardTextFn) + { + const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0; + const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW; + edit_state.TempTextBuffer.resize((ie-ib) * 4 + 1); + ImTextStrToUtf8(edit_state.TempTextBuffer.Data, edit_state.TempTextBuffer.Size, edit_state.Text.Data+ib, edit_state.Text.Data+ie); + SetClipboardText(edit_state.TempTextBuffer.Data); + } + + if (cut) + { + edit_state.CursorFollow = true; + stb_textedit_cut(&edit_state, &edit_state.StbState); + } + } + else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_V) && is_editable) + { + // Paste + if (const char* clipboard = GetClipboardText()) + { + // Filter pasted buffer + const int clipboard_len = (int)strlen(clipboard); + ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar)); + int clipboard_filtered_len = 0; + for (const char* s = clipboard; *s; ) + { + unsigned int c; + s += ImTextCharFromUtf8(&c, s, NULL); + if (c == 0) + break; + if (c >= 0x10000 || !InputTextFilterCharacter(&c, flags, callback, user_data)) + continue; + clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; + } + clipboard_filtered[clipboard_filtered_len] = 0; + if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation + { + stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); + edit_state.CursorFollow = true; + } + ImGui::MemFree(clipboard_filtered); + } + } + } + + if (g.ActiveId == id) + { + if (cancel_edit) + { + // Restore initial value + if (is_editable) + { + ImStrncpy(buf, edit_state.InitialText.Data, buf_size); + value_changed = true; + } + } + + // When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame. + // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. Also this allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage. + bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); + if (apply_edit_back_to_user_buffer) + { + // Apply new value immediately - copy modified buffer back + // Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer + // FIXME: We actually always render 'buf' when calling DrawList->AddText, making the comment above incorrect. + // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks. + if (is_editable) + { + edit_state.TempTextBuffer.resize(edit_state.Text.Size * 4); + ImTextStrToUtf8(edit_state.TempTextBuffer.Data, edit_state.TempTextBuffer.Size, edit_state.Text.Data, NULL); + } + + // User callback + if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0) + { + IM_ASSERT(callback != NULL); + + // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment. + ImGuiInputTextFlags event_flag = 0; + ImGuiKey event_key = ImGuiKey_COUNT; + if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab)) + { + event_flag = ImGuiInputTextFlags_CallbackCompletion; + event_key = ImGuiKey_Tab; + } + else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow)) + { + event_flag = ImGuiInputTextFlags_CallbackHistory; + event_key = ImGuiKey_UpArrow; + } + else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow)) + { + event_flag = ImGuiInputTextFlags_CallbackHistory; + event_key = ImGuiKey_DownArrow; + } + else if (flags & ImGuiInputTextFlags_CallbackAlways) + event_flag = ImGuiInputTextFlags_CallbackAlways; + + if (event_flag) + { + ImGuiTextEditCallbackData callback_data; + memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData)); + callback_data.EventFlag = event_flag; + callback_data.Flags = flags; + callback_data.UserData = user_data; + callback_data.ReadOnly = !is_editable; + + callback_data.EventKey = event_key; + callback_data.Buf = edit_state.TempTextBuffer.Data; + callback_data.BufTextLen = edit_state.CurLenA; + callback_data.BufSize = edit_state.BufSizeA; + callback_data.BufDirty = false; + + // We have to convert from wchar-positions to UTF-8-positions, which can be pretty slow (an incentive to ditch the ImWchar buffer, see https://github.com/nothings/stb/issues/188) + ImWchar* text = edit_state.Text.Data; + const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.cursor); + const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.select_start); + const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(text, text + edit_state.StbState.select_end); + + // Call user code + callback(&callback_data); + + // Read back what user may have modified + IM_ASSERT(callback_data.Buf == edit_state.TempTextBuffer.Data); // Invalid to modify those fields + IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA); + IM_ASSERT(callback_data.Flags == flags); + if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos); + if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart); + if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd); + if (callback_data.BufDirty) + { + IM_ASSERT(callback_data.BufTextLen == (int)strlen(callback_data.Buf)); // You need to maintain BufTextLen if you change the text! + edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.Data, edit_state.Text.Size, callback_data.Buf, NULL); + edit_state.CurLenA = callback_data.BufTextLen; // Assume correct length and valid UTF-8 from user, saves us an extra strlen() + edit_state.CursorAnimReset(); + } + } + } + + // Copy back to user buffer + if (is_editable && strcmp(edit_state.TempTextBuffer.Data, buf) != 0) + { + ImStrncpy(buf, edit_state.TempTextBuffer.Data, buf_size); + value_changed = true; + } + } + } + + // Release active ID at the end of the function (so e.g. pressing Return still does a final application of the value) + if (clear_active_id && g.ActiveId == id) + ClearActiveID(); + + // Render + // Select which buffer we are going to display. When ImGuiInputTextFlags_NoLiveEdit is set 'buf' might still be the old value. We set buf to NULL to prevent accidental usage from now on. + const char* buf_display = (g.ActiveId == id && is_editable) ? edit_state.TempTextBuffer.Data : buf; buf = NULL; + + if (!is_multiline) + RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); + + const ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size + ImVec2 render_pos = is_multiline ? draw_window->DC.CursorPos : frame_bb.Min + style.FramePadding; + ImVec2 text_size(0.f, 0.f); + const bool is_currently_scrolling = (edit_state.Id == id && is_multiline && g.ActiveId == draw_window->GetIDNoKeepAlive("#SCROLLY")); + if (g.ActiveId == id || is_currently_scrolling) + { + edit_state.CursorAnim += io.DeltaTime; + + // This is going to be messy. We need to: + // - Display the text (this alone can be more easily clipped) + // - Handle scrolling, highlight selection, display cursor (those all requires some form of 1d->2d cursor position calculation) + // - Measure text height (for scrollbar) + // We are attempting to do most of that in **one main pass** to minimize the computation cost (non-negligible for large amount of text) + 2nd pass for selection rendering (we could merge them by an extra refactoring effort) + // FIXME: This should occur on buf_display but we'd need to maintain cursor/select_start/select_end for UTF-8. + const ImWchar* text_begin = edit_state.Text.Data; + ImVec2 cursor_offset, select_start_offset; + + { + // Count lines + find lines numbers straddling 'cursor' and 'select_start' position. + const ImWchar* searches_input_ptr[2]; + searches_input_ptr[0] = text_begin + edit_state.StbState.cursor; + searches_input_ptr[1] = NULL; + int searches_remaining = 1; + int searches_result_line_number[2] = { -1, -999 }; + if (edit_state.StbState.select_start != edit_state.StbState.select_end) + { + searches_input_ptr[1] = text_begin + ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end); + searches_result_line_number[1] = -1; + searches_remaining++; + } + + // Iterate all lines to find our line numbers + // In multi-line mode, we never exit the loop until all lines are counted, so add one extra to the searches_remaining counter. + searches_remaining += is_multiline ? 1 : 0; + int line_count = 0; + for (const ImWchar* s = text_begin; *s != 0; s++) + if (*s == '\n') + { + line_count++; + if (searches_result_line_number[0] == -1 && s >= searches_input_ptr[0]) { searches_result_line_number[0] = line_count; if (--searches_remaining <= 0) break; } + if (searches_result_line_number[1] == -1 && s >= searches_input_ptr[1]) { searches_result_line_number[1] = line_count; if (--searches_remaining <= 0) break; } + } + line_count++; + if (searches_result_line_number[0] == -1) searches_result_line_number[0] = line_count; + if (searches_result_line_number[1] == -1) searches_result_line_number[1] = line_count; + + // Calculate 2d position by finding the beginning of the line and measuring distance + cursor_offset.x = InputTextCalcTextSizeW(ImStrbolW(searches_input_ptr[0], text_begin), searches_input_ptr[0]).x; + cursor_offset.y = searches_result_line_number[0] * g.FontSize; + if (searches_result_line_number[1] >= 0) + { + select_start_offset.x = InputTextCalcTextSizeW(ImStrbolW(searches_input_ptr[1], text_begin), searches_input_ptr[1]).x; + select_start_offset.y = searches_result_line_number[1] * g.FontSize; + } + + // Store text height (note that we haven't calculated text width at all, see GitHub issues #383, #1224) + if (is_multiline) + text_size = ImVec2(size.x, line_count * g.FontSize); + } + + // Scroll + if (edit_state.CursorFollow) + { + // Horizontal scroll in chunks of quarter width + if (!(flags & ImGuiInputTextFlags_NoHorizontalScroll)) + { + const float scroll_increment_x = size.x * 0.25f; + if (cursor_offset.x < edit_state.ScrollX) + edit_state.ScrollX = (float)(int)ImMax(0.0f, cursor_offset.x - scroll_increment_x); + else if (cursor_offset.x - size.x >= edit_state.ScrollX) + edit_state.ScrollX = (float)(int)(cursor_offset.x - size.x + scroll_increment_x); + } + else + { + edit_state.ScrollX = 0.0f; + } + + // Vertical scroll + if (is_multiline) + { + float scroll_y = draw_window->Scroll.y; + if (cursor_offset.y - g.FontSize < scroll_y) + scroll_y = ImMax(0.0f, cursor_offset.y - g.FontSize); + else if (cursor_offset.y - size.y >= scroll_y) + scroll_y = cursor_offset.y - size.y; + draw_window->DC.CursorPos.y += (draw_window->Scroll.y - scroll_y); // To avoid a frame of lag + draw_window->Scroll.y = scroll_y; + render_pos.y = draw_window->DC.CursorPos.y; + } + } + edit_state.CursorFollow = false; + const ImVec2 render_scroll = ImVec2(edit_state.ScrollX, 0.0f); + + // Draw selection + if (edit_state.StbState.select_start != edit_state.StbState.select_end) + { + const ImWchar* text_selected_begin = text_begin + ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end); + const ImWchar* text_selected_end = text_begin + ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end); + + float bg_offy_up = is_multiline ? 0.0f : -1.0f; // FIXME: those offsets should be part of the style? they don't play so well with multi-line selection. + float bg_offy_dn = is_multiline ? 0.0f : 2.0f; + ImU32 bg_color = GetColorU32(ImGuiCol_TextSelectedBg); + ImVec2 rect_pos = render_pos + select_start_offset - render_scroll; + for (const ImWchar* p = text_selected_begin; p < text_selected_end; ) + { + if (rect_pos.y > clip_rect.w + g.FontSize) + break; + if (rect_pos.y < clip_rect.y) + { + while (p < text_selected_end) + if (*p++ == '\n') + break; + } + else + { + ImVec2 rect_size = InputTextCalcTextSizeW(p, text_selected_end, &p, NULL, true); + if (rect_size.x <= 0.0f) rect_size.x = (float)(int)(g.Font->GetCharAdvance((unsigned short)' ') * 0.50f); // So we can see selected empty lines + ImRect rect(rect_pos + ImVec2(0.0f, bg_offy_up - g.FontSize), rect_pos +ImVec2(rect_size.x, bg_offy_dn)); + rect.ClipWith(clip_rect); + if (rect.Overlaps(clip_rect)) + draw_window->DrawList->AddRectFilled(rect.Min, rect.Max, bg_color); + } + rect_pos.x = render_pos.x - render_scroll.x; + rect_pos.y += g.FontSize; + } + } + + draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos - render_scroll, GetColorU32(ImGuiCol_Text), buf_display, buf_display + edit_state.CurLenA, 0.0f, is_multiline ? NULL : &clip_rect); + + // Draw blinking cursor + bool cursor_is_visible = (!g.IO.OptCursorBlink) || (g.InputTextState.CursorAnim <= 0.0f) || fmodf(g.InputTextState.CursorAnim, 1.20f) <= 0.80f; + ImVec2 cursor_screen_pos = render_pos + cursor_offset - render_scroll; + ImRect cursor_screen_rect(cursor_screen_pos.x, cursor_screen_pos.y-g.FontSize+0.5f, cursor_screen_pos.x+1.0f, cursor_screen_pos.y-1.5f); + if (cursor_is_visible && cursor_screen_rect.Overlaps(clip_rect)) + draw_window->DrawList->AddLine(cursor_screen_rect.Min, cursor_screen_rect.GetBL(), GetColorU32(ImGuiCol_Text)); + + // Notify OS of text input position for advanced IME (-1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.) + if (is_editable) + g.OsImePosRequest = ImVec2(cursor_screen_pos.x - 1, cursor_screen_pos.y - g.FontSize); + } + else + { + // Render text only + const char* buf_end = NULL; + if (is_multiline) + text_size = ImVec2(size.x, InputTextCalcTextLenAndLineCount(buf_display, &buf_end) * g.FontSize); // We don't need width + draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos, GetColorU32(ImGuiCol_Text), buf_display, buf_end, 0.0f, is_multiline ? NULL : &clip_rect); + } + + if (is_multiline) + { + Dummy(text_size + ImVec2(0.0f, g.FontSize)); // Always add room to scroll an extra line + EndChildFrame(); + EndGroup(); + } + + if (is_password) + PopFont(); + + // Log as text + if (g.LogEnabled && !is_password) + LogRenderedText(&render_pos, buf_display, NULL); + + if (label_size.x > 0) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + + if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0) + return enter_pressed; + else + return value_changed; +} + +bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) +{ + IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline() + return InputTextEx(label, buf, (int)buf_size, ImVec2(0,0), flags, callback, user_data); +} + +bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) +{ + return InputTextEx(label, buf, (int)buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data); +} + +// NB: scalar_format here must be a simple "%xx" format string with no prefix/suffix (unlike the Drag/Slider functions "display_format" argument) +bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + BeginGroup(); + PushID(label); + const ImVec2 button_sz = ImVec2(GetFrameHeight(), GetFrameHeight()); + if (step_ptr) + PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_sz.x + style.ItemInnerSpacing.x)*2)); + + char buf[64]; + DataTypeFormatString(data_type, data_ptr, scalar_format, buf, IM_ARRAYSIZE(buf)); + + bool value_changed = false; + if (!(extra_flags & ImGuiInputTextFlags_CharsHexadecimal)) + extra_flags |= ImGuiInputTextFlags_CharsDecimal; + extra_flags |= ImGuiInputTextFlags_AutoSelectAll; + if (InputText("", buf, IM_ARRAYSIZE(buf), extra_flags)) // PushId(label) + "" gives us the expected ID from outside point of view + value_changed = DataTypeApplyOpFromText(buf, GImGui->InputTextState.InitialText.begin(), data_type, data_ptr, scalar_format); + + // Step buttons + if (step_ptr) + { + PopItemWidth(); + SameLine(0, style.ItemInnerSpacing.x); + if (ButtonEx("-", button_sz, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups)) + { + DataTypeApplyOp(data_type, '-', data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr); + value_changed = true; + } + SameLine(0, style.ItemInnerSpacing.x); + if (ButtonEx("+", button_sz, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups)) + { + DataTypeApplyOp(data_type, '+', data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr); + value_changed = true; + } + } + PopID(); + + if (label_size.x > 0) + { + SameLine(0, style.ItemInnerSpacing.x); + RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label); + ItemSize(label_size, style.FramePadding.y); + } + EndGroup(); + + return value_changed; +} + +bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + char display_format[16]; + if (decimal_precision < 0) + strcpy(display_format, "%f"); // Ideally we'd have a minimum decimal precision of 1 to visually denote that this is a float, while hiding non-significant digits? %f doesn't have a minimum of 1 + else + ImFormatString(display_format, IM_ARRAYSIZE(display_format), "%%.%df", decimal_precision); + return InputScalarEx(label, ImGuiDataType_Float, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), display_format, extra_flags); +} + +bool ImGui::InputInt(const char* label, int* v, int step, int step_fast, ImGuiInputTextFlags extra_flags) +{ + // Hexadecimal input provided as a convenience but the flag name is awkward. Typically you'd use InputText() to parse your own data, if you want to handle prefixes. + const char* scalar_format = (extra_flags & ImGuiInputTextFlags_CharsHexadecimal) ? "%08X" : "%d"; + return InputScalarEx(label, ImGuiDataType_Int, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), scalar_format, extra_flags); +} + +bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + bool value_changed = false; + BeginGroup(); + PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + PushID(i); + value_changed |= InputFloat("##v", &v[i], 0, 0, decimal_precision, extra_flags); + SameLine(0, g.Style.ItemInnerSpacing.x); + PopID(); + PopItemWidth(); + } + PopID(); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + + return value_changed; +} + +bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return InputFloatN(label, v, 2, decimal_precision, extra_flags); +} + +bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return InputFloatN(label, v, 3, decimal_precision, extra_flags); +} + +bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return InputFloatN(label, v, 4, decimal_precision, extra_flags); +} + +bool ImGui::InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + bool value_changed = false; + BeginGroup(); + PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + PushID(i); + value_changed |= InputInt("##v", &v[i], 0, 0, extra_flags); + SameLine(0, g.Style.ItemInnerSpacing.x); + PopID(); + PopItemWidth(); + } + PopID(); + + TextUnformatted(label, FindRenderedTextEnd(label)); + EndGroup(); + + return value_changed; +} + +bool ImGui::InputInt2(const char* label, int v[2], ImGuiInputTextFlags extra_flags) +{ + return InputIntN(label, v, 2, extra_flags); +} + +bool ImGui::InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags) +{ + return InputIntN(label, v, 3, extra_flags); +} + +bool ImGui::InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags) +{ + return InputIntN(label, v, 4, extra_flags); +} + +static float CalcMaxPopupHeightFromItemCount(int items_count) +{ + ImGuiContext& g = *GImGui; + if (items_count <= 0) + return FLT_MAX; + return (g.FontSize + g.Style.ItemSpacing.y) * items_count - g.Style.ItemSpacing.y + (g.Style.WindowPadding.y * 2); +} + +bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags) +{ + // Always consume the SetNextWindowSizeConstraint() call in our early return paths + ImGuiContext& g = *GImGui; + bool backup_has_next_window_size_constraint = g.SetNextWindowSizeConstraint; + g.SetNextWindowSizeConstraint = false; + + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w = CalcItemWidth(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f)); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, id)) + return false; + + bool hovered, held; + bool pressed = ButtonBehavior(frame_bb, id, &hovered, &held); + bool popup_open = IsPopupOpen(id); + + const float arrow_size = GetFrameHeight(); + const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f)); + RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); + RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, GetColorU32(popup_open || hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING + RenderTriangle(ImVec2(frame_bb.Max.x - arrow_size + style.FramePadding.y, frame_bb.Min.y + style.FramePadding.y), ImGuiDir_Down); + if (preview_value != NULL) + RenderTextClipped(frame_bb.Min + style.FramePadding, value_bb.Max, preview_value, NULL, NULL, ImVec2(0.0f,0.0f)); + if (label_size.x > 0) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + + if (pressed && !popup_open) + { + OpenPopupEx(id, false); + popup_open = true; + } + + if (!popup_open) + return false; + + if (backup_has_next_window_size_constraint) + { + g.SetNextWindowSizeConstraint = true; + g.SetNextWindowSizeConstraintRect.Min.x = ImMax(g.SetNextWindowSizeConstraintRect.Min.x, w); + } + else + { + if ((flags & ImGuiComboFlags_HeightMask_) == 0) + flags |= ImGuiComboFlags_HeightRegular; + IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiComboFlags_HeightMask_)); // Only one + int popup_max_height_in_items = -1; + if (flags & ImGuiComboFlags_HeightRegular) popup_max_height_in_items = 8; + else if (flags & ImGuiComboFlags_HeightSmall) popup_max_height_in_items = 4; + else if (flags & ImGuiComboFlags_HeightLarge) popup_max_height_in_items = 20; + SetNextWindowSizeConstraints(ImVec2(w, 0.0f), ImVec2(FLT_MAX, CalcMaxPopupHeightFromItemCount(popup_max_height_in_items))); + } + + char name[16]; + ImFormatString(name, IM_ARRAYSIZE(name), "##Combo_%02d", g.CurrentPopupStack.Size); // Recycle windows based on depth + + // Peak into expected window size so we can position it + if (ImGuiWindow* popup_window = FindWindowByName(name)) + { + ImVec2 size_contents = CalcSizeContents(popup_window); + ImVec2 size_expected = CalcSizeAfterConstraint(popup_window, CalcSizeAutoFit(popup_window, size_contents)); + if (flags & ImGuiComboFlags_PopupAlignLeft) + popup_window->AutoPosLastDirection = ImGuiDir_Left; + ImVec2 pos = FindBestWindowPosForPopup(frame_bb.GetBL(), size_expected, &popup_window->AutoPosLastDirection, frame_bb, ImGuiPopupPositionPolicy_ComboBox); + SetNextWindowPos(pos); + } + + ImGuiWindowFlags window_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings; + if (!Begin(name, NULL, window_flags)) + { + EndPopup(); + IM_ASSERT(0); // This should never happen as we tested for IsPopupOpen() above + return false; + } + + // Horizontally align ourselves with the framed text + if (style.FramePadding.x != style.WindowPadding.x) + Indent(style.FramePadding.x - style.WindowPadding.x); + + return true; +} + +void ImGui::EndCombo() +{ + const ImGuiStyle& style = GImGui->Style; + if (style.FramePadding.x != style.WindowPadding.x) + Unindent(style.FramePadding.x - style.WindowPadding.x); + EndPopup(); +} + +// Old API, prefer using BeginCombo() nowadays if you can. +bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_max_height_in_items) +{ + ImGuiContext& g = *GImGui; + + const char* preview_text = NULL; + if (*current_item >= 0 && *current_item < items_count) + items_getter(data, *current_item, &preview_text); + + // The old Combo() API exposed "popup_max_height_in_items", however the new more general BeginCombo() API doesn't, so we emulate it here. + if (popup_max_height_in_items != -1 && !g.SetNextWindowSizeConstraint) + { + float popup_max_height = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); + SetNextWindowSizeConstraints(ImVec2(0,0), ImVec2(FLT_MAX, popup_max_height)); + } + + if (!BeginCombo(label, preview_text, 0)) + return false; + + // Display items + // FIXME-OPT: Use clipper (but we need to disable it on the appearing frame to make sure our call to SetItemDefaultFocus() is processed) + bool value_changed = false; + for (int i = 0; i < items_count; i++) + { + PushID((void*)(intptr_t)i); + const bool item_selected = (i == *current_item); + const char* item_text; + if (!items_getter(data, i, &item_text)) + item_text = "*Unknown item*"; + if (Selectable(item_text, item_selected)) + { + value_changed = true; + *current_item = i; + } + if (item_selected) + SetItemDefaultFocus(); + PopID(); + } + + EndCombo(); + return value_changed; +} + +static bool Items_ArrayGetter(void* data, int idx, const char** out_text) +{ + const char* const* items = (const char* const*)data; + if (out_text) + *out_text = items[idx]; + return true; +} + +static bool Items_SingleStringGetter(void* data, int idx, const char** out_text) +{ + // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited. + const char* items_separated_by_zeros = (const char*)data; + int items_count = 0; + const char* p = items_separated_by_zeros; + while (*p) + { + if (idx == items_count) + break; + p += strlen(p) + 1; + items_count++; + } + if (!*p) + return false; + if (out_text) + *out_text = p; + return true; +} + +// Combo box helper allowing to pass an array of strings. +bool ImGui::Combo(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items) +{ + const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items); + return value_changed; +} + +// Combo box helper allowing to pass all items in a single string. +bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items) +{ + int items_count = 0; + const char* p = items_separated_by_zeros; // FIXME-OPT: Avoid computing this, or at least only when combo is open + while (*p) + { + p += strlen(p) + 1; + items_count++; + } + bool value_changed = Combo(label, current_item, Items_SingleStringGetter, (void*)items_separated_by_zeros, items_count, height_in_items); + return value_changed; +} + +// Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image. +// But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID. +bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsSet) // FIXME-OPT: Avoid if vertically clipped. + PopClipRect(); + + ImGuiID id = window->GetID(label); + ImVec2 label_size = CalcTextSize(label, NULL, true); + ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); + ImVec2 pos = window->DC.CursorPos; + pos.y += window->DC.CurrentLineTextBaseOffset; + ImRect bb(pos, pos + size); + ItemSize(bb); + + // Fill horizontal space. + ImVec2 window_padding = window->WindowPadding; + float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x : GetContentRegionMax().x; + float w_draw = ImMax(label_size.x, window->Pos.x + max_x - window_padding.x - window->DC.CursorPos.x); + ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size_arg.y != 0.0f ? size_arg.y : size.y); + ImRect bb_with_spacing(pos, pos + size_draw); + if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth)) + bb_with_spacing.Max.x += window_padding.x; + + // Selectables are tightly packed together, we extend the box to cover spacing between selectable. + float spacing_L = (float)(int)(style.ItemSpacing.x * 0.5f); + float spacing_U = (float)(int)(style.ItemSpacing.y * 0.5f); + float spacing_R = style.ItemSpacing.x - spacing_L; + float spacing_D = style.ItemSpacing.y - spacing_U; + bb_with_spacing.Min.x -= spacing_L; + bb_with_spacing.Min.y -= spacing_U; + bb_with_spacing.Max.x += spacing_R; + bb_with_spacing.Max.y += spacing_D; + if (!ItemAdd(bb_with_spacing, id)) + { + if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsSet) + PushColumnClipRect(); + return false; + } + + ImGuiButtonFlags button_flags = 0; + if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_NoHoldingActiveID; + if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnRelease; + if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled; + if (flags & ImGuiSelectableFlags_AllowDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; + bool hovered, held; + bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, button_flags); + if (flags & ImGuiSelectableFlags_Disabled) + selected = false; + + // Render + if (hovered || selected) + { + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); + RenderFrame(bb_with_spacing.Min, bb_with_spacing.Max, col, false, 0.0f); + } + + if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsSet) + { + PushColumnClipRect(); + bb_with_spacing.Max.x -= (GetContentRegionMax().x - max_x); + } + + if (flags & ImGuiSelectableFlags_Disabled) PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); + RenderTextClipped(bb.Min, bb_with_spacing.Max, label, NULL, &label_size, ImVec2(0.0f,0.0f)); + if (flags & ImGuiSelectableFlags_Disabled) PopStyleColor(); + + // Automatically close popups + if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(window->DC.ItemFlags & ImGuiItemFlags_SelectableDontClosePopup)) + CloseCurrentPopup(); + return pressed; +} + +bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags, const ImVec2& size_arg) +{ + if (Selectable(label, *p_selected, flags, size_arg)) + { + *p_selected = !*p_selected; + return true; + } + return false; +} + +// Helper to calculate the size of a listbox and display a label on the right. +// Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an empty label "##empty" +bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = GetStyle(); + const ImGuiID id = GetID(label); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar. + ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y); + ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y)); + ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); + ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + window->DC.LastItemRect = bb; + + BeginGroup(); + if (label_size.x > 0) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + + BeginChildFrame(id, frame_bb.GetSize()); + return true; +} + +bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_items) +{ + // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar. + // However we don't add +0.40f if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size. + // I am expecting that someone will come and complain about this behavior in a remote future, then we can advise on a better solution. + if (height_in_items < 0) + height_in_items = ImMin(items_count, 7); + float height_in_items_f = height_in_items < items_count ? (height_in_items + 0.40f) : (height_in_items + 0.00f); + + // We include ItemSpacing.y so that a list sized for the exact number of items doesn't make a scrollbar appears. We could also enforce that by passing a flag to BeginChild(). + ImVec2 size; + size.x = 0.0f; + size.y = GetTextLineHeightWithSpacing() * height_in_items_f + GetStyle().ItemSpacing.y; + return ListBoxHeader(label, size); +} + +void ImGui::ListBoxFooter() +{ + ImGuiWindow* parent_window = GetCurrentWindow()->ParentWindow; + const ImRect bb = parent_window->DC.LastItemRect; + const ImGuiStyle& style = GetStyle(); + + EndChildFrame(); + + // Redeclare item size so that it includes the label (we have stored the full size in LastItemRect) + // We call SameLine() to restore DC.CurrentLine* data + SameLine(); + parent_window->DC.CursorPos = bb.Min; + ItemSize(bb, style.FramePadding.y); + EndGroup(); +} + +bool ImGui::ListBox(const char* label, int* current_item, const char* const* items, int items_count, int height_items) +{ + const bool value_changed = ListBox(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_items); + return value_changed; +} + +bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items) +{ + if (!ListBoxHeader(label, items_count, height_in_items)) + return false; + + // Assume all items have even height (= 1 line of text). If you need items of different or variable sizes you can create a custom version of ListBox() in your code without using the clipper. + bool value_changed = false; + ImGuiListClipper clipper(items_count, GetTextLineHeightWithSpacing()); // We know exactly our line height here so we pass it as a minor optimization, but generally you don't need to. + while (clipper.Step()) + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) + { + const bool item_selected = (i == *current_item); + const char* item_text; + if (!items_getter(data, i, &item_text)) + item_text = "*Unknown item*"; + + PushID(i); + if (Selectable(item_text, item_selected)) + { + *current_item = i; + value_changed = true; + } + PopID(); + } + ListBoxFooter(); + return value_changed; +} + +bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, bool enabled) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + ImGuiStyle& style = g.Style; + ImVec2 pos = window->DC.CursorPos; + ImVec2 label_size = CalcTextSize(label, NULL, true); + + ImGuiSelectableFlags flags = ImGuiSelectableFlags_MenuItem | (enabled ? 0 : ImGuiSelectableFlags_Disabled); + bool pressed; + if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) + { + // Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful + // Note that in this situation we render neither the shortcut neither the selected tick mark + float w = label_size.x; + window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); + PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f); + pressed = Selectable(label, false, flags, ImVec2(w, 0.0f)); + PopStyleVar(); + window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). + } + else + { + ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f); + float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame + float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); + pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(w, 0.0f)); + if (shortcut_size.x > 0.0f) + { + PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); + RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false); + PopStyleColor(); + } + if (selected) + RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); + } + return pressed; +} + +bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled) +{ + if (MenuItem(label, shortcut, p_selected ? *p_selected : false, enabled)) + { + if (p_selected) + *p_selected = !*p_selected; + return true; + } + return false; +} + +bool ImGui::BeginMainMenuBar() +{ + ImGuiContext& g = *GImGui; + SetNextWindowPos(ImVec2(0.0f, 0.0f)); + SetNextWindowSize(ImVec2(g.IO.DisplaySize.x, g.FontBaseSize + g.Style.FramePadding.y * 2.0f)); + PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0)); + if (!Begin("##MainMenuBar", NULL, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_MenuBar) + || !BeginMenuBar()) + { + End(); + PopStyleVar(2); + return false; + } + g.CurrentWindow->DC.MenuBarOffsetX += g.Style.DisplaySafeAreaPadding.x; + return true; +} + +void ImGui::EndMainMenuBar() +{ + EndMenuBar(); + End(); + PopStyleVar(2); +} + +bool ImGui::BeginMenuBar() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + if (!(window->Flags & ImGuiWindowFlags_MenuBar)) + return false; + + IM_ASSERT(!window->DC.MenuBarAppending); + BeginGroup(); // Save position + PushID("##menubar"); + + // We don't clip with regular window clipping rectangle as it is already set to the area below. However we clip with window full rect. + // We remove 1 worth of rounding to Max.x to that text in long menus don't tend to display over the lower-right rounded area, which looks particularly glitchy. + ImRect bar_rect = window->MenuBarRect(); + ImRect clip_rect(ImFloor(bar_rect.Min.x + 0.5f), ImFloor(bar_rect.Min.y + window->WindowBorderSize + 0.5f), ImFloor(ImMax(bar_rect.Min.x, bar_rect.Max.x - window->WindowRounding) + 0.5f), ImFloor(bar_rect.Max.y + 0.5f)); + clip_rect.ClipWith(window->Rect()); + PushClipRect(clip_rect.Min, clip_rect.Max, false); + + window->DC.CursorPos = ImVec2(bar_rect.Min.x + window->DC.MenuBarOffsetX, bar_rect.Min.y);// + g.Style.FramePadding.y); + window->DC.LayoutType = ImGuiLayoutType_Horizontal; + window->DC.MenuBarAppending = true; + AlignTextToFramePadding(); + return true; +} + +void ImGui::EndMenuBar() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + IM_ASSERT(window->Flags & ImGuiWindowFlags_MenuBar); + IM_ASSERT(window->DC.MenuBarAppending); + PopClipRect(); + PopID(); + window->DC.MenuBarOffsetX = window->DC.CursorPos.x - window->MenuBarRect().Min.x; + window->DC.GroupStack.back().AdvanceCursor = false; + EndGroup(); + window->DC.LayoutType = ImGuiLayoutType_Vertical; + window->DC.MenuBarAppending = false; +} + +bool ImGui::BeginMenu(const char* label, bool enabled) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + + ImVec2 label_size = CalcTextSize(label, NULL, true); + + bool pressed; + bool menu_is_open = IsPopupOpen(id); + bool menuset_is_open = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].ParentMenuSet == window->GetID("##Menus")); + ImGuiWindow* backed_nav_window = g.NavWindow; + if (menuset_is_open) + g.NavWindow = window; // Odd hack to allow hovering across menus of a same menu-set (otherwise we wouldn't be able to hover parent) + + // The reference position stored in popup_pos will be used by Begin() to find a suitable position for the child menu (using FindBestPopupWindowPos). + ImVec2 popup_pos, pos = window->DC.CursorPos; + if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) + { + // Menu inside an horizontal menu bar + // Selectable extend their highlight by half ItemSpacing in each direction. + // For ChildMenu, the popup position will be overwritten by the call to FindBestPopupWindowPos() in Begin() + popup_pos = ImVec2(pos.x - window->WindowPadding.x, pos.y - style.FramePadding.y + window->MenuBarHeight()); + window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); + PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f); + float w = label_size.x; + pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + PopStyleVar(); + window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). + } + else + { + // Menu inside a menu + popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); + float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, (float)(int)(g.FontSize * 1.20f)); // Feedback to next frame + float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); + pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + if (!enabled) PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); + RenderTriangle(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), ImGuiDir_Right); + if (!enabled) PopStyleColor(); + } + + const bool hovered = enabled && ItemHoverable(window->DC.LastItemRect, id); + if (menuset_is_open) + g.NavWindow = backed_nav_window; + + bool want_open = false, want_close = false; + if (window->DC.LayoutType != ImGuiLayoutType_Horizontal) // (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) + { + // Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers, so menus feels more reactive. + bool moving_within_opened_triangle = false; + if (g.HoveredWindow == window && g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].ParentWindow == window) + { + if (ImGuiWindow* next_window = g.OpenPopupStack[g.CurrentPopupStack.Size].Window) + { + ImRect next_window_rect = next_window->Rect(); + ImVec2 ta = g.IO.MousePos - g.IO.MouseDelta; + ImVec2 tb = (window->Pos.x < next_window->Pos.x) ? next_window_rect.GetTL() : next_window_rect.GetTR(); + ImVec2 tc = (window->Pos.x < next_window->Pos.x) ? next_window_rect.GetBL() : next_window_rect.GetBR(); + float extra = ImClamp(fabsf(ta.x - tb.x) * 0.30f, 5.0f, 30.0f); // add a bit of extra slack. + ta.x += (window->Pos.x < next_window->Pos.x) ? -0.5f : +0.5f; // to avoid numerical issues + tb.y = ta.y + ImMax((tb.y - extra) - ta.y, -100.0f); // triangle is maximum 200 high to limit the slope and the bias toward large sub-menus // FIXME: Multiply by fb_scale? + tc.y = ta.y + ImMin((tc.y + extra) - ta.y, +100.0f); + moving_within_opened_triangle = ImTriangleContainsPoint(ta, tb, tc, g.IO.MousePos); + //window->DrawList->PushClipRectFullScreen(); window->DrawList->AddTriangleFilled(ta, tb, tc, moving_within_opened_triangle ? IM_COL32(0,128,0,128) : IM_COL32(128,0,0,128)); window->DrawList->PopClipRect(); // Debug + } + } + + want_close = (menu_is_open && !hovered && g.HoveredWindow == window && g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrame != id && !moving_within_opened_triangle); + want_open = (!menu_is_open && hovered && !moving_within_opened_triangle) || (!menu_is_open && hovered && pressed); + } + else + { + // Menu bar + if (menu_is_open && pressed && menuset_is_open) // Click an open menu again to close it + { + want_close = true; + want_open = menu_is_open = false; + } + else if (pressed || (hovered && menuset_is_open && !menu_is_open)) // First click to open, then hover to open others + { + want_open = true; + } + } + + if (!enabled) // explicitly close if an open menu becomes disabled, facilitate users code a lot in pattern such as 'if (BeginMenu("options", has_object)) { ..use object.. }' + want_close = true; + if (want_close && IsPopupOpen(id)) + ClosePopupToLevel(GImGui->CurrentPopupStack.Size); + + if (!menu_is_open && want_open && g.OpenPopupStack.Size > g.CurrentPopupStack.Size) + { + // Don't recycle same menu level in the same frame, first close the other menu and yield for a frame. + OpenPopup(label); + return false; + } + + menu_is_open |= want_open; + if (want_open) + OpenPopup(label); + + if (menu_is_open) + { + SetNextWindowPos(popup_pos, ImGuiCond_Always); + ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ((window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) ? ImGuiWindowFlags_ChildMenu|ImGuiWindowFlags_ChildWindow : ImGuiWindowFlags_ChildMenu); + menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) + } + + return menu_is_open; +} + +void ImGui::EndMenu() +{ + EndPopup(); +} + +// Note: only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. +void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags) +{ + ImGuiContext& g = *GImGui; + + int cr = IM_F32_TO_INT8_SAT(col[0]), cg = IM_F32_TO_INT8_SAT(col[1]), cb = IM_F32_TO_INT8_SAT(col[2]), ca = (flags & ImGuiColorEditFlags_NoAlpha) ? 255 : IM_F32_TO_INT8_SAT(col[3]); + BeginTooltipEx(0, true); + + const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text; + if (text_end > text) + { + TextUnformatted(text, text_end); + Separator(); + } + + ImVec2 sz(g.FontSize * 3 + g.Style.FramePadding.y * 2, g.FontSize * 3 + g.Style.FramePadding.y * 2); + ColorButton("##preview", ImVec4(col[0], col[1], col[2], col[3]), (flags & (ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf)) | ImGuiColorEditFlags_NoTooltip, sz); + SameLine(); + if (flags & ImGuiColorEditFlags_NoAlpha) + Text("#%02X%02X%02X\nR: %d, G: %d, B: %d\n(%.3f, %.3f, %.3f)", cr, cg, cb, cr, cg, cb, col[0], col[1], col[2]); + else + Text("#%02X%02X%02X%02X\nR:%d, G:%d, B:%d, A:%d\n(%.3f, %.3f, %.3f, %.3f)", cr, cg, cb, ca, cr, cg, cb, ca, col[0], col[1], col[2], col[3]); + EndTooltip(); +} + +static inline ImU32 ImAlphaBlendColor(ImU32 col_a, ImU32 col_b) +{ + float t = ((col_b >> IM_COL32_A_SHIFT) & 0xFF) / 255.f; + int r = ImLerp((int)(col_a >> IM_COL32_R_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_R_SHIFT) & 0xFF, t); + int g = ImLerp((int)(col_a >> IM_COL32_G_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_G_SHIFT) & 0xFF, t); + int b = ImLerp((int)(col_a >> IM_COL32_B_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_B_SHIFT) & 0xFF, t); + return IM_COL32(r, g, b, 0xFF); +} + +// NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that. +// I spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding alltogether. +void ImGui::RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, ImVec2 grid_off, float rounding, int rounding_corners_flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF) + { + ImU32 col_bg1 = GetColorU32(ImAlphaBlendColor(IM_COL32(204,204,204,255), col)); + ImU32 col_bg2 = GetColorU32(ImAlphaBlendColor(IM_COL32(128,128,128,255), col)); + window->DrawList->AddRectFilled(p_min, p_max, col_bg1, rounding, rounding_corners_flags); + + int yi = 0; + for (float y = p_min.y + grid_off.y; y < p_max.y; y += grid_step, yi++) + { + float y1 = ImClamp(y, p_min.y, p_max.y), y2 = ImMin(y + grid_step, p_max.y); + if (y2 <= y1) + continue; + for (float x = p_min.x + grid_off.x + (yi & 1) * grid_step; x < p_max.x; x += grid_step * 2.0f) + { + float x1 = ImClamp(x, p_min.x, p_max.x), x2 = ImMin(x + grid_step, p_max.x); + if (x2 <= x1) + continue; + int rounding_corners_flags_cell = 0; + if (y1 <= p_min.y) { if (x1 <= p_min.x) rounding_corners_flags_cell |= ImDrawCornerFlags_TopLeft; if (x2 >= p_max.x) rounding_corners_flags_cell |= ImDrawCornerFlags_TopRight; } + if (y2 >= p_max.y) { if (x1 <= p_min.x) rounding_corners_flags_cell |= ImDrawCornerFlags_BotLeft; if (x2 >= p_max.x) rounding_corners_flags_cell |= ImDrawCornerFlags_BotRight; } + rounding_corners_flags_cell &= rounding_corners_flags; + window->DrawList->AddRectFilled(ImVec2(x1,y1), ImVec2(x2,y2), col_bg2, rounding_corners_flags_cell ? rounding : 0.0f, rounding_corners_flags_cell); + } + } + } + else + { + window->DrawList->AddRectFilled(p_min, p_max, col, rounding, rounding_corners_flags); + } +} + +void ImGui::SetColorEditOptions(ImGuiColorEditFlags flags) +{ + ImGuiContext& g = *GImGui; + if ((flags & ImGuiColorEditFlags__InputsMask) == 0) + flags |= ImGuiColorEditFlags__OptionsDefault & ImGuiColorEditFlags__InputsMask; + if ((flags & ImGuiColorEditFlags__DataTypeMask) == 0) + flags |= ImGuiColorEditFlags__OptionsDefault & ImGuiColorEditFlags__DataTypeMask; + if ((flags & ImGuiColorEditFlags__PickerMask) == 0) + flags |= ImGuiColorEditFlags__OptionsDefault & ImGuiColorEditFlags__PickerMask; + IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags__InputsMask))); // Check only 1 option is selected + IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags__DataTypeMask))); // Check only 1 option is selected + IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags__PickerMask))); // Check only 1 option is selected + g.ColorEditOptions = flags; +} + +// A little colored square. Return true when clicked. +// FIXME: May want to display/ignore the alpha component in the color display? Yet show it in the tooltip. +// 'desc_id' is not called 'label' because we don't display it next to the button, but only in the tooltip. +bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags, ImVec2 size) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiID id = window->GetID(desc_id); + float default_size = GetFrameHeight(); + if (size.x == 0.0f) + size.x = default_size; + if (size.y == 0.0f) + size.y = default_size; + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + ItemSize(bb, (size.y >= default_size) ? g.Style.FramePadding.y : 0.0f); + if (!ItemAdd(bb, id)) + return false; + + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held); + + if (flags & ImGuiColorEditFlags_NoAlpha) + flags &= ~(ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf); + + ImVec4 col_without_alpha(col.x, col.y, col.z, 1.0f); + float grid_step = ImMin(size.x, size.y) / 2.99f; + float rounding = ImMin(g.Style.FrameRounding, grid_step * 0.5f); + ImRect bb_inner = bb; + float off = -0.75f; // The border (using Col_FrameBg) tends to look off when color is near-opaque and rounding is enabled. This offset seemed like a good middle ground to reduce those artifacts. + bb_inner.Expand(off); + if ((flags & ImGuiColorEditFlags_AlphaPreviewHalf) && col.w < 1.0f) + { + float mid_x = (float)(int)((bb_inner.Min.x + bb_inner.Max.x) * 0.5f + 0.5f); + RenderColorRectWithAlphaCheckerboard(ImVec2(bb_inner.Min.x + grid_step, bb_inner.Min.y), bb_inner.Max, GetColorU32(col), grid_step, ImVec2(-grid_step + off, off), rounding, ImDrawCornerFlags_TopRight| ImDrawCornerFlags_BotRight); + window->DrawList->AddRectFilled(bb_inner.Min, ImVec2(mid_x, bb_inner.Max.y), GetColorU32(col_without_alpha), rounding, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotLeft); + } + else + { + // Because GetColorU32() multiplies by the global style Alpha and we don't want to display a checkerboard if the source code had no alpha + ImVec4 col_source = (flags & ImGuiColorEditFlags_AlphaPreview) ? col : col_without_alpha; + if (col_source.w < 1.0f) + RenderColorRectWithAlphaCheckerboard(bb_inner.Min, bb_inner.Max, GetColorU32(col_source), grid_step, ImVec2(off, off), rounding); + else + window->DrawList->AddRectFilled(bb_inner.Min, bb_inner.Max, GetColorU32(col_source), rounding, ImDrawCornerFlags_All); + } + if (g.Style.FrameBorderSize > 0.0f) + RenderFrameBorder(bb.Min, bb.Max, rounding); + else + window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), rounding); // Color button are often in need of some sort of border + + // Drag and Drop Source + if (g.ActiveId == id && BeginDragDropSource()) // NB: The ActiveId test is merely an optional micro-optimization + { + if (flags & ImGuiColorEditFlags_NoAlpha) + SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F, &col, sizeof(float) * 3, ImGuiCond_Once); + else + SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F, &col, sizeof(float) * 4, ImGuiCond_Once); + ColorButton(desc_id, col, flags); + SameLine(); + TextUnformatted("Color"); + EndDragDropSource(); + hovered = false; + } + + // Tooltip + if (!(flags & ImGuiColorEditFlags_NoTooltip) && hovered) + ColorTooltip(desc_id, &col.x, flags & (ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf)); + + return pressed; +} + +bool ImGui::ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags) +{ + return ColorEdit4(label, col, flags | ImGuiColorEditFlags_NoAlpha); +} + +void ImGui::ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags) +{ + bool allow_opt_inputs = !(flags & ImGuiColorEditFlags__InputsMask); + bool allow_opt_datatype = !(flags & ImGuiColorEditFlags__DataTypeMask); + if ((!allow_opt_inputs && !allow_opt_datatype) || !BeginPopup("context")) + return; + ImGuiContext& g = *GImGui; + ImGuiColorEditFlags opts = g.ColorEditOptions; + if (allow_opt_inputs) + { + if (RadioButton("RGB", (opts & ImGuiColorEditFlags_RGB) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_RGB; + if (RadioButton("HSV", (opts & ImGuiColorEditFlags_HSV) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_HSV; + if (RadioButton("HEX", (opts & ImGuiColorEditFlags_HEX) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_HEX; + } + if (allow_opt_datatype) + { + if (allow_opt_inputs) Separator(); + if (RadioButton("0..255", (opts & ImGuiColorEditFlags_Uint8) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__DataTypeMask) | ImGuiColorEditFlags_Uint8; + if (RadioButton("0.00..1.00", (opts & ImGuiColorEditFlags_Float) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__DataTypeMask) | ImGuiColorEditFlags_Float; + } + + if (allow_opt_inputs || allow_opt_datatype) + Separator(); + if (Button("Copy as..", ImVec2(-1,0))) + OpenPopup("Copy"); + if (BeginPopup("Copy")) + { + int cr = IM_F32_TO_INT8_SAT(col[0]), cg = IM_F32_TO_INT8_SAT(col[1]), cb = IM_F32_TO_INT8_SAT(col[2]), ca = (flags & ImGuiColorEditFlags_NoAlpha) ? 255 : IM_F32_TO_INT8_SAT(col[3]); + char buf[64]; + ImFormatString(buf, IM_ARRAYSIZE(buf), "(%.3ff, %.3ff, %.3ff, %.3ff)", col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]); + if (Selectable(buf)) + SetClipboardText(buf); + ImFormatString(buf, IM_ARRAYSIZE(buf), "(%d,%d,%d,%d)", cr, cg, cb, ca); + if (Selectable(buf)) + SetClipboardText(buf); + if (flags & ImGuiColorEditFlags_NoAlpha) + ImFormatString(buf, IM_ARRAYSIZE(buf), "0x%02X%02X%02X", cr, cg, cb); + else + ImFormatString(buf, IM_ARRAYSIZE(buf), "0x%02X%02X%02X%02X", cr, cg, cb, ca); + if (Selectable(buf)) + SetClipboardText(buf); + EndPopup(); + } + + g.ColorEditOptions = opts; + EndPopup(); +} + +static void ColorPickerOptionsPopup(ImGuiColorEditFlags flags, const float* ref_col) +{ + bool allow_opt_picker = !(flags & ImGuiColorEditFlags__PickerMask); + bool allow_opt_alpha_bar = !(flags & ImGuiColorEditFlags_NoAlpha) && !(flags & ImGuiColorEditFlags_AlphaBar); + if ((!allow_opt_picker && !allow_opt_alpha_bar) || !ImGui::BeginPopup("context")) + return; + ImGuiContext& g = *GImGui; + if (allow_opt_picker) + { + ImVec2 picker_size(g.FontSize * 8, ImMax(g.FontSize * 8 - (ImGui::GetFrameHeight() + g.Style.ItemInnerSpacing.x), 1.0f)); // FIXME: Picker size copied from main picker function + ImGui::PushItemWidth(picker_size.x); + for (int picker_type = 0; picker_type < 2; picker_type++) + { + // Draw small/thumbnail version of each picker type (over an invisible button for selection) + if (picker_type > 0) ImGui::Separator(); + ImGui::PushID(picker_type); + ImGuiColorEditFlags picker_flags = ImGuiColorEditFlags_NoInputs|ImGuiColorEditFlags_NoOptions|ImGuiColorEditFlags_NoLabel|ImGuiColorEditFlags_NoSidePreview|(flags & ImGuiColorEditFlags_NoAlpha); + if (picker_type == 0) picker_flags |= ImGuiColorEditFlags_PickerHueBar; + if (picker_type == 1) picker_flags |= ImGuiColorEditFlags_PickerHueWheel; + ImVec2 backup_pos = ImGui::GetCursorScreenPos(); + if (ImGui::Selectable("##selectable", false, 0, picker_size)) // By default, Selectable() is closing popup + g.ColorEditOptions = (g.ColorEditOptions & ~ImGuiColorEditFlags__PickerMask) | (picker_flags & ImGuiColorEditFlags__PickerMask); + ImGui::SetCursorScreenPos(backup_pos); + ImVec4 dummy_ref_col; + memcpy(&dummy_ref_col.x, ref_col, sizeof(float) * (picker_flags & ImGuiColorEditFlags_NoAlpha ? 3 : 4)); + ImGui::ColorPicker4("##dummypicker", &dummy_ref_col.x, picker_flags); + ImGui::PopID(); + } + ImGui::PopItemWidth(); + } + if (allow_opt_alpha_bar) + { + if (allow_opt_picker) ImGui::Separator(); + ImGui::CheckboxFlags("Alpha Bar", (unsigned int*)&g.ColorEditOptions, ImGuiColorEditFlags_AlphaBar); + } + ImGui::EndPopup(); +} + +// Edit colors components (each component in 0.0f..1.0f range). +// See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. +// With typical options: Left-click on colored square to open color picker. Right-click to open option menu. CTRL-Click over input fields to edit them and TAB to go to next item. +bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const float square_sz = GetFrameHeight(); + const float w_extra = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x); + const float w_items_all = CalcItemWidth() - w_extra; + const char* label_display_end = FindRenderedTextEnd(label); + + const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0; + const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0; + const int components = alpha ? 4 : 3; + const ImGuiColorEditFlags flags_untouched = flags; + + BeginGroup(); + PushID(label); + + // If we're not showing any slider there's no point in doing any HSV conversions + if (flags & ImGuiColorEditFlags_NoInputs) + flags = (flags & (~ImGuiColorEditFlags__InputsMask)) | ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_NoOptions; + + // Context menu: display and modify options (before defaults are applied) + if (!(flags & ImGuiColorEditFlags_NoOptions)) + ColorEditOptionsPopup(col, flags); + + // Read stored options + if (!(flags & ImGuiColorEditFlags__InputsMask)) + flags |= (g.ColorEditOptions & ImGuiColorEditFlags__InputsMask); + if (!(flags & ImGuiColorEditFlags__DataTypeMask)) + flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DataTypeMask); + if (!(flags & ImGuiColorEditFlags__PickerMask)) + flags |= (g.ColorEditOptions & ImGuiColorEditFlags__PickerMask); + flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags__InputsMask | ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask)); + + // Convert to the formats we need + float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f }; + if (flags & ImGuiColorEditFlags_HSV) + ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); + int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) }; + + bool value_changed = false; + bool value_changed_as_float = false; + + if ((flags & (ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV)) != 0 && (flags & ImGuiColorEditFlags_NoInputs) == 0) + { + // RGB/HSV 0..255 Sliders + const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); + + const bool hide_prefix = (w_item_one <= CalcTextSize((flags & ImGuiColorEditFlags_Float) ? "M:0.000" : "M:000").x); + const char* ids[4] = { "##X", "##Y", "##Z", "##W" }; + const char* fmt_table_int[3][4] = + { + { "%3.0f", "%3.0f", "%3.0f", "%3.0f" }, // Short display + { "R:%3.0f", "G:%3.0f", "B:%3.0f", "A:%3.0f" }, // Long display for RGBA + { "H:%3.0f", "S:%3.0f", "V:%3.0f", "A:%3.0f" } // Long display for HSVA + }; + const char* fmt_table_float[3][4] = + { + { "%0.3f", "%0.3f", "%0.3f", "%0.3f" }, // Short display + { "R:%0.3f", "G:%0.3f", "B:%0.3f", "A:%0.3f" }, // Long display for RGBA + { "H:%0.3f", "S:%0.3f", "V:%0.3f", "A:%0.3f" } // Long display for HSVA + }; + const int fmt_idx = hide_prefix ? 0 : (flags & ImGuiColorEditFlags_HSV) ? 2 : 1; + + PushItemWidth(w_item_one); + for (int n = 0; n < components; n++) + { + if (n > 0) + SameLine(0, style.ItemInnerSpacing.x); + if (n + 1 == components) + PushItemWidth(w_item_last); + if (flags & ImGuiColorEditFlags_Float) + value_changed = value_changed_as_float = value_changed | DragFloat(ids[n], &f[n], 1.0f/255.0f, 0.0f, hdr ? 0.0f : 1.0f, fmt_table_float[fmt_idx][n]); + else + value_changed |= DragInt(ids[n], &i[n], 1.0f, 0, hdr ? 0 : 255, fmt_table_int[fmt_idx][n]); + if (!(flags & ImGuiColorEditFlags_NoOptions)) + OpenPopupOnItemClick("context"); + } + PopItemWidth(); + PopItemWidth(); + } + else if ((flags & ImGuiColorEditFlags_HEX) != 0 && (flags & ImGuiColorEditFlags_NoInputs) == 0) + { + // RGB Hexadecimal Input + char buf[64]; + if (alpha) + ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", ImClamp(i[0],0,255), ImClamp(i[1],0,255), ImClamp(i[2],0,255), ImClamp(i[3],0,255)); + else + ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", ImClamp(i[0],0,255), ImClamp(i[1],0,255), ImClamp(i[2],0,255)); + PushItemWidth(w_items_all); + if (InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase)) + { + value_changed = true; + char* p = buf; + while (*p == '#' || ImCharIsSpace(*p)) + p++; + i[0] = i[1] = i[2] = i[3] = 0; + if (alpha) + sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]); // Treat at unsigned (%X is unsigned) + else + sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]); + } + if (!(flags & ImGuiColorEditFlags_NoOptions)) + OpenPopupOnItemClick("context"); + PopItemWidth(); + } + + ImGuiWindow* picker_active_window = NULL; + if (!(flags & ImGuiColorEditFlags_NoSmallPreview)) + { + if (!(flags & ImGuiColorEditFlags_NoInputs)) + SameLine(0, style.ItemInnerSpacing.x); + + const ImVec4 col_v4(col[0], col[1], col[2], alpha ? col[3] : 1.0f); + if (ColorButton("##ColorButton", col_v4, flags)) + { + if (!(flags & ImGuiColorEditFlags_NoPicker)) + { + // Store current color and open a picker + g.ColorPickerRef = col_v4; + OpenPopup("picker"); + SetNextWindowPos(window->DC.LastItemRect.GetBL() + ImVec2(-1,style.ItemSpacing.y)); + } + } + if (!(flags & ImGuiColorEditFlags_NoOptions)) + OpenPopupOnItemClick("context"); + + if (BeginPopup("picker")) + { + picker_active_window = g.CurrentWindow; + if (label != label_display_end) + { + TextUnformatted(label, label_display_end); + Separator(); + } + ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar; + ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__InputsMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf; + PushItemWidth(square_sz * 12.0f); // Use 256 + bar sizes? + value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x); + PopItemWidth(); + EndPopup(); + } + } + + if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel)) + { + SameLine(0, style.ItemInnerSpacing.x); + TextUnformatted(label, label_display_end); + } + + // Convert back + if (picker_active_window == NULL) + { + if (!value_changed_as_float) + for (int n = 0; n < 4; n++) + f[n] = i[n] / 255.0f; + if (flags & ImGuiColorEditFlags_HSV) + ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); + if (value_changed) + { + col[0] = f[0]; + col[1] = f[1]; + col[2] = f[2]; + if (alpha) + col[3] = f[3]; + } + } + + PopID(); + EndGroup(); + + // Drag and Drop Target + if (window->DC.LastItemRectHoveredRect && BeginDragDropTarget()) // NB: The LastItemRectHoveredRect test is merely an optional micro-optimization + { + if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) + { + memcpy((float*)col, payload->Data, sizeof(float) * 3); + value_changed = true; + } + if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F)) + { + memcpy((float*)col, payload->Data, sizeof(float) * components); + value_changed = true; + } + EndDragDropTarget(); + } + + // When picker is being actively used, use its active id so IsItemActive() will function on ColorEdit4(). + if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window) + window->DC.LastItemId = g.ActiveId; + + return value_changed; +} + +bool ImGui::ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags) +{ + float col4[4] = { col[0], col[1], col[2], 1.0f }; + if (!ColorPicker4(label, col4, flags | ImGuiColorEditFlags_NoAlpha)) + return false; + col[0] = col4[0]; col[1] = col4[1]; col[2] = col4[2]; + return true; +} + +// 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side. +static void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col) +{ + switch (direction) + { + case ImGuiDir_Left: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), pos, col); return; + case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return; + case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return; + case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return; + case ImGuiDir_None: case ImGuiDir_Count_: break; // Fix warnings + } +} + +static void RenderArrowsForVerticalBar(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, float bar_w) +{ + RenderArrow(draw_list, ImVec2(pos.x + half_sz.x + 1, pos.y), ImVec2(half_sz.x + 2, half_sz.y + 1), ImGuiDir_Right, IM_COL32_BLACK); + RenderArrow(draw_list, ImVec2(pos.x + half_sz.x, pos.y), half_sz, ImGuiDir_Right, IM_COL32_WHITE); + RenderArrow(draw_list, ImVec2(pos.x + bar_w - half_sz.x - 1, pos.y), ImVec2(half_sz.x + 2, half_sz.y + 1), ImGuiDir_Left, IM_COL32_BLACK); + RenderArrow(draw_list, ImVec2(pos.x + bar_w - half_sz.x, pos.y), half_sz, ImGuiDir_Left, IM_COL32_WHITE); +} + +// ColorPicker +// Note: only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. +// FIXME: we adjust the big color square height based on item width, which may cause a flickering feedback loop (if automatic height makes a vertical scrollbar appears, affecting automatic width..) +bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags, const float* ref_col) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + ImDrawList* draw_list = window->DrawList; + + ImGuiStyle& style = g.Style; + ImGuiIO& io = g.IO; + + PushID(label); + BeginGroup(); + + if (!(flags & ImGuiColorEditFlags_NoSidePreview)) + flags |= ImGuiColorEditFlags_NoSmallPreview; + + // Context menu: display and store options. + if (!(flags & ImGuiColorEditFlags_NoOptions)) + ColorPickerOptionsPopup(flags, col); + + // Read stored options + if (!(flags & ImGuiColorEditFlags__PickerMask)) + flags |= ((g.ColorEditOptions & ImGuiColorEditFlags__PickerMask) ? g.ColorEditOptions : ImGuiColorEditFlags__OptionsDefault) & ImGuiColorEditFlags__PickerMask; + IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags__PickerMask))); // Check that only 1 is selected + if (!(flags & ImGuiColorEditFlags_NoOptions)) + flags |= (g.ColorEditOptions & ImGuiColorEditFlags_AlphaBar); + + // Setup + int components = (flags & ImGuiColorEditFlags_NoAlpha) ? 3 : 4; + bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha); + ImVec2 picker_pos = window->DC.CursorPos; + float square_sz = GetFrameHeight(); + float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars + float sv_picker_size = ImMax(bars_width * 1, CalcItemWidth() - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box + float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x; + float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x; + float bars_triangles_half_sz = (float)(int)(bars_width * 0.20f); + + float backup_initial_col[4]; + memcpy(backup_initial_col, col, components * sizeof(float)); + + float wheel_thickness = sv_picker_size * 0.08f; + float wheel_r_outer = sv_picker_size * 0.50f; + float wheel_r_inner = wheel_r_outer - wheel_thickness; + ImVec2 wheel_center(picker_pos.x + (sv_picker_size + bars_width)*0.5f, picker_pos.y + sv_picker_size*0.5f); + + // Note: the triangle is displayed rotated with triangle_pa pointing to Hue, but most coordinates stays unrotated for logic. + float triangle_r = wheel_r_inner - (int)(sv_picker_size * 0.027f); + ImVec2 triangle_pa = ImVec2(triangle_r, 0.0f); // Hue point. + ImVec2 triangle_pb = ImVec2(triangle_r * -0.5f, triangle_r * -0.866025f); // Black point. + ImVec2 triangle_pc = ImVec2(triangle_r * -0.5f, triangle_r * +0.866025f); // White point. + + float H,S,V; + ColorConvertRGBtoHSV(col[0], col[1], col[2], H, S, V); + + bool value_changed = false, value_changed_h = false, value_changed_sv = false; + + if (flags & ImGuiColorEditFlags_PickerHueWheel) + { + // Hue wheel + SV triangle logic + InvisibleButton("hsv", ImVec2(sv_picker_size + style.ItemInnerSpacing.x + bars_width, sv_picker_size)); + if (IsItemActive()) + { + ImVec2 initial_off = g.IO.MouseClickedPos[0] - wheel_center; + ImVec2 current_off = g.IO.MousePos - wheel_center; + float initial_dist2 = ImLengthSqr(initial_off); + if (initial_dist2 >= (wheel_r_inner-1)*(wheel_r_inner-1) && initial_dist2 <= (wheel_r_outer+1)*(wheel_r_outer+1)) + { + // Interactive with Hue wheel + H = atan2f(current_off.y, current_off.x) / IM_PI*0.5f; + if (H < 0.0f) + H += 1.0f; + value_changed = value_changed_h = true; + } + float cos_hue_angle = cosf(-H * 2.0f * IM_PI); + float sin_hue_angle = sinf(-H * 2.0f * IM_PI); + if (ImTriangleContainsPoint(triangle_pa, triangle_pb, triangle_pc, ImRotate(initial_off, cos_hue_angle, sin_hue_angle))) + { + // Interacting with SV triangle + ImVec2 current_off_unrotated = ImRotate(current_off, cos_hue_angle, sin_hue_angle); + if (!ImTriangleContainsPoint(triangle_pa, triangle_pb, triangle_pc, current_off_unrotated)) + current_off_unrotated = ImTriangleClosestPoint(triangle_pa, triangle_pb, triangle_pc, current_off_unrotated); + float uu, vv, ww; + ImTriangleBarycentricCoords(triangle_pa, triangle_pb, triangle_pc, current_off_unrotated, uu, vv, ww); + V = ImClamp(1.0f - vv, 0.0001f, 1.0f); + S = ImClamp(uu / V, 0.0001f, 1.0f); + value_changed = value_changed_sv = true; + } + } + if (!(flags & ImGuiColorEditFlags_NoOptions)) + OpenPopupOnItemClick("context"); + } + else if (flags & ImGuiColorEditFlags_PickerHueBar) + { + // SV rectangle logic + InvisibleButton("sv", ImVec2(sv_picker_size, sv_picker_size)); + if (IsItemActive()) + { + S = ImSaturate((io.MousePos.x - picker_pos.x) / (sv_picker_size-1)); + V = 1.0f - ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size-1)); + value_changed = value_changed_sv = true; + } + if (!(flags & ImGuiColorEditFlags_NoOptions)) + OpenPopupOnItemClick("context"); + + // Hue bar logic + SetCursorScreenPos(ImVec2(bar0_pos_x, picker_pos.y)); + InvisibleButton("hue", ImVec2(bars_width, sv_picker_size)); + if (IsItemActive()) + { + H = ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size-1)); + value_changed = value_changed_h = true; + } + } + + // Alpha bar logic + if (alpha_bar) + { + SetCursorScreenPos(ImVec2(bar1_pos_x, picker_pos.y)); + InvisibleButton("alpha", ImVec2(bars_width, sv_picker_size)); + if (IsItemActive()) + { + col[3] = 1.0f - ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size-1)); + value_changed = true; + } + } + + if (!(flags & ImGuiColorEditFlags_NoSidePreview)) + { + SameLine(0, style.ItemInnerSpacing.x); + BeginGroup(); + } + + if (!(flags & ImGuiColorEditFlags_NoLabel)) + { + const char* label_display_end = FindRenderedTextEnd(label); + if (label != label_display_end) + { + if ((flags & ImGuiColorEditFlags_NoSidePreview)) + SameLine(0, style.ItemInnerSpacing.x); + TextUnformatted(label, label_display_end); + } + } + + if (!(flags & ImGuiColorEditFlags_NoSidePreview)) + { + ImVec4 col_v4(col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]); + if ((flags & ImGuiColorEditFlags_NoLabel)) + Text("Current"); + ColorButton("##current", col_v4, (flags & (ImGuiColorEditFlags_HDR|ImGuiColorEditFlags_AlphaPreview|ImGuiColorEditFlags_AlphaPreviewHalf|ImGuiColorEditFlags_NoTooltip)), ImVec2(square_sz * 3, square_sz * 2)); + if (ref_col != NULL) + { + Text("Original"); + ImVec4 ref_col_v4(ref_col[0], ref_col[1], ref_col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : ref_col[3]); + if (ColorButton("##original", ref_col_v4, (flags & (ImGuiColorEditFlags_HDR|ImGuiColorEditFlags_AlphaPreview|ImGuiColorEditFlags_AlphaPreviewHalf|ImGuiColorEditFlags_NoTooltip)), ImVec2(square_sz * 3, square_sz * 2))) + { + memcpy(col, ref_col, components * sizeof(float)); + value_changed = true; + } + } + EndGroup(); + } + + // Convert back color to RGB + if (value_changed_h || value_changed_sv) + ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]); + + // R,G,B and H,S,V slider color editor + if ((flags & ImGuiColorEditFlags_NoInputs) == 0) + { + PushItemWidth((alpha_bar ? bar1_pos_x : bar0_pos_x) + bars_width - picker_pos.x); + ImGuiColorEditFlags sub_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoOptions | ImGuiColorEditFlags_NoSmallPreview | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf; + ImGuiColorEditFlags sub_flags = (flags & sub_flags_to_forward) | ImGuiColorEditFlags_NoPicker; + if (flags & ImGuiColorEditFlags_RGB || (flags & ImGuiColorEditFlags__InputsMask) == 0) + value_changed |= ColorEdit4("##rgb", col, sub_flags | ImGuiColorEditFlags_RGB); + if (flags & ImGuiColorEditFlags_HSV || (flags & ImGuiColorEditFlags__InputsMask) == 0) + value_changed |= ColorEdit4("##hsv", col, sub_flags | ImGuiColorEditFlags_HSV); + if (flags & ImGuiColorEditFlags_HEX || (flags & ImGuiColorEditFlags__InputsMask) == 0) + value_changed |= ColorEdit4("##hex", col, sub_flags | ImGuiColorEditFlags_HEX); + PopItemWidth(); + } + + // Try to cancel hue wrap (after ColorEdit), if any + if (value_changed) + { + float new_H, new_S, new_V; + ColorConvertRGBtoHSV(col[0], col[1], col[2], new_H, new_S, new_V); + if (new_H <= 0 && H > 0) + { + if (new_V <= 0 && V != new_V) + ColorConvertHSVtoRGB(H, S, new_V <= 0 ? V * 0.5f : new_V, col[0], col[1], col[2]); + else if (new_S <= 0) + ColorConvertHSVtoRGB(H, new_S <= 0 ? S * 0.5f : new_S, new_V, col[0], col[1], col[2]); + } + } + + ImVec4 hue_color_f(1, 1, 1, 1); ColorConvertHSVtoRGB(H, 1, 1, hue_color_f.x, hue_color_f.y, hue_color_f.z); + ImU32 hue_color32 = ColorConvertFloat4ToU32(hue_color_f); + ImU32 col32_no_alpha = ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 1.0f)); + + const ImU32 hue_colors[6+1] = { IM_COL32(255,0,0,255), IM_COL32(255,255,0,255), IM_COL32(0,255,0,255), IM_COL32(0,255,255,255), IM_COL32(0,0,255,255), IM_COL32(255,0,255,255), IM_COL32(255,0,0,255) }; + ImVec2 sv_cursor_pos; + + if (flags & ImGuiColorEditFlags_PickerHueWheel) + { + // Render Hue Wheel + const float aeps = 1.5f / wheel_r_outer; // Half a pixel arc length in radians (2pi cancels out). + const int segment_per_arc = ImMax(4, (int)wheel_r_outer / 12); + for (int n = 0; n < 6; n++) + { + const float a0 = (n) /6.0f * 2.0f * IM_PI - aeps; + const float a1 = (n+1.0f)/6.0f * 2.0f * IM_PI + aeps; + const int vert_start_idx = draw_list->VtxBuffer.Size; + draw_list->PathArcTo(wheel_center, (wheel_r_inner + wheel_r_outer)*0.5f, a0, a1, segment_per_arc); + draw_list->PathStroke(IM_COL32_WHITE, false, wheel_thickness); + const int vert_end_idx = draw_list->VtxBuffer.Size; + + // Paint colors over existing vertices + ImVec2 gradient_p0(wheel_center.x + cosf(a0) * wheel_r_inner, wheel_center.y + sinf(a0) * wheel_r_inner); + ImVec2 gradient_p1(wheel_center.x + cosf(a1) * wheel_r_inner, wheel_center.y + sinf(a1) * wheel_r_inner); + ShadeVertsLinearColorGradientKeepAlpha(draw_list->VtxBuffer.Data + vert_start_idx, draw_list->VtxBuffer.Data + vert_end_idx, gradient_p0, gradient_p1, hue_colors[n], hue_colors[n+1]); + } + + // Render Cursor + preview on Hue Wheel + float cos_hue_angle = cosf(H * 2.0f * IM_PI); + float sin_hue_angle = sinf(H * 2.0f * IM_PI); + ImVec2 hue_cursor_pos(wheel_center.x + cos_hue_angle * (wheel_r_inner+wheel_r_outer)*0.5f, wheel_center.y + sin_hue_angle * (wheel_r_inner+wheel_r_outer)*0.5f); + float hue_cursor_rad = value_changed_h ? wheel_thickness * 0.65f : wheel_thickness * 0.55f; + int hue_cursor_segments = ImClamp((int)(hue_cursor_rad / 1.4f), 9, 32); + draw_list->AddCircleFilled(hue_cursor_pos, hue_cursor_rad, hue_color32, hue_cursor_segments); + draw_list->AddCircle(hue_cursor_pos, hue_cursor_rad+1, IM_COL32(128,128,128,255), hue_cursor_segments); + draw_list->AddCircle(hue_cursor_pos, hue_cursor_rad, IM_COL32_WHITE, hue_cursor_segments); + + // Render SV triangle (rotated according to hue) + ImVec2 tra = wheel_center + ImRotate(triangle_pa, cos_hue_angle, sin_hue_angle); + ImVec2 trb = wheel_center + ImRotate(triangle_pb, cos_hue_angle, sin_hue_angle); + ImVec2 trc = wheel_center + ImRotate(triangle_pc, cos_hue_angle, sin_hue_angle); + ImVec2 uv_white = GetFontTexUvWhitePixel(); + draw_list->PrimReserve(6, 6); + draw_list->PrimVtx(tra, uv_white, hue_color32); + draw_list->PrimVtx(trb, uv_white, hue_color32); + draw_list->PrimVtx(trc, uv_white, IM_COL32_WHITE); + draw_list->PrimVtx(tra, uv_white, IM_COL32_BLACK_TRANS); + draw_list->PrimVtx(trb, uv_white, IM_COL32_BLACK); + draw_list->PrimVtx(trc, uv_white, IM_COL32_BLACK_TRANS); + draw_list->AddTriangle(tra, trb, trc, IM_COL32(128,128,128,255), 1.5f); + sv_cursor_pos = ImLerp(ImLerp(trc, tra, ImSaturate(S)), trb, ImSaturate(1 - V)); + } + else if (flags & ImGuiColorEditFlags_PickerHueBar) + { + // Render SV Square + draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size,sv_picker_size), IM_COL32_WHITE, hue_color32, hue_color32, IM_COL32_WHITE); + draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size,sv_picker_size), IM_COL32_BLACK_TRANS, IM_COL32_BLACK_TRANS, IM_COL32_BLACK, IM_COL32_BLACK); + RenderFrameBorder(picker_pos, picker_pos + ImVec2(sv_picker_size,sv_picker_size), 0.0f); + sv_cursor_pos.x = ImClamp((float)(int)(picker_pos.x + ImSaturate(S) * sv_picker_size + 0.5f), picker_pos.x + 2, picker_pos.x + sv_picker_size - 2); // Sneakily prevent the circle to stick out too much + sv_cursor_pos.y = ImClamp((float)(int)(picker_pos.y + ImSaturate(1 - V) * sv_picker_size + 0.5f), picker_pos.y + 2, picker_pos.y + sv_picker_size - 2); + + // Render Hue Bar + for (int i = 0; i < 6; ++i) + draw_list->AddRectFilledMultiColor(ImVec2(bar0_pos_x, picker_pos.y + i * (sv_picker_size / 6)), ImVec2(bar0_pos_x + bars_width, picker_pos.y + (i + 1) * (sv_picker_size / 6)), hue_colors[i], hue_colors[i], hue_colors[i + 1], hue_colors[i + 1]); + float bar0_line_y = (float)(int)(picker_pos.y + H * sv_picker_size + 0.5f); + RenderFrameBorder(ImVec2(bar0_pos_x, picker_pos.y), ImVec2(bar0_pos_x + bars_width, picker_pos.y + sv_picker_size), 0.0f); + RenderArrowsForVerticalBar(draw_list, ImVec2(bar0_pos_x - 1, bar0_line_y), ImVec2(bars_triangles_half_sz + 1, bars_triangles_half_sz), bars_width + 2.0f); + } + + // Render cursor/preview circle (clamp S/V within 0..1 range because floating points colors may lead HSV values to be out of range) + float sv_cursor_rad = value_changed_sv ? 10.0f : 6.0f; + draw_list->AddCircleFilled(sv_cursor_pos, sv_cursor_rad, col32_no_alpha, 12); + draw_list->AddCircle(sv_cursor_pos, sv_cursor_rad+1, IM_COL32(128,128,128,255), 12); + draw_list->AddCircle(sv_cursor_pos, sv_cursor_rad, IM_COL32_WHITE, 12); + + // Render alpha bar + if (alpha_bar) + { + float alpha = ImSaturate(col[3]); + ImRect bar1_bb(bar1_pos_x, picker_pos.y, bar1_pos_x + bars_width, picker_pos.y + sv_picker_size); + RenderColorRectWithAlphaCheckerboard(bar1_bb.Min, bar1_bb.Max, IM_COL32(0,0,0,0), bar1_bb.GetWidth() / 2.0f, ImVec2(0.0f, 0.0f)); + draw_list->AddRectFilledMultiColor(bar1_bb.Min, bar1_bb.Max, col32_no_alpha, col32_no_alpha, col32_no_alpha & ~IM_COL32_A_MASK, col32_no_alpha & ~IM_COL32_A_MASK); + float bar1_line_y = (float)(int)(picker_pos.y + (1.0f - alpha) * sv_picker_size + 0.5f); + RenderFrameBorder(bar1_bb.Min, bar1_bb.Max, 0.0f); + RenderArrowsForVerticalBar(draw_list, ImVec2(bar1_pos_x - 1, bar1_line_y), ImVec2(bars_triangles_half_sz + 1, bars_triangles_half_sz), bars_width + 2.0f); + } + + EndGroup(); + PopID(); + + return value_changed && memcmp(backup_initial_col, col, components * sizeof(float)); +} + +// Horizontal separating line. +void ImGui::Separator() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + ImGuiContext& g = *GImGui; + + ImGuiWindowFlags flags = 0; + if ((flags & (ImGuiSeparatorFlags_Horizontal | ImGuiSeparatorFlags_Vertical)) == 0) + flags |= (window->DC.LayoutType == ImGuiLayoutType_Horizontal) ? ImGuiSeparatorFlags_Vertical : ImGuiSeparatorFlags_Horizontal; + IM_ASSERT(ImIsPowerOfTwo((int)(flags & (ImGuiSeparatorFlags_Horizontal | ImGuiSeparatorFlags_Vertical)))); // Check that only 1 option is selected + if (flags & ImGuiSeparatorFlags_Vertical) + { + VerticalSeparator(); + return; + } + + // Horizontal Separator + if (window->DC.ColumnsSet) + PopClipRect(); + + float x1 = window->Pos.x; + float x2 = window->Pos.x + window->Size.x; + if (!window->DC.GroupStack.empty()) + x1 += window->DC.IndentX; + + const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y+1.0f)); + ItemSize(ImVec2(0.0f, 0.0f)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit, we don't provide height to not alter layout. + if (!ItemAdd(bb, 0)) + { + if (window->DC.ColumnsSet) + PushColumnClipRect(); + return; + } + + window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x,bb.Min.y), GetColorU32(ImGuiCol_Separator)); + + if (g.LogEnabled) + LogRenderedText(NULL, IM_NEWLINE "--------------------------------"); + + if (window->DC.ColumnsSet) + { + PushColumnClipRect(); + window->DC.ColumnsSet->CellMinY = window->DC.CursorPos.y; + } +} + +void ImGui::VerticalSeparator() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + ImGuiContext& g = *GImGui; + + float y1 = window->DC.CursorPos.y; + float y2 = window->DC.CursorPos.y + window->DC.CurrentLineHeight; + const ImRect bb(ImVec2(window->DC.CursorPos.x, y1), ImVec2(window->DC.CursorPos.x + 1.0f, y2)); + ItemSize(ImVec2(bb.GetWidth(), 0.0f)); + if (!ItemAdd(bb, 0)) + return; + + window->DrawList->AddLine(ImVec2(bb.Min.x, bb.Min.y), ImVec2(bb.Min.x, bb.Max.y), GetColorU32(ImGuiCol_Separator)); + if (g.LogEnabled) + LogText(" |"); +} + +bool ImGui::SplitterBehavior(ImGuiID id, const ImRect& bb, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + const ImGuiItemFlags item_flags_backup = window->DC.ItemFlags; +#ifdef IMGUI_HAS_NAV + window->DC.ItemFlags |= ImGuiItemFlags_NoNav | ImGuiItemFlags_NoNavDefaultFocus; +#endif + bool add = ItemAdd(bb, id); + window->DC.ItemFlags = item_flags_backup; + if (!add) + return false; + + bool hovered, held; + ImRect bb_interact = bb; + bb_interact.Expand(axis == ImGuiAxis_Y ? ImVec2(0.0f, hover_extend) : ImVec2(hover_extend, 0.0f)); + ButtonBehavior(bb_interact, id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap); + if (g.ActiveId != id) + SetItemAllowOverlap(); + + if (held || (g.HoveredId == id && g.HoveredIdPreviousFrame == id)) + SetMouseCursor(axis == ImGuiAxis_Y ? ImGuiMouseCursor_ResizeNS : ImGuiMouseCursor_ResizeEW); + + ImRect bb_render = bb; + if (held) + { + ImVec2 mouse_delta_2d = g.IO.MousePos - g.ActiveIdClickOffset - bb_interact.Min; + float mouse_delta = (axis == ImGuiAxis_Y) ? mouse_delta_2d.y : mouse_delta_2d.x; + + // Minimum pane size + if (mouse_delta < min_size1 - *size1) + mouse_delta = min_size1 - *size1; + if (mouse_delta > *size2 - min_size2) + mouse_delta = *size2 - min_size2; + + // Apply resize + *size1 += mouse_delta; + *size2 -= mouse_delta; + bb_render.Translate((axis == ImGuiAxis_X) ? ImVec2(mouse_delta, 0.0f) : ImVec2(0.0f, mouse_delta)); + } + + // Render + const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); + window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, col, g.Style.FrameRounding); + + return held; +} + +void ImGui::Spacing() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + ItemSize(ImVec2(0,0)); +} + +void ImGui::Dummy(const ImVec2& size) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + ItemSize(bb); + ItemAdd(bb, 0); +} + +bool ImGui::IsRectVisible(const ImVec2& size) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->ClipRect.Overlaps(ImRect(window->DC.CursorPos, window->DC.CursorPos + size)); +} + +bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->ClipRect.Overlaps(ImRect(rect_min, rect_max)); +} + +// Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.) +void ImGui::BeginGroup() +{ + ImGuiWindow* window = GetCurrentWindow(); + + window->DC.GroupStack.resize(window->DC.GroupStack.Size + 1); + ImGuiGroupData& group_data = window->DC.GroupStack.back(); + group_data.BackupCursorPos = window->DC.CursorPos; + group_data.BackupCursorMaxPos = window->DC.CursorMaxPos; + group_data.BackupIndentX = window->DC.IndentX; + group_data.BackupGroupOffsetX = window->DC.GroupOffsetX; + group_data.BackupCurrentLineHeight = window->DC.CurrentLineHeight; + group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset; + group_data.BackupLogLinePosY = window->DC.LogLinePosY; + group_data.BackupActiveIdIsAlive = GImGui->ActiveIdIsAlive; + group_data.AdvanceCursor = true; + + window->DC.GroupOffsetX = window->DC.CursorPos.x - window->Pos.x - window->DC.ColumnsOffsetX; + window->DC.IndentX = window->DC.GroupOffsetX; + window->DC.CursorMaxPos = window->DC.CursorPos; + window->DC.CurrentLineHeight = 0.0f; + window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; +} + +void ImGui::EndGroup() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + + IM_ASSERT(!window->DC.GroupStack.empty()); // Mismatched BeginGroup()/EndGroup() calls + + ImGuiGroupData& group_data = window->DC.GroupStack.back(); + + ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos); + group_bb.Max = ImMax(group_bb.Min, group_bb.Max); + + window->DC.CursorPos = group_data.BackupCursorPos; + window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos); + window->DC.CurrentLineHeight = group_data.BackupCurrentLineHeight; + window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset; + window->DC.IndentX = group_data.BackupIndentX; + window->DC.GroupOffsetX = group_data.BackupGroupOffsetX; + window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; + + if (group_data.AdvanceCursor) + { + window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrentLineTextBaseOffset); // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now. + ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset); + ItemAdd(group_bb, 0); + } + + // If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive() will be functional on the entire group. + // It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but if you search for LastItemId you'll notice it is only used in that context. + const bool active_id_within_group = (!group_data.BackupActiveIdIsAlive && g.ActiveIdIsAlive && g.ActiveId && g.ActiveIdWindow->RootWindow == window->RootWindow); + if (active_id_within_group) + window->DC.LastItemId = g.ActiveId; + window->DC.LastItemRect = group_bb; + + window->DC.GroupStack.pop_back(); + + //window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // [Debug] +} + +// Gets back to previous line and continue with horizontal layout +// pos_x == 0 : follow right after previous item +// pos_x != 0 : align to specified x position (relative to window/group left) +// spacing_w < 0 : use default spacing if pos_x == 0, no spacing if pos_x != 0 +// spacing_w >= 0 : enforce spacing amount +void ImGui::SameLine(float pos_x, float spacing_w) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + if (pos_x != 0.0f) + { + if (spacing_w < 0.0f) spacing_w = 0.0f; + window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + pos_x + spacing_w + window->DC.GroupOffsetX + window->DC.ColumnsOffsetX; + window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; + } + else + { + if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x; + window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w; + window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; + } + window->DC.CurrentLineHeight = window->DC.PrevLineHeight; + window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; +} + +void ImGui::NewLine() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiLayoutType backup_layout_type = window->DC.LayoutType; + window->DC.LayoutType = ImGuiLayoutType_Vertical; + if (window->DC.CurrentLineHeight > 0.0f) // In the event that we are on a line with items that is smaller that FontSize high, we will preserve its height. + ItemSize(ImVec2(0,0)); + else + ItemSize(ImVec2(0.0f, g.FontSize)); + window->DC.LayoutType = backup_layout_type; +} + +void ImGui::NextColumn() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems || window->DC.ColumnsSet == NULL) + return; + + ImGuiContext& g = *GImGui; + PopItemWidth(); + PopClipRect(); + + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + columns->CellMaxY = ImMax(columns->CellMaxY, window->DC.CursorPos.y); + if (++columns->Current < columns->Count) + { + // Columns 1+ cancel out IndentX + window->DC.ColumnsOffsetX = GetColumnOffset(columns->Current) - window->DC.IndentX + g.Style.ItemSpacing.x; + window->DrawList->ChannelsSetCurrent(columns->Current); + } + else + { + window->DC.ColumnsOffsetX = 0.0f; + window->DrawList->ChannelsSetCurrent(0); + columns->Current = 0; + columns->CellMinY = columns->CellMaxY; + } + window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX); + window->DC.CursorPos.y = columns->CellMinY; + window->DC.CurrentLineHeight = 0.0f; + window->DC.CurrentLineTextBaseOffset = 0.0f; + + PushColumnClipRect(); + PushItemWidth(GetColumnWidth() * 0.65f); // FIXME: Move on columns setup +} + +int ImGui::GetColumnIndex() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.ColumnsSet ? window->DC.ColumnsSet->Current : 0; +} + +int ImGui::GetColumnsCount() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.ColumnsSet ? window->DC.ColumnsSet->Count : 1; +} + +static float OffsetNormToPixels(const ImGuiColumnsSet* columns, float offset_norm) +{ + return offset_norm * (columns->MaxX - columns->MinX); +} + +static float PixelsToOffsetNorm(const ImGuiColumnsSet* columns, float offset) +{ + return offset / (columns->MaxX - columns->MinX); +} + +static inline float GetColumnsRectHalfWidth() { return 4.0f; } + +static float GetDraggedColumnOffset(ImGuiColumnsSet* columns, int column_index) +{ + // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing + // window creates a feedback loop because we store normalized positions. So while dragging we enforce absolute positioning. + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets. + IM_ASSERT(g.ActiveId == columns->ID + ImGuiID(column_index)); + + float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x + GetColumnsRectHalfWidth() - window->Pos.x; + x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) + g.Style.ColumnsMinSpacing); + if ((columns->Flags & ImGuiColumnsFlags_NoPreserveWidths)) + x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) - g.Style.ColumnsMinSpacing); + + return x; +} + +float ImGui::GetColumnOffset(int column_index) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + IM_ASSERT(columns != NULL); + + if (column_index < 0) + column_index = columns->Current; + IM_ASSERT(column_index < columns->Columns.Size); + + /* + if (g.ActiveId) + { + ImGuiContext& g = *GImGui; + const ImGuiID column_id = columns->ColumnsSetId + ImGuiID(column_index); + if (g.ActiveId == column_id) + return GetDraggedColumnOffset(columns, column_index); + } + */ + + const float t = columns->Columns[column_index].OffsetNorm; + const float x_offset = ImLerp(columns->MinX, columns->MaxX, t); + return x_offset; +} + +static float GetColumnWidthEx(ImGuiColumnsSet* columns, int column_index, bool before_resize = false) +{ + if (column_index < 0) + column_index = columns->Current; + + float offset_norm; + if (before_resize) + offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize; + else + offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm; + return OffsetNormToPixels(columns, offset_norm); +} + +float ImGui::GetColumnWidth(int column_index) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + IM_ASSERT(columns != NULL); + + if (column_index < 0) + column_index = columns->Current; + return OffsetNormToPixels(columns, columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm); +} + +void ImGui::SetColumnOffset(int column_index, float offset) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + IM_ASSERT(columns != NULL); + + if (column_index < 0) + column_index = columns->Current; + IM_ASSERT(column_index < columns->Columns.Size); + + const bool preserve_width = !(columns->Flags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < columns->Count-1); + const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f; + + if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow)) + offset = ImMin(offset, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index)); + columns->Columns[column_index].OffsetNorm = PixelsToOffsetNorm(columns, offset - columns->MinX); + + if (preserve_width) + SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width)); +} + +void ImGui::SetColumnWidth(int column_index, float width) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + IM_ASSERT(columns != NULL); + + if (column_index < 0) + column_index = columns->Current; + SetColumnOffset(column_index + 1, GetColumnOffset(column_index) + width); +} + +void ImGui::PushColumnClipRect(int column_index) +{ + ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + if (column_index < 0) + column_index = columns->Current; + + PushClipRect(columns->Columns[column_index].ClipRect.Min, columns->Columns[column_index].ClipRect.Max, false); +} + +static ImGuiColumnsSet* FindOrAddColumnsSet(ImGuiWindow* window, ImGuiID id) +{ + for (int n = 0; n < window->ColumnsStorage.Size; n++) + if (window->ColumnsStorage[n].ID == id) + return &window->ColumnsStorage[n]; + + window->ColumnsStorage.push_back(ImGuiColumnsSet()); + ImGuiColumnsSet* columns = &window->ColumnsStorage.back(); + columns->ID = id; + return columns; +} + +void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + + IM_ASSERT(columns_count > 1); + IM_ASSERT(window->DC.ColumnsSet == NULL); // Nested columns are currently not supported + + // Differentiate column ID with an arbitrary prefix for cases where users name their columns set the same as another widget. + // In addition, when an identifier isn't explicitly provided we include the number of columns in the hash to make it uniquer. + PushID(0x11223347 + (str_id ? 0 : columns_count)); + ImGuiID id = window->GetID(str_id ? str_id : "columns"); + PopID(); + + // Acquire storage for the columns set + ImGuiColumnsSet* columns = FindOrAddColumnsSet(window, id); + IM_ASSERT(columns->ID == id); + columns->Current = 0; + columns->Count = columns_count; + columns->Flags = flags; + window->DC.ColumnsSet = columns; + + // Set state for first column + const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->Size.x -window->ScrollbarSizes.x); + columns->MinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range + //column->MaxX = content_region_width - window->Scroll.x - ((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x; + columns->MaxX = content_region_width - window->Scroll.x; + columns->StartPosY = window->DC.CursorPos.y; + columns->StartMaxPosX = window->DC.CursorMaxPos.x; + columns->CellMinY = columns->CellMaxY = window->DC.CursorPos.y; + window->DC.ColumnsOffsetX = 0.0f; + window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX); + + // Initialize defaults + columns->IsFirstFrame = (columns->Columns.Size == 0); + if (columns->Columns.Size == 0) + { + columns->Columns.reserve(columns_count + 1); + for (int n = 0; n < columns_count + 1; n++) + { + ImGuiColumnData column; + column.OffsetNorm = n / (float)columns_count; + columns->Columns.push_back(column); + } + } + IM_ASSERT(columns->Columns.Size == columns_count + 1); + + for (int n = 0; n < columns_count + 1; n++) + { + // Clamp position + ImGuiColumnData* column = &columns->Columns[n]; + float t = column->OffsetNorm; + if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow)) + t = ImMin(t, PixelsToOffsetNorm(columns, (columns->MaxX - columns->MinX) - g.Style.ColumnsMinSpacing * (columns->Count - n))); + column->OffsetNorm = t; + + if (n == columns_count) + continue; + + // Compute clipping rectangle + float clip_x1 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(n) - 1.0f); + float clip_x2 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(n + 1) - 1.0f); + column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX); + column->ClipRect.ClipWith(window->ClipRect); + } + + window->DrawList->ChannelsSplit(columns->Count); + PushColumnClipRect(); + PushItemWidth(GetColumnWidth() * 0.65f); +} + +void ImGui::EndColumns() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + ImGuiColumnsSet* columns = window->DC.ColumnsSet; + IM_ASSERT(columns != NULL); + + PopItemWidth(); + PopClipRect(); + window->DrawList->ChannelsMerge(); + + columns->CellMaxY = ImMax(columns->CellMaxY, window->DC.CursorPos.y); + window->DC.CursorPos.y = columns->CellMaxY; + if (!(columns->Flags & ImGuiColumnsFlags_GrowParentContentsSize)) + window->DC.CursorMaxPos.x = ImMax(columns->StartMaxPosX, columns->MaxX); // Restore cursor max pos, as columns don't grow parent + + // Draw columns borders and handle resize + bool is_being_resized = false; + if (!(columns->Flags & ImGuiColumnsFlags_NoBorder) && !window->SkipItems) + { + const float y1 = columns->StartPosY; + const float y2 = window->DC.CursorPos.y; + int dragging_column = -1; + for (int n = 1; n < columns->Count; n++) + { + float x = window->Pos.x + GetColumnOffset(n); + const ImGuiID column_id = columns->ID + ImGuiID(n); + const float column_hw = GetColumnsRectHalfWidth(); // Half-width for interaction + const ImRect column_rect(ImVec2(x - column_hw, y1), ImVec2(x + column_hw, y2)); + KeepAliveID(column_id); + if (IsClippedEx(column_rect, column_id, false)) + continue; + + bool hovered = false, held = false; + if (!(columns->Flags & ImGuiColumnsFlags_NoResize)) + { + ButtonBehavior(column_rect, column_id, &hovered, &held); + if (hovered || held) + g.MouseCursor = ImGuiMouseCursor_ResizeEW; + if (held && !(columns->Columns[n].Flags & ImGuiColumnsFlags_NoResize)) + dragging_column = n; + } + + // Draw column (we clip the Y boundaries CPU side because very long triangles are mishandled by some GPU drivers.) + const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); + const float xi = (float)(int)x; + window->DrawList->AddLine(ImVec2(xi, ImMax(y1 + 1.0f, window->ClipRect.Min.y)), ImVec2(xi, ImMin(y2, window->ClipRect.Max.y)), col); + } + + // Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame. + if (dragging_column != -1) + { + if (!columns->IsBeingResized) + for (int n = 0; n < columns->Count + 1; n++) + columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm; + columns->IsBeingResized = is_being_resized = true; + float x = GetDraggedColumnOffset(columns, dragging_column); + SetColumnOffset(dragging_column, x); + } + } + columns->IsBeingResized = is_being_resized; + + window->DC.ColumnsSet = NULL; + window->DC.ColumnsOffsetX = 0.0f; + window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX); +} + +// [2017/12: This is currently the only public API, while we are working on making BeginColumns/EndColumns user-facing] +void ImGui::Columns(int columns_count, const char* id, bool border) +{ + ImGuiWindow* window = GetCurrentWindow(); + IM_ASSERT(columns_count >= 1); + if (window->DC.ColumnsSet != NULL && window->DC.ColumnsSet->Count != columns_count) + EndColumns(); + + ImGuiColumnsFlags flags = (border ? 0 : ImGuiColumnsFlags_NoBorder); + //flags |= ImGuiColumnsFlags_NoPreserveWidths; // NB: Legacy behavior + if (columns_count != 1) + BeginColumns(id, columns_count, flags); +} + +void ImGui::Indent(float indent_w) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.IndentX += (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX; +} + +void ImGui::Unindent(float indent_w) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.IndentX -= (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX; +} + +void ImGui::TreePush(const char* str_id) +{ + ImGuiWindow* window = GetCurrentWindow(); + Indent(); + window->DC.TreeDepth++; + PushID(str_id ? str_id : "#TreePush"); +} + +void ImGui::TreePush(const void* ptr_id) +{ + ImGuiWindow* window = GetCurrentWindow(); + Indent(); + window->DC.TreeDepth++; + PushID(ptr_id ? ptr_id : (const void*)"#TreePush"); +} + +void ImGui::TreePushRawID(ImGuiID id) +{ + ImGuiWindow* window = GetCurrentWindow(); + Indent(); + window->DC.TreeDepth++; + window->IDStack.push_back(id); +} + +void ImGui::TreePop() +{ + ImGuiWindow* window = GetCurrentWindow(); + Unindent(); + window->DC.TreeDepth--; + PopID(); +} + +void ImGui::Value(const char* prefix, bool b) +{ + Text("%s: %s", prefix, (b ? "true" : "false")); +} + +void ImGui::Value(const char* prefix, int v) +{ + Text("%s: %d", prefix, v); +} + +void ImGui::Value(const char* prefix, unsigned int v) +{ + Text("%s: %d", prefix, v); +} + +void ImGui::Value(const char* prefix, float v, const char* float_format) +{ + if (float_format) + { + char fmt[64]; + ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%s: %s", float_format); + Text(fmt, prefix, v); + } + else + { + Text("%s: %.3f", prefix, v); + } +} + +//----------------------------------------------------------------------------- +// DRAG AND DROP +//----------------------------------------------------------------------------- + +void ImGui::ClearDragDrop() +{ + ImGuiContext& g = *GImGui; + g.DragDropActive = false; + g.DragDropPayload.Clear(); + g.DragDropAcceptIdCurr = g.DragDropAcceptIdPrev = 0; + g.DragDropAcceptIdCurrRectSurface = FLT_MAX; + g.DragDropAcceptFrameCount = -1; +} + +// Call when current ID is active. +// When this returns true you need to: a) call SetDragDropPayload() exactly once, b) you may render the payload visual/description, c) call EndDragDropSource() +bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags, int mouse_button) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + bool source_drag_active = false; + ImGuiID source_id = 0; + ImGuiID source_parent_id = 0; + if (!(flags & ImGuiDragDropFlags_SourceExtern)) + { + source_id = window->DC.LastItemId; + if (source_id != 0 && g.ActiveId != source_id) // Early out for most common case + return false; + if (g.IO.MouseDown[mouse_button] == false) + return false; + + if (source_id == 0) + { + // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to: + // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag, C) Swallow your programmer pride. + if (!(flags & ImGuiDragDropFlags_SourceAllowNullID)) + { + IM_ASSERT(0); + return false; + } + + // Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image() + // We build a throwaway ID based on current ID stack + relative AABB of items in window. + // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled. + // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive. + bool is_hovered = window->DC.LastItemRectHoveredRect; + if (!is_hovered && (g.ActiveId == 0 || g.ActiveIdWindow != window)) + return false; + source_id = window->DC.LastItemId = window->GetIDFromRectangle(window->DC.LastItemRect); + if (is_hovered) + SetHoveredID(source_id); + if (is_hovered && g.IO.MouseClicked[mouse_button]) + { + SetActiveID(source_id, window); + FocusWindow(window); + } + if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker. + g.ActiveIdAllowOverlap = is_hovered; + } + if (g.ActiveId != source_id) + return false; + source_parent_id = window->IDStack.back(); + source_drag_active = IsMouseDragging(mouse_button); + } + else + { + window = NULL; + source_id = ImHash("#SourceExtern", 0); + source_drag_active = true; + } + + if (source_drag_active) + { + if (!g.DragDropActive) + { + IM_ASSERT(source_id != 0); + ClearDragDrop(); + ImGuiPayload& payload = g.DragDropPayload; + payload.SourceId = source_id; + payload.SourceParentId = source_parent_id; + g.DragDropActive = true; + g.DragDropSourceFlags = flags; + g.DragDropMouseButton = mouse_button; + } + + if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) + { + // FIXME-DRAG + //SetNextWindowPos(g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding); + //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This is better but e.g ColorButton with checkboard has issue with transparent colors :( + SetNextWindowPos(g.IO.MousePos); + PushStyleColor(ImGuiCol_PopupBg, GetStyleColorVec4(ImGuiCol_PopupBg) * ImVec4(1.0f, 1.0f, 1.0f, 0.6f)); + BeginTooltipEx(ImGuiWindowFlags_NoInputs); + } + + if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern)) + window->DC.LastItemRectHoveredRect = false; + + return true; + } + return false; +} + +void ImGui::EndDragDropSource() +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.DragDropActive); + + if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) + { + EndTooltip(); + PopStyleColor(); + //PopStyleVar(); + } + + // Discard the drag if have not called SetDragDropPayload() + if (g.DragDropPayload.DataFrameCount == -1) + ClearDragDrop(); +} + +// Use 'cond' to choose to submit payload on drag start or every frame +bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond) +{ + ImGuiContext& g = *GImGui; + ImGuiPayload& payload = g.DragDropPayload; + if (cond == 0) + cond = ImGuiCond_Always; + + IM_ASSERT(type != NULL); + IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType)); // Payload type can be at most 8 characters longs + IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0)); + IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once); + IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource() + + if (cond == ImGuiCond_Always || payload.DataFrameCount == -1) + { + // Copy payload + ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType)); + g.DragDropPayloadBufHeap.resize(0); + if (data_size > sizeof(g.DragDropPayloadBufLocal)) + { + // Store in heap + g.DragDropPayloadBufHeap.resize((int)data_size); + payload.Data = g.DragDropPayloadBufHeap.Data; + memcpy((void*)payload.Data, data, data_size); + } + else if (data_size > 0) + { + // Store locally + memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal)); + payload.Data = g.DragDropPayloadBufLocal; + memcpy((void*)payload.Data, data, data_size); + } + else + { + payload.Data = NULL; + } + payload.DataSize = (int)data_size; + } + payload.DataFrameCount = g.FrameCount; + + return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1); +} + +bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) +{ + ImGuiContext& g = *GImGui; + if (!g.DragDropActive) + return false; + + ImGuiWindow* window = g.CurrentWindow; + if (g.HoveredWindow == NULL || window->RootWindow != g.HoveredWindow->RootWindow) + return false; + IM_ASSERT(id != 0); + if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id == g.DragDropPayload.SourceId)) + return false; + + g.DragDropTargetRect = bb; + g.DragDropTargetId = id; + return true; +} + +// We don't use BeginDragDropTargetCustom() and duplicate its code because: +// 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them. +// 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can. +// Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case) +bool ImGui::BeginDragDropTarget() +{ + ImGuiContext& g = *GImGui; + if (!g.DragDropActive) + return false; + + ImGuiWindow* window = g.CurrentWindow; + if (!window->DC.LastItemRectHoveredRect) + return false; + if (g.HoveredWindow == NULL || window->RootWindow != g.HoveredWindow->RootWindow) + return false; + + ImGuiID id = window->DC.LastItemId; + if (id == 0) + id = window->GetIDFromRectangle(window->DC.LastItemRect); + if (g.DragDropPayload.SourceId == id) + return false; + + g.DragDropTargetRect = window->DC.LastItemRect; + g.DragDropTargetId = id; + return true; +} + +bool ImGui::IsDragDropPayloadBeingAccepted() +{ + ImGuiContext& g = *GImGui; + return g.DragDropActive && g.DragDropAcceptIdPrev != 0; +} + +const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiPayload& payload = g.DragDropPayload; + IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ? + IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ? + if (type != NULL && !payload.IsDataType(type)) + return NULL; + + // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints. + // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function! + const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); + ImRect r = g.DragDropTargetRect; + float r_surface = r.GetWidth() * r.GetHeight(); + if (r_surface < g.DragDropAcceptIdCurrRectSurface) + { + g.DragDropAcceptIdCurr = g.DragDropTargetId; + g.DragDropAcceptIdCurrRectSurface = r_surface; + } + + // Render default drop visuals + payload.Preview = was_accepted_previously; + flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that lives for 1 frame) + if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview) + { + // FIXME-DRAG: Settle on a proper default visuals for drop target. + r.Expand(3.5f); + bool push_clip_rect = !window->ClipRect.Contains(r); + if (push_clip_rect) window->DrawList->PushClipRectFullScreen(); + window->DrawList->AddRect(r.Min, r.Max, GetColorU32(ImGuiCol_DragDropTarget), 0.0f, ~0, 2.0f); + if (push_clip_rect) window->DrawList->PopClipRect(); + } + + g.DragDropAcceptFrameCount = g.FrameCount; + payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased() + if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) + return NULL; + + return &payload; +} + +// We don't really use/need this now, but added it for the sake of consistency and because we might need it later. +void ImGui::EndDragDropTarget() +{ + ImGuiContext& g = *GImGui; (void)g; + IM_ASSERT(g.DragDropActive); +} + +//----------------------------------------------------------------------------- +// PLATFORM DEPENDENT HELPERS +//----------------------------------------------------------------------------- + +#if defined(_WIN32) && !defined(_WINDOWS_) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)) +#undef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#include +#endif + +// Win32 API clipboard implementation +#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) + +#ifdef _MSC_VER +#pragma comment(lib, "user32") +#endif + +static const char* GetClipboardTextFn_DefaultImpl(void*) +{ + static ImVector buf_local; + buf_local.clear(); + if (!OpenClipboard(NULL)) + return NULL; + HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT); + if (wbuf_handle == NULL) + { + CloseClipboard(); + return NULL; + } + if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle)) + { + int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1; + buf_local.resize(buf_len); + ImTextStrToUtf8(buf_local.Data, buf_len, wbuf_global, NULL); + } + GlobalUnlock(wbuf_handle); + CloseClipboard(); + return buf_local.Data; +} + +static void SetClipboardTextFn_DefaultImpl(void*, const char* text) +{ + if (!OpenClipboard(NULL)) + return; + const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1; + HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar)); + if (wbuf_handle == NULL) + { + CloseClipboard(); + return; + } + ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle); + ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL); + GlobalUnlock(wbuf_handle); + EmptyClipboard(); + SetClipboardData(CF_UNICODETEXT, wbuf_handle); + CloseClipboard(); +} + +#else + +// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers +static const char* GetClipboardTextFn_DefaultImpl(void*) +{ + ImGuiContext& g = *GImGui; + return g.PrivateClipboard.empty() ? NULL : g.PrivateClipboard.begin(); +} + +// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers +static void SetClipboardTextFn_DefaultImpl(void*, const char* text) +{ + ImGuiContext& g = *GImGui; + g.PrivateClipboard.clear(); + const char* text_end = text + strlen(text); + g.PrivateClipboard.resize((int)(text_end - text) + 1); + memcpy(&g.PrivateClipboard[0], text, (size_t)(text_end - text)); + g.PrivateClipboard[(int)(text_end - text)] = 0; +} + +#endif + +// Win32 API IME support (for Asian languages, etc.) +#if defined(_WIN32) && !defined(__GNUC__) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) + +#include +#ifdef _MSC_VER +#pragma comment(lib, "imm32") +#endif + +static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) +{ + // Notify OS Input Method Editor of text input position + if (HWND hwnd = (HWND)GImGui->IO.ImeWindowHandle) + if (HIMC himc = ImmGetContext(hwnd)) + { + COMPOSITIONFORM cf; + cf.ptCurrentPos.x = x; + cf.ptCurrentPos.y = y; + cf.dwStyle = CFS_FORCE_POSITION; + ImmSetCompositionWindow(himc, &cf); + } +} + +#else + +static void ImeSetInputScreenPosFn_DefaultImpl(int, int) {} + +#endif + +//----------------------------------------------------------------------------- +// HELP +//----------------------------------------------------------------------------- + +void ImGui::ShowMetricsWindow(bool* p_open) +{ + if (ImGui::Begin("ImGui Metrics", p_open)) + { + ImGui::Text("ImGui %s", ImGui::GetVersion()); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::Text("%d vertices, %d indices (%d triangles)", ImGui::GetIO().MetricsRenderVertices, ImGui::GetIO().MetricsRenderIndices, ImGui::GetIO().MetricsRenderIndices / 3); + ImGui::Text("%d allocations", ImGui::GetIO().MetricsAllocs); + static bool show_clip_rects = true; + ImGui::Checkbox("Show clipping rectangles when hovering an ImDrawCmd", &show_clip_rects); + ImGui::Separator(); + + struct Funcs + { + static void NodeDrawList(ImDrawList* draw_list, const char* label) + { + bool node_open = ImGui::TreeNode(draw_list, "%s: '%s' %d vtx, %d indices, %d cmds", label, draw_list->_OwnerName ? draw_list->_OwnerName : "", draw_list->VtxBuffer.Size, draw_list->IdxBuffer.Size, draw_list->CmdBuffer.Size); + if (draw_list == ImGui::GetWindowDrawList()) + { + ImGui::SameLine(); + ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered) + if (node_open) ImGui::TreePop(); + return; + } + if (!node_open) + return; + + ImDrawList* overlay_draw_list = &GImGui->OverlayDrawList; // Render additional visuals into the top-most draw list + int elem_offset = 0; + for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++) + { + if (pcmd->UserCallback == NULL && pcmd->ElemCount == 0) + continue; + if (pcmd->UserCallback) + { + ImGui::BulletText("Callback %p, user_data %p", pcmd->UserCallback, pcmd->UserCallbackData); + continue; + } + ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL; + bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "Draw %-4d %s vtx, tex = %p, clip_rect = (%.0f,%.0f)..(%.0f,%.0f)", pcmd->ElemCount, draw_list->IdxBuffer.Size > 0 ? "indexed" : "non-indexed", pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); + if (show_clip_rects && ImGui::IsItemHovered()) + { + ImRect clip_rect = pcmd->ClipRect; + ImRect vtxs_rect; + for (int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) + vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos); + clip_rect.Floor(); overlay_draw_list->AddRect(clip_rect.Min, clip_rect.Max, IM_COL32(255,255,0,255)); + vtxs_rect.Floor(); overlay_draw_list->AddRect(vtxs_rect.Min, vtxs_rect.Max, IM_COL32(255,0,255,255)); + } + if (!pcmd_node_open) + continue; + + // Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted. + ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible. + while (clipper.Step()) + for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++) + { + char buf[300]; + char *buf_p = buf, *buf_end = buf + IM_ARRAYSIZE(buf); + ImVec2 triangles_pos[3]; + for (int n = 0; n < 3; n++, vtx_i++) + { + ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i]; + triangles_pos[n] = v.pos; + buf_p += ImFormatString(buf_p, (int)(buf_end - buf_p), "%s %04d { pos = (%8.2f,%8.2f), uv = (%.6f,%.6f), col = %08X }\n", (n == 0) ? "vtx" : " ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col); + } + ImGui::Selectable(buf, false); + if (ImGui::IsItemHovered()) + { + ImDrawListFlags backup_flags = overlay_draw_list->Flags; + overlay_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines at is more readable for very large and thin triangles. + overlay_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255,255,0,255), true, 1.0f); + overlay_draw_list->Flags = backup_flags; + } + } + ImGui::TreePop(); + } + ImGui::TreePop(); + } + + static void NodeWindows(ImVector& windows, const char* label) + { + if (!ImGui::TreeNode(label, "%s (%d)", label, windows.Size)) + return; + for (int i = 0; i < windows.Size; i++) + Funcs::NodeWindow(windows[i], "Window"); + ImGui::TreePop(); + } + + static void NodeWindow(ImGuiWindow* window, const char* label) + { + if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, window->Active || window->WasActive, window)) + return; + NodeDrawList(window->DrawList, "DrawList"); + ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), SizeContents (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->SizeContents.x, window->SizeContents.y); + if (ImGui::IsItemHovered()) + GImGui->OverlayDrawList.AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255,255,0,255)); + ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window)); + ImGui::BulletText("Active: %d, WriteAccessed: %d", window->Active, window->WriteAccessed); + if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow"); + if (window->DC.ChildWindows.Size > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows"); + ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.Size * (int)sizeof(ImGuiStorage::Pair)); + ImGui::TreePop(); + } + }; + + ImGuiContext& g = *GImGui; // Access private state + Funcs::NodeWindows(g.Windows, "Windows"); + if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", g.RenderDrawLists[0].Size)) + { + for (int layer = 0; layer < IM_ARRAYSIZE(g.RenderDrawLists); layer++) + for (int i = 0; i < g.RenderDrawLists[layer].Size; i++) + Funcs::NodeDrawList(g.RenderDrawLists[0][i], "DrawList"); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Popups", "Open Popups Stack (%d)", g.OpenPopupStack.Size)) + { + for (int i = 0; i < g.OpenPopupStack.Size; i++) + { + ImGuiWindow* window = g.OpenPopupStack[i].Window; + ImGui::BulletText("PopupID: %08x, Window: '%s'%s%s", g.OpenPopupStack[i].PopupId, window ? window->Name : "NULL", window && (window->Flags & ImGuiWindowFlags_ChildWindow) ? " ChildWindow" : "", window && (window->Flags & ImGuiWindowFlags_ChildMenu) ? " ChildMenu" : ""); + } + ImGui::TreePop(); + } + if (ImGui::TreeNode("Basic state")) + { + ImGui::Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL"); + ImGui::Text("HoveredRootWindow: '%s'", g.HoveredRootWindow ? g.HoveredRootWindow->Name : "NULL"); + ImGui::Text("HoveredId: 0x%08X/0x%08X (%.2f sec)", g.HoveredId, g.HoveredIdPreviousFrame, g.HoveredIdTimer); // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not + ImGui::Text("ActiveId: 0x%08X/0x%08X (%.2f sec)", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer); + ImGui::Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL"); + ImGui::Text("NavWindow: '%s'", g.NavWindow ? g.NavWindow->Name : "NULL"); + ImGui::TreePop(); + } + } + ImGui::End(); +} + +//----------------------------------------------------------------------------- + +// Include imgui_user.inl at the end of imgui.cpp to access private data/functions that aren't exposed. +// Prefer just including imgui_internal.h from your code rather than using this define. If a declaration is missing from imgui_internal.h add it or request it on the github. +#ifdef IMGUI_INCLUDE_IMGUI_USER_INL +#include "imgui_user.inl" +#endif + +//----------------------------------------------------------------------------- diff --git a/lib/cimgui-1.53.1/imgui-1.53/imgui.h b/lib/cimgui-1.53.1/imgui-1.53/imgui.h new file mode 100644 index 0000000..22e2139 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/imgui.h @@ -0,0 +1,1684 @@ +// dear imgui, v1.53 +// (headers) + +// See imgui.cpp file for documentation. +// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. +// Read 'Programmer guide' in imgui.cpp for notes on how to setup ImGui in your codebase. +// Get latest version at https://github.com/ocornut/imgui + +#pragma once + +#if !defined(IMGUI_DISABLE_INCLUDE_IMCONFIG_H) || defined(IMGUI_INCLUDE_IMCONFIG_H) +#include "imconfig.h" // User-editable configuration file +#endif +#include // FLT_MAX +#include // va_list +#include // ptrdiff_t, NULL +#include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp + +#define IMGUI_VERSION "1.53" + +// Define attributes of all API symbols declarations, e.g. for DLL under Windows. +#ifndef IMGUI_API +#define IMGUI_API +#endif + +// Define assertion handler. +#ifndef IM_ASSERT +#include +#define IM_ASSERT(_EXPR) assert(_EXPR) +#endif + +// Helpers +// Some compilers support applying printf-style warnings to user functions. +#if defined(__clang__) || defined(__GNUC__) +#define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) +#define IM_FMTLIST(FMT) __attribute__((format(printf, FMT, 0))) +#else +#define IM_FMTARGS(FMT) +#define IM_FMTLIST(FMT) +#endif +#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" +#endif + +// Forward declarations +struct ImDrawChannel; // Temporary storage for outputting drawing commands out of order, used by ImDrawList::ChannelsSplit() +struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call) +struct ImDrawData; // All draw command lists required to render the frame +struct ImDrawList; // A single draw command list (generally one per window) +struct ImDrawListSharedData; // Data shared among multiple draw lists (typically owned by parent ImGui context, but you may create one yourself) +struct ImDrawVert; // A single vertex (20 bytes by default, override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT) +struct ImFont; // Runtime data for a single font within a parent ImFontAtlas +struct ImFontAtlas; // Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader +struct ImFontConfig; // Configuration data when adding a font or merging fonts +struct ImColor; // Helper functions to create a color that can be converted to either u32 or float4 +struct ImGuiIO; // Main configuration and I/O between your application and ImGui +struct ImGuiOnceUponAFrame; // Simple helper for running a block of code not more than once a frame, used by IMGUI_ONCE_UPON_A_FRAME macro +struct ImGuiStorage; // Simple custom key value storage +struct ImGuiStyle; // Runtime data for styling/colors +struct ImGuiTextFilter; // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" +struct ImGuiTextBuffer; // Text buffer for logging/accumulating text +struct ImGuiTextEditCallbackData; // Shared state of ImGui::InputText() when using custom ImGuiTextEditCallback (rare/advanced use) +struct ImGuiSizeConstraintCallbackData;// Structure used to constraint window size in custom ways when using custom ImGuiSizeConstraintCallback (rare/advanced use) +struct ImGuiListClipper; // Helper to manually clip large list of items +struct ImGuiPayload; // User data payload for drag and drop operations +struct ImGuiContext; // ImGui context (opaque) + +// Typedefs and Enumerations (declared as int for compatibility and to not pollute the top of this file) +typedef unsigned int ImU32; // 32-bit unsigned integer (typically used to store packed colors) +typedef unsigned int ImGuiID; // unique ID used by widgets (typically hashed from a stack of string) +typedef unsigned short ImWchar; // character for keyboard input/display +typedef void* ImTextureID; // user data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp) +typedef int ImGuiCol; // enum: a color identifier for styling // enum ImGuiCol_ +typedef int ImGuiCond; // enum: a condition for Set*() // enum ImGuiCond_ +typedef int ImGuiKey; // enum: a key identifier (ImGui-side enum) // enum ImGuiKey_ +typedef int ImGuiMouseCursor; // enum: a mouse cursor identifier // enum ImGuiMouseCursor_ +typedef int ImGuiStyleVar; // enum: a variable identifier for styling // enum ImGuiStyleVar_ +typedef int ImDrawCornerFlags; // flags: for ImDrawList::AddRect*() etc. // enum ImDrawCornerFlags_ +typedef int ImDrawListFlags; // flags: for ImDrawList // enum ImDrawListFlags_ +typedef int ImGuiColorEditFlags; // flags: for ColorEdit*(), ColorPicker*() // enum ImGuiColorEditFlags_ +typedef int ImGuiColumnsFlags; // flags: for *Columns*() // enum ImGuiColumnsFlags_ +typedef int ImGuiDragDropFlags; // flags: for *DragDrop*() // enum ImGuiDragDropFlags_ +typedef int ImGuiComboFlags; // flags: for BeginCombo() // enum ImGuiComboFlags_ +typedef int ImGuiFocusedFlags; // flags: for IsWindowFocused() // enum ImGuiFocusedFlags_ +typedef int ImGuiHoveredFlags; // flags: for IsItemHovered() etc. // enum ImGuiHoveredFlags_ +typedef int ImGuiInputTextFlags; // flags: for InputText*() // enum ImGuiInputTextFlags_ +typedef int ImGuiSelectableFlags; // flags: for Selectable() // enum ImGuiSelectableFlags_ +typedef int ImGuiTreeNodeFlags; // flags: for TreeNode*(),CollapsingHeader()// enum ImGuiTreeNodeFlags_ +typedef int ImGuiWindowFlags; // flags: for Begin*() // enum ImGuiWindowFlags_ +typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data); +typedef void (*ImGuiSizeConstraintCallback)(ImGuiSizeConstraintCallbackData* data); +#if defined(_MSC_VER) && !defined(__clang__) +typedef unsigned __int64 ImU64; // 64-bit unsigned integer +#else +typedef unsigned long long ImU64; // 64-bit unsigned integer +#endif + +// Others helpers at bottom of the file: +// class ImVector<> // Lightweight std::vector like class. +// IMGUI_ONCE_UPON_A_FRAME // Execute a block of code once per frame only (convenient for creating UI within deep-nested code that runs multiple times) + +struct ImVec2 +{ + float x, y; + ImVec2() { x = y = 0.0f; } + ImVec2(float _x, float _y) { x = _x; y = _y; } +#ifdef IM_VEC2_CLASS_EXTRA // Define constructor and implicit cast operators in imconfig.h to convert back<>forth from your math types and ImVec2. + IM_VEC2_CLASS_EXTRA +#endif +}; + +struct ImVec4 +{ + float x, y, z, w; + ImVec4() { x = y = z = w = 0.0f; } + ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } +#ifdef IM_VEC4_CLASS_EXTRA // Define constructor and implicit cast operators in imconfig.h to convert back<>forth from your math types and ImVec4. + IM_VEC4_CLASS_EXTRA +#endif +}; + +// ImGui end-user API +// In a namespace so that user can add extra functions in a separate file (e.g. Value() helpers for your vector or common types) +namespace ImGui +{ + // Main + IMGUI_API ImGuiIO& GetIO(); + IMGUI_API ImGuiStyle& GetStyle(); + IMGUI_API ImDrawData* GetDrawData(); // same value as passed to your io.RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame() + IMGUI_API void NewFrame(); // start a new ImGui frame, you can submit any command from this point until Render()/EndFrame(). + IMGUI_API void Render(); // ends the ImGui frame, finalize the draw data, then call your io.RenderDrawListsFn() function if set. + IMGUI_API void EndFrame(); // ends the ImGui frame. automatically called by Render(), so most likely don't need to ever call that yourself directly. If you don't need to render you may call EndFrame() but you'll have wasted CPU already. If you don't need to render, better to not create any imgui windows instead! + IMGUI_API void Shutdown(); + + // Demo, Debug, Informations + IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application! + IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create metrics window. display ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc. + IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style) + IMGUI_API bool ShowStyleSelector(const char* label); + IMGUI_API void ShowFontSelector(const char* label); + IMGUI_API void ShowUserGuide(); // add basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls). + + // Window + IMGUI_API bool Begin(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0); // push window to the stack and start appending to it. see .cpp for details. return false when window is collapsed, so you can early out in your code. 'bool* p_open' creates a widget on the upper-right to close the window (which sets your bool to false). + IMGUI_API void End(); // finish appending to current window, pop it off the window stack. + IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // begin a scrolling region. size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. ImVec2(0,400). + IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // " + IMGUI_API void EndChild(); + IMGUI_API ImVec2 GetContentRegionMax(); // current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates + IMGUI_API ImVec2 GetContentRegionAvail(); // == GetContentRegionMax() - GetCursorPos() + IMGUI_API float GetContentRegionAvailWidth(); // + IMGUI_API ImVec2 GetWindowContentRegionMin(); // content boundaries min (roughly (0,0)-Scroll), in window coordinates + IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max (roughly (0,0)+Size-Scroll) where Size can be override with SetNextWindowContentSize(), in window coordinates + IMGUI_API float GetWindowContentRegionWidth(); // + IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives + IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList api) + IMGUI_API ImVec2 GetWindowSize(); // get current window size + IMGUI_API float GetWindowWidth(); + IMGUI_API float GetWindowHeight(); + IMGUI_API bool IsWindowCollapsed(); + IMGUI_API bool IsWindowAppearing(); + IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows + + IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiCond cond = 0, const ImVec2& pivot = ImVec2(0,0)); // set next window position. call before Begin(). use pivot=(0.5f,0.5f) to center on given point, etc. + IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiCond cond = 0); // set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin() + IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback = NULL, void* custom_callback_data = NULL); // set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Use callback to apply non-trivial programmatic constraints. + IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ enforce the range of scrollbars). not including window decorations (title bar, menu bar, etc.). set an axis to 0.0f to leave it automatic. call before Begin() + IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin() + IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin() + IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects. + IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiCond cond = 0); // (not recommended) set current window size - call within Begin()/End(). set to ImVec2(0,0) to force an auto-fit. prefer using SetNextWindowSize(), as this may incur tearing and minor side-effects. + IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed(). + IMGUI_API void SetWindowFocus(); // (not recommended) set current window to be focused / front-most. prefer using SetNextWindowFocus(). + IMGUI_API void SetWindowPos(const char* name, const ImVec2& pos, ImGuiCond cond = 0); // set named window position. + IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiCond cond = 0); // set named window size. set axis to 0.0f to force an auto-fit on this axis. + IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond = 0); // set named window collapsed state + IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most. use NULL to remove focus. + + IMGUI_API float GetScrollX(); // get scrolling amount [0..GetScrollMaxX()] + IMGUI_API float GetScrollY(); // get scrolling amount [0..GetScrollMaxY()] + IMGUI_API float GetScrollMaxX(); // get maximum scrolling amount ~~ ContentSize.X - WindowSize.X + IMGUI_API float GetScrollMaxY(); // get maximum scrolling amount ~~ ContentSize.Y - WindowSize.Y + IMGUI_API void SetScrollX(float scroll_x); // set scrolling amount [0..GetScrollMaxX()] + IMGUI_API void SetScrollY(float scroll_y); // set scrolling amount [0..GetScrollMaxY()] + IMGUI_API void SetScrollHere(float center_y_ratio = 0.5f); // adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom. When using to make a "default/current item" visible, consider using SetItemDefaultFocus() instead. + IMGUI_API void SetScrollFromPosY(float pos_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions. + IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it) + IMGUI_API ImGuiStorage* GetStateStorage(); + + // Parameters stacks (shared) + IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font + IMGUI_API void PopFont(); + IMGUI_API void PushStyleColor(ImGuiCol idx, ImU32 col); + IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col); + IMGUI_API void PopStyleColor(int count = 1); + IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val); + IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val); + IMGUI_API void PopStyleVar(int count = 1); + IMGUI_API const ImVec4& GetStyleColorVec4(ImGuiCol idx); // retrieve style color as stored in ImGuiStyle structure. use to feed back into PushStyleColor(), otherwhise use GetColorU32() to get style color + style alpha. + IMGUI_API ImFont* GetFont(); // get current font + IMGUI_API float GetFontSize(); // get current font size (= height in pixels) of current font with current scale applied + IMGUI_API ImVec2 GetFontTexUvWhitePixel(); // get UV coordinate for a while pixel, useful to draw custom shapes via the ImDrawList API + IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul = 1.0f); // retrieve given style color with style alpha applied and optional extra alpha multiplier + IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied + IMGUI_API ImU32 GetColorU32(ImU32 col); // retrieve given color with style alpha applied + + // Parameters stacks (current window) + IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side) + IMGUI_API void PopItemWidth(); + IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position + IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space + IMGUI_API void PopTextWrapPos(); + IMGUI_API void PushAllowKeyboardFocus(bool allow_keyboard_focus); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets + IMGUI_API void PopAllowKeyboardFocus(); + IMGUI_API void PushButtonRepeat(bool repeat); // in 'repeat' mode, Button*() functions return repeated true in a typematic manner (using io.KeyRepeatDelay/io.KeyRepeatRate setting). Note that you can call IsItemActive() after any Button() to tell if the button is held in the current frame. + IMGUI_API void PopButtonRepeat(); + + // Cursor / Layout + IMGUI_API void Separator(); // separator, generally horizontal. inside a menu bar or in horizontal layout mode, this becomes a vertical separator. + IMGUI_API void SameLine(float pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally + IMGUI_API void NewLine(); // undo a SameLine() + IMGUI_API void Spacing(); // add vertical spacing + IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size + IMGUI_API void Indent(float indent_w = 0.0f); // move content position toward the right, by style.IndentSpacing or indent_w if != 0 + IMGUI_API void Unindent(float indent_w = 0.0f); // move content position back to the left, by style.IndentSpacing or indent_w if != 0 + IMGUI_API void BeginGroup(); // lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.) + IMGUI_API void EndGroup(); + IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position + IMGUI_API float GetCursorPosX(); // " + IMGUI_API float GetCursorPosY(); // " + IMGUI_API void SetCursorPos(const ImVec2& local_pos); // " + IMGUI_API void SetCursorPosX(float x); // " + IMGUI_API void SetCursorPosY(float y); // " + IMGUI_API ImVec2 GetCursorStartPos(); // initial cursor position + IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates [0..io.DisplaySize] (useful to work with ImDrawList API) + IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates [0..io.DisplaySize] + IMGUI_API void AlignTextToFramePadding(); // vertically align/lower upcoming text to FramePadding.y so that it will aligns to upcoming widgets (call if you have text on a line before regular widgets) + IMGUI_API float GetTextLineHeight(); // ~ FontSize + IMGUI_API float GetTextLineHeightWithSpacing(); // ~ FontSize + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of text) + IMGUI_API float GetFrameHeight(); // ~ FontSize + style.FramePadding.y * 2 + IMGUI_API float GetFrameHeightWithSpacing(); // ~ FontSize + style.FramePadding.y * 2 + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of framed widgets) + + // Columns + // You can also use SameLine(pos_x) for simplified columns. The columns API is still work-in-progress and rather lacking. + IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); + IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished + IMGUI_API int GetColumnIndex(); // get current column index + IMGUI_API float GetColumnWidth(int column_index = -1); // get column width (in pixels). pass -1 to use current column + IMGUI_API void SetColumnWidth(int column_index, float width); // set column width (in pixels). pass -1 to use current column + IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetColumnsCount() inclusive. column 0 is typically 0.0f + IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column + IMGUI_API int GetColumnsCount(); + + // ID scopes + // If you are creating widgets in a loop you most likely want to push a unique identifier (e.g. object pointer, loop index) so ImGui can differentiate them. + // You can also use the "##foobar" syntax within widget label to distinguish them from each others. Read "A primer on the use of labels/IDs" in the FAQ for more details. + IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the entire stack! + IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end); + IMGUI_API void PushID(const void* ptr_id); + IMGUI_API void PushID(int int_id); + IMGUI_API void PopID(); + IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). e.g. if you want to query into ImGuiStorage yourself + IMGUI_API ImGuiID GetID(const char* str_id_begin, const char* str_id_end); + IMGUI_API ImGuiID GetID(const void* ptr_id); + + // Widgets: Text + IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // raw text without formatting. Roughly equivalent to Text("%s", text) but: A) doesn't require null terminated string if 'text_end' is specified, B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text. + IMGUI_API void Text(const char* fmt, ...) IM_FMTARGS(1); // simple formatted text + IMGUI_API void TextV(const char* fmt, va_list args) IM_FMTLIST(1); + IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...) IM_FMTARGS(2); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor(); + IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args) IM_FMTLIST(2); + IMGUI_API void TextDisabled(const char* fmt, ...) IM_FMTARGS(1); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor(); + IMGUI_API void TextDisabledV(const char* fmt, va_list args) IM_FMTLIST(1); + IMGUI_API void TextWrapped(const char* fmt, ...) IM_FMTARGS(1); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize(). + IMGUI_API void TextWrappedV(const char* fmt, va_list args) IM_FMTLIST(1); + IMGUI_API void LabelText(const char* label, const char* fmt, ...) IM_FMTARGS(2); // display text+label aligned the same way as value+label widgets + IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args) IM_FMTLIST(2); + IMGUI_API void BulletText(const char* fmt, ...) IM_FMTARGS(1); // shortcut for Bullet()+Text() + IMGUI_API void BulletTextV(const char* fmt, va_list args) IM_FMTLIST(1); + IMGUI_API void Bullet(); // draw a small circle and keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses + + // Widgets: Main + IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); // button + IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text + IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.) + IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); + IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding + IMGUI_API bool Checkbox(const char* label, bool* v); + IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); + IMGUI_API bool RadioButton(const char* label, bool active); + IMGUI_API bool RadioButton(const char* label, int* v, int v_button); + IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), int stride = sizeof(float)); + IMGUI_API void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); + IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), int stride = sizeof(float)); + IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); + IMGUI_API void ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-1,0), const char* overlay = NULL); + + // Widgets: Combo Box + // The new BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it. + // The old Combo() api are helpers over BeginCombo()/EndCombo() which are kept available for convenience purpose. + IMGUI_API bool BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0); + IMGUI_API void EndCombo(); + IMGUI_API bool Combo(const char* label, int* current_item, const char* const items[], int items_count, int popup_max_height_in_items = -1); + IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_max_height_in_items = -1); // Separate items with \0 within a string, end item-list with \0\0. e.g. "One\0Two\0Three\0" + IMGUI_API bool Combo(const char* label, int* current_item, bool(*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_max_height_in_items = -1); + + // Widgets: Drags (tip: ctrl+click on a drag box to input with keyboard. manually input values aren't clamped, can go off-bounds) + // For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x + IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound + IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragFloat4(const char* label, float v[4], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", const char* display_format_max = NULL, float power = 1.0f); + IMGUI_API bool DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); // If v_min >= v_max we have no bound + IMGUI_API bool DragInt2(const char* label, int v[2], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + IMGUI_API bool DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f", const char* display_format_max = NULL); + + // Widgets: Input with Keyboard + IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); + IMGUI_API bool InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size = ImVec2(0,0), ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); + IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputFloat2(const char* label, float v[2], int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputFloat3(const char* label, float v[3], int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputFloat4(const char* label, float v[4], int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt2(const char* label, int v[2], ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags = 0); + + // Widgets: Sliders (tip: ctrl+click on a slider to input with keyboard. manually input values aren't clamped, can go off-bounds) + IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix for in-slider labels or unit display. Use power!=1.0 for logarithmic sliders + IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool SliderAngle(const char* label, float* v_rad, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); + IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + + // Widgets: Color Editor/Picker (tip: the ColorEdit* functions have a little colored preview square that can be left-clicked to open a picker, and right-clicked to open an option menu.) + // Note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can the pass the address of a first float element out of a contiguous structure, e.g. &myvector.x + IMGUI_API bool ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags = 0); + IMGUI_API bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0); + IMGUI_API bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0); + IMGUI_API bool ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags = 0, const float* ref_col = NULL); + IMGUI_API bool ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags = 0, ImVec2 size = ImVec2(0,0)); // display a colored square/button, hover for details, return true when pressed. + IMGUI_API void SetColorEditOptions(ImGuiColorEditFlags flags); // initialize current options (generally on application startup) if you want to select a default format, picker type, etc. User will be able to change many settings, unless you pass the _NoOptions flag to your calls. + + // Widgets: Trees + IMGUI_API bool TreeNode(const char* label); // if returning 'true' the node is open and the tree id is pushed into the id stack. user is responsible for calling TreePop(). + IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...) IM_FMTARGS(2); // read the FAQ about why and how to use ID. to align arbitrary text at the same level as a TreeNode() you can use Bullet(). + IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...) IM_FMTARGS(2); // " + IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args) IM_FMTLIST(2); + IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args) IM_FMTLIST(2); + IMGUI_API bool TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags = 0); + IMGUI_API bool TreeNodeEx(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, ...) IM_FMTARGS(3); + IMGUI_API bool TreeNodeEx(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, ...) IM_FMTARGS(3); + IMGUI_API bool TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) IM_FMTLIST(3); + IMGUI_API bool TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) IM_FMTLIST(3); + IMGUI_API void TreePush(const char* str_id); // ~ Indent()+PushId(). Already called by TreeNode() when returning true, but you can call Push/Pop yourself for layout purpose + IMGUI_API void TreePush(const void* ptr_id = NULL); // " + IMGUI_API void TreePop(); // ~ Unindent()+PopId() + IMGUI_API void TreeAdvanceToLabelPos(); // advance cursor x position by GetTreeNodeToLabelSpacing() + IMGUI_API float GetTreeNodeToLabelSpacing(); // horizontal distance preceding label when using TreeNode*() or Bullet() == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode + IMGUI_API void SetNextTreeNodeOpen(bool is_open, ImGuiCond cond = 0); // set next TreeNode/CollapsingHeader open state. + IMGUI_API bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0); // if returning 'true' the header is open. doesn't indent nor push on ID stack. user doesn't have to call TreePop(). + IMGUI_API bool CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags flags = 0); // when 'p_open' isn't NULL, display an additional small close button on upper right of the header + + // Widgets: Selectable / Lists + IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height + IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); + IMGUI_API bool ListBox(const char* label, int* current_item, const char* const* items, int items_count, int height_in_items = -1); + IMGUI_API bool ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); + IMGUI_API bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0,0)); // use if you want to reimplement ListBox() will custom data or interactions. make sure to call ListBoxFooter() afterwards. + IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // " + IMGUI_API void ListBoxFooter(); // terminate the scrolling region + + // Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare more in your code to handle your types. you can add functions to the ImGui namespace) + IMGUI_API void Value(const char* prefix, bool b); + IMGUI_API void Value(const char* prefix, int v); + IMGUI_API void Value(const char* prefix, unsigned int v); + IMGUI_API void Value(const char* prefix, float v, const char* float_format = NULL); + + // Tooltips + IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set text tooltip under mouse-cursor, typically use with ImGui::IsItemHovered(). overidde any previous call to SetTooltip(). + IMGUI_API void SetTooltipV(const char* fmt, va_list args) IM_FMTLIST(1); + IMGUI_API void BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of contents). + IMGUI_API void EndTooltip(); + + // Menus + IMGUI_API bool BeginMainMenuBar(); // create and append to a full screen menu-bar. only call EndMainMenuBar() if this returns true! + IMGUI_API void EndMainMenuBar(); + IMGUI_API bool BeginMenuBar(); // append to menu-bar of current window (requires ImGuiWindowFlags_MenuBar flag set on parent window). only call EndMenuBar() if this returns true! + IMGUI_API void EndMenuBar(); + IMGUI_API bool BeginMenu(const char* label, bool enabled = true); // create a sub-menu entry. only call EndMenu() if this returns true! + IMGUI_API void EndMenu(); + IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment + IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL + + // Popups + IMGUI_API void OpenPopup(const char* str_id); // call to mark popup as open (don't call every frame!). popups are closed when user click outside, or if CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. By default, Selectable()/MenuItem() are calling CloseCurrentPopup(). Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). + IMGUI_API bool OpenPopupOnItemClick(const char* str_id = NULL, int mouse_button = 1); // helper to open popup when clicked on last item. return true when just opened. + IMGUI_API bool BeginPopup(const char* str_id); // return true if the popup is open, and you can start outputting to it. only call EndPopup() if BeginPopup() returned true! + IMGUI_API bool BeginPopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (block interactions behind the modal window, can't close the modal window by clicking outside) + IMGUI_API bool BeginPopupContextItem(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id. If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp! + IMGUI_API bool BeginPopupContextWindow(const char* str_id = NULL, int mouse_button = 1, bool also_over_items = true); // helper to open and begin popup when clicked on current window. + IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked in void (where there are no imgui windows). + IMGUI_API void EndPopup(); + IMGUI_API bool IsPopupOpen(const char* str_id); // return true if the popup is open + IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup. + + // Logging/Capture: all text output from interface is captured to tty/file/clipboard. By default, tree nodes are automatically opened during logging. + IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty + IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file + IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard + IMGUI_API void LogFinish(); // stop logging (close file, etc.) + IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard + IMGUI_API void LogText(const char* fmt, ...) IM_FMTARGS(1); // pass text data straight to log (without being displayed) + + // Drag and Drop + // [BETA API] Missing Demo code. API may evolve. + IMGUI_API bool BeginDragDropSource(ImGuiDragDropFlags flags = 0, int mouse_button = 0); // call when the current item is active. If this return true, you can call SetDragDropPayload() + EndDragDropSource() + IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t size, ImGuiCond cond = 0);// type is a user defined string of maximum 8 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui. + IMGUI_API void EndDragDropSource(); + IMGUI_API bool BeginDragDropTarget(); // call after submitting an item that may receive an item. If this returns true, you can call AcceptDragDropPayload() + EndDragDropTarget() + IMGUI_API const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags = 0); // accept contents of a given type. If ImGuiDragDropFlags_AcceptBeforeDelivery is set you can peek into the payload before the mouse button is released. + IMGUI_API void EndDragDropTarget(); + + // Clipping + IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect); + IMGUI_API void PopClipRect(); + + // Styles + IMGUI_API void StyleColorsClassic(ImGuiStyle* dst = NULL); + IMGUI_API void StyleColorsDark(ImGuiStyle* dst = NULL); + IMGUI_API void StyleColorsLight(ImGuiStyle* dst = NULL); + + // Focus + // (FIXME: Those functions will be reworked after we merge the navigation branch + have a pass at focusing/tabbing features.) + // (Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHere()" when applicable, to make your code more forward compatible when navigation branch is merged) + IMGUI_API void SetItemDefaultFocus(); // make last item the default focused item of a window (WIP navigation branch only). Pleaase use instead of SetScrollHere(). + IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. Use -1 to access previous widget. + + // Utilities + IMGUI_API bool IsItemHovered(ImGuiHoveredFlags flags = 0); // is the last item hovered? (and usable, aka not blocked by a popup, etc.). See ImGuiHoveredFlags for more options. + IMGUI_API bool IsItemActive(); // is the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) + IMGUI_API bool IsItemClicked(int mouse_button = 0); // is the last item clicked? (e.g. button/node just clicked on) + IMGUI_API bool IsItemVisible(); // is the last item visible? (aka not out of sight due to clipping/scrolling.) + IMGUI_API bool IsAnyItemHovered(); + IMGUI_API bool IsAnyItemActive(); + IMGUI_API ImVec2 GetItemRectMin(); // get bounding rectangle of last item, in screen space + IMGUI_API ImVec2 GetItemRectMax(); // " + IMGUI_API ImVec2 GetItemRectSize(); // get size of last item, in screen space + IMGUI_API void SetItemAllowOverlap(); // allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area. + IMGUI_API bool IsWindowFocused(ImGuiFocusedFlags flags = 0); // is current window focused? or its root/child, depending on flags. see flags for options. + IMGUI_API bool IsWindowHovered(ImGuiHoveredFlags flags = 0); // is current window hovered (and typically: not blocked by a popup/modal)? see flags for options. + IMGUI_API bool IsAnyWindowFocused(); + IMGUI_API bool IsAnyWindowHovered(); // is mouse hovering any visible window + IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle (of given size, starting from cursor position) is visible / not clipped. + IMGUI_API bool IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max); // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side. + IMGUI_API float GetTime(); + IMGUI_API int GetFrameCount(); + IMGUI_API ImDrawList* GetOverlayDrawList(); // this draw list will be the last rendered one, useful to quickly draw overlays shapes/text + IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); + IMGUI_API const char* GetStyleColorName(ImGuiCol idx); + IMGUI_API ImVec2 CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge = false, float outward = +0.0f); // utility to find the closest point the last item bounding rectangle edge. useful to visually link items + IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); + IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // calculate coarse clipping for large list of evenly sized items. Prefer using the ImGuiListClipper higher-level helper if you can. + + IMGUI_API bool BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags extra_flags = 0); // helper to create a child window / scrolling region that looks like a normal widget frame + IMGUI_API void EndChildFrame(); + + IMGUI_API ImVec4 ColorConvertU32ToFloat4(ImU32 in); + IMGUI_API ImU32 ColorConvertFloat4ToU32(const ImVec4& in); + IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v); + IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); + + // Inputs + IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key] + IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. note that imgui doesn't know the semantic of each entry of io.KeyDown[]. Use your own indices/enums according to how your backend/engine stored them into KeyDown[]! + IMGUI_API bool IsKeyPressed(int user_key_index, bool repeat = true); // was key pressed (went from !Down to Down). if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate + IMGUI_API bool IsKeyReleased(int user_key_index); // was key released (went from Down to !Down).. + IMGUI_API int GetKeyPressedAmount(int key_index, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate + IMGUI_API bool IsMouseDown(int button); // is mouse button held + IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked (went from !Down to Down) + IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked. a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime. + IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down) + IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold + IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup. + IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // + IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls + IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into + IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking. if lock_threshold < -1.0f uses io.MouseDraggingThreshold + IMGUI_API void ResetMouseDragDelta(int button = 0); // + IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you + IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type + IMGUI_API void CaptureKeyboardFromApp(bool capture = true); // manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application handle). e.g. force capture keyboard when your widget is being hovered. + IMGUI_API void CaptureMouseFromApp(bool capture = true); // manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application handle). + + // Helpers functions to access functions pointers in ImGui::GetIO() + IMGUI_API void* MemAlloc(size_t sz); + IMGUI_API void MemFree(void* ptr); + IMGUI_API const char* GetClipboardText(); + IMGUI_API void SetClipboardText(const char* text); + + // Internal context access - if you want to use multiple context, share context between modules (e.g. DLL). There is a default context created and active by default. + // All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context. + IMGUI_API const char* GetVersion(); + IMGUI_API ImGuiContext* CreateContext(void* (*malloc_fn)(size_t) = NULL, void (*free_fn)(void*) = NULL); + IMGUI_API void DestroyContext(ImGuiContext* ctx); + IMGUI_API ImGuiContext* GetCurrentContext(); + IMGUI_API void SetCurrentContext(ImGuiContext* ctx); + +} // namespace ImGui + +// Flags for ImGui::Begin() +enum ImGuiWindowFlags_ +{ + ImGuiWindowFlags_NoTitleBar = 1 << 0, // Disable title-bar + ImGuiWindowFlags_NoResize = 1 << 1, // Disable user resizing with the lower-right grip + ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window + ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbars (window can still scroll with mouse or programatically) + ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set. + ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it + ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame + //ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items (OBSOLETE! Use e.g. style.FrameBorderSize=1.0f to enable borders). + ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file + ImGuiWindowFlags_NoInputs = 1 << 9, // Disable catching mouse or keyboard inputs, hovering test with pass through. + ImGuiWindowFlags_MenuBar = 1 << 10, // Has a menu-bar + ImGuiWindowFlags_HorizontalScrollbar = 1 << 11, // Allow horizontal scrollbar to appear (off by default). You may use SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section. + ImGuiWindowFlags_NoFocusOnAppearing = 1 << 12, // Disable taking focus when transitioning from hidden to visible state + ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, // Disable bringing window to front when taking focus (e.g. clicking on it or programatically giving it focus) + ImGuiWindowFlags_AlwaysVerticalScrollbar= 1 << 14, // Always show vertical scrollbar (even if ContentSize.y < Size.y) + ImGuiWindowFlags_AlwaysHorizontalScrollbar=1<< 15, // Always show horizontal scrollbar (even if ContentSize.x < Size.x) + ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16, // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient) + ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, // (WIP) Enable resize from any corners and borders. Your back-end needs to honor the different values of io.MouseCursor set by imgui. + + // [Internal] + ImGuiWindowFlags_ChildWindow = 1 << 24, // Don't use! For internal use by BeginChild() + ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip() + ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup() + ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal() + ImGuiWindowFlags_ChildMenu = 1 << 28 // Don't use! For internal use by BeginMenu() +}; + +// Flags for ImGui::InputText() +enum ImGuiInputTextFlags_ +{ + ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/ + ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef + ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z + ImGuiInputTextFlags_CharsNoBlank = 1 << 3, // Filter out spaces, tabs + ImGuiInputTextFlags_AutoSelectAll = 1 << 4, // Select entire text when first taking mouse focus + ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to when the value was modified) + ImGuiInputTextFlags_CallbackCompletion = 1 << 6, // Call user function on pressing TAB (for completion handling) + ImGuiInputTextFlags_CallbackHistory = 1 << 7, // Call user function on pressing Up/Down arrows (for history handling) + ImGuiInputTextFlags_CallbackAlways = 1 << 8, // Call user function every time. User code may query cursor position, modify text buffer. + ImGuiInputTextFlags_CallbackCharFilter = 1 << 9, // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character. + ImGuiInputTextFlags_AllowTabInput = 1 << 10, // Pressing TAB input a '\t' character into the text field + ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11, // In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite: unfocus with Ctrl+Enter, add line with Enter). + ImGuiInputTextFlags_NoHorizontalScroll = 1 << 12, // Disable following the cursor horizontally + ImGuiInputTextFlags_AlwaysInsertMode = 1 << 13, // Insert mode + ImGuiInputTextFlags_ReadOnly = 1 << 14, // Read-only mode + ImGuiInputTextFlags_Password = 1 << 15, // Password mode, display all characters as '*' + ImGuiInputTextFlags_NoUndoRedo = 1 << 16, // Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID(). + // [Internal] + ImGuiInputTextFlags_Multiline = 1 << 20 // For internal use by InputTextMultiline() +}; + +// Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*() +enum ImGuiTreeNodeFlags_ +{ + ImGuiTreeNodeFlags_Selected = 1 << 0, // Draw as selected + ImGuiTreeNodeFlags_Framed = 1 << 1, // Full colored frame (e.g. for CollapsingHeader) + ImGuiTreeNodeFlags_AllowItemOverlap = 1 << 2, // Hit testing to allow subsequent widgets to overlap this one + ImGuiTreeNodeFlags_NoTreePushOnOpen = 1 << 3, // Don't do a TreePush() when open (e.g. for CollapsingHeader) = no extra indent nor pushing on ID stack + ImGuiTreeNodeFlags_NoAutoOpenOnLog = 1 << 4, // Don't automatically and temporarily open node when Logging is active (by default logging will automatically open tree nodes) + ImGuiTreeNodeFlags_DefaultOpen = 1 << 5, // Default node to be open + ImGuiTreeNodeFlags_OpenOnDoubleClick = 1 << 6, // Need double-click to open node + ImGuiTreeNodeFlags_OpenOnArrow = 1 << 7, // Only open when clicking on the arrow part. If ImGuiTreeNodeFlags_OpenOnDoubleClick is also set, single-click arrow or double-click all box to open. + ImGuiTreeNodeFlags_Leaf = 1 << 8, // No collapsing, no arrow (use as a convenience for leaf nodes). + ImGuiTreeNodeFlags_Bullet = 1 << 9, // Display a bullet instead of arrow + ImGuiTreeNodeFlags_FramePadding = 1 << 10, // Use FramePadding (even for an unframed text node) to vertically align text baseline to regular widget height. Equivalent to calling AlignTextToFramePadding(). + //ImGuITreeNodeFlags_SpanAllAvailWidth = 1 << 11, // FIXME: TODO: Extend hit box horizontally even if not framed + //ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 12, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible + ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoAutoOpenOnLog + + // Obsolete names (will be removed) +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + , ImGuiTreeNodeFlags_AllowOverlapMode = ImGuiTreeNodeFlags_AllowItemOverlap +#endif +}; + +// Flags for ImGui::Selectable() +enum ImGuiSelectableFlags_ +{ + ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this don't close parent popup window + ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column) + ImGuiSelectableFlags_AllowDoubleClick = 1 << 2 // Generate press events on double clicks too +}; + +// Flags for ImGui::BeginCombo() +enum ImGuiComboFlags_ +{ + ImGuiComboFlags_PopupAlignLeft = 1 << 0, // Align the popup toward the left by default + ImGuiComboFlags_HeightSmall = 1 << 1, // Max ~4 items visible. Tip: If you want your combo popup to be a specific size you can use SetNextWindowSizeConstraints() prior to calling BeginCombo() + ImGuiComboFlags_HeightRegular = 1 << 2, // Max ~8 items visible (default) + ImGuiComboFlags_HeightLarge = 1 << 3, // Max ~20 items visible + ImGuiComboFlags_HeightLargest = 1 << 4, // As many fitting items as possible + ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest +}; + +// Flags for ImGui::IsWindowFocused() +enum ImGuiFocusedFlags_ +{ + ImGuiFocusedFlags_ChildWindows = 1 << 0, // IsWindowFocused(): Return true if any children of the window is focused + ImGuiFocusedFlags_RootWindow = 1 << 1, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy) + ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows +}; + +// Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() +enum ImGuiHoveredFlags_ +{ + ImGuiHoveredFlags_Default = 0, // Return true if directly over the item/window, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under them. + ImGuiHoveredFlags_ChildWindows = 1 << 0, // IsWindowHovered() only: Return true if any children of the window is hovered + ImGuiHoveredFlags_RootWindow = 1 << 1, // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy) + ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 2, // Return true even if a popup window is normally blocking access to this item/window + //ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 3, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet. + ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 4, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns. + ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 5, // Return true even if the position is overlapped by another window + ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, + ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows +}; + +// Flags for ImGui::BeginDragDropSource(), ImGui::AcceptDragDropPayload() +enum ImGuiDragDropFlags_ +{ + // BeginDragDropSource() flags + ImGuiDragDropFlags_SourceNoPreviewTooltip = 1 << 0, // By default, a successful call to BeginDragDropSource opens a tooltip so you can display a preview or description of the source contents. This flag disable this behavior. + ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, // By default, when dragging we clear data so that IsItemHovered() will return true, to avoid subsequent user code submitting tooltips. This flag disable this behavior so you can still call IsItemHovered() on the source item. + ImGuiDragDropFlags_SourceNoHoldToOpenOthers = 1 << 2, // Disable the behavior that allows to open tree nodes and collapsing header by holding over them while dragging a source item. + ImGuiDragDropFlags_SourceAllowNullID = 1 << 3, // Allow items such as Text(), Image() that have no unique identifier to be used as drag source, by manufacturing a temporary identifier based on their window-relative position. This is extremely unusual within the dear imgui ecosystem and so we made it explicit. + ImGuiDragDropFlags_SourceExtern = 1 << 4, // External source (from outside of imgui), won't attempt to read current item/window info. Will always return true. Only one Extern source can be active simultaneously. + // AcceptDragDropPayload() flags + ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, // AcceptDragDropPayload() will returns true even before the mouse button is released. You can then call IsDelivery() to test if the payload needs to be delivered. + ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, // Do not draw the default highlight rectangle when hovering over target. + ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect // For peeking ahead and inspecting the payload before delivery. +}; + +// Standard Drag and Drop payload types. You can define you own payload types using 8-characters long strings. Types starting with '_' are defined by Dear ImGui. +#define IMGUI_PAYLOAD_TYPE_COLOR_3F "_COL3F" // float[3] // Standard type for colors, without alpha. User code may use this type. +#define IMGUI_PAYLOAD_TYPE_COLOR_4F "_COL4F" // float[4] // Standard type for colors. User code may use this type. + +// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array +enum ImGuiKey_ +{ + ImGuiKey_Tab, // for tabbing through fields + ImGuiKey_LeftArrow, // for text edit + ImGuiKey_RightArrow,// for text edit + ImGuiKey_UpArrow, // for text edit + ImGuiKey_DownArrow, // for text edit + ImGuiKey_PageUp, + ImGuiKey_PageDown, + ImGuiKey_Home, // for text edit + ImGuiKey_End, // for text edit + ImGuiKey_Delete, // for text edit + ImGuiKey_Backspace, // for text edit + ImGuiKey_Enter, // for text edit + ImGuiKey_Escape, // for text edit + ImGuiKey_A, // for text edit CTRL+A: select all + ImGuiKey_C, // for text edit CTRL+C: copy + ImGuiKey_V, // for text edit CTRL+V: paste + ImGuiKey_X, // for text edit CTRL+X: cut + ImGuiKey_Y, // for text edit CTRL+Y: redo + ImGuiKey_Z, // for text edit CTRL+Z: undo + ImGuiKey_COUNT +}; + +// Enumeration for PushStyleColor() / PopStyleColor() +enum ImGuiCol_ +{ + ImGuiCol_Text, + ImGuiCol_TextDisabled, + ImGuiCol_WindowBg, // Background of normal windows + ImGuiCol_ChildBg, // Background of child windows + ImGuiCol_PopupBg, // Background of popups, menus, tooltips windows + ImGuiCol_Border, + ImGuiCol_BorderShadow, + ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input + ImGuiCol_FrameBgHovered, + ImGuiCol_FrameBgActive, + ImGuiCol_TitleBg, + ImGuiCol_TitleBgActive, + ImGuiCol_TitleBgCollapsed, + ImGuiCol_MenuBarBg, + ImGuiCol_ScrollbarBg, + ImGuiCol_ScrollbarGrab, + ImGuiCol_ScrollbarGrabHovered, + ImGuiCol_ScrollbarGrabActive, + ImGuiCol_CheckMark, + ImGuiCol_SliderGrab, + ImGuiCol_SliderGrabActive, + ImGuiCol_Button, + ImGuiCol_ButtonHovered, + ImGuiCol_ButtonActive, + ImGuiCol_Header, + ImGuiCol_HeaderHovered, + ImGuiCol_HeaderActive, + ImGuiCol_Separator, + ImGuiCol_SeparatorHovered, + ImGuiCol_SeparatorActive, + ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGripHovered, + ImGuiCol_ResizeGripActive, + ImGuiCol_CloseButton, + ImGuiCol_CloseButtonHovered, + ImGuiCol_CloseButtonActive, + ImGuiCol_PlotLines, + ImGuiCol_PlotLinesHovered, + ImGuiCol_PlotHistogram, + ImGuiCol_PlotHistogramHovered, + ImGuiCol_TextSelectedBg, + ImGuiCol_ModalWindowDarkening, // darken entire screen when a modal window is active + ImGuiCol_DragDropTarget, + ImGuiCol_COUNT + + // Obsolete names (will be removed) +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + //, ImGuiCol_ComboBg = ImGuiCol_PopupBg // ComboBg has been merged with PopupBg, so a redirect isn't accurate. + , ImGuiCol_ChildWindowBg = ImGuiCol_ChildBg, ImGuiCol_Column = ImGuiCol_Separator, ImGuiCol_ColumnHovered = ImGuiCol_SeparatorHovered, ImGuiCol_ColumnActive = ImGuiCol_SeparatorActive +#endif +}; + +// Enumeration for PushStyleVar() / PopStyleVar() to temporarily modify the ImGuiStyle structure. +// NB: the enum only refers to fields of ImGuiStyle which makes sense to be pushed/popped inside UI code. During initialization, feel free to just poke into ImGuiStyle directly. +// NB: if changing this enum, you need to update the associated internal table GStyleVarInfo[] accordingly. This is where we link enum values to members offset/type. +enum ImGuiStyleVar_ +{ + // Enum name ......................// Member in ImGuiStyle structure (see ImGuiStyle for descriptions) + ImGuiStyleVar_Alpha, // float Alpha + ImGuiStyleVar_WindowPadding, // ImVec2 WindowPadding + ImGuiStyleVar_WindowRounding, // float WindowRounding + ImGuiStyleVar_WindowBorderSize, // float WindowBorderSize + ImGuiStyleVar_WindowMinSize, // ImVec2 WindowMinSize + ImGuiStyleVar_ChildRounding, // float ChildRounding + ImGuiStyleVar_ChildBorderSize, // float ChildBorderSize + ImGuiStyleVar_PopupRounding, // float PopupRounding + ImGuiStyleVar_PopupBorderSize, // float PopupBorderSize + ImGuiStyleVar_FramePadding, // ImVec2 FramePadding + ImGuiStyleVar_FrameRounding, // float FrameRounding + ImGuiStyleVar_FrameBorderSize, // float FrameBorderSize + ImGuiStyleVar_ItemSpacing, // ImVec2 ItemSpacing + ImGuiStyleVar_ItemInnerSpacing, // ImVec2 ItemInnerSpacing + ImGuiStyleVar_IndentSpacing, // float IndentSpacing + ImGuiStyleVar_GrabMinSize, // float GrabMinSize + ImGuiStyleVar_ButtonTextAlign, // ImVec2 ButtonTextAlign + ImGuiStyleVar_Count_ + + // Obsolete names (will be removed) +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + , ImGuiStyleVar_ChildWindowRounding = ImGuiStyleVar_ChildRounding +#endif +}; + +// Enumeration for ColorEdit3() / ColorEdit4() / ColorPicker3() / ColorPicker4() / ColorButton() +enum ImGuiColorEditFlags_ +{ + ImGuiColorEditFlags_NoAlpha = 1 << 1, // // ColorEdit, ColorPicker, ColorButton: ignore Alpha component (read 3 components from the input pointer). + ImGuiColorEditFlags_NoPicker = 1 << 2, // // ColorEdit: disable picker when clicking on colored square. + ImGuiColorEditFlags_NoOptions = 1 << 3, // // ColorEdit: disable toggling options menu when right-clicking on inputs/small preview. + ImGuiColorEditFlags_NoSmallPreview = 1 << 4, // // ColorEdit, ColorPicker: disable colored square preview next to the inputs. (e.g. to show only the inputs) + ImGuiColorEditFlags_NoInputs = 1 << 5, // // ColorEdit, ColorPicker: disable inputs sliders/text widgets (e.g. to show only the small preview colored square). + ImGuiColorEditFlags_NoTooltip = 1 << 6, // // ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview. + ImGuiColorEditFlags_NoLabel = 1 << 7, // // ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker). + ImGuiColorEditFlags_NoSidePreview = 1 << 8, // // ColorPicker: disable bigger color preview on right side of the picker, use small colored square preview instead. + // User Options (right-click on widget to change some of them). You can set application defaults using SetColorEditOptions(). The idea is that you probably don't want to override them in most of your calls, let the user choose and/or call SetColorEditOptions() during startup. + ImGuiColorEditFlags_AlphaBar = 1 << 9, // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker. + ImGuiColorEditFlags_AlphaPreview = 1 << 10, // // ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque. + ImGuiColorEditFlags_AlphaPreviewHalf= 1 << 11, // // ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque. + ImGuiColorEditFlags_HDR = 1 << 12, // // (WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well). + ImGuiColorEditFlags_RGB = 1 << 13, // [Inputs] // ColorEdit: choose one among RGB/HSV/HEX. ColorPicker: choose any combination using RGB/HSV/HEX. + ImGuiColorEditFlags_HSV = 1 << 14, // [Inputs] // " + ImGuiColorEditFlags_HEX = 1 << 15, // [Inputs] // " + ImGuiColorEditFlags_Uint8 = 1 << 16, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255. + ImGuiColorEditFlags_Float = 1 << 17, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers. + ImGuiColorEditFlags_PickerHueBar = 1 << 18, // [PickerMode] // ColorPicker: bar for Hue, rectangle for Sat/Value. + ImGuiColorEditFlags_PickerHueWheel = 1 << 19, // [PickerMode] // ColorPicker: wheel for Hue, triangle for Sat/Value. + // Internals/Masks + ImGuiColorEditFlags__InputsMask = ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_HSV|ImGuiColorEditFlags_HEX, + ImGuiColorEditFlags__DataTypeMask = ImGuiColorEditFlags_Uint8|ImGuiColorEditFlags_Float, + ImGuiColorEditFlags__PickerMask = ImGuiColorEditFlags_PickerHueWheel|ImGuiColorEditFlags_PickerHueBar, + ImGuiColorEditFlags__OptionsDefault = ImGuiColorEditFlags_Uint8|ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_PickerHueBar // Change application default using SetColorEditOptions() +}; + +// Enumeration for GetMouseCursor() +enum ImGuiMouseCursor_ +{ + ImGuiMouseCursor_None = -1, + ImGuiMouseCursor_Arrow = 0, + ImGuiMouseCursor_TextInput, // When hovering over InputText, etc. + ImGuiMouseCursor_Move, // Unused + ImGuiMouseCursor_ResizeNS, // When hovering over an horizontal border + ImGuiMouseCursor_ResizeEW, // When hovering over a vertical border or a column + ImGuiMouseCursor_ResizeNESW, // When hovering over the bottom-left corner of a window + ImGuiMouseCursor_ResizeNWSE, // When hovering over the bottom-right corner of a window + ImGuiMouseCursor_Count_ +}; + +// Condition for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions +// All those functions treat 0 as a shortcut to ImGuiCond_Always. From the point of view of the user use this as an enum (don't combine multiple values into flags). +enum ImGuiCond_ +{ + ImGuiCond_Always = 1 << 0, // Set the variable + ImGuiCond_Once = 1 << 1, // Set the variable once per runtime session (only the first call with succeed) + ImGuiCond_FirstUseEver = 1 << 2, // Set the variable if the window has no saved data (if doesn't exist in the .ini file) + ImGuiCond_Appearing = 1 << 3 // Set the variable if the window is appearing after being hidden/inactive (or the first time) + + // Obsolete names (will be removed) +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + , ImGuiSetCond_Always = ImGuiCond_Always, ImGuiSetCond_Once = ImGuiCond_Once, ImGuiSetCond_FirstUseEver = ImGuiCond_FirstUseEver, ImGuiSetCond_Appearing = ImGuiCond_Appearing +#endif +}; + +struct ImGuiStyle +{ + float Alpha; // Global alpha applies to everything in ImGui + ImVec2 WindowPadding; // Padding within a window + float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + float WindowBorderSize; // Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly) + ImVec2 WindowMinSize; // Minimum window size + ImVec2 WindowTitleAlign; // Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. + float ChildRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows. + float ChildBorderSize; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly) + float PopupRounding; // Radius of popup window corners rounding. + float PopupBorderSize; // Thickness of border around popup windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly) + ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) + float FrameRounding; // Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets). + float FrameBorderSize; // Thickness of border around frames. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly) + ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines + ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) + ImVec2 TouchExtraPadding; // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much! + float IndentSpacing; // Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2). + float ColumnsMinSpacing; // Minimum horizontal spacing between two columns + float ScrollbarSize; // Width of the vertical scrollbar, Height of the horizontal scrollbar + float ScrollbarRounding; // Radius of grab corners for scrollbar + float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar. + float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs. + ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f,0.5f) for horizontally+vertically centered. + ImVec2 DisplayWindowPadding; // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows. + ImVec2 DisplaySafeAreaPadding; // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. + bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU. + bool AntiAliasedFill; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) + float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. + ImVec4 Colors[ImGuiCol_COUNT]; + + IMGUI_API ImGuiStyle(); + IMGUI_API void ScaleAllSizes(float scale_factor); +}; + +// This is where your app communicate with ImGui. Access via ImGui::GetIO(). +// Read 'Programmer guide' section in .cpp file for general usage. +struct ImGuiIO +{ + //------------------------------------------------------------------ + // Settings (fill once) // Default value: + //------------------------------------------------------------------ + + ImVec2 DisplaySize; // // Display size, in pixels. For clamping windows positions. + float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. + float IniSavingRate; // = 5.0f // Maximum time between saving positions/sizes to .ini file, in seconds. + const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving. + const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified). + float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. + float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. + float MouseDragThreshold; // = 6.0f // Distance threshold before considering we are dragging + int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array + float KeyRepeatDelay; // = 0.250f // When holding a key/button, time before it starts repeating, in seconds (for buttons in Repeat mode, etc.). + float KeyRepeatRate; // = 0.050f // When holding a key/button, rate at which it repeats, in seconds. + void* UserData; // = NULL // Store your own data for retrieval by callbacks. + + ImFontAtlas* Fonts; // // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array. + float FontGlobalScale; // = 1.0f // Global scale all fonts + bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel. + ImFont* FontDefault; // = NULL // Font to use on NewFrame(). Use NULL to uses Fonts->Fonts[0]. + ImVec2 DisplayFramebufferScale; // = (1.0f,1.0f) // For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui. + ImVec2 DisplayVisibleMin; // (0.0f,0.0f) // If you use DisplaySize as a virtual space larger than your screen, set DisplayVisibleMin/Max to the visible area. + ImVec2 DisplayVisibleMax; // (0.0f,0.0f) // If the values are the same, we defaults to Min=(0.0f) and Max=DisplaySize + + // Advanced/subtle behaviors + bool OptMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl + bool OptCursorBlink; // = true // Enable blinking cursor, for users who consider it annoying. + + //------------------------------------------------------------------ + // Settings (User Functions) + //------------------------------------------------------------------ + + // Rendering function, will be called in Render(). + // Alternatively you can keep this to NULL and call GetDrawData() after Render() to get the same pointer. + // See example applications if you are unsure of how to implement this. + void (*RenderDrawListsFn)(ImDrawData* data); + + // Optional: access OS clipboard + // (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures) + const char* (*GetClipboardTextFn)(void* user_data); + void (*SetClipboardTextFn)(void* user_data, const char* text); + void* ClipboardUserData; + + // Optional: override memory allocations. MemFreeFn() may be called with a NULL pointer. + // (default to posix malloc/free) + void* (*MemAllocFn)(size_t sz); + void (*MemFreeFn)(void* ptr); + + // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME in Windows) + // (default to use native imm32 api on Windows) + void (*ImeSetInputScreenPosFn)(int x, int y); + void* ImeWindowHandle; // (Windows) Set this to your HWND to get automatic IME cursor positioning. + + //------------------------------------------------------------------ + // Input - Fill before calling NewFrame() + //------------------------------------------------------------------ + + ImVec2 MousePos; // Mouse position, in pixels. Set to ImVec2(-FLT_MAX,-FLT_MAX) if mouse is unavailable (on another screen, etc.) + bool MouseDown[5]; // Mouse buttons: left, right, middle + extras. ImGui itself mostly only uses left button (BeginPopupContext** are using right button). Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. + float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text. + bool MouseDrawCursor; // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). + bool KeyCtrl; // Keyboard modifier pressed: Control + bool KeyShift; // Keyboard modifier pressed: Shift + bool KeyAlt; // Keyboard modifier pressed: Alt + bool KeySuper; // Keyboard modifier pressed: Cmd/Super/Windows + bool KeysDown[512]; // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data) + ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. + + // Functions + IMGUI_API void AddInputCharacter(ImWchar c); // Add new character into InputCharacters[] + IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Add new characters into InputCharacters[] from an UTF-8 string + inline void ClearInputCharacters() { InputCharacters[0] = 0; } // Clear the text input buffer manually + + //------------------------------------------------------------------ + // Output - Retrieve after calling NewFrame() + //------------------------------------------------------------------ + + bool WantCaptureMouse; // When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. This is set by ImGui when it wants to use your mouse (e.g. unclicked mouse is hovering a window, or a widget is active). + bool WantCaptureKeyboard; // When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. This is set by ImGui when it wants to use your keyboard inputs. + bool WantTextInput; // Mobile/console: when io.WantTextInput is true, you may display an on-screen keyboard. This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). + bool WantMoveMouse; // [BETA-NAV] MousePos has been altered, back-end should reposition mouse on next frame. Set only when 'NavMovesMouse=true'. + float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames + int MetricsAllocs; // Number of active memory allocations + int MetricsRenderVertices; // Vertices output during last call to Render() + int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 + int MetricsActiveWindows; // Number of visible root windows (exclude child windows) + ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta. + + //------------------------------------------------------------------ + // [Internal] ImGui will maintain those fields. Forward compatibility not guaranteed! + //------------------------------------------------------------------ + + ImVec2 MousePosPrev; // Previous mouse position temporary storage (nb: not for public use, set to MousePos in NewFrame()) + ImVec2 MouseClickedPos[5]; // Position at time of clicking + float MouseClickedTime[5]; // Time of last click (used to figure out double-click) + bool MouseClicked[5]; // Mouse button went from !Down to Down + bool MouseDoubleClicked[5]; // Has mouse button been double-clicked? + bool MouseReleased[5]; // Mouse button went from Down to !Down + bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds. + float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked) + float MouseDownDurationPrev[5]; // Previous time the mouse button has been down + ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point + float KeysDownDuration[512]; // Duration the keyboard key has been down (0.0f == just pressed) + float KeysDownDurationPrev[512]; // Previous duration the key has been down + + IMGUI_API ImGuiIO(); +}; + +//----------------------------------------------------------------------------- +// Obsolete functions (Will be removed! Also see 'API BREAKING CHANGES' section in imgui.cpp) +//----------------------------------------------------------------------------- + +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS +namespace ImGui +{ + static inline void ShowTestWindow() { return ShowDemoWindow(); } // OBSOLETE 1.53+ + static inline bool IsRootWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootWindow); } // OBSOLETE 1.53+ + static inline bool IsRootWindowOrAnyChildFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); } // OBSOLETE 1.53+ + static inline void SetNextWindowContentWidth(float width) { SetNextWindowContentSize(ImVec2(width, 0.0f)); } // OBSOLETE 1.53+ (nb: original version preserved last Y value set by SetNextWindowContentSize()) + static inline bool IsRootWindowOrAnyChildHovered(ImGuiHoveredFlags flags = 0) { return IsItemHovered(flags | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows); } // OBSOLETE 1.53+ use flags directly + bool Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override = -1.0f, ImGuiWindowFlags flags = 0); // OBSOLETE 1.52+. use SetNextWindowSize() instead if you want to set a window size. + static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); } // OBSOLETE 1.52+ + static inline void SetNextWindowPosCenter(ImGuiCond cond = 0) { SetNextWindowPos(ImVec2(GetIO().DisplaySize.x * 0.5f, GetIO().DisplaySize.y * 0.5f), cond, ImVec2(0.5f, 0.5f)); } // OBSOLETE 1.52+ + static inline bool IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); } // OBSOLETE 1.51+ + static inline bool IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // OBSOLETE 1.51+. This was partly broken. You probably wanted to use ImGui::GetIO().WantCaptureMouse instead. + static inline bool IsMouseHoveringAnyWindow() { return IsAnyWindowHovered(); } // OBSOLETE 1.51+ + static inline bool IsMouseHoveringWindow() { return IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); } // OBSOLETE 1.51+ + static inline bool CollapsingHeader(const char* label, const char* str_id, bool framed = true, bool default_open = false) { (void)str_id; (void)framed; ImGuiTreeNodeFlags default_open_flags = 1 << 5; return CollapsingHeader(label, (default_open ? default_open_flags : 0)); } // OBSOLETE 1.49+ +} +#endif + +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- + +// Lightweight std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). +// Our implementation does NOT call C++ constructors/destructors. This is intentional and we do not require it. Do not use this class as a straight std::vector replacement in your code! +template +class ImVector +{ +public: + int Size; + int Capacity; + T* Data; + + typedef T value_type; + typedef value_type* iterator; + typedef const value_type* const_iterator; + + inline ImVector() { Size = Capacity = 0; Data = NULL; } + inline ~ImVector() { if (Data) ImGui::MemFree(Data); } + + inline bool empty() const { return Size == 0; } + inline int size() const { return Size; } + inline int capacity() const { return Capacity; } + + inline value_type& operator[](int i) { IM_ASSERT(i < Size); return Data[i]; } + inline const value_type& operator[](int i) const { IM_ASSERT(i < Size); return Data[i]; } + + inline void clear() { if (Data) { Size = Capacity = 0; ImGui::MemFree(Data); Data = NULL; } } + inline iterator begin() { return Data; } + inline const_iterator begin() const { return Data; } + inline iterator end() { return Data + Size; } + inline const_iterator end() const { return Data + Size; } + inline value_type& front() { IM_ASSERT(Size > 0); return Data[0]; } + inline const value_type& front() const { IM_ASSERT(Size > 0); return Data[0]; } + inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size - 1]; } + inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size - 1]; } + inline void swap(ImVector& rhs) { int rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; int rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } + + inline int _grow_capacity(int size) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > size ? new_capacity : size; } + + inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; } + inline void resize(int new_size, const T& v){ if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) Data[n] = v; Size = new_size; } + inline void reserve(int new_capacity) + { + if (new_capacity <= Capacity) + return; + T* new_data = (value_type*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); + if (Data) + memcpy(new_data, Data, (size_t)Size * sizeof(T)); + ImGui::MemFree(Data); + Data = new_data; + Capacity = new_capacity; + } + + inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); Data[Size++] = v; } + inline void pop_back() { IM_ASSERT(Size > 0); Size--; } + inline void push_front(const value_type& v) { if (Size == 0) push_back(v); else insert(Data, v); } + + inline iterator erase(const_iterator it) { IM_ASSERT(it >= Data && it < Data+Size); const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + 1, ((size_t)Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; } + inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(_grow_capacity(Size + 1)); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; return Data + off; } + inline bool contains(const value_type& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data++ == v) return true; return false; } +}; + +// Helper: execute a block of code at maximum once a frame. Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame. +// Usage: +// static ImGuiOnceUponAFrame oaf; +// if (oaf) +// ImGui::Text("This will be called only once per frame"); +struct ImGuiOnceUponAFrame +{ + ImGuiOnceUponAFrame() { RefFrame = -1; } + mutable int RefFrame; + operator bool() const { int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; } +}; + +// Helper macro for ImGuiOnceUponAFrame. Attention: The macro expands into 2 statement so make sure you don't use it within e.g. an if() statement without curly braces. +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS // Will obsolete +#define IMGUI_ONCE_UPON_A_FRAME static ImGuiOnceUponAFrame imgui_oaf; if (imgui_oaf) +#endif + +// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" +struct ImGuiTextFilter +{ + struct TextRange + { + const char* b; + const char* e; + + TextRange() { b = e = NULL; } + TextRange(const char* _b, const char* _e) { b = _b; e = _e; } + const char* begin() const { return b; } + const char* end() const { return e; } + bool empty() const { return b == e; } + char front() const { return *b; } + static bool is_blank(char c) { return c == ' ' || c == '\t'; } + void trim_blanks() { while (b < e && is_blank(*b)) b++; while (e > b && is_blank(*(e-1))) e--; } + IMGUI_API void split(char separator, ImVector& out); + }; + + char InputBuf[256]; + ImVector Filters; + int CountGrep; + + IMGUI_API ImGuiTextFilter(const char* default_filter = ""); + IMGUI_API bool Draw(const char* label = "Filter (inc,-exc)", float width = 0.0f); // Helper calling InputText+Build + IMGUI_API bool PassFilter(const char* text, const char* text_end = NULL) const; + IMGUI_API void Build(); + void Clear() { InputBuf[0] = 0; Build(); } + bool IsActive() const { return !Filters.empty(); } +}; + +// Helper: Text buffer for logging/accumulating text +struct ImGuiTextBuffer +{ + ImVector Buf; + + ImGuiTextBuffer() { Buf.push_back(0); } + inline char operator[](int i) { return Buf.Data[i]; } + const char* begin() const { return &Buf.front(); } + const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator + int size() const { return Buf.Size - 1; } + bool empty() { return Buf.Size <= 1; } + void clear() { Buf.clear(); Buf.push_back(0); } + void reserve(int capacity) { Buf.reserve(capacity); } + const char* c_str() const { return Buf.Data; } + IMGUI_API void appendf(const char* fmt, ...) IM_FMTARGS(2); + IMGUI_API void appendfv(const char* fmt, va_list args) IM_FMTLIST(2); +}; + +// Helper: Simple Key->value storage +// Typically you don't have to worry about this since a storage is held within each Window. +// We use it to e.g. store collapse state for a tree (Int 0/1), store color edit options. +// This is optimized for efficient reading (dichotomy into a contiguous buffer), rare writing (typically tied to user interactions) +// You can use it as custom user storage for temporary values. Declare your own storage if, for example: +// - You want to manipulate the open/close state of a particular sub-tree in your interface (tree node uses Int 0/1 to store their state). +// - You want to store custom debug data easily without adding or editing structures in your code (probably not efficient, but convenient) +// Types are NOT stored, so it is up to you to make sure your Key don't collide with different types. +struct ImGuiStorage +{ + struct Pair + { + ImGuiID key; + union { int val_i; float val_f; void* val_p; }; + Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } + Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } + Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; } + }; + ImVector Data; + + // - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N) + // - Set***() functions find pair, insertion on demand if missing. + // - Sorted insertion is costly, paid once. A typical frame shouldn't need to insert any new pair. + void Clear() { Data.clear(); } + IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const; + IMGUI_API void SetInt(ImGuiID key, int val); + IMGUI_API bool GetBool(ImGuiID key, bool default_val = false) const; + IMGUI_API void SetBool(ImGuiID key, bool val); + IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const; + IMGUI_API void SetFloat(ImGuiID key, float val); + IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL + IMGUI_API void SetVoidPtr(ImGuiID key, void* val); + + // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set. + // - References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer. + // - A typical use case where this is convenient for quick hacking (e.g. add storage during a live Edit&Continue session if you can't modify existing struct) + // float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar; + IMGUI_API int* GetIntRef(ImGuiID key, int default_val = 0); + IMGUI_API bool* GetBoolRef(ImGuiID key, bool default_val = false); + IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0.0f); + IMGUI_API void** GetVoidPtrRef(ImGuiID key, void* default_val = NULL); + + // Use on your own storage if you know only integer are being stored (open/close all tree nodes) + IMGUI_API void SetAllInt(int val); + + // For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once. + IMGUI_API void BuildSortByKey(); +}; + +// Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used and the corresponding callback is triggered. +struct ImGuiTextEditCallbackData +{ + ImGuiInputTextFlags EventFlag; // One of ImGuiInputTextFlags_Callback* // Read-only + ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only + void* UserData; // What user passed to InputText() // Read-only + bool ReadOnly; // Read-only mode // Read-only + + // CharFilter event: + ImWchar EventChar; // Character input // Read-write (replace character or set to zero) + + // Completion,History,Always events: + // If you modify the buffer contents make sure you update 'BufTextLen' and set 'BufDirty' to true. + ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only + char* Buf; // Current text buffer // Read-write (pointed data only, can't replace the actual pointer) + int BufTextLen; // Current text length in bytes // Read-write + int BufSize; // Maximum text length in bytes // Read-only + bool BufDirty; // Set if you modify Buf/BufTextLen!! // Write + int CursorPos; // // Read-write + int SelectionStart; // // Read-write (== to SelectionEnd when no selection) + int SelectionEnd; // // Read-write + + // NB: Helper functions for text manipulation. Calling those function loses selection. + IMGUI_API void DeleteChars(int pos, int bytes_count); + IMGUI_API void InsertChars(int pos, const char* text, const char* text_end = NULL); + bool HasSelection() const { return SelectionStart != SelectionEnd; } +}; + +// Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraints(). Callback is called during the next Begin(). +// NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraints() parameters are enough. +struct ImGuiSizeConstraintCallbackData +{ + void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraints() + ImVec2 Pos; // Read-only. Window position, for reference. + ImVec2 CurrentSize; // Read-only. Current window size. + ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing. +}; + +// Data payload for Drag and Drop operations +struct ImGuiPayload +{ + // Members + const void* Data; // Data (copied and owned by dear imgui) + int DataSize; // Data size + + // [Internal] + ImGuiID SourceId; // Source item id + ImGuiID SourceParentId; // Source parent id (if available) + int DataFrameCount; // Data timestamp + char DataType[8 + 1]; // Data type tag (short user-supplied string) + bool Preview; // Set when AcceptDragDropPayload() was called and mouse has been hovering the target item (nb: handle overlapping drag targets) + bool Delivery; // Set when AcceptDragDropPayload() was called and mouse button is released over the target item. + + ImGuiPayload() { Clear(); } + void Clear() { SourceId = SourceParentId = 0; Data = NULL; DataSize = 0; memset(DataType, 0, sizeof(DataType)); DataFrameCount = -1; Preview = Delivery = false; } + bool IsDataType(const char* type) const { return DataFrameCount != -1 && strcmp(type, DataType) == 0; } + bool IsPreview() const { return Preview; } + bool IsDelivery() const { return Delivery; } +}; + +// Helpers macros to generate 32-bits encoded colors +#ifdef IMGUI_USE_BGRA_PACKED_COLOR +#define IM_COL32_R_SHIFT 16 +#define IM_COL32_G_SHIFT 8 +#define IM_COL32_B_SHIFT 0 +#define IM_COL32_A_SHIFT 24 +#define IM_COL32_A_MASK 0xFF000000 +#else +#define IM_COL32_R_SHIFT 0 +#define IM_COL32_G_SHIFT 8 +#define IM_COL32_B_SHIFT 16 +#define IM_COL32_A_SHIFT 24 +#define IM_COL32_A_MASK 0xFF000000 +#endif +#define IM_COL32(R,G,B,A) (((ImU32)(A)<>IM_COL32_R_SHIFT)&0xFF) * sc; Value.y = (float)((rgba>>IM_COL32_G_SHIFT)&0xFF) * sc; Value.z = (float)((rgba>>IM_COL32_B_SHIFT)&0xFF) * sc; Value.w = (float)((rgba>>IM_COL32_A_SHIFT)&0xFF) * sc; } + ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; } + ImColor(const ImVec4& col) { Value = col; } + inline operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); } + inline operator ImVec4() const { return Value; } + + // FIXME-OBSOLETE: May need to obsolete/cleanup those helpers. + inline void SetHSV(float h, float s, float v, float a = 1.0f){ ImGui::ColorConvertHSVtoRGB(h, s, v, Value.x, Value.y, Value.z); Value.w = a; } + static ImColor HSV(float h, float s, float v, float a = 1.0f) { float r,g,b; ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); return ImColor(r,g,b,a); } +}; + +// Helper: Manually clip large list of items. +// If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse clipping based on visibility to save yourself from processing those items at all. +// The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped. +// ImGui already clip items based on their bounds but it needs to measure text size to do so. Coarse clipping before submission makes this cost and your own data fetching/submission cost null. +// Usage: +// ImGuiListClipper clipper(1000); // we have 1000 elements, evenly spaced. +// while (clipper.Step()) +// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) +// ImGui::Text("line number %d", i); +// - Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height (step skipped if we passed a known height as second arg to constructor). +// - Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element. +// - (Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user call Step(). Does nothing and switch to Step 3.) +// - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop. +struct ImGuiListClipper +{ + float StartPosY; + float ItemsHeight; + int ItemsCount, StepNo, DisplayStart, DisplayEnd; + + // items_count: Use -1 to ignore (you can call Begin later). Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step). + // items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing(). + // If you don't specify an items_height, you NEED to call Step(). If you specify items_height you may call the old Begin()/End() api directly, but prefer calling Step(). + ImGuiListClipper(int items_count = -1, float items_height = -1.0f) { Begin(items_count, items_height); } // NB: Begin() initialize every fields (as we allow user to call Begin/End multiple times on a same instance if they want). + ~ImGuiListClipper() { IM_ASSERT(ItemsCount == -1); } // Assert if user forgot to call End() or Step() until false. + + IMGUI_API bool Step(); // Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items. + IMGUI_API void Begin(int items_count, float items_height = -1.0f); // Automatically called by constructor if you passed 'items_count' or by Step() in Step 1. + IMGUI_API void End(); // Automatically called on the last call of Step() that returns false. +}; + +//----------------------------------------------------------------------------- +// Draw List +// Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList. +//----------------------------------------------------------------------------- + +// Draw callbacks for advanced uses. +// NB- You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that) +// Draw callback may be useful for example, A) Change your GPU render state, B) render a complex 3D scene inside a UI element (without an intermediate texture/render target), etc. +// The expected behavior from your rendering function is 'if (cmd.UserCallback != NULL) cmd.UserCallback(parent_list, cmd); else RenderTriangles()' +typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd); + +// Typically, 1 command = 1 GPU draw call (unless command is a callback) +struct ImDrawCmd +{ + unsigned int ElemCount; // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[]. + ImVec4 ClipRect; // Clipping rectangle (x1, y1, x2, y2) + ImTextureID TextureId; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas. + ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally. + void* UserCallbackData; // The draw callback code can access this. + + ImDrawCmd() { ElemCount = 0; ClipRect.x = ClipRect.y = ClipRect.z = ClipRect.w = 0.0f; TextureId = NULL; UserCallback = NULL; UserCallbackData = NULL; } +}; + +// Vertex index (override with '#define ImDrawIdx unsigned int' inside in imconfig.h) +#ifndef ImDrawIdx +typedef unsigned short ImDrawIdx; +#endif + +// Vertex layout +#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT +struct ImDrawVert +{ + ImVec2 pos; + ImVec2 uv; + ImU32 col; +}; +#else +// You can override the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h +// The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine. +// The type has to be described within the macro (you can either declare the struct or use a typedef) +// NOTE: IMGUI DOESN'T CLEAR THE STRUCTURE AND DOESN'T CALL A CONSTRUCTOR SO ANY CUSTOM FIELD WILL BE UNINITIALIZED. IF YOU ADD EXTRA FIELDS (SUCH AS A 'Z' COORDINATES) YOU WILL NEED TO CLEAR THEM DURING RENDER OR TO IGNORE THEM. +IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT; +#endif + +// Draw channels are used by the Columns API to "split" the render list into different channels while building, so items of each column can be batched together. +// You can also use them to simulate drawing layers and submit primitives in a different order than how they will be rendered. +struct ImDrawChannel +{ + ImVector CmdBuffer; + ImVector IdxBuffer; +}; + +enum ImDrawCornerFlags_ +{ + ImDrawCornerFlags_TopLeft = 1 << 0, // 0x1 + ImDrawCornerFlags_TopRight = 1 << 1, // 0x2 + ImDrawCornerFlags_BotLeft = 1 << 2, // 0x4 + ImDrawCornerFlags_BotRight = 1 << 3, // 0x8 + ImDrawCornerFlags_Top = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight, // 0x3 + ImDrawCornerFlags_Bot = ImDrawCornerFlags_BotLeft | ImDrawCornerFlags_BotRight, // 0xC + ImDrawCornerFlags_Left = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft, // 0x5 + ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight, // 0xA + ImDrawCornerFlags_All = 0xF // In your function calls you may use ~0 (= all bits sets) instead of ImDrawCornerFlags_All, as a convenience +}; + +enum ImDrawListFlags_ +{ + ImDrawListFlags_AntiAliasedLines = 1 << 0, + ImDrawListFlags_AntiAliasedFill = 1 << 1 +}; + +// Draw command list +// This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering. +// Each ImGui window contains its own ImDrawList. You can use ImGui::GetWindowDrawList() to access the current window draw list and draw custom primitives. +// You can interleave normal ImGui:: calls and adding primitives to the current draw list. +// All positions are generally in pixel coordinates (top-left at (0,0), bottom-right at io.DisplaySize), however you are totally free to apply whatever transformation matrix to want to the data (if you apply such transformation you'll want to apply it to ClipRect as well) +// Important: Primitives are always added to the list and not culled (culling is done at higher-level by ImGui:: functions), if you use this API a lot consider coarse culling your drawn objects. +struct ImDrawList +{ + // This is what you have to render + ImVector CmdBuffer; // Draw commands. Typically 1 command = 1 GPU draw call, unless the command is a callback. + ImVector IdxBuffer; // Index buffer. Each command consume ImDrawCmd::ElemCount of those + ImVector VtxBuffer; // Vertex buffer. + + // [Internal, used while building lists] + ImDrawListFlags Flags; // Flags, you may poke into these to adjust anti-aliasing settings per-primitive. + const ImDrawListSharedData* _Data; // Pointer to shared draw data (you can use ImGui::GetDrawListSharedData() to get the one from current ImGui context) + const char* _OwnerName; // Pointer to owner window's name for debugging + unsigned int _VtxCurrentIdx; // [Internal] == VtxBuffer.Size + ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much) + ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much) + ImVector _ClipRectStack; // [Internal] + ImVector _TextureIdStack; // [Internal] + ImVector _Path; // [Internal] current path building + int _ChannelsCurrent; // [Internal] current channel number (0) + int _ChannelsCount; // [Internal] number of active channels (1+) + ImVector _Channels; // [Internal] draw channels for columns API (not resized down so _ChannelsCount may be smaller than _Channels.Size) + + ImDrawList(const ImDrawListSharedData* shared_data) { _Data = shared_data; _OwnerName = NULL; Clear(); } + ~ImDrawList() { ClearFreeMemory(); } + IMGUI_API void PushClipRect(ImVec2 clip_rect_min, ImVec2 clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) + IMGUI_API void PushClipRectFullScreen(); + IMGUI_API void PopClipRect(); + IMGUI_API void PushTextureID(const ImTextureID& texture_id); + IMGUI_API void PopTextureID(); + inline ImVec2 GetClipRectMin() const { const ImVec4& cr = _ClipRectStack.back(); return ImVec2(cr.x, cr.y); } + inline ImVec2 GetClipRectMax() const { const ImVec4& cr = _ClipRectStack.back(); return ImVec2(cr.z, cr.w); } + + // Primitives + IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); + IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners_flags = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right, rounding_corners_flags: 4-bits corresponding to which corner to round + IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners_flags = ImDrawCornerFlags_All); // a: upper-left, b: lower-right + IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); + IMGUI_API void AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col, float thickness = 1.0f); + IMGUI_API void AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col); + IMGUI_API void AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness = 1.0f); + IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); + IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); + IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); + IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); + IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); + IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a = ImVec2(0,0), const ImVec2& uv_b = ImVec2(1,1), ImU32 col = 0xFFFFFFFF); + IMGUI_API void AddImageQuad(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a = ImVec2(0,0), const ImVec2& uv_b = ImVec2(1,0), const ImVec2& uv_c = ImVec2(1,1), const ImVec2& uv_d = ImVec2(0,1), ImU32 col = 0xFFFFFFFF); + IMGUI_API void AddImageRounded(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col, float rounding, int rounding_corners = ImDrawCornerFlags_All); + IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness); + IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col); + IMGUI_API void AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments = 0); + + // Stateful path API, add points then finish with PathFill() or PathStroke() + inline void PathClear() { _Path.resize(0); } + inline void PathLineTo(const ImVec2& pos) { _Path.push_back(pos); } + inline void PathLineToMergeDuplicate(const ImVec2& pos) { if (_Path.Size == 0 || memcmp(&_Path[_Path.Size-1], &pos, 8) != 0) _Path.push_back(pos); } + inline void PathFillConvex(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col); PathClear(); } + inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness); PathClear(); } + IMGUI_API void PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 10); + IMGUI_API void PathArcToFast(const ImVec2& centre, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle + IMGUI_API void PathBezierCurveTo(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, int num_segments = 0); + IMGUI_API void PathRect(const ImVec2& rect_min, const ImVec2& rect_max, float rounding = 0.0f, int rounding_corners_flags = ImDrawCornerFlags_All); + + // Channels + // - Use to simulate layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives) + // - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end) + IMGUI_API void ChannelsSplit(int channels_count); + IMGUI_API void ChannelsMerge(); + IMGUI_API void ChannelsSetCurrent(int channel_index); + + // Advanced + IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles. + IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible + + // Internal helpers + // NB: all primitives needs to be reserved via PrimReserve() beforehand! + IMGUI_API void Clear(); + IMGUI_API void ClearFreeMemory(); + IMGUI_API void PrimReserve(int idx_count, int vtx_count); + IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col); // Axis aligned rectangle (composed of two triangles) + IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col); + IMGUI_API void PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col); + inline void PrimWriteVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col){ _VtxWritePtr->pos = pos; _VtxWritePtr->uv = uv; _VtxWritePtr->col = col; _VtxWritePtr++; _VtxCurrentIdx++; } + inline void PrimWriteIdx(ImDrawIdx idx) { *_IdxWritePtr = idx; _IdxWritePtr++; } + inline void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { PrimWriteIdx((ImDrawIdx)_VtxCurrentIdx); PrimWriteVtx(pos, uv, col); } + IMGUI_API void UpdateClipRect(); + IMGUI_API void UpdateTextureID(); +}; + +// All draw data to render an ImGui frame +struct ImDrawData +{ + bool Valid; // Only valid after Render() is called and before the next NewFrame() is called. + ImDrawList** CmdLists; + int CmdListsCount; + int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size + int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size + + // Functions + ImDrawData() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; } + IMGUI_API void DeIndexAllBuffers(); // For backward compatibility or convenience: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering! + IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution. +}; + +struct ImFontConfig +{ + void* FontData; // // TTF/OTF data + int FontDataSize; // // TTF/OTF data size + bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the container ImFontAtlas (will delete memory itself). + int FontNo; // 0 // Index of font within TTF/OTF file + float SizePixels; // // Size in pixels for rasterizer. + int OversampleH, OversampleV; // 3, 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis. + bool PixelSnapH; // false // Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font. If enabled, you can set OversampleH/V to 1. + ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now. + ImVec2 GlyphOffset; // 0, 0 // Offset all glyphs from this font input. + const ImWchar* GlyphRanges; // NULL // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. + bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights. + unsigned int RasterizerFlags; // 0x00 // Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one. + float RasterizerMultiply; // 1.0f // Brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable. + + // [Internal] + char Name[32]; // Name (strictly to ease debugging) + ImFont* DstFont; + + IMGUI_API ImFontConfig(); +}; + +struct ImFontGlyph +{ + ImWchar Codepoint; // 0x0000..0xFFFF + float AdvanceX; // Distance to next character (= data from font + ImFontConfig::GlyphExtraSpacing.x baked in) + float X0, Y0, X1, Y1; // Glyph corners + float U0, V0, U1, V1; // Texture coordinates +}; + +// Load and rasterize multiple TTF/OTF fonts into a same texture. +// Sharing a texture for multiple fonts allows us to reduce the number of draw calls during rendering. +// We also add custom graphic data into the texture that serves for ImGui. +// 1. (Optional) Call AddFont*** functions. If you don't call any, the default font will be loaded for you. +// 2. Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data. +// 3. Upload the pixels data into a texture within your graphics system. +// 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture. +// IMPORTANT: If you pass a 'glyph_ranges' array to AddFont*** functions, you need to make sure that your array persist up until the ImFont is build (when calling GetTextData*** or Build()). We only copy the pointer, not the data. +struct ImFontAtlas +{ + IMGUI_API ImFontAtlas(); + IMGUI_API ~ImFontAtlas(); + IMGUI_API ImFont* AddFont(const ImFontConfig* font_cfg); + IMGUI_API ImFont* AddFontDefault(const ImFontConfig* font_cfg = NULL); + IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); + IMGUI_API ImFont* AddFontFromMemoryTTF(void* font_data, int font_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after Build(). Set font_cfg->FontDataOwnedByAtlas to false to keep ownership. + IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_font_data, int compressed_font_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. + IMGUI_API ImFont* AddFontFromMemoryCompressedBase85TTF(const char* compressed_font_data_base85, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter. + IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory. + IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges) + IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates) + IMGUI_API void Clear(); // Clear all + + // Build atlas, retrieve pixel data. + // User is in charge of copying the pixels into graphics memory (e.g. create a texture with your engine). Then store your texture handle with SetTexID(). + // RGBA32 format is provided for convenience and compatibility, but note that unless you use CustomRect to draw color data, the RGB pixels emitted from Fonts will all be white (~75% of waste). + // Pitch = Width * BytesPerPixels + IMGUI_API bool Build(); // Build pixels data. This is called automatically for you by the GetTexData*** functions. + IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel + IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel + void SetTexID(ImTextureID id) { TexID = id; } + + //------------------------------------------- + // Glyph Ranges + //------------------------------------------- + + // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list) + // NB: Make sure that your string are UTF-8 and NOT in your local code page. In C++11, you can create UTF-8 string literal using the u8"Hello world" syntax. See FAQ for details. + IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin + IMGUI_API const ImWchar* GetGlyphRangesKorean(); // Default + Korean characters + IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs + IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Default + Japanese + full set of about 21000 CJK Unified Ideographs + IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters + IMGUI_API const ImWchar* GetGlyphRangesThai(); // Default + Thai characters + + // Helpers to build glyph ranges from text data. Feed your application strings/characters to it then call BuildRanges(). + struct GlyphRangesBuilder + { + ImVector UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used) + GlyphRangesBuilder() { UsedChars.resize(0x10000 / 8); memset(UsedChars.Data, 0, 0x10000 / 8); } + bool GetBit(int n) { return (UsedChars[n >> 3] & (1 << (n & 7))) != 0; } + void SetBit(int n) { UsedChars[n >> 3] |= 1 << (n & 7); } // Set bit 'c' in the array + void AddChar(ImWchar c) { SetBit(c); } // Add character + IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added) + IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault) to force add all of ASCII/Latin+Ext + IMGUI_API void BuildRanges(ImVector* out_ranges); // Output new ranges + }; + + //------------------------------------------- + // Custom Rectangles/Glyphs API + //------------------------------------------- + + // You can request arbitrary rectangles to be packed into the atlas, for your own purposes. After calling Build(), you can query the rectangle position and render your pixels. + // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), so you can render e.g. custom colorful icons and use them as regular glyphs. + struct CustomRect + { + unsigned int ID; // Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data. + unsigned short Width, Height; // Input // Desired rectangle dimension + unsigned short X, Y; // Output // Packed position in Atlas + float GlyphAdvanceX; // Input // For custom font glyphs only (ID<0x10000): glyph xadvance + ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID<0x10000): glyph display offset + ImFont* Font; // Input // For custom font glyphs only (ID<0x10000): target font + CustomRect() { ID = 0xFFFFFFFF; Width = Height = 0; X = Y = 0xFFFF; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0,0); Font = NULL; } + bool IsPacked() const { return X != 0xFFFF; } + }; + + IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList + IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font. + IMGUI_API void CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max); + const CustomRect* GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; } + + //------------------------------------------- + // Members + //------------------------------------------- + + ImTextureID TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure. + int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. + int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. + + // [Internal] + // NB: Access texture data via GetTexData*() calls! Which will setup a default font for you. + unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight + unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4 + int TexWidth; // Texture width calculated during Build(). + int TexHeight; // Texture height calculated during Build(). + ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel + ImVector Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font. + ImVector CustomRects; // Rectangles for packing custom texture data into the atlas. + ImVector ConfigData; // Internal data + int CustomRectIds[1]; // Identifiers of custom texture rectangle used by ImFontAtlas/ImDrawList +}; + +// Font runtime data and rendering +// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32(). +struct ImFont +{ + // Members: Hot ~62/78 bytes + float FontSize; // // Height of characters, set during loading (don't change after loading) + float Scale; // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale() + ImVec2 DisplayOffset; // = (0.f,1.f) // Offset font rendering by xx pixels + ImVector Glyphs; // // All glyphs. + ImVector IndexAdvanceX; // // Sparse. Glyphs->AdvanceX in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI). + ImVector IndexLookup; // // Sparse. Index glyphs by Unicode code-point. + const ImFontGlyph* FallbackGlyph; // == FindGlyph(FontFallbackChar) + float FallbackAdvanceX; // == FallbackGlyph->AdvanceX + ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar() + + // Members: Cold ~18/26 bytes + short ConfigDataCount; // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont. + ImFontConfig* ConfigData; // // Pointer within ContainerAtlas->ConfigData + ImFontAtlas* ContainerAtlas; // // What we has been loaded into + float Ascent, Descent; // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] + int MetricsTotalSurface;// // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) + + // Methods + IMGUI_API ImFont(); + IMGUI_API ~ImFont(); + IMGUI_API void ClearOutputData(); + IMGUI_API void BuildLookupTable(); + IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const; + IMGUI_API void SetFallbackChar(ImWchar c); + float GetCharAdvance(ImWchar c) const { return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; } + bool IsLoaded() const { return ContainerAtlas != NULL; } + const char* GetDebugName() const { return ConfigData ? ConfigData->Name : ""; } + + // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable. + // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable. + IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8 + IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const; + IMGUI_API void RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, unsigned short c) const; + IMGUI_API void RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false) const; + + // [Internal] + IMGUI_API void GrowIndex(int new_size); + IMGUI_API void AddGlyph(ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x); + IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built. + +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + typedef ImFontGlyph Glyph; // OBSOLETE 1.52+ +#endif +}; + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + +// Include imgui_user.h at the end of imgui.h (convenient for user to only explicitly include vanilla imgui.h) +#ifdef IMGUI_INCLUDE_IMGUI_USER_H +#include "imgui_user.h" +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/imgui_demo.cpp b/lib/cimgui-1.53.1/imgui-1.53/imgui_demo.cpp new file mode 100644 index 0000000..d739dfa --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/imgui_demo.cpp @@ -0,0 +1,3067 @@ +// dear imgui, v1.53 +// (demo code) + +// Message to the person tempted to delete this file when integrating ImGui into their code base: +// Don't do it! Do NOT remove this file from your project! It is useful reference code that you and other users will want to refer to. +// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow(). +// During development, you can call ImGui::ShowDemoWindow() in your code to learn about various features of ImGui. Have it wired in a debug menu! +// Removing this file from your project is hindering access to documentation for everyone in your team, likely leading you to poorer usage of the library. +// Note that you can #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h for the same effect. +// If you want to link core ImGui in your final builds but not those demo windows, #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h and those functions will be empty. +// In other situation, when you have ImGui available you probably want this to be available for reference and execution. +// Thank you, +// -Your beloved friend, imgui_demo.cpp (that you won't delete) + +// Message to beginner C/C++ programmers. About the meaning of 'static': in this demo code, we frequently we use 'static' variables inside functions. +// We do this as a way to gather code and data in the same place, just to make the demo code faster to read, faster to write, and use less code. +// A static variable persist across calls, so it is essentially like a global variable but declared inside the scope of the function. +// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant or used in threads. +// This might be a pattern you occasionally want to use in your code, but most of the real data you would be editing is likely to be stored outside your function. + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include "imgui.h" +#include // toupper, isprint +#include // sqrtf, powf, cosf, sinf, floorf, ceilf +#include // vsnprintf, sscanf, printf +#include // NULL, malloc, free, atoi +#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier +#include // intptr_t +#else +#include // intptr_t +#endif + +#ifdef _MSC_VER +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#define snprintf _snprintf +#endif +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse. +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // warning : 'xx' is deprecated: The POSIX name for this item.. // for strdup used in demo code (so user can copy & paste the code) +#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int' +#pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal +#pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals. +#if __has_warning("-Wreserved-id-macro") +#pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier // +#endif +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size +#pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure) +#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function +#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value +#if (__GNUC__ >= 6) +#pragma GCC diagnostic ignored "-Wmisleading-indentation" // warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub. +#endif +#endif + +// Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n. +#ifdef _WIN32 +#define IM_NEWLINE "\r\n" +#else +#define IM_NEWLINE "\n" +#endif + +#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B)) + +//----------------------------------------------------------------------------- +// DEMO CODE +//----------------------------------------------------------------------------- + +#if !defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) && defined(IMGUI_DISABLE_TEST_WINDOWS) && !defined(IMGUI_DISABLE_DEMO_WINDOWS) // Obsolete name since 1.53, TEST->DEMO +#define IMGUI_DISABLE_DEMO_WINDOWS +#endif + +#if !defined(IMGUI_DISABLE_DEMO_WINDOWS) + +static void ShowExampleAppConsole(bool* p_open); +static void ShowExampleAppLog(bool* p_open); +static void ShowExampleAppLayout(bool* p_open); +static void ShowExampleAppPropertyEditor(bool* p_open); +static void ShowExampleAppLongText(bool* p_open); +static void ShowExampleAppAutoResize(bool* p_open); +static void ShowExampleAppConstrainedResize(bool* p_open); +static void ShowExampleAppFixedOverlay(bool* p_open); +static void ShowExampleAppWindowTitles(bool* p_open); +static void ShowExampleAppCustomRendering(bool* p_open); +static void ShowExampleAppMainMenuBar(); +static void ShowExampleMenuFile(); + +static void ShowHelpMarker(const char* desc) +{ + ImGui::TextDisabled("(?)"); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(450.0f); + ImGui::TextUnformatted(desc); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } +} + +void ImGui::ShowUserGuide() +{ + ImGui::BulletText("Double-click on title bar to collapse window."); + ImGui::BulletText("Click and drag on lower right corner to resize window\n(double-click to auto fit window to its contents)."); + ImGui::BulletText("Click and drag on any empty space to move window."); + ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields."); + ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text."); + if (ImGui::GetIO().FontAllowUserScaling) + ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents."); + ImGui::BulletText("Mouse Wheel to scroll."); + ImGui::BulletText("While editing text:\n"); + ImGui::Indent(); + ImGui::BulletText("Hold SHIFT or use mouse to select text."); + ImGui::BulletText("CTRL+Left/Right to word jump."); + ImGui::BulletText("CTRL+A or double-click to select all."); + ImGui::BulletText("CTRL+X,CTRL+C,CTRL+V to use clipboard."); + ImGui::BulletText("CTRL+Z,CTRL+Y to undo/redo."); + ImGui::BulletText("ESCAPE to revert."); + ImGui::BulletText("You can apply arithmetic operators +,*,/ on numerical values.\nUse +- to subtract."); + ImGui::Unindent(); +} + +// Demonstrate most ImGui features (big function!) +void ImGui::ShowDemoWindow(bool* p_open) +{ + // Examples apps + static bool show_app_main_menu_bar = false; + static bool show_app_console = false; + static bool show_app_log = false; + static bool show_app_layout = false; + static bool show_app_property_editor = false; + static bool show_app_long_text = false; + static bool show_app_auto_resize = false; + static bool show_app_constrained_resize = false; + static bool show_app_fixed_overlay = false; + static bool show_app_window_titles = false; + static bool show_app_custom_rendering = false; + static bool show_app_style_editor = false; + + static bool show_app_metrics = false; + static bool show_app_about = false; + + if (show_app_main_menu_bar) ShowExampleAppMainMenuBar(); + if (show_app_console) ShowExampleAppConsole(&show_app_console); + if (show_app_log) ShowExampleAppLog(&show_app_log); + if (show_app_layout) ShowExampleAppLayout(&show_app_layout); + if (show_app_property_editor) ShowExampleAppPropertyEditor(&show_app_property_editor); + if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text); + if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize); + if (show_app_constrained_resize) ShowExampleAppConstrainedResize(&show_app_constrained_resize); + if (show_app_fixed_overlay) ShowExampleAppFixedOverlay(&show_app_fixed_overlay); + if (show_app_window_titles) ShowExampleAppWindowTitles(&show_app_window_titles); + if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering); + + if (show_app_metrics) { ImGui::ShowMetricsWindow(&show_app_metrics); } + if (show_app_style_editor) { ImGui::Begin("Style Editor", &show_app_style_editor); ImGui::ShowStyleEditor(); ImGui::End(); } + if (show_app_about) + { + ImGui::Begin("About Dear ImGui", &show_app_about, ImGuiWindowFlags_AlwaysAutoResize); + ImGui::Text("dear imgui, %s", ImGui::GetVersion()); + ImGui::Separator(); + ImGui::Text("By Omar Cornut and all dear imgui contributors."); + ImGui::Text("Dear ImGui is licensed under the MIT License, see LICENSE for more information."); + ImGui::End(); + } + + static bool no_titlebar = false; + static bool no_scrollbar = false; + static bool no_menu = false; + static bool no_move = false; + static bool no_resize = false; + static bool no_collapse = false; + static bool no_close = false; + + // Demonstrate the various window flags. Typically you would just use the default. + ImGuiWindowFlags window_flags = 0; + if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar; + if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar; + if (!no_menu) window_flags |= ImGuiWindowFlags_MenuBar; + if (no_move) window_flags |= ImGuiWindowFlags_NoMove; + if (no_resize) window_flags |= ImGuiWindowFlags_NoResize; + if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse; + if (no_close) p_open = NULL; // Don't pass our bool* to Begin + + ImGui::SetNextWindowSize(ImVec2(550,680), ImGuiCond_FirstUseEver); + if (!ImGui::Begin("ImGui Demo", p_open, window_flags)) + { + // Early out if the window is collapsed, as an optimization. + ImGui::End(); + return; + } + + //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels + ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels + + ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION); + + // Menu + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("Menu")) + { + ShowExampleMenuFile(); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Examples")) + { + ImGui::MenuItem("Main menu bar", NULL, &show_app_main_menu_bar); + ImGui::MenuItem("Console", NULL, &show_app_console); + ImGui::MenuItem("Log", NULL, &show_app_log); + ImGui::MenuItem("Simple layout", NULL, &show_app_layout); + ImGui::MenuItem("Property editor", NULL, &show_app_property_editor); + ImGui::MenuItem("Long text display", NULL, &show_app_long_text); + ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize); + ImGui::MenuItem("Constrained-resizing window", NULL, &show_app_constrained_resize); + ImGui::MenuItem("Simple overlay", NULL, &show_app_fixed_overlay); + ImGui::MenuItem("Manipulating window titles", NULL, &show_app_window_titles); + ImGui::MenuItem("Custom rendering", NULL, &show_app_custom_rendering); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Help")) + { + ImGui::MenuItem("Metrics", NULL, &show_app_metrics); + ImGui::MenuItem("Style Editor", NULL, &show_app_style_editor); + ImGui::MenuItem("About Dear ImGui", NULL, &show_app_about); + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } + + ImGui::Spacing(); + if (ImGui::CollapsingHeader("Help")) + { + ImGui::TextWrapped("This window is being created by the ShowDemoWindow() function. Please refer to the code in imgui_demo.cpp for reference.\n\n"); + ImGui::Text("USER GUIDE:"); + ImGui::ShowUserGuide(); + } + + if (ImGui::CollapsingHeader("Window options")) + { + ImGui::Checkbox("No titlebar", &no_titlebar); ImGui::SameLine(150); + ImGui::Checkbox("No scrollbar", &no_scrollbar); ImGui::SameLine(300); + ImGui::Checkbox("No menu", &no_menu); + ImGui::Checkbox("No move", &no_move); ImGui::SameLine(150); + ImGui::Checkbox("No resize", &no_resize); ImGui::SameLine(300); + ImGui::Checkbox("No collapse", &no_collapse); + ImGui::Checkbox("No close", &no_close); + + if (ImGui::TreeNode("Style")) + { + ImGui::ShowStyleEditor(); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Capture/Logging")) + { + ImGui::TextWrapped("The logging API redirects all text output so you can easily capture the content of a window or a block. Tree nodes can be automatically expanded. You can also call ImGui::LogText() to output directly to the log without a visual output."); + ImGui::LogButtons(); + ImGui::TreePop(); + } + } + + if (ImGui::CollapsingHeader("Widgets")) + { + if (ImGui::TreeNode("Basic")) + { + static int clicked = 0; + if (ImGui::Button("Button")) + clicked++; + if (clicked & 1) + { + ImGui::SameLine(); + ImGui::Text("Thanks for clicking me!"); + } + + static bool check = true; + ImGui::Checkbox("checkbox", &check); + + static int e = 0; + ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine(); + ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine(); + ImGui::RadioButton("radio c", &e, 2); + + // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style. + for (int i = 0; i < 7; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i/7.0f, 0.6f, 0.6f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(i/7.0f, 0.7f, 0.7f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(i/7.0f, 0.8f, 0.8f)); + ImGui::Button("Click"); + ImGui::PopStyleColor(3); + ImGui::PopID(); + } + + ImGui::Text("Hover over me"); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("I am a tooltip"); + + ImGui::SameLine(); + ImGui::Text("- or me"); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("I am a fancy tooltip"); + static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; + ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr)); + ImGui::EndTooltip(); + } + + // Testing ImGuiOnceUponAFrame helper. + //static ImGuiOnceUponAFrame once; + //for (int i = 0; i < 5; i++) + // if (once) + // ImGui::Text("This will be displayed only once."); + + ImGui::Separator(); + + ImGui::LabelText("label", "Value"); + + { + // Simplified one-liner Combo() API, using values packed in a single constant string + static int current_item_1 = 1; + ImGui::Combo("combo", ¤t_item_1, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); + //ImGui::Combo("combo w/ array of char*", ¤t_item_2_idx, items, IM_ARRAYSIZE(items)); // Combo using proper array. You can also pass a callback to retrieve array value, no need to create/copy an array just for that. + + // General BeginCombo() API, you have full control over your selection data and display type + const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO", "PPPP", "QQQQQQQQQQ", "RRR", "SSSS" }; + static const char* current_item_2 = NULL; + if (ImGui::BeginCombo("combo 2", current_item_2)) // The second parameter is the label previewed before opening the combo. + { + for (int n = 0; n < IM_ARRAYSIZE(items); n++) + { + bool is_selected = (current_item_2 == items[n]); // You can store your selection however you want, outside or inside your objects + if (ImGui::Selectable(items[n], is_selected)) + current_item_2 = items[n]; + if (is_selected) + ImGui::SetItemDefaultFocus(); // Set the initial focus when opening the combo (scrolling + for keyboard navigation support in the upcoming navigation branch) + } + ImGui::EndCombo(); + } + } + + { + static char str0[128] = "Hello, world!"; + static int i0=123; + static float f0=0.001f; + ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0)); + ImGui::SameLine(); ShowHelpMarker("Hold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n"); + + ImGui::InputInt("input int", &i0); + ImGui::SameLine(); ShowHelpMarker("You can apply arithmetic operators +,*,/ on numerical values.\n e.g. [ 100 ], input \'*2\', result becomes [ 200 ]\nUse +- to subtract.\n"); + + ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); + + static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + ImGui::InputFloat3("input float3", vec4a); + } + + { + static int i1=50, i2=42; + ImGui::DragInt("drag int", &i1, 1); + ImGui::SameLine(); ShowHelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input value."); + + ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%"); + + static float f1=1.00f, f2=0.0067f; + ImGui::DragFloat("drag float", &f1, 0.005f); + ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns"); + } + + { + static int i1=0; + ImGui::SliderInt("slider int", &i1, -1, 3); + ImGui::SameLine(); ShowHelpMarker("CTRL+click to input value."); + + static float f1=0.123f, f2=0.0f; + ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f"); + ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f); + static float angle = 0.0f; + ImGui::SliderAngle("slider angle", &angle); + } + + static float col1[3] = { 1.0f,0.0f,0.2f }; + static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; + ImGui::ColorEdit3("color 1", col1); + ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n"); + + ImGui::ColorEdit4("color 2", col2); + + const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" }; + static int listbox_item_current = 1; + ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4); + + //static int listbox_item_current2 = 2; + //ImGui::PushItemWidth(-1); + //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4); + //ImGui::PopItemWidth(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Trees")) + { + if (ImGui::TreeNode("Basic trees")) + { + for (int i = 0; i < 5; i++) + if (ImGui::TreeNode((void*)(intptr_t)i, "Child %d", i)) + { + ImGui::Text("blah blah"); + ImGui::SameLine(); + if (ImGui::SmallButton("print")) printf("Child %d pressed", i); + ImGui::TreePop(); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Advanced, with Selectable nodes")) + { + ShowHelpMarker("This is a more standard looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open."); + static bool align_label_with_current_x_position = false; + ImGui::Checkbox("Align label with current X position)", &align_label_with_current_x_position); + ImGui::Text("Hello!"); + if (align_label_with_current_x_position) + ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing()); + + static int selection_mask = (1 << 2); // Dumb representation of what may be user-side selection state. You may carry selection state inside or outside your objects in whatever format you see fit. + int node_clicked = -1; // Temporary storage of what node we have clicked to process selection at the end of the loop. May be a pointer to your own node type, etc. + ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize()*3); // Increase spacing to differentiate leaves from expanded contents. + for (int i = 0; i < 6; i++) + { + // Disable the default open on single-click behavior and pass in Selected flag according to our selection state. + ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ((selection_mask & (1 << i)) ? ImGuiTreeNodeFlags_Selected : 0); + if (i < 3) + { + // Node + bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Node %d", i); + if (ImGui::IsItemClicked()) + node_clicked = i; + if (node_open) + { + ImGui::Text("Blah blah\nBlah Blah"); + ImGui::TreePop(); + } + } + else + { + // Leaf: The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or TreeAdvanceToLabelPos()+Text(). + node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet + ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Leaf %d", i); + if (ImGui::IsItemClicked()) + node_clicked = i; + } + } + if (node_clicked != -1) + { + // Update selection state. Process outside of tree loop to avoid visual inconsistencies during the clicking-frame. + if (ImGui::GetIO().KeyCtrl) + selection_mask ^= (1 << node_clicked); // CTRL+click to toggle + else //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, this commented bit preserve selection when clicking on item that is part of the selection + selection_mask = (1 << node_clicked); // Click to single-select + } + ImGui::PopStyleVar(); + if (align_label_with_current_x_position) + ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing()); + ImGui::TreePop(); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Collapsing Headers")) + { + static bool closable_group = true; + ImGui::Checkbox("Enable extra group", &closable_group); + if (ImGui::CollapsingHeader("Header")) + { + ImGui::Text("IsItemHovered: %d", IsItemHovered()); + for (int i = 0; i < 5; i++) + ImGui::Text("Some content %d", i); + } + if (ImGui::CollapsingHeader("Header with a close button", &closable_group)) + { + ImGui::Text("IsItemHovered: %d", IsItemHovered()); + for (int i = 0; i < 5; i++) + ImGui::Text("More content %d", i); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Bullets")) + { + ImGui::BulletText("Bullet point 1"); + ImGui::BulletText("Bullet point 2\nOn multiple lines"); + ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)"); + ImGui::Bullet(); ImGui::SmallButton("Button"); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Text")) + { + if (ImGui::TreeNode("Colored Text")) + { + // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility. + ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink"); + ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow"); + ImGui::TextDisabled("Disabled"); + ImGui::SameLine(); ShowHelpMarker("The TextDisabled color is stored in ImGuiStyle."); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Word Wrapping")) + { + // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility. + ImGui::TextWrapped("This text should automatically wrap on the edge of the window. The current implementation for text wrapping follows simple rules suitable for English and possibly other languages."); + ImGui::Spacing(); + + static float wrap_width = 200.0f; + ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f"); + + ImGui::Text("Test paragraph 1:"); + ImVec2 pos = ImGui::GetCursorScreenPos(); + ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255)); + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width); + ImGui::Text("The lazy dog is a good dog. This paragraph is made to fit within %.0f pixels. Testing a 1 character word. The quick brown fox jumps over the lazy dog.", wrap_width); + ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255)); + ImGui::PopTextWrapPos(); + + ImGui::Text("Test paragraph 2:"); + pos = ImGui::GetCursorScreenPos(); + ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255)); + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width); + ImGui::Text("aaaaaaaa bbbbbbbb, c cccccccc,dddddddd. d eeeeeeee ffffffff. gggggggg!hhhhhhhh"); + ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255)); + ImGui::PopTextWrapPos(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("UTF-8 Text")) + { + // UTF-8 test with Japanese characters + // (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html) + // - From C++11 you can use the u8"my text" syntax to encode literal strings as UTF-8 + // - For earlier compiler, you may be able to encode your sources as UTF-8 (e.g. Visual Studio save your file as 'UTF-8 without signature') + // - HOWEVER, FOR THIS DEMO FILE, BECAUSE WE WANT TO SUPPORT COMPILER, WE ARE *NOT* INCLUDING RAW UTF-8 CHARACTERS IN THIS SOURCE FILE. + // Instead we are encoding a few string with hexadecimal constants. Don't do this in your application! + // Note that characters values are preserved even by InputText() if the font cannot be displayed, so you can safely copy & paste garbled characters into another application. + ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->LoadFromFileTTF() manually to load extra character ranges."); + ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)"); + ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)"); + static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"; // "nihongo" + ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf)); + ImGui::TreePop(); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Images")) + { + ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!"); + ImGuiIO& io = ImGui::GetIO(); + + // Here we are grabbing the font texture because that's the only one we have access to inside the demo code. + // Remember that ImTextureID is just storage for whatever you want it to be, it is essentially a value that will be passed to the render function inside the ImDrawCmd structure. + // If you use one of the default imgui_impl_XXXX.cpp renderer, they all have comments at the top of their file to specify what they expect to be stored in ImTextureID. + // (for example, the imgui_impl_dx11.cpp renderer expect a 'ID3D11ShaderResourceView*' pointer. The imgui_impl_glfw_gl3.cpp renderer expect a GLuint OpenGL texture identifier etc.) + // If you decided that ImTextureID = MyEngineTexture*, then you can pass your MyEngineTexture* pointers to ImGui::Image(), and gather width/height through your own functions, etc. + // Using ShowMetricsWindow() as a "debugger" to inspect the draw data that are being passed to your render will help you debug issues if you are confused about this. + // Consider using the lower-level ImDrawList::AddImage() API, via ImGui::GetWindowDrawList()->AddImage(). + ImTextureID my_tex_id = io.Fonts->TexID; + float my_tex_w = (float)io.Fonts->TexWidth; + float my_tex_h = (float)io.Fonts->TexHeight; + + ImGui::Text("%.0fx%.0f", my_tex_w, my_tex_h); + ImVec2 pos = ImGui::GetCursorScreenPos(); + ImGui::Image(my_tex_id, ImVec2(my_tex_w, my_tex_h), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128)); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + float focus_sz = 32.0f; + float focus_x = io.MousePos.x - pos.x - focus_sz * 0.5f; if (focus_x < 0.0f) focus_x = 0.0f; else if (focus_x > my_tex_w - focus_sz) focus_x = my_tex_w - focus_sz; + float focus_y = io.MousePos.y - pos.y - focus_sz * 0.5f; if (focus_y < 0.0f) focus_y = 0.0f; else if (focus_y > my_tex_h - focus_sz) focus_y = my_tex_h - focus_sz; + ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y); + ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz); + ImVec2 uv0 = ImVec2((focus_x) / my_tex_w, (focus_y) / my_tex_h); + ImVec2 uv1 = ImVec2((focus_x + focus_sz) / my_tex_w, (focus_y + focus_sz) / my_tex_h); + ImGui::Image(my_tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128)); + ImGui::EndTooltip(); + } + ImGui::TextWrapped("And now some textured buttons.."); + static int pressed_count = 0; + for (int i = 0; i < 8; i++) + { + ImGui::PushID(i); + int frame_padding = -1 + i; // -1 = uses default padding + if (ImGui::ImageButton(my_tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/my_tex_w,32/my_tex_h), frame_padding, ImColor(0,0,0,255))) + pressed_count += 1; + ImGui::PopID(); + ImGui::SameLine(); + } + ImGui::NewLine(); + ImGui::Text("Pressed %d times.", pressed_count); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Selectables")) + { + if (ImGui::TreeNode("Basic")) + { + static bool selected[4] = { false, true, false, false }; + ImGui::Selectable("1. I am selectable", &selected[0]); + ImGui::Selectable("2. I am selectable", &selected[1]); + ImGui::Text("3. I am not selectable"); + ImGui::Selectable("4. I am selectable", &selected[2]); + if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_AllowDoubleClick)) + if (ImGui::IsMouseDoubleClicked(0)) + selected[3] = !selected[3]; + ImGui::TreePop(); + } + if (ImGui::TreeNode("Rendering more text into the same block")) + { + static bool selected[3] = { false, false, false }; + ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); + ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes"); + ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); + ImGui::TreePop(); + } + if (ImGui::TreeNode("In columns")) + { + ImGui::Columns(3, NULL, false); + static bool selected[16] = { 0 }; + for (int i = 0; i < 16; i++) + { + char label[32]; sprintf(label, "Item %d", i); + if (ImGui::Selectable(label, &selected[i])) {} + ImGui::NextColumn(); + } + ImGui::Columns(1); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Grid")) + { + static bool selected[16] = { true, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true }; + for (int i = 0; i < 16; i++) + { + ImGui::PushID(i); + if (ImGui::Selectable("Sailor", &selected[i], 0, ImVec2(50,50))) + { + int x = i % 4, y = i / 4; + if (x > 0) selected[i - 1] ^= 1; + if (x < 3) selected[i + 1] ^= 1; + if (y > 0) selected[i - 4] ^= 1; + if (y < 3) selected[i + 4] ^= 1; + } + if ((i % 4) < 3) ImGui::SameLine(); + ImGui::PopID(); + } + ImGui::TreePop(); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Filtered Text Input")) + { + static char buf1[64] = ""; ImGui::InputText("default", buf1, 64); + static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal); + static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase); + static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase); + static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank); + struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } }; + static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters); + + ImGui::Text("Password input"); + static char bufpass[64] = "password123"; + ImGui::InputText("password", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank); + ImGui::SameLine(); ShowHelpMarker("Display all characters as '*'.\nDisable clipboard cut and copy.\nDisable logging.\n"); + ImGui::InputText("password (clear)", bufpass, 64, ImGuiInputTextFlags_CharsNoBlank); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Multi-line Text Input")) + { + static bool read_only = false; + static char text[1024*16] = + "/*\n" + " The Pentium F00F bug, shorthand for F0 0F C7 C8,\n" + " the hexadecimal encoding of one offending instruction,\n" + " more formally, the invalid operand with locked CMPXCHG8B\n" + " instruction bug, is a design flaw in the majority of\n" + " Intel Pentium, Pentium MMX, and Pentium OverDrive\n" + " processors (all in the P5 microarchitecture).\n" + "*/\n\n" + "label:\n" + "\tlock cmpxchg8b eax\n"; + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); + ImGui::Checkbox("Read-only", &read_only); + ImGui::PopStyleVar(); + ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(-1.0f, ImGui::GetTextLineHeight() * 16), ImGuiInputTextFlags_AllowTabInput | (read_only ? ImGuiInputTextFlags_ReadOnly : 0)); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Plots widgets")) + { + static bool animate = true; + ImGui::Checkbox("Animate", &animate); + + static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; + ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr)); + + // Create a dummy array of contiguous float values to plot + // Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter. + static float values[90] = { 0 }; + static int values_offset = 0; + static float refresh_time = 0.0f; + if (!animate || refresh_time == 0.0f) + refresh_time = ImGui::GetTime(); + while (refresh_time < ImGui::GetTime()) // Create dummy data at fixed 60 hz rate for the demo + { + static float phase = 0.0f; + values[values_offset] = cosf(phase); + values_offset = (values_offset+1) % IM_ARRAYSIZE(values); + phase += 0.10f*values_offset; + refresh_time += 1.0f/60.0f; + } + ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); + ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80)); + + // Use functions to generate output + // FIXME: This is rather awkward because current plot API only pass in indices. We probably want an API passing floats and user provide sample rate/count. + struct Funcs + { + static float Sin(void*, int i) { return sinf(i * 0.1f); } + static float Saw(void*, int i) { return (i & 1) ? 1.0f : -1.0f; } + }; + static int func_type = 0, display_count = 70; + ImGui::Separator(); + ImGui::PushItemWidth(100); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::PopItemWidth(); + ImGui::SameLine(); + ImGui::SliderInt("Sample count", &display_count, 1, 400); + float (*func)(void*, int) = (func_type == 0) ? Funcs::Sin : Funcs::Saw; + ImGui::PlotLines("Lines", func, NULL, display_count, 0, NULL, -1.0f, 1.0f, ImVec2(0,80)); + ImGui::PlotHistogram("Histogram", func, NULL, display_count, 0, NULL, -1.0f, 1.0f, ImVec2(0,80)); + ImGui::Separator(); + + // Animate a simple progress bar + static float progress = 0.0f, progress_dir = 1.0f; + if (animate) + { + progress += progress_dir * 0.4f * ImGui::GetIO().DeltaTime; + if (progress >= +1.1f) { progress = +1.1f; progress_dir *= -1.0f; } + if (progress <= -0.1f) { progress = -0.1f; progress_dir *= -1.0f; } + } + + // Typically we would use ImVec2(-1.0f,0.0f) to use all available width, or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth. + ImGui::ProgressBar(progress, ImVec2(0.0f,0.0f)); + ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::Text("Progress Bar"); + + float progress_saturated = (progress < 0.0f) ? 0.0f : (progress > 1.0f) ? 1.0f : progress; + char buf[32]; + sprintf(buf, "%d/%d", (int)(progress_saturated*1753), 1753); + ImGui::ProgressBar(progress, ImVec2(0.f,0.f), buf); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Color/Picker Widgets")) + { + static ImVec4 color = ImColor(114, 144, 154, 200); + + static bool hdr = false; + static bool alpha_preview = true; + static bool alpha_half_preview = false; + static bool options_menu = true; + ImGui::Checkbox("With HDR", &hdr); ImGui::SameLine(); ShowHelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets."); + ImGui::Checkbox("With Alpha Preview", &alpha_preview); + ImGui::Checkbox("With Half Alpha Preview", &alpha_half_preview); + ImGui::Checkbox("With Options Menu", &options_menu); ImGui::SameLine(); ShowHelpMarker("Right-click on the individual color widget to show options."); + int misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions); + + ImGui::Text("Color widget:"); + ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nCTRL+click on individual component to input value.\n"); + ImGui::ColorEdit3("MyColor##1", (float*)&color, misc_flags); + + ImGui::Text("Color widget HSV with Alpha:"); + ImGui::ColorEdit4("MyColor##2", (float*)&color, ImGuiColorEditFlags_HSV | misc_flags); + + ImGui::Text("Color widget with Float Display:"); + ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | misc_flags); + + ImGui::Text("Color button with Picker:"); + ImGui::SameLine(); ShowHelpMarker("With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\nWith the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only be used for the tooltip and picker popup."); + ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | misc_flags); + + ImGui::Text("Color button with Custom Picker Popup:"); + + // Generate a dummy palette + static bool saved_palette_inited = false; + static ImVec4 saved_palette[32]; + if (!saved_palette_inited) + for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++) + { + ImGui::ColorConvertHSVtoRGB(n / 31.0f, 0.8f, 0.8f, saved_palette[n].x, saved_palette[n].y, saved_palette[n].z); + saved_palette[n].w = 1.0f; // Alpha + } + saved_palette_inited = true; + + static ImVec4 backup_color; + bool open_popup = ImGui::ColorButton("MyColor##3b", color, misc_flags); + ImGui::SameLine(); + open_popup |= ImGui::Button("Palette"); + if (open_popup) + { + ImGui::OpenPopup("mypicker"); + backup_color = color; + } + if (ImGui::BeginPopup("mypicker")) + { + // FIXME: Adding a drag and drop example here would be perfect! + ImGui::Text("MY CUSTOM COLOR PICKER WITH AN AMAZING PALETTE!"); + ImGui::Separator(); + ImGui::ColorPicker4("##picker", (float*)&color, misc_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview); + ImGui::SameLine(); + ImGui::BeginGroup(); + ImGui::Text("Current"); + ImGui::ColorButton("##current", color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60,40)); + ImGui::Text("Previous"); + if (ImGui::ColorButton("##previous", backup_color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60,40))) + color = backup_color; + ImGui::Separator(); + ImGui::Text("Palette"); + for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++) + { + ImGui::PushID(n); + if ((n % 8) != 0) + ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y); + if (ImGui::ColorButton("##palette", saved_palette[n], ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip, ImVec2(20,20))) + color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z, color.w); // Preserve alpha! + + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) + memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 3); + if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F)) + memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 4); + EndDragDropTarget(); + } + + ImGui::PopID(); + } + ImGui::EndGroup(); + ImGui::EndPopup(); + } + + ImGui::Text("Color button only:"); + ImGui::ColorButton("MyColor##3c", *(ImVec4*)&color, misc_flags, ImVec2(80,80)); + + ImGui::Text("Color picker:"); + static bool alpha = true; + static bool alpha_bar = true; + static bool side_preview = true; + static bool ref_color = false; + static ImVec4 ref_color_v(1.0f,0.0f,1.0f,0.5f); + static int inputs_mode = 2; + static int picker_mode = 0; + ImGui::Checkbox("With Alpha", &alpha); + ImGui::Checkbox("With Alpha Bar", &alpha_bar); + ImGui::Checkbox("With Side Preview", &side_preview); + if (side_preview) + { + ImGui::SameLine(); + ImGui::Checkbox("With Ref Color", &ref_color); + if (ref_color) + { + ImGui::SameLine(); + ImGui::ColorEdit4("##RefColor", &ref_color_v.x, ImGuiColorEditFlags_NoInputs | misc_flags); + } + } + ImGui::Combo("Inputs Mode", &inputs_mode, "All Inputs\0No Inputs\0RGB Input\0HSV Input\0HEX Input\0"); + ImGui::Combo("Picker Mode", &picker_mode, "Auto/Current\0Hue bar + SV rect\0Hue wheel + SV triangle\0"); + ImGui::SameLine(); ShowHelpMarker("User can right-click the picker to change mode."); + ImGuiColorEditFlags flags = misc_flags; + if (!alpha) flags |= ImGuiColorEditFlags_NoAlpha; // This is by default if you call ColorPicker3() instead of ColorPicker4() + if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar; + if (!side_preview) flags |= ImGuiColorEditFlags_NoSidePreview; + if (picker_mode == 1) flags |= ImGuiColorEditFlags_PickerHueBar; + if (picker_mode == 2) flags |= ImGuiColorEditFlags_PickerHueWheel; + if (inputs_mode == 1) flags |= ImGuiColorEditFlags_NoInputs; + if (inputs_mode == 2) flags |= ImGuiColorEditFlags_RGB; + if (inputs_mode == 3) flags |= ImGuiColorEditFlags_HSV; + if (inputs_mode == 4) flags |= ImGuiColorEditFlags_HEX; + ImGui::ColorPicker4("MyColor##4", (float*)&color, flags, ref_color ? &ref_color_v.x : NULL); + + ImGui::Text("Programmatically set defaults/options:"); + ImGui::SameLine(); ShowHelpMarker("SetColorEditOptions() is designed to allow you to set boot-time default.\nWe don't have Push/Pop functions because you can force options on a per-widget basis if needed, and the user can change non-forced ones with the options menu.\nWe don't have a getter to avoid encouraging you to persistently save values that aren't forward-compatible."); + if (ImGui::Button("Uint8 + HSV")) + ImGui::SetColorEditOptions(ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_HSV); + ImGui::SameLine(); + if (ImGui::Button("Float + HDR")) + ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_RGB); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Range Widgets")) + { + static float begin = 10, end = 90; + static int begin_i = 100, end_i = 1000; + ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units"); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Multi-component Widgets")) + { + static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + static int vec4i[4] = { 1, 5, 100, 255 }; + + ImGui::InputFloat2("input float2", vec4f); + ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f); + ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f); + ImGui::DragInt2("drag int2", vec4i, 1, 0, 255); + ImGui::InputInt2("input int2", vec4i); + ImGui::SliderInt2("slider int2", vec4i, 0, 255); + ImGui::Spacing(); + + ImGui::InputFloat3("input float3", vec4f); + ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f); + ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f); + ImGui::DragInt3("drag int3", vec4i, 1, 0, 255); + ImGui::InputInt3("input int3", vec4i); + ImGui::SliderInt3("slider int3", vec4i, 0, 255); + ImGui::Spacing(); + + ImGui::InputFloat4("input float4", vec4f); + ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f); + ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f); + ImGui::InputInt4("input int4", vec4i); + ImGui::DragInt4("drag int4", vec4i, 1, 0, 255); + ImGui::SliderInt4("slider int4", vec4i, 0, 255); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Vertical Sliders")) + { + const float spacing = 4; + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, spacing)); + + static int int_value = 0; + ImGui::VSliderInt("##int", ImVec2(18,160), &int_value, 0, 5); + ImGui::SameLine(); + + static float values[7] = { 0.0f, 0.60f, 0.35f, 0.9f, 0.70f, 0.20f, 0.0f }; + ImGui::PushID("set1"); + for (int i = 0; i < 7; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::PushStyleColor(ImGuiCol_FrameBg, (ImVec4)ImColor::HSV(i/7.0f, 0.5f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, (ImVec4)ImColor::HSV(i/7.0f, 0.6f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, (ImVec4)ImColor::HSV(i/7.0f, 0.7f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_SliderGrab, (ImVec4)ImColor::HSV(i/7.0f, 0.9f, 0.9f)); + ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, ""); + if (ImGui::IsItemActive() || ImGui::IsItemHovered()) + ImGui::SetTooltip("%.3f", values[i]); + ImGui::PopStyleColor(4); + ImGui::PopID(); + } + ImGui::PopID(); + + ImGui::SameLine(); + ImGui::PushID("set2"); + static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f }; + const int rows = 3; + const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows); + for (int nx = 0; nx < 4; nx++) + { + if (nx > 0) ImGui::SameLine(); + ImGui::BeginGroup(); + for (int ny = 0; ny < rows; ny++) + { + ImGui::PushID(nx*rows+ny); + ImGui::VSliderFloat("##v", small_slider_size, &values2[nx], 0.0f, 1.0f, ""); + if (ImGui::IsItemActive() || ImGui::IsItemHovered()) + ImGui::SetTooltip("%.3f", values2[nx]); + ImGui::PopID(); + } + ImGui::EndGroup(); + } + ImGui::PopID(); + + ImGui::SameLine(); + ImGui::PushID("set3"); + for (int i = 0; i < 4; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40); + ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f\nsec"); + ImGui::PopStyleVar(); + ImGui::PopID(); + } + ImGui::PopID(); + ImGui::PopStyleVar(); + ImGui::TreePop(); + } + } + + if (ImGui::CollapsingHeader("Layout")) + { + if (ImGui::TreeNode("Child regions")) + { + static bool disable_mouse_wheel = false; + ImGui::Checkbox("Disable Mouse Wheel", &disable_mouse_wheel); + + ImGui::Text("Without border"); + static int line = 50; + bool goto_line = ImGui::Button("Goto"); + ImGui::SameLine(); + ImGui::PushItemWidth(100); + goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue); + ImGui::PopItemWidth(); + + ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f,300), false, ImGuiWindowFlags_HorizontalScrollbar | (disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0)); + for (int i = 0; i < 100; i++) + { + ImGui::Text("%04d: scrollable region", i); + if (goto_line && line == i) + ImGui::SetScrollHere(); + } + if (goto_line && line >= 100) + ImGui::SetScrollHere(); + ImGui::EndChild(); + + ImGui::SameLine(); + + ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); + ImGui::BeginChild("Sub2", ImVec2(0,300), true, (disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0)); + ImGui::Text("With border"); + ImGui::Columns(2); + for (int i = 0; i < 100; i++) + { + if (i == 50) + ImGui::NextColumn(); + char buf[32]; + sprintf(buf, "%08x", i*5731); + ImGui::Button(buf, ImVec2(-1.0f, 0.0f)); + } + ImGui::EndChild(); + ImGui::PopStyleVar(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Widgets Width")) + { + static float f = 0.0f; + ImGui::Text("PushItemWidth(100)"); + ImGui::SameLine(); ShowHelpMarker("Fixed width."); + ImGui::PushItemWidth(100); + ImGui::DragFloat("float##1", &f); + ImGui::PopItemWidth(); + + ImGui::Text("PushItemWidth(GetWindowWidth() * 0.5f)"); + ImGui::SameLine(); ShowHelpMarker("Half of window width."); + ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f); + ImGui::DragFloat("float##2", &f); + ImGui::PopItemWidth(); + + ImGui::Text("PushItemWidth(GetContentRegionAvailWidth() * 0.5f)"); + ImGui::SameLine(); ShowHelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)"); + ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f); + ImGui::DragFloat("float##3", &f); + ImGui::PopItemWidth(); + + ImGui::Text("PushItemWidth(-100)"); + ImGui::SameLine(); ShowHelpMarker("Align to right edge minus 100"); + ImGui::PushItemWidth(-100); + ImGui::DragFloat("float##4", &f); + ImGui::PopItemWidth(); + + ImGui::Text("PushItemWidth(-1)"); + ImGui::SameLine(); ShowHelpMarker("Align to right edge"); + ImGui::PushItemWidth(-1); + ImGui::DragFloat("float##5", &f); + ImGui::PopItemWidth(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Basic Horizontal Layout")) + { + ImGui::TextWrapped("(Use ImGui::SameLine() to keep adding items to the right of the preceding item)"); + + // Text + ImGui::Text("Two items: Hello"); ImGui::SameLine(); + ImGui::TextColored(ImVec4(1,1,0,1), "Sailor"); + + // Adjust spacing + ImGui::Text("More spacing: Hello"); ImGui::SameLine(0, 20); + ImGui::TextColored(ImVec4(1,1,0,1), "Sailor"); + + // Button + ImGui::AlignTextToFramePadding(); + ImGui::Text("Normal buttons"); ImGui::SameLine(); + ImGui::Button("Banana"); ImGui::SameLine(); + ImGui::Button("Apple"); ImGui::SameLine(); + ImGui::Button("Corniflower"); + + // Button + ImGui::Text("Small buttons"); ImGui::SameLine(); + ImGui::SmallButton("Like this one"); ImGui::SameLine(); + ImGui::Text("can fit within a text block."); + + // Aligned to arbitrary position. Easy/cheap column. + ImGui::Text("Aligned"); + ImGui::SameLine(150); ImGui::Text("x=150"); + ImGui::SameLine(300); ImGui::Text("x=300"); + ImGui::Text("Aligned"); + ImGui::SameLine(150); ImGui::SmallButton("x=150"); + ImGui::SameLine(300); ImGui::SmallButton("x=300"); + + // Checkbox + static bool c1=false,c2=false,c3=false,c4=false; + ImGui::Checkbox("My", &c1); ImGui::SameLine(); + ImGui::Checkbox("Tailor", &c2); ImGui::SameLine(); + ImGui::Checkbox("Is", &c3); ImGui::SameLine(); + ImGui::Checkbox("Rich", &c4); + + // Various + static float f0=1.0f, f1=2.0f, f2=3.0f; + ImGui::PushItemWidth(80); + const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" }; + static int item = -1; + ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine(); + ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine(); + ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine(); + ImGui::SliderFloat("Z", &f2, 0.0f,5.0f); + ImGui::PopItemWidth(); + + ImGui::PushItemWidth(80); + ImGui::Text("Lists:"); + static int selection[4] = { 0, 1, 2, 3 }; + for (int i = 0; i < 4; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items)); + ImGui::PopID(); + //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i); + } + ImGui::PopItemWidth(); + + // Dummy + ImVec2 sz(30,30); + ImGui::Button("A", sz); ImGui::SameLine(); + ImGui::Dummy(sz); ImGui::SameLine(); + ImGui::Button("B", sz); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Groups")) + { + ImGui::TextWrapped("(Using ImGui::BeginGroup()/EndGroup() to layout items. BeginGroup() basically locks the horizontal position. EndGroup() bundles the whole group so that you can use functions such as IsItemHovered() on it.)"); + ImGui::BeginGroup(); + { + ImGui::BeginGroup(); + ImGui::Button("AAA"); + ImGui::SameLine(); + ImGui::Button("BBB"); + ImGui::SameLine(); + ImGui::BeginGroup(); + ImGui::Button("CCC"); + ImGui::Button("DDD"); + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::Button("EEE"); + ImGui::EndGroup(); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("First group hovered"); + } + // Capture the group size and create widgets using the same size + ImVec2 size = ImGui::GetItemRectSize(); + const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f }; + ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size); + + ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y)); + ImGui::SameLine(); + ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y)); + ImGui::EndGroup(); + ImGui::SameLine(); + + ImGui::Button("LEVERAGE\nBUZZWORD", size); + ImGui::SameLine(); + + ImGui::ListBoxHeader("List", size); + ImGui::Selectable("Selected", true); + ImGui::Selectable("Not Selected", false); + ImGui::ListBoxFooter(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Text Baseline Alignment")) + { + ImGui::TextWrapped("(This is testing the vertical alignment that occurs on text to keep it at the same baseline as widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets)"); + + ImGui::Text("One\nTwo\nThree"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Text("Banana"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("One\nTwo\nThree"); + + ImGui::Button("HOP##1"); ImGui::SameLine(); + ImGui::Text("Banana"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Button("HOP##2"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Button("TEST##1"); ImGui::SameLine(); + ImGui::Text("TEST"); ImGui::SameLine(); + ImGui::SmallButton("TEST##2"); + + ImGui::AlignTextToFramePadding(); // If your line starts with text, call this to align it to upcoming widgets. + ImGui::Text("Text aligned to Widget"); ImGui::SameLine(); + ImGui::Button("Widget##1"); ImGui::SameLine(); + ImGui::Text("Widget"); ImGui::SameLine(); + ImGui::SmallButton("Widget##2"); ImGui::SameLine(); + ImGui::Button("Widget##3"); + + // Tree + const float spacing = ImGui::GetStyle().ItemInnerSpacing.x; + ImGui::Button("Button##1"); + ImGui::SameLine(0.0f, spacing); + if (ImGui::TreeNode("Node##1")) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); } // Dummy tree data + + ImGui::AlignTextToFramePadding(); // Vertically align text node a bit lower so it'll be vertically centered with upcoming widget. Otherwise you can use SmallButton (smaller fit). + bool node_open = ImGui::TreeNode("Node##2"); // Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add child content. + ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##2"); + if (node_open) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); } // Dummy tree data + + // Bullet + ImGui::Button("Button##3"); + ImGui::SameLine(0.0f, spacing); + ImGui::BulletText("Bullet text"); + + ImGui::AlignTextToFramePadding(); + ImGui::BulletText("Node"); + ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##4"); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Scrolling")) + { + ImGui::TextWrapped("(Use SetScrollHere() or SetScrollFromPosY() to scroll to a given position.)"); + static bool track = true; + static int track_line = 50, scroll_to_px = 200; + ImGui::Checkbox("Track", &track); + ImGui::PushItemWidth(100); + ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 99, "Line = %.0f"); + bool scroll_to = ImGui::Button("Scroll To Pos"); + ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "Y = %.0f px"); + ImGui::PopItemWidth(); + if (scroll_to) track = false; + + for (int i = 0; i < 5; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::BeginGroup(); + ImGui::Text("%s", i == 0 ? "Top" : i == 1 ? "25%" : i == 2 ? "Center" : i == 3 ? "75%" : "Bottom"); + ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true); + if (scroll_to) + ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.25f); + for (int line = 0; line < 100; line++) + { + if (track && line == track_line) + { + ImGui::TextColored(ImColor(255,255,0), "Line %d", line); + ImGui::SetScrollHere(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom + } + else + { + ImGui::Text("Line %d", line); + } + } + float scroll_y = ImGui::GetScrollY(), scroll_max_y = ImGui::GetScrollMaxY(); + ImGui::EndChild(); + ImGui::Text("%.0f/%0.f", scroll_y, scroll_max_y); + ImGui::EndGroup(); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Horizontal Scrolling")) + { + ImGui::Bullet(); ImGui::TextWrapped("Horizontal scrolling for a window has to be enabled explicitly via the ImGuiWindowFlags_HorizontalScrollbar flag."); + ImGui::Bullet(); ImGui::TextWrapped("You may want to explicitly specify content width by calling SetNextWindowContentWidth() before Begin()."); + static int lines = 7; + ImGui::SliderInt("Lines", &lines, 1, 15); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 1.0f)); + ImGui::BeginChild("scrolling", ImVec2(0, ImGui::GetFrameHeightWithSpacing()*7 + 30), true, ImGuiWindowFlags_HorizontalScrollbar); + for (int line = 0; line < lines; line++) + { + // Display random stuff (for the sake of this trivial demo we are using basic Button+SameLine. If you want to create your own time line for a real application you may be better off + // manipulating the cursor position yourself, aka using SetCursorPos/SetCursorScreenPos to position the widgets yourself. You may also want to use the lower-level ImDrawList API) + int num_buttons = 10 + ((line & 1) ? line * 9 : line * 3); + for (int n = 0; n < num_buttons; n++) + { + if (n > 0) ImGui::SameLine(); + ImGui::PushID(n + line * 1000); + char num_buf[16]; + sprintf(num_buf, "%d", n); + const char* label = (!(n%15)) ? "FizzBuzz" : (!(n%3)) ? "Fizz" : (!(n%5)) ? "Buzz" : num_buf; + float hue = n*0.05f; + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(hue, 0.6f, 0.6f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(hue, 0.7f, 0.7f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(hue, 0.8f, 0.8f)); + ImGui::Button(label, ImVec2(40.0f + sinf((float)(line + n)) * 20.0f, 0.0f)); + ImGui::PopStyleColor(3); + ImGui::PopID(); + } + } + float scroll_x = ImGui::GetScrollX(), scroll_max_x = ImGui::GetScrollMaxX(); + ImGui::EndChild(); + ImGui::PopStyleVar(2); + float scroll_x_delta = 0.0f; + ImGui::SmallButton("<<"); if (ImGui::IsItemActive()) scroll_x_delta = -ImGui::GetIO().DeltaTime * 1000.0f; ImGui::SameLine(); + ImGui::Text("Scroll from code"); ImGui::SameLine(); + ImGui::SmallButton(">>"); if (ImGui::IsItemActive()) scroll_x_delta = +ImGui::GetIO().DeltaTime * 1000.0f; ImGui::SameLine(); + ImGui::Text("%.0f/%.0f", scroll_x, scroll_max_x); + if (scroll_x_delta != 0.0f) + { + ImGui::BeginChild("scrolling"); // Demonstrate a trick: you can use Begin to set yourself in the context of another window (here we are already out of your child window) + ImGui::SetScrollX(ImGui::GetScrollX() + scroll_x_delta); + ImGui::End(); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Clipping")) + { + static ImVec2 size(100, 100), offset(50, 20); + ImGui::TextWrapped("On a per-widget basis we are occasionally clipping text CPU-side if it won't fit in its frame. Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and CPU/GPU rendering cost."); + ImGui::DragFloat2("size", (float*)&size, 0.5f, 0.0f, 200.0f, "%.0f"); + ImGui::TextWrapped("(Click and drag)"); + ImVec2 pos = ImGui::GetCursorScreenPos(); + ImVec4 clip_rect(pos.x, pos.y, pos.x+size.x, pos.y+size.y); + ImGui::InvisibleButton("##dummy", size); + if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } + ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x+size.x,pos.y+size.y), ImColor(90,90,120,255)); + ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize()*2.0f, ImVec2(pos.x+offset.x,pos.y+offset.y), ImColor(255,255,255,255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect); + ImGui::TreePop(); + } + } + + if (ImGui::CollapsingHeader("Popups & Modal windows")) + { + if (ImGui::TreeNode("Popups")) + { + ImGui::TextWrapped("When a popup is active, it inhibits interacting with windows that are behind the popup. Clicking outside the popup closes it."); + + static int selected_fish = -1; + const char* names[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" }; + static bool toggles[] = { true, false, false, false, false }; + + // Simple selection popup + // (If you want to show the current selection inside the Button itself, you may want to build a string using the "###" operator to preserve a constant ID with a variable label) + if (ImGui::Button("Select..")) + ImGui::OpenPopup("select"); + ImGui::SameLine(); + ImGui::TextUnformatted(selected_fish == -1 ? "" : names[selected_fish]); + if (ImGui::BeginPopup("select")) + { + ImGui::Text("Aquarium"); + ImGui::Separator(); + for (int i = 0; i < IM_ARRAYSIZE(names); i++) + if (ImGui::Selectable(names[i])) + selected_fish = i; + ImGui::EndPopup(); + } + + // Showing a menu with toggles + if (ImGui::Button("Toggle..")) + ImGui::OpenPopup("toggle"); + if (ImGui::BeginPopup("toggle")) + { + for (int i = 0; i < IM_ARRAYSIZE(names); i++) + ImGui::MenuItem(names[i], "", &toggles[i]); + if (ImGui::BeginMenu("Sub-menu")) + { + ImGui::MenuItem("Click me"); + ImGui::EndMenu(); + } + + ImGui::Separator(); + ImGui::Text("Tooltip here"); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("I am a tooltip over a popup"); + + if (ImGui::Button("Stacked Popup")) + ImGui::OpenPopup("another popup"); + if (ImGui::BeginPopup("another popup")) + { + for (int i = 0; i < IM_ARRAYSIZE(names); i++) + ImGui::MenuItem(names[i], "", &toggles[i]); + if (ImGui::BeginMenu("Sub-menu")) + { + ImGui::MenuItem("Click me"); + ImGui::EndMenu(); + } + ImGui::EndPopup(); + } + ImGui::EndPopup(); + } + + if (ImGui::Button("Popup Menu..")) + ImGui::OpenPopup("FilePopup"); + if (ImGui::BeginPopup("FilePopup")) + { + ShowExampleMenuFile(); + ImGui::EndPopup(); + } + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Context menus")) + { + // BeginPopupContextItem() is a helper to provide common/simple popup behavior of essentially doing: + // if (IsItemHovered() && IsMouseClicked(0)) + // OpenPopup(id); + // return BeginPopup(id); + // For more advanced uses you may want to replicate and cuztomize this code. This the comments inside BeginPopupContextItem() implementation. + static float value = 0.5f; + ImGui::Text("Value = %.3f (<-- right-click here)", value); + if (ImGui::BeginPopupContextItem("item context menu")) + { + if (ImGui::Selectable("Set to zero")) value = 0.0f; + if (ImGui::Selectable("Set to PI")) value = 3.1415f; + ImGui::PushItemWidth(-1); + ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f); + ImGui::PopItemWidth(); + ImGui::EndPopup(); + } + + static char name[32] = "Label1"; + char buf[64]; sprintf(buf, "Button: %s###Button", name); // ### operator override ID ignoring the preceding label + ImGui::Button(buf); + if (ImGui::BeginPopupContextItem()) // When used after an item that has an ID (here the Button), we can skip providing an ID to BeginPopupContextItem(). + { + ImGui::Text("Edit name:"); + ImGui::InputText("##edit", name, IM_ARRAYSIZE(name)); + if (ImGui::Button("Close")) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + ImGui::SameLine(); ImGui::Text("(<-- right-click here)"); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Modals")) + { + ImGui::TextWrapped("Modal windows are like popups but the user cannot close them by clicking outside the window."); + + if (ImGui::Button("Delete..")) + ImGui::OpenPopup("Delete?"); + if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n"); + ImGui::Separator(); + + //static int dummy_i = 0; + //ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0"); + + static bool dont_ask_me_next_time = false; + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); + ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time); + ImGui::PopStyleVar(); + + if (ImGui::Button("OK", ImVec2(120,0))) { ImGui::CloseCurrentPopup(); } + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120,0))) { ImGui::CloseCurrentPopup(); } + ImGui::EndPopup(); + } + + if (ImGui::Button("Stacked modals..")) + ImGui::OpenPopup("Stacked 1"); + if (ImGui::BeginPopupModal("Stacked 1")) + { + ImGui::Text("Hello from Stacked The First\nUsing style.Colors[ImGuiCol_ModalWindowDarkening] for darkening."); + static int item = 1; + ImGui::Combo("Combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); + static float color[4] = { 0.4f,0.7f,0.0f,0.5f }; + ImGui::ColorEdit4("color", color); // This is to test behavior of stacked regular popups over a modal + + if (ImGui::Button("Add another modal..")) + ImGui::OpenPopup("Stacked 2"); + if (ImGui::BeginPopupModal("Stacked 2")) + { + ImGui::Text("Hello from Stacked The Second"); + if (ImGui::Button("Close")) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + + if (ImGui::Button("Close")) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Menus inside a regular window")) + { + ImGui::TextWrapped("Below we are testing adding menu items to a regular window. It's rather unusual but should work!"); + ImGui::Separator(); + // NB: As a quirk in this very specific example, we want to differentiate the parent of this menu from the parent of the various popup menus above. + // To do so we are encloding the items in a PushID()/PopID() block to make them two different menusets. If we don't, opening any popup above and hovering our menu here + // would open it. This is because once a menu is active, we allow to switch to a sibling menu by just hovering on it, which is the desired behavior for regular menus. + ImGui::PushID("foo"); + ImGui::MenuItem("Menu item", "CTRL+M"); + if (ImGui::BeginMenu("Menu inside a regular window")) + { + ShowExampleMenuFile(); + ImGui::EndMenu(); + } + ImGui::PopID(); + ImGui::Separator(); + ImGui::TreePop(); + } + } + + if (ImGui::CollapsingHeader("Columns")) + { + ImGui::PushID("Columns"); + + // Basic columns + if (ImGui::TreeNode("Basic")) + { + ImGui::Text("Without border:"); + ImGui::Columns(3, "mycolumns3", false); // 3-ways, no border + ImGui::Separator(); + for (int n = 0; n < 14; n++) + { + char label[32]; + sprintf(label, "Item %d", n); + if (ImGui::Selectable(label)) {} + //if (ImGui::Button(label, ImVec2(-1,0))) {} + ImGui::NextColumn(); + } + ImGui::Columns(1); + ImGui::Separator(); + + ImGui::Text("With border:"); + ImGui::Columns(4, "mycolumns"); // 4-ways, with border + ImGui::Separator(); + ImGui::Text("ID"); ImGui::NextColumn(); + ImGui::Text("Name"); ImGui::NextColumn(); + ImGui::Text("Path"); ImGui::NextColumn(); + ImGui::Text("Hovered"); ImGui::NextColumn(); + ImGui::Separator(); + const char* names[3] = { "One", "Two", "Three" }; + const char* paths[3] = { "/path/one", "/path/two", "/path/three" }; + static int selected = -1; + for (int i = 0; i < 3; i++) + { + char label[32]; + sprintf(label, "%04d", i); + if (ImGui::Selectable(label, selected == i, ImGuiSelectableFlags_SpanAllColumns)) + selected = i; + bool hovered = ImGui::IsItemHovered(); + ImGui::NextColumn(); + ImGui::Text(names[i]); ImGui::NextColumn(); + ImGui::Text(paths[i]); ImGui::NextColumn(); + ImGui::Text("%d", hovered); ImGui::NextColumn(); + } + ImGui::Columns(1); + ImGui::Separator(); + ImGui::TreePop(); + } + + // Create multiple items in a same cell before switching to next column + if (ImGui::TreeNode("Mixed items")) + { + ImGui::Columns(3, "mixed"); + ImGui::Separator(); + + ImGui::Text("Hello"); + ImGui::Button("Banana"); + ImGui::NextColumn(); + + ImGui::Text("ImGui"); + ImGui::Button("Apple"); + static float foo = 1.0f; + ImGui::InputFloat("red", &foo, 0.05f, 0, 3); + ImGui::Text("An extra line here."); + ImGui::NextColumn(); + + ImGui::Text("Sailor"); + ImGui::Button("Corniflower"); + static float bar = 1.0f; + ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); + ImGui::NextColumn(); + + if (ImGui::CollapsingHeader("Category A")) { ImGui::Text("Blah blah blah"); } ImGui::NextColumn(); + if (ImGui::CollapsingHeader("Category B")) { ImGui::Text("Blah blah blah"); } ImGui::NextColumn(); + if (ImGui::CollapsingHeader("Category C")) { ImGui::Text("Blah blah blah"); } ImGui::NextColumn(); + ImGui::Columns(1); + ImGui::Separator(); + ImGui::TreePop(); + } + + // Word wrapping + if (ImGui::TreeNode("Word-wrapping")) + { + ImGui::Columns(2, "word-wrapping"); + ImGui::Separator(); + ImGui::TextWrapped("The quick brown fox jumps over the lazy dog."); + ImGui::TextWrapped("Hello Left"); + ImGui::NextColumn(); + ImGui::TextWrapped("The quick brown fox jumps over the lazy dog."); + ImGui::TextWrapped("Hello Right"); + ImGui::Columns(1); + ImGui::Separator(); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Borders")) + { + // NB: Future columns API should allow automatic horizontal borders. + static bool h_borders = true; + static bool v_borders = true; + ImGui::Checkbox("horizontal", &h_borders); + ImGui::SameLine(); + ImGui::Checkbox("vertical", &v_borders); + ImGui::Columns(4, NULL, v_borders); + for (int i = 0; i < 4*3; i++) + { + if (h_borders && ImGui::GetColumnIndex() == 0) + ImGui::Separator(); + ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i); + ImGui::Text("Width %.2f\nOffset %.2f", ImGui::GetColumnWidth(), ImGui::GetColumnOffset()); + ImGui::NextColumn(); + } + ImGui::Columns(1); + if (h_borders) + ImGui::Separator(); + ImGui::TreePop(); + } + + // Scrolling columns + /* + if (ImGui::TreeNode("Vertical Scrolling")) + { + ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y)); + ImGui::Columns(3); + ImGui::Text("ID"); ImGui::NextColumn(); + ImGui::Text("Name"); ImGui::NextColumn(); + ImGui::Text("Path"); ImGui::NextColumn(); + ImGui::Columns(1); + ImGui::Separator(); + ImGui::EndChild(); + ImGui::BeginChild("##scrollingregion", ImVec2(0, 60)); + ImGui::Columns(3); + for (int i = 0; i < 10; i++) + { + ImGui::Text("%04d", i); ImGui::NextColumn(); + ImGui::Text("Foobar"); ImGui::NextColumn(); + ImGui::Text("/path/foobar/%04d/", i); ImGui::NextColumn(); + } + ImGui::Columns(1); + ImGui::EndChild(); + ImGui::TreePop(); + } + */ + + if (ImGui::TreeNode("Horizontal Scrolling")) + { + ImGui::SetNextWindowContentSize(ImVec2(1500.0f, 0.0f)); + ImGui::BeginChild("##ScrollingRegion", ImVec2(0, ImGui::GetFontSize() * 20), false, ImGuiWindowFlags_HorizontalScrollbar); + ImGui::Columns(10); + int ITEMS_COUNT = 2000; + ImGuiListClipper clipper(ITEMS_COUNT); // Also demonstrate using the clipper for large list + while (clipper.Step()) + { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) + for (int j = 0; j < 10; j++) + { + ImGui::Text("Line %d Column %d...", i, j); + ImGui::NextColumn(); + } + } + ImGui::Columns(1); + ImGui::EndChild(); + ImGui::TreePop(); + } + + bool node_open = ImGui::TreeNode("Tree within single cell"); + ImGui::SameLine(); ShowHelpMarker("NB: Tree node must be poped before ending the cell. There's no storage of state per-cell."); + if (node_open) + { + ImGui::Columns(2, "tree items"); + ImGui::Separator(); + if (ImGui::TreeNode("Hello")) { ImGui::BulletText("Sailor"); ImGui::TreePop(); } ImGui::NextColumn(); + if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Marin"); ImGui::TreePop(); } ImGui::NextColumn(); + ImGui::Columns(1); + ImGui::Separator(); + ImGui::TreePop(); + } + ImGui::PopID(); + } + + if (ImGui::CollapsingHeader("Filtering")) + { + static ImGuiTextFilter filter; + ImGui::Text("Filter usage:\n" + " \"\" display all lines\n" + " \"xxx\" display lines containing \"xxx\"\n" + " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n" + " \"-xxx\" hide lines containing \"xxx\""); + filter.Draw(); + const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }; + for (int i = 0; i < IM_ARRAYSIZE(lines); i++) + if (filter.PassFilter(lines[i])) + ImGui::BulletText("%s", lines[i]); + } + + if (ImGui::CollapsingHeader("Inputs & Focus")) + { + ImGuiIO& io = ImGui::GetIO(); + ImGui::Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor); + ImGui::SameLine(); ShowHelpMarker("Request ImGui to render a mouse cursor for you in software. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something)."); + + ImGui::Text("WantCaptureMouse: %d", io.WantCaptureMouse); + ImGui::Text("WantCaptureKeyboard: %d", io.WantCaptureKeyboard); + ImGui::Text("WantTextInput: %d", io.WantTextInput); + ImGui::Text("WantMoveMouse: %d", io.WantMoveMouse); + + if (ImGui::TreeNode("Keyboard & Mouse State")) + { + if (ImGui::IsMousePosValid()) + ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + ImGui::Text("Mouse pos: "); + ImGui::Text("Mouse down:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (io.MouseDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); } + ImGui::Text("Mouse clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); } + ImGui::Text("Mouse dbl-clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseDoubleClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); } + ImGui::Text("Mouse released:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); } + ImGui::Text("Mouse wheel: %.1f", io.MouseWheel); + + ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.KeysDownDuration[i]); } + ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d", i); } + ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); } + ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); + + + ImGui::Button("Hovering me sets the\nkeyboard capture flag"); + if (ImGui::IsItemHovered()) + ImGui::CaptureKeyboardFromApp(true); + ImGui::SameLine(); + ImGui::Button("Holding me clears the\nthe keyboard capture flag"); + if (ImGui::IsItemActive()) + ImGui::CaptureKeyboardFromApp(false); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Tabbing")) + { + ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields."); + static char buf[32] = "dummy"; + ImGui::InputText("1", buf, IM_ARRAYSIZE(buf)); + ImGui::InputText("2", buf, IM_ARRAYSIZE(buf)); + ImGui::InputText("3", buf, IM_ARRAYSIZE(buf)); + ImGui::PushAllowKeyboardFocus(false); + ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf)); + //ImGui::SameLine(); ShowHelperMarker("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets."); + ImGui::PopAllowKeyboardFocus(); + ImGui::InputText("5", buf, IM_ARRAYSIZE(buf)); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Focus from code")) + { + bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine(); + bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine(); + bool focus_3 = ImGui::Button("Focus on 3"); + int has_focus = 0; + static char buf[128] = "click on a button to set focus"; + + if (focus_1) ImGui::SetKeyboardFocusHere(); + ImGui::InputText("1", buf, IM_ARRAYSIZE(buf)); + if (ImGui::IsItemActive()) has_focus = 1; + + if (focus_2) ImGui::SetKeyboardFocusHere(); + ImGui::InputText("2", buf, IM_ARRAYSIZE(buf)); + if (ImGui::IsItemActive()) has_focus = 2; + + ImGui::PushAllowKeyboardFocus(false); + if (focus_3) ImGui::SetKeyboardFocusHere(); + ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf)); + if (ImGui::IsItemActive()) has_focus = 3; + ImGui::PopAllowKeyboardFocus(); + if (has_focus) + ImGui::Text("Item with focus: %d", has_focus); + else + ImGui::Text("Item with focus: "); + ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code."); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Focused & Hovered Test")) + { + static bool embed_all_inside_a_child_window = false; + ImGui::Checkbox("Embed everything inside a child window (for additional testing)", &embed_all_inside_a_child_window); + if (embed_all_inside_a_child_window) + ImGui::BeginChild("embeddingchild", ImVec2(0, ImGui::GetFontSize() * 25), true); + + // Testing IsWindowFocused() function with its various flags (note that the flags can be combined) + ImGui::BulletText( + "IsWindowFocused() = %d\n" + "IsWindowFocused(_ChildWindows) = %d\n" + "IsWindowFocused(_ChildWindows|_RootWindow) = %d\n" + "IsWindowFocused(_RootWindow) = %d\n", + ImGui::IsWindowFocused(), + ImGui::IsWindowFocused(ImGuiHoveredFlags_ChildWindows), + ImGui::IsWindowFocused(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow), + ImGui::IsWindowFocused(ImGuiHoveredFlags_RootWindow)); + + // Testing IsWindowHovered() function with its various flags (note that the flags can be combined) + ImGui::BulletText( + "IsWindowHovered() = %d\n" + "IsWindowHovered(_AllowWhenBlockedByPopup) = %d\n" + "IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d\n" + "IsWindowHovered(_ChildWindows) = %d\n" + "IsWindowHovered(_ChildWindows|_RootWindow) = %d\n" + "IsWindowHovered(_RootWindow) = %d\n", + ImGui::IsWindowHovered(), + ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup), + ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), + ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows), + ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow), + ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow)); + + // Testing IsItemHovered() function (because BulletText is an item itself and that would affect the output of IsItemHovered, we pass all lines in a single items to shorten the code) + ImGui::Button("ITEM"); + ImGui::BulletText( + "IsItemHovered() = %d\n" + "IsItemHovered(_AllowWhenBlockedByPopup) = %d\n" + "IsItemHovered(_AllowWhenBlockedByActiveItem) = %d\n" + "IsItemHovered(_AllowWhenOverlapped) = %d\n" + "IsItemhovered(_RectOnly) = %d\n", + ImGui::IsItemHovered(), + ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup), + ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), + ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped), + ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly)); + + ImGui::BeginChild("child", ImVec2(0,50), true); + ImGui::Text("This is another child window for testing IsWindowHovered() flags."); + ImGui::EndChild(); + + if (embed_all_inside_a_child_window) + EndChild(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Dragging")) + { + ImGui::TextWrapped("You can use ImGui::GetMouseDragDelta(0) to query for the dragged amount on any widget."); + for (int button = 0; button < 3; button++) + ImGui::Text("IsMouseDragging(%d):\n w/ default threshold: %d,\n w/ zero threshold: %d\n w/ large threshold: %d", + button, ImGui::IsMouseDragging(button), ImGui::IsMouseDragging(button, 0.0f), ImGui::IsMouseDragging(button, 20.0f)); + ImGui::Button("Drag Me"); + if (ImGui::IsItemActive()) + { + // Draw a line between the button and the mouse cursor + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_list->PushClipRectFullScreen(); + draw_list->AddLine(ImGui::CalcItemRectClosestPoint(io.MousePos, true, -2.0f), io.MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f); + draw_list->PopClipRect(); + + // Drag operations gets "unlocked" when the mouse has moved past a certain threshold (the default threshold is stored in io.MouseDragThreshold) + // You can request a lower or higher threshold using the second parameter of IsMouseDragging() and GetMouseDragDelta() + ImVec2 value_raw = ImGui::GetMouseDragDelta(0, 0.0f); + ImVec2 value_with_lock_threshold = ImGui::GetMouseDragDelta(0); + ImVec2 mouse_delta = io.MouseDelta; + ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f), MouseDelta (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y, mouse_delta.x, mouse_delta.y); + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Mouse cursors")) + { + const char* mouse_cursors_names[] = { "Arrow", "TextInput", "Move", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE" }; + IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_Count_); + + ImGui::Text("Current mouse cursor = %d: %s", ImGui::GetMouseCursor(), mouse_cursors_names[ImGui::GetMouseCursor()]); + ImGui::Text("Hover to see mouse cursors:"); + ImGui::SameLine(); ShowHelpMarker("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, otherwise your backend needs to handle it."); + for (int i = 0; i < ImGuiMouseCursor_Count_; i++) + { + char label[32]; + sprintf(label, "Mouse cursor %d: %s", i, mouse_cursors_names[i]); + ImGui::Bullet(); ImGui::Selectable(label, false); + if (ImGui::IsItemHovered()) + ImGui::SetMouseCursor(i); + } + ImGui::TreePop(); + } + } + + ImGui::End(); +} + +// Demo helper function to select among default colors. See ShowStyleEditor() for more advanced options. +// Here we use the simplified Combo() api that packs items into a single literal string. Useful for quick combo boxes where the choices are known locally. +bool ImGui::ShowStyleSelector(const char* label) +{ + static int style_idx = 0; + if (ImGui::Combo(label, &style_idx, "Classic\0Dark\0Light\0")) + { + switch (style_idx) + { + case 0: ImGui::StyleColorsClassic(); break; + case 1: ImGui::StyleColorsDark(); break; + case 2: ImGui::StyleColorsLight(); break; + } + return true; + } + return false; +} + +// Demo helper function to select among loaded fonts. +// Here we use the regular BeginCombo()/EndCombo() api which is more the more flexible one. +void ImGui::ShowFontSelector(const char* label) +{ + ImGuiIO& io = ImGui::GetIO(); + ImFont* font_current = ImGui::GetFont(); + if (ImGui::BeginCombo(label, font_current->GetDebugName())) + { + for (int n = 0; n < io.Fonts->Fonts.Size; n++) + if (ImGui::Selectable(io.Fonts->Fonts[n]->GetDebugName(), io.Fonts->Fonts[n] == font_current)) + io.FontDefault = io.Fonts->Fonts[n]; + ImGui::EndCombo(); + } + ImGui::SameLine(); + ShowHelpMarker( + "- Load additional fonts with io.Fonts->AddFontFromFileTTF().\n" + "- The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build().\n" + "- Read FAQ and documentation in extra_fonts/ for more details.\n" + "- If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame()."); +} + +void ImGui::ShowStyleEditor(ImGuiStyle* ref) +{ + // You can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it compares to an internally stored reference) + ImGuiStyle& style = ImGui::GetStyle(); + static ImGuiStyle ref_saved_style; + + // Default to using internal storage as reference + static bool init = true; + if (init && ref == NULL) + ref_saved_style = style; + init = false; + if (ref == NULL) + ref = &ref_saved_style; + + ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f); + + if (ImGui::ShowStyleSelector("Colors##Selector")) + ref_saved_style = style; + ImGui::ShowFontSelector("Fonts##Selector"); + + // Simplified Settings + if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f")) + style.GrabRounding = style.FrameRounding; // Make GrabRounding always the same value as FrameRounding + { bool window_border = (style.WindowBorderSize > 0.0f); if (ImGui::Checkbox("WindowBorder", &window_border)) style.WindowBorderSize = window_border ? 1.0f : 0.0f; } + ImGui::SameLine(); + { bool frame_border = (style.FrameBorderSize > 0.0f); if (ImGui::Checkbox("FrameBorder", &frame_border)) style.FrameBorderSize = frame_border ? 1.0f : 0.0f; } + ImGui::SameLine(); + { bool popup_border = (style.PopupBorderSize > 0.0f); if (ImGui::Checkbox("PopupBorder", &popup_border)) style.PopupBorderSize = popup_border ? 1.0f : 0.0f; } + + // Save/Revert button + if (ImGui::Button("Save Ref")) + *ref = ref_saved_style = style; + ImGui::SameLine(); + if (ImGui::Button("Revert Ref")) + style = *ref; + ImGui::SameLine(); + ShowHelpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \"Export Colors\" below to save them somewhere."); + + if (ImGui::TreeNode("Rendering")) + { + ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); ShowHelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well."); + ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill); + ImGui::PushItemWidth(100); + ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, FLT_MAX, NULL, 2.0f); + if (style.CurveTessellationTol < 0.0f) style.CurveTessellationTol = 0.10f; + ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. + ImGui::PopItemWidth(); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Settings")) + { + ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 16.0f, "%.0f"); + ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); + ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f, "%.0f"); + ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f"); + ImGui::Text("BorderSize"); + ImGui::SliderFloat("WindowBorderSize", &style.WindowBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui::SliderFloat("ChildBorderSize", &style.ChildBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui::Text("Rounding"); + ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 14.0f, "%.0f"); + ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 16.0f, "%.0f"); + ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f"); + ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f"); + ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f"); + ImGui::Text("Alignment"); + ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); + ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a button is larger than its text content."); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Colors")) + { + static int output_dest = 0; + static bool output_only_modified = true; + if (ImGui::Button("Export Unsaved")) + { + if (output_dest == 0) + ImGui::LogToClipboard(); + else + ImGui::LogToTTY(); + ImGui::LogText("ImVec4* colors = ImGui::GetStyle().Colors;" IM_NEWLINE); + for (int i = 0; i < ImGuiCol_COUNT; i++) + { + const ImVec4& col = style.Colors[i]; + const char* name = ImGui::GetStyleColorName(i); + if (!output_only_modified || memcmp(&col, &ref->Colors[i], sizeof(ImVec4)) != 0) + ImGui::LogText("colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" IM_NEWLINE, name, 23-(int)strlen(name), "", col.x, col.y, col.z, col.w); + } + ImGui::LogFinish(); + } + ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth(); + ImGui::SameLine(); ImGui::Checkbox("Only Modified Colors", &output_only_modified); + + ImGui::Text("Tip: Left-click on colored square to open color picker,\nRight-click to open edit options menu."); + + static ImGuiTextFilter filter; + filter.Draw("Filter colors", 200); + + static ImGuiColorEditFlags alpha_flags = 0; + ImGui::RadioButton("Opaque", &alpha_flags, 0); ImGui::SameLine(); + ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine(); + ImGui::RadioButton("Both", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf); + + ImGui::BeginChild("#colors", ImVec2(0, 300), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar); + ImGui::PushItemWidth(-160); + for (int i = 0; i < ImGuiCol_COUNT; i++) + { + const char* name = ImGui::GetStyleColorName(i); + if (!filter.PassFilter(name)) + continue; + ImGui::PushID(i); + ImGui::ColorEdit4("##color", (float*)&style.Colors[i], ImGuiColorEditFlags_AlphaBar | alpha_flags); + if (memcmp(&style.Colors[i], &ref->Colors[i], sizeof(ImVec4)) != 0) + { + // Tips: in a real user application, you may want to merge and use an icon font into the main font, so instead of "Save"/"Revert" you'd use icons. + // Read the FAQ and extra_fonts/README.txt about using icon fonts. It's really easy and super convenient! + ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; + ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); if (ImGui::Button("Revert")) style.Colors[i] = ref->Colors[i]; + } + ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); + ImGui::TextUnformatted(name); + ImGui::PopID(); + } + ImGui::PopItemWidth(); + ImGui::EndChild(); + + ImGui::TreePop(); + } + + bool fonts_opened = ImGui::TreeNode("Fonts", "Fonts (%d)", ImGui::GetIO().Fonts->Fonts.Size); + if (fonts_opened) + { + ImFontAtlas* atlas = ImGui::GetIO().Fonts; + if (ImGui::TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) + { + ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128)); + ImGui::TreePop(); + } + ImGui::PushItemWidth(100); + for (int i = 0; i < atlas->Fonts.Size; i++) + { + ImFont* font = atlas->Fonts[i]; + ImGui::PushID(font); + bool font_details_opened = ImGui::TreeNode(font, "Font %d: \'%s\', %.2f px, %d glyphs", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size); + ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font; + if (font_details_opened) + { + ImGui::PushFont(font); + ImGui::Text("The quick brown fox jumps over the lazy dog"); + ImGui::PopFont(); + ImGui::DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // Scale only this font + ImGui::SameLine(); ShowHelpMarker("Note than the default embedded font is NOT meant to be scaled.\n\nFont are currently rendered into bitmaps at a given size at the time of building the atlas. You may oversample them to get some flexibility with scaling. You can also render at multiple sizes and select which one to use at runtime.\n\n(Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.)"); + ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent); + ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar); + ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)sqrtf((float)font->MetricsTotalSurface), (int)sqrtf((float)font->MetricsTotalSurface)); + for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) + { + ImFontConfig* cfg = &font->ConfigData[config_i]; + ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d", config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH); + } + if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size)) + { + // Display all glyphs of the fonts in separate pages of 256 characters + const ImFontGlyph* glyph_fallback = font->FallbackGlyph; // Forcefully/dodgily make FindGlyph() return NULL on fallback, which isn't the default behavior. + font->FallbackGlyph = NULL; + for (int base = 0; base < 0x10000; base += 256) + { + int count = 0; + for (int n = 0; n < 256; n++) + count += font->FindGlyph((ImWchar)(base + n)) ? 1 : 0; + if (count > 0 && ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base+255, count, count > 1 ? "glyphs" : "glyph")) + { + float cell_spacing = style.ItemSpacing.y; + ImVec2 cell_size(font->FontSize * 1, font->FontSize * 1); + ImVec2 base_pos = ImGui::GetCursorScreenPos(); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + for (int n = 0; n < 256; n++) + { + ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size.x + cell_spacing), base_pos.y + (n / 16) * (cell_size.y + cell_spacing)); + ImVec2 cell_p2(cell_p1.x + cell_size.x, cell_p1.y + cell_size.y); + const ImFontGlyph* glyph = font->FindGlyph((ImWchar)(base+n));; + draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255,255,255,100) : IM_COL32(255,255,255,50)); + font->RenderChar(draw_list, cell_size.x, cell_p1, ImGui::GetColorU32(ImGuiCol_Text), (ImWchar)(base+n)); // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string. + if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2)) + { + ImGui::BeginTooltip(); + ImGui::Text("Codepoint: U+%04X", base+n); + ImGui::Separator(); + ImGui::Text("AdvanceX: %.1f", glyph->AdvanceX); + ImGui::Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1); + ImGui::Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1); + ImGui::EndTooltip(); + } + } + ImGui::Dummy(ImVec2((cell_size.x + cell_spacing) * 16, (cell_size.y + cell_spacing) * 16)); + ImGui::TreePop(); + } + } + font->FallbackGlyph = glyph_fallback; + ImGui::TreePop(); + } + ImGui::TreePop(); + } + ImGui::PopID(); + } + static float window_scale = 1.0f; + ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this window + ImGui::DragFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale everything + ImGui::PopItemWidth(); + ImGui::SetWindowFontScale(window_scale); + ImGui::TreePop(); + } + + ImGui::PopItemWidth(); +} + +// Demonstrate creating a fullscreen menu bar and populating it. +static void ShowExampleAppMainMenuBar() +{ + if (ImGui::BeginMainMenuBar()) + { + if (ImGui::BeginMenu("File")) + { + ShowExampleMenuFile(); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Edit")) + { + if (ImGui::MenuItem("Undo", "CTRL+Z")) {} + if (ImGui::MenuItem("Redo", "CTRL+Y", false, false)) {} // Disabled item + ImGui::Separator(); + if (ImGui::MenuItem("Cut", "CTRL+X")) {} + if (ImGui::MenuItem("Copy", "CTRL+C")) {} + if (ImGui::MenuItem("Paste", "CTRL+V")) {} + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); + } +} + +static void ShowExampleMenuFile() +{ + ImGui::MenuItem("(dummy menu)", NULL, false, false); + if (ImGui::MenuItem("New")) {} + if (ImGui::MenuItem("Open", "Ctrl+O")) {} + if (ImGui::BeginMenu("Open Recent")) + { + ImGui::MenuItem("fish_hat.c"); + ImGui::MenuItem("fish_hat.inl"); + ImGui::MenuItem("fish_hat.h"); + if (ImGui::BeginMenu("More..")) + { + ImGui::MenuItem("Hello"); + ImGui::MenuItem("Sailor"); + if (ImGui::BeginMenu("Recurse..")) + { + ShowExampleMenuFile(); + ImGui::EndMenu(); + } + ImGui::EndMenu(); + } + ImGui::EndMenu(); + } + if (ImGui::MenuItem("Save", "Ctrl+S")) {} + if (ImGui::MenuItem("Save As..")) {} + ImGui::Separator(); + if (ImGui::BeginMenu("Options")) + { + static bool enabled = true; + ImGui::MenuItem("Enabled", "", &enabled); + ImGui::BeginChild("child", ImVec2(0, 60), true); + for (int i = 0; i < 10; i++) + ImGui::Text("Scrolling Text %d", i); + ImGui::EndChild(); + static float f = 0.5f; + static int n = 0; + static bool b = true; + ImGui::SliderFloat("Value", &f, 0.0f, 1.0f); + ImGui::InputFloat("Input", &f, 0.1f); + ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0"); + ImGui::Checkbox("Check", &b); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Colors")) + { + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); + for (int i = 0; i < ImGuiCol_COUNT; i++) + { + const char* name = ImGui::GetStyleColorName((ImGuiCol)i); + ImGui::ColorButton(name, ImGui::GetStyleColorVec4((ImGuiCol)i)); + ImGui::SameLine(); + ImGui::MenuItem(name); + } + ImGui::PopStyleVar(); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Disabled", false)) // Disabled + { + IM_ASSERT(0); + } + if (ImGui::MenuItem("Checked", NULL, true)) {} + if (ImGui::MenuItem("Quit", "Alt+F4")) {} +} + +// Demonstrate creating a window which gets auto-resized according to its content. +static void ShowExampleAppAutoResize(bool* p_open) +{ + if (!ImGui::Begin("Example: Auto-resizing window", p_open, ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::End(); + return; + } + + static int lines = 10; + ImGui::Text("Window will resize every-frame to the size of its content.\nNote that you probably don't want to query the window size to\noutput your content because that would create a feedback loop."); + ImGui::SliderInt("Number of lines", &lines, 1, 20); + for (int i = 0; i < lines; i++) + ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally + ImGui::End(); +} + +// Demonstrate creating a window with custom resize constraints. +static void ShowExampleAppConstrainedResize(bool* p_open) +{ + struct CustomConstraints // Helper functions to demonstrate programmatic constraints + { + static void Square(ImGuiSizeConstraintCallbackData* data) { data->DesiredSize = ImVec2(IM_MAX(data->DesiredSize.x, data->DesiredSize.y), IM_MAX(data->DesiredSize.x, data->DesiredSize.y)); } + static void Step(ImGuiSizeConstraintCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); } + }; + + static bool auto_resize = false; + static int type = 0; + static int display_lines = 10; + if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Vertical only + if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Horizontal only + if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100 + if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width 400-500 + if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, 500)); // Height 400-500 + if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square + if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)100);// Fixed Step + + ImGuiWindowFlags flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0; + if (ImGui::Begin("Example: Constrained Resize", p_open, flags)) + { + const char* desc[] = + { + "Resize vertical only", + "Resize horizontal only", + "Width > 100, Height > 100", + "Width 400-500", + "Height 400-500", + "Custom: Always Square", + "Custom: Fixed Steps (100)", + }; + if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine(); + if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine(); + if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); } + ImGui::PushItemWidth(200); + ImGui::Combo("Constraint", &type, desc, IM_ARRAYSIZE(desc)); + ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100); + ImGui::PopItemWidth(); + ImGui::Checkbox("Auto-resize", &auto_resize); + for (int i = 0; i < display_lines; i++) + ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, ""); + } + ImGui::End(); +} + +// Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use. +static void ShowExampleAppFixedOverlay(bool* p_open) +{ + const float DISTANCE = 10.0f; + static int corner = 0; + ImVec2 window_pos = ImVec2((corner & 1) ? ImGui::GetIO().DisplaySize.x - DISTANCE : DISTANCE, (corner & 2) ? ImGui::GetIO().DisplaySize.y - DISTANCE : DISTANCE); + ImVec2 window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f); + ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 0.3f)); // Transparent background + if (ImGui::Begin("Example: Fixed Overlay", p_open, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings)) + { + ImGui::Text("Simple overlay\nin the corner of the screen.\n(right-click to change position)"); + ImGui::Separator(); + ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); + if (ImGui::BeginPopupContextWindow()) + { + if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0; + if (ImGui::MenuItem("Top-right", NULL, corner == 1)) corner = 1; + if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2; + if (ImGui::MenuItem("Bottom-right", NULL, corner == 3)) corner = 3; + ImGui::EndPopup(); + } + ImGui::End(); + } + ImGui::PopStyleColor(); +} + +// Demonstrate using "##" and "###" in identifiers to manipulate ID generation. +// This apply to regular items as well. Read FAQ section "How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on the purpose of labels/IDs." for details. +static void ShowExampleAppWindowTitles(bool*) +{ + // By default, Windows are uniquely identified by their title. + // You can use the "##" and "###" markers to manipulate the display/ID. + + // Using "##" to display same title but have unique identifier. + ImGui::SetNextWindowPos(ImVec2(100,100), ImGuiCond_FirstUseEver); + ImGui::Begin("Same title as another window##1"); + ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique."); + ImGui::End(); + + ImGui::SetNextWindowPos(ImVec2(100,200), ImGuiCond_FirstUseEver); + ImGui::Begin("Same title as another window##2"); + ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique."); + ImGui::End(); + + // Using "###" to display a changing title but keep a static identifier "AnimatedTitle" + char buf[128]; + sprintf(buf, "Animated title %c %d###AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], ImGui::GetFrameCount()); + ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiCond_FirstUseEver); + ImGui::Begin(buf); + ImGui::Text("This window has a changing title."); + ImGui::End(); +} + +// Demonstrate using the low-level ImDrawList to draw custom shapes. +static void ShowExampleAppCustomRendering(bool* p_open) +{ + ImGui::SetNextWindowSize(ImVec2(350,560), ImGuiCond_FirstUseEver); + if (!ImGui::Begin("Example: Custom rendering", p_open)) + { + ImGui::End(); + return; + } + + // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc. + // Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4. + // ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types) + // In this example we are not using the maths operators! + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + + // Primitives + ImGui::Text("Primitives"); + static float sz = 36.0f; + static ImVec4 col = ImVec4(1.0f,1.0f,0.4f,1.0f); + ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f"); + ImGui::ColorEdit3("Color", &col.x); + { + const ImVec2 p = ImGui::GetCursorScreenPos(); + const ImU32 col32 = ImColor(col); + float x = p.x + 4.0f, y = p.y + 4.0f, spacing = 8.0f; + for (int n = 0; n < 2; n++) + { + float thickness = (n == 0) ? 1.0f : 4.0f; + draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 20, thickness); x += sz+spacing; + draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 0.0f, ImDrawCornerFlags_All, thickness); x += sz+spacing; + draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ImDrawCornerFlags_All, thickness); x += sz+spacing; + draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotRight, thickness); x += sz+spacing; + draw_list->AddTriangle(ImVec2(x+sz*0.5f, y), ImVec2(x+sz,y+sz-0.5f), ImVec2(x,y+sz-0.5f), col32, thickness); x += sz+spacing; + draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, thickness); x += sz+spacing; + draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, thickness); x += sz+spacing; + draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32, thickness); x += spacing; + draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, thickness); + x = p.x + 4; + y += sz+spacing; + } + draw_list->AddCircleFilled(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; + draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; + draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing; + draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotRight); x += sz+spacing; + draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f, y), ImVec2(x+sz,y+sz-0.5f), ImVec2(x,y+sz-0.5f), col32); x += sz+spacing; + draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x+sz, y+sz), ImColor(0,0,0), ImColor(255,0,0), ImColor(255,255,0), ImColor(0,255,0)); + ImGui::Dummy(ImVec2((sz+spacing)*8, (sz+spacing)*3)); + } + ImGui::Separator(); + { + static ImVector points; + static bool adding_line = false; + ImGui::Text("Canvas example"); + if (ImGui::Button("Clear")) points.clear(); + if (points.Size >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } } + ImGui::Text("Left-click and drag to add lines,\nRight-click to undo"); + + // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered() + // However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos(). + // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max). + ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates! + ImVec2 canvas_size = ImGui::GetContentRegionAvail(); // Resize canvas to what's available + if (canvas_size.x < 50.0f) canvas_size.x = 50.0f; + if (canvas_size.y < 50.0f) canvas_size.y = 50.0f; + draw_list->AddRectFilledMultiColor(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(50,50,50), ImColor(50,50,60), ImColor(60,60,70), ImColor(50,50,60)); + draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(255,255,255)); + + bool adding_preview = false; + ImGui::InvisibleButton("canvas", canvas_size); + ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y); + if (adding_line) + { + adding_preview = true; + points.push_back(mouse_pos_in_canvas); + if (!ImGui::GetIO().MouseDown[0]) + adding_line = adding_preview = false; + } + if (ImGui::IsItemHovered()) + { + if (!adding_line && ImGui::IsMouseClicked(0)) + { + points.push_back(mouse_pos_in_canvas); + adding_line = true; + } + if (ImGui::IsMouseClicked(1) && !points.empty()) + { + adding_line = adding_preview = false; + points.pop_back(); + points.pop_back(); + } + } + draw_list->PushClipRect(canvas_pos, ImVec2(canvas_pos.x+canvas_size.x, canvas_pos.y+canvas_size.y), true); // clip lines within the canvas (if we resize it, etc.) + for (int i = 0; i < points.Size - 1; i += 2) + draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), IM_COL32(255,255,0,255), 2.0f); + draw_list->PopClipRect(); + if (adding_preview) + points.pop_back(); + } + ImGui::End(); +} + +// Demonstrating creating a simple console window, with scrolling, filtering, completion and history. +// For the console example, here we are using a more C++ like approach of declaring a class to hold the data and the functions. +struct ExampleAppConsole +{ + char InputBuf[256]; + ImVector Items; + bool ScrollToBottom; + ImVector History; + int HistoryPos; // -1: new line, 0..History.Size-1 browsing history. + ImVector Commands; + + ExampleAppConsole() + { + ClearLog(); + memset(InputBuf, 0, sizeof(InputBuf)); + HistoryPos = -1; + Commands.push_back("HELP"); + Commands.push_back("HISTORY"); + Commands.push_back("CLEAR"); + Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches. + AddLog("Welcome to ImGui!"); + } + ~ExampleAppConsole() + { + ClearLog(); + for (int i = 0; i < History.Size; i++) + free(History[i]); + } + + // Portable helpers + static int Stricmp(const char* str1, const char* str2) { int d; while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } return d; } + static int Strnicmp(const char* str1, const char* str2, int n) { int d = 0; while (n > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; n--; } return d; } + static char* Strdup(const char *str) { size_t len = strlen(str) + 1; void* buff = malloc(len); return (char*)memcpy(buff, (const void*)str, len); } + + void ClearLog() + { + for (int i = 0; i < Items.Size; i++) + free(Items[i]); + Items.clear(); + ScrollToBottom = true; + } + + void AddLog(const char* fmt, ...) IM_FMTARGS(2) + { + // FIXME-OPT + char buf[1024]; + va_list args; + va_start(args, fmt); + vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); + buf[IM_ARRAYSIZE(buf)-1] = 0; + va_end(args); + Items.push_back(Strdup(buf)); + ScrollToBottom = true; + } + + void Draw(const char* title, bool* p_open) + { + ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiCond_FirstUseEver); + if (!ImGui::Begin(title, p_open)) + { + ImGui::End(); + return; + } + + // As a specific feature guaranteed by the library, after calling Begin() the last Item represent the title bar. So e.g. IsItemHovered() will return true when hovering the title bar. + // Here we create a context menu only available from the title bar. + if (ImGui::BeginPopupContextItem()) + { + if (ImGui::MenuItem("Close")) + *p_open = false; + ImGui::EndPopup(); + } + + ImGui::TextWrapped("This example implements a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc."); + ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion."); + + // TODO: display items starting from the bottom + + if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine(); + if (ImGui::SmallButton("Add Dummy Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine(); + if (ImGui::SmallButton("Clear")) { ClearLog(); } ImGui::SameLine(); + bool copy_to_clipboard = ImGui::SmallButton("Copy"); ImGui::SameLine(); + if (ImGui::SmallButton("Scroll to bottom")) ScrollToBottom = true; + //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); } + + ImGui::Separator(); + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); + static ImGuiTextFilter filter; + filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180); + ImGui::PopStyleVar(); + ImGui::Separator(); + + const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); // 1 separator, 1 input text + ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar); // Leave room for 1 separator + 1 InputText + if (ImGui::BeginPopupContextWindow()) + { + if (ImGui::Selectable("Clear")) ClearLog(); + ImGui::EndPopup(); + } + + // Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end()); + // NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping to only process visible items. + // You can seek and display only the lines that are visible using the ImGuiListClipper helper, if your elements are evenly spaced and you have cheap random access to the elements. + // To use the clipper we could replace the 'for (int i = 0; i < Items.Size; i++)' loop with: + // ImGuiListClipper clipper(Items.Size); + // while (clipper.Step()) + // for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) + // However take note that you can not use this code as is if a filter is active because it breaks the 'cheap random-access' property. We would need random-access on the post-filtered list. + // A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices that passed the filtering test, recomputing this array when user changes the filter, + // and appending newly elements as they are inserted. This is left as a task to the user until we can manage to improve this example code! + // If your items are of variable size you may want to implement code similar to what ImGuiListClipper does. Or split your data into fixed height items to allow random-seeking into your list. + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing + if (copy_to_clipboard) + ImGui::LogToClipboard(); + for (int i = 0; i < Items.Size; i++) + { + const char* item = Items[i]; + if (!filter.PassFilter(item)) + continue; + ImVec4 col = ImVec4(1.0f,1.0f,1.0f,1.0f); // A better implementation may store a type per-item. For the sample let's just parse the text. + if (strstr(item, "[error]")) col = ImColor(1.0f,0.4f,0.4f,1.0f); + else if (strncmp(item, "# ", 2) == 0) col = ImColor(1.0f,0.78f,0.58f,1.0f); + ImGui::PushStyleColor(ImGuiCol_Text, col); + ImGui::TextUnformatted(item); + ImGui::PopStyleColor(); + } + if (copy_to_clipboard) + ImGui::LogFinish(); + if (ScrollToBottom) + ImGui::SetScrollHere(); + ScrollToBottom = false; + ImGui::PopStyleVar(); + ImGui::EndChild(); + ImGui::Separator(); + + // Command-line + if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this)) + { + char* input_end = InputBuf+strlen(InputBuf); + while (input_end > InputBuf && input_end[-1] == ' ') { input_end--; } *input_end = 0; + if (InputBuf[0]) + ExecCommand(InputBuf); + strcpy(InputBuf, ""); + } + + // Demonstrate keeping auto focus on the input box + if (ImGui::IsItemHovered() || (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0))) + ImGui::SetKeyboardFocusHere(-1); // Auto focus previous widget + + ImGui::End(); + } + + void ExecCommand(const char* command_line) + { + AddLog("# %s\n", command_line); + + // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal. + HistoryPos = -1; + for (int i = History.Size-1; i >= 0; i--) + if (Stricmp(History[i], command_line) == 0) + { + free(History[i]); + History.erase(History.begin() + i); + break; + } + History.push_back(Strdup(command_line)); + + // Process command + if (Stricmp(command_line, "CLEAR") == 0) + { + ClearLog(); + } + else if (Stricmp(command_line, "HELP") == 0) + { + AddLog("Commands:"); + for (int i = 0; i < Commands.Size; i++) + AddLog("- %s", Commands[i]); + } + else if (Stricmp(command_line, "HISTORY") == 0) + { + int first = History.Size - 10; + for (int i = first > 0 ? first : 0; i < History.Size; i++) + AddLog("%3d: %s\n", i, History[i]); + } + else + { + AddLog("Unknown command: '%s'\n", command_line); + } + } + + static int TextEditCallbackStub(ImGuiTextEditCallbackData* data) // In C++11 you are better off using lambdas for this sort of forwarding callbacks + { + ExampleAppConsole* console = (ExampleAppConsole*)data->UserData; + return console->TextEditCallback(data); + } + + int TextEditCallback(ImGuiTextEditCallbackData* data) + { + //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd); + switch (data->EventFlag) + { + case ImGuiInputTextFlags_CallbackCompletion: + { + // Example of TEXT COMPLETION + + // Locate beginning of current word + const char* word_end = data->Buf + data->CursorPos; + const char* word_start = word_end; + while (word_start > data->Buf) + { + const char c = word_start[-1]; + if (c == ' ' || c == '\t' || c == ',' || c == ';') + break; + word_start--; + } + + // Build a list of candidates + ImVector candidates; + for (int i = 0; i < Commands.Size; i++) + if (Strnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0) + candidates.push_back(Commands[i]); + + if (candidates.Size == 0) + { + // No match + AddLog("No match for \"%.*s\"!\n", (int)(word_end-word_start), word_start); + } + else if (candidates.Size == 1) + { + // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing + data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start)); + data->InsertChars(data->CursorPos, candidates[0]); + data->InsertChars(data->CursorPos, " "); + } + else + { + // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY" + int match_len = (int)(word_end - word_start); + for (;;) + { + int c = 0; + bool all_candidates_matches = true; + for (int i = 0; i < candidates.Size && all_candidates_matches; i++) + if (i == 0) + c = toupper(candidates[i][match_len]); + else if (c == 0 || c != toupper(candidates[i][match_len])) + all_candidates_matches = false; + if (!all_candidates_matches) + break; + match_len++; + } + + if (match_len > 0) + { + data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start)); + data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len); + } + + // List matches + AddLog("Possible matches:\n"); + for (int i = 0; i < candidates.Size; i++) + AddLog("- %s\n", candidates[i]); + } + + break; + } + case ImGuiInputTextFlags_CallbackHistory: + { + // Example of HISTORY + const int prev_history_pos = HistoryPos; + if (data->EventKey == ImGuiKey_UpArrow) + { + if (HistoryPos == -1) + HistoryPos = History.Size - 1; + else if (HistoryPos > 0) + HistoryPos--; + } + else if (data->EventKey == ImGuiKey_DownArrow) + { + if (HistoryPos != -1) + if (++HistoryPos >= History.Size) + HistoryPos = -1; + } + + // A better implementation would preserve the data on the current input line along with cursor position. + if (prev_history_pos != HistoryPos) + { + data->CursorPos = data->SelectionStart = data->SelectionEnd = data->BufTextLen = (int)snprintf(data->Buf, (size_t)data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : ""); + data->BufDirty = true; + } + } + } + return 0; + } +}; + +static void ShowExampleAppConsole(bool* p_open) +{ + static ExampleAppConsole console; + console.Draw("Example: Console", p_open); +} + +// Usage: +// static ExampleAppLog my_log; +// my_log.AddLog("Hello %d world\n", 123); +// my_log.Draw("title"); +struct ExampleAppLog +{ + ImGuiTextBuffer Buf; + ImGuiTextFilter Filter; + ImVector LineOffsets; // Index to lines offset + bool ScrollToBottom; + + void Clear() { Buf.clear(); LineOffsets.clear(); } + + void AddLog(const char* fmt, ...) IM_FMTARGS(2) + { + int old_size = Buf.size(); + va_list args; + va_start(args, fmt); + Buf.appendfv(fmt, args); + va_end(args); + for (int new_size = Buf.size(); old_size < new_size; old_size++) + if (Buf[old_size] == '\n') + LineOffsets.push_back(old_size); + ScrollToBottom = true; + } + + void Draw(const char* title, bool* p_open = NULL) + { + ImGui::SetNextWindowSize(ImVec2(500,400), ImGuiCond_FirstUseEver); + ImGui::Begin(title, p_open); + if (ImGui::Button("Clear")) Clear(); + ImGui::SameLine(); + bool copy = ImGui::Button("Copy"); + ImGui::SameLine(); + Filter.Draw("Filter", -100.0f); + ImGui::Separator(); + ImGui::BeginChild("scrolling", ImVec2(0,0), false, ImGuiWindowFlags_HorizontalScrollbar); + if (copy) ImGui::LogToClipboard(); + + if (Filter.IsActive()) + { + const char* buf_begin = Buf.begin(); + const char* line = buf_begin; + for (int line_no = 0; line != NULL; line_no++) + { + const char* line_end = (line_no < LineOffsets.Size) ? buf_begin + LineOffsets[line_no] : NULL; + if (Filter.PassFilter(line, line_end)) + ImGui::TextUnformatted(line, line_end); + line = line_end && line_end[1] ? line_end + 1 : NULL; + } + } + else + { + ImGui::TextUnformatted(Buf.begin()); + } + + if (ScrollToBottom) + ImGui::SetScrollHere(1.0f); + ScrollToBottom = false; + ImGui::EndChild(); + ImGui::End(); + } +}; + +// Demonstrate creating a simple log window with basic filtering. +static void ShowExampleAppLog(bool* p_open) +{ + static ExampleAppLog log; + + // Demo: add random items (unless Ctrl is held) + static float last_time = -1.0f; + float time = ImGui::GetTime(); + if (time - last_time >= 0.20f && !ImGui::GetIO().KeyCtrl) + { + const char* random_words[] = { "system", "info", "warning", "error", "fatal", "notice", "log" }; + log.AddLog("[%s] Hello, time is %.1f, frame count is %d\n", random_words[rand() % IM_ARRAYSIZE(random_words)], time, ImGui::GetFrameCount()); + last_time = time; + } + + log.Draw("Example: Log", p_open); +} + +// Demonstrate create a window with multiple child windows. +static void ShowExampleAppLayout(bool* p_open) +{ + ImGui::SetNextWindowSize(ImVec2(500, 440), ImGuiCond_FirstUseEver); + if (ImGui::Begin("Example: Layout", p_open, ImGuiWindowFlags_MenuBar)) + { + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("File")) + { + if (ImGui::MenuItem("Close")) *p_open = false; + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } + + // left + static int selected = 0; + ImGui::BeginChild("left pane", ImVec2(150, 0), true); + for (int i = 0; i < 100; i++) + { + char label[128]; + sprintf(label, "MyObject %d", i); + if (ImGui::Selectable(label, selected == i)) + selected = i; + } + ImGui::EndChild(); + ImGui::SameLine(); + + // right + ImGui::BeginGroup(); + ImGui::BeginChild("item view", ImVec2(0, -ImGui::GetFrameHeightWithSpacing())); // Leave room for 1 line below us + ImGui::Text("MyObject: %d", selected); + ImGui::Separator(); + ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); + ImGui::EndChild(); + if (ImGui::Button("Revert")) {} + ImGui::SameLine(); + if (ImGui::Button("Save")) {} + ImGui::EndGroup(); + } + ImGui::End(); +} + +// Demonstrate create a simple property editor. +static void ShowExampleAppPropertyEditor(bool* p_open) +{ + ImGui::SetNextWindowSize(ImVec2(430,450), ImGuiCond_FirstUseEver); + if (!ImGui::Begin("Example: Property editor", p_open)) + { + ImGui::End(); + return; + } + + ShowHelpMarker("This example shows how you may implement a property editor using two columns.\nAll objects/fields data are dummies here.\nRemember that in many simple cases, you can use ImGui::SameLine(xxx) to position\nyour cursor horizontally instead of using the Columns() API."); + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2,2)); + ImGui::Columns(2); + ImGui::Separator(); + + struct funcs + { + static void ShowDummyObject(const char* prefix, int uid) + { + ImGui::PushID(uid); // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID. + ImGui::AlignTextToFramePadding(); // Text and Tree nodes are less high than regular widgets, here we add vertical spacing to make the tree lines equal high. + bool node_open = ImGui::TreeNode("Object", "%s_%u", prefix, uid); + ImGui::NextColumn(); + ImGui::AlignTextToFramePadding(); + ImGui::Text("my sailor is rich"); + ImGui::NextColumn(); + if (node_open) + { + static float dummy_members[8] = { 0.0f,0.0f,1.0f,3.1416f,100.0f,999.0f }; + for (int i = 0; i < 8; i++) + { + ImGui::PushID(i); // Use field index as identifier. + if (i < 2) + { + ShowDummyObject("Child", 424242); + } + else + { + ImGui::AlignTextToFramePadding(); + // Here we use a Selectable (instead of Text) to highlight on hover + //ImGui::Text("Field_%d", i); + char label[32]; + sprintf(label, "Field_%d", i); + ImGui::Bullet(); + ImGui::Selectable(label); + ImGui::NextColumn(); + ImGui::PushItemWidth(-1); + if (i >= 5) + ImGui::InputFloat("##value", &dummy_members[i], 1.0f); + else + ImGui::DragFloat("##value", &dummy_members[i], 0.01f); + ImGui::PopItemWidth(); + ImGui::NextColumn(); + } + ImGui::PopID(); + } + ImGui::TreePop(); + } + ImGui::PopID(); + } + }; + + // Iterate dummy objects with dummy members (all the same data) + for (int obj_i = 0; obj_i < 3; obj_i++) + funcs::ShowDummyObject("Object", obj_i); + + ImGui::Columns(1); + ImGui::Separator(); + ImGui::PopStyleVar(); + ImGui::End(); +} + +// Demonstrate/test rendering huge amount of text, and the incidence of clipping. +static void ShowExampleAppLongText(bool* p_open) +{ + ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiCond_FirstUseEver); + if (!ImGui::Begin("Example: Long text display", p_open)) + { + ImGui::End(); + return; + } + + static int test_type = 0; + static ImGuiTextBuffer log; + static int lines = 0; + ImGui::Text("Printing unusually long amount of text."); + ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped (slow)\0"); + ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); + if (ImGui::Button("Clear")) { log.clear(); lines = 0; } + ImGui::SameLine(); + if (ImGui::Button("Add 1000 lines")) + { + for (int i = 0; i < 1000; i++) + log.appendf("%i The quick brown fox jumps over the lazy dog\n", lines+i); + lines += 1000; + } + ImGui::BeginChild("Log"); + switch (test_type) + { + case 0: + // Single call to TextUnformatted() with a big buffer + ImGui::TextUnformatted(log.begin(), log.end()); + break; + case 1: + { + // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper. + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0)); + ImGuiListClipper clipper(lines); + while (clipper.Step()) + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) + ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); + ImGui::PopStyleVar(); + break; + } + case 2: + // Multiple calls to Text(), not clipped (slow) + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0)); + for (int i = 0; i < lines; i++) + ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); + ImGui::PopStyleVar(); + break; + } + ImGui::EndChild(); + ImGui::End(); +} + +// End of Demo code +#else + +void ImGui::ShowDemoWindow(bool*) {} +void ImGui::ShowUserGuide() {} +void ImGui::ShowStyleEditor(ImGuiStyle*) {} + +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/imgui_draw.cpp b/lib/cimgui-1.53.1/imgui-1.53/imgui_draw.cpp new file mode 100644 index 0000000..6efb6bc --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/imgui_draw.cpp @@ -0,0 +1,2906 @@ +// dear imgui, v1.53 +// (drawing and font code) + +// Contains implementation for +// - Default styles +// - ImDrawList +// - ImDrawData +// - ImFontAtlas +// - ImFont +// - Default font data + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include "imgui.h" +#define IMGUI_DEFINE_MATH_OPERATORS +#include "imgui_internal.h" + +#include // vsnprintf, sscanf, printf +#if !defined(alloca) +#ifdef _WIN32 +#include // alloca +#if !defined(alloca) +#define alloca _alloca // for clang with MS Codegen +#endif +#elif defined(__GLIBC__) || defined(__sun) +#include // alloca +#else +#include // alloca +#endif +#endif + +#ifdef _MSC_VER +#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#define snprintf _snprintf +#endif + +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse. +#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok. +#pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. +#pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // +#pragma clang diagnostic ignored "-Wcomma" // warning : possible misuse of comma operator here // +#if __has_warning("-Wreserved-id-macro") +#pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier // +#endif +#if __has_warning("-Wdouble-promotion") +#pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function +#endif +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used +#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function +#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value +#pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'xxxx' to type 'xxxx' casts away qualifiers +#endif + +//------------------------------------------------------------------------- +// STB libraries implementation +//------------------------------------------------------------------------- + +//#define IMGUI_STB_NAMESPACE ImGuiStb +//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION +//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION + +#ifdef IMGUI_STB_NAMESPACE +namespace IMGUI_STB_NAMESPACE +{ +#endif + +#ifdef _MSC_VER +#pragma warning (push) +#pragma warning (disable: 4456) // declaration of 'xx' hides previous local declaration +#endif + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" +#pragma clang diagnostic ignored "-Wmissing-prototypes" +#pragma clang diagnostic ignored "-Wimplicit-fallthrough" +#endif + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type [-Wtype-limits] +#endif + +#define STBRP_ASSERT(x) IM_ASSERT(x) +#ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION +#define STBRP_STATIC +#define STB_RECT_PACK_IMPLEMENTATION +#endif +#include "stb_rect_pack.h" + +#define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x)) +#define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x)) +#define STBTT_assert(x) IM_ASSERT(x) +#ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION +#define STBTT_STATIC +#define STB_TRUETYPE_IMPLEMENTATION +#else +#define STBTT_DEF extern +#endif +#include "stb_truetype.h" + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#ifdef _MSC_VER +#pragma warning (pop) +#endif + +#ifdef IMGUI_STB_NAMESPACE +} // namespace ImGuiStb +using namespace IMGUI_STB_NAMESPACE; +#endif + +//----------------------------------------------------------------------------- +// Style functions +//----------------------------------------------------------------------------- + +void ImGui::StyleColorsClassic(ImGuiStyle* dst) +{ + ImGuiStyle* style = dst ? dst : &ImGui::GetStyle(); + ImVec4* colors = style->Colors; + + colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.70f); + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f); + colors[ImGuiCol_Border] = ImVec4(0.50f, 0.50f, 0.50f, 0.50f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_FrameBg] = ImVec4(0.43f, 0.43f, 0.43f, 0.39f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.47f, 0.47f, 0.69f, 0.40f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.42f, 0.41f, 0.64f, 0.69f); + colors[ImGuiCol_TitleBg] = ImVec4(0.27f, 0.27f, 0.54f, 0.83f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.32f, 0.32f, 0.63f, 0.87f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.40f, 0.40f, 0.55f, 0.80f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.25f, 0.30f, 0.60f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.41f, 0.39f, 0.80f, 0.60f); + colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); + colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.41f, 0.39f, 0.80f, 0.60f); + colors[ImGuiCol_Button] = ImVec4(0.35f, 0.40f, 0.61f, 0.62f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.40f, 0.48f, 0.71f, 0.79f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.46f, 0.54f, 0.80f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f); + colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.16f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f); + colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f); + colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f); + colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); + colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); + colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); + colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); +} + +void ImGui::StyleColorsDark(ImGuiStyle* dst) +{ + ImGuiStyle* style = dst ? dst : &ImGui::GetStyle(); + ImVec4* colors = style->Colors; + + colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f); + colors[ImGuiCol_ChildBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); + colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.29f, 0.48f, 0.54f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.29f, 0.48f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); + colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_Separator] = colors[ImGuiCol_Border];//ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + colors[ImGuiCol_CloseButton] = ImVec4(0.41f, 0.41f, 0.41f, 0.50f); + colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); + colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); + colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); + colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); + colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); +} + +// Those light colors are better suited with a thicker font than the default one + FrameBorder +void ImGui::StyleColorsLight(ImGuiStyle* dst) +{ + ImGuiStyle* style = dst ? dst : &ImGui::GetStyle(); + ImVec4* colors = style->Colors; + + colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); + //colors[ImGuiCol_TextHovered] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + //colors[ImGuiCol_TextActive] = ImVec4(1.00f, 1.00f, 0.00f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f); + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.98f); + colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 0.80f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.49f, 0.49f, 0.49f, 0.80f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f); + colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.46f, 0.54f, 0.80f, 0.60f); + colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(0.80f, 0.80f, 0.80f, 0.56f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f); + colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); + colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); + colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.45f, 0.00f, 1.00f); + colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); + colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); + colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); +} + +//----------------------------------------------------------------------------- +// ImDrawListData +//----------------------------------------------------------------------------- + +ImDrawListSharedData::ImDrawListSharedData() +{ + Font = NULL; + FontSize = 0.0f; + CurveTessellationTol = 0.0f; + ClipRectFullscreen = ImVec4(-8192.0f, -8192.0f, +8192.0f, +8192.0f); + + // Const data + for (int i = 0; i < IM_ARRAYSIZE(CircleVtx12); i++) + { + const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(CircleVtx12); + CircleVtx12[i] = ImVec2(cosf(a), sinf(a)); + } +} + +//----------------------------------------------------------------------------- +// ImDrawList +//----------------------------------------------------------------------------- + +void ImDrawList::Clear() +{ + CmdBuffer.resize(0); + IdxBuffer.resize(0); + VtxBuffer.resize(0); + Flags = ImDrawListFlags_AntiAliasedLines | ImDrawListFlags_AntiAliasedFill; + _VtxCurrentIdx = 0; + _VtxWritePtr = NULL; + _IdxWritePtr = NULL; + _ClipRectStack.resize(0); + _TextureIdStack.resize(0); + _Path.resize(0); + _ChannelsCurrent = 0; + _ChannelsCount = 1; + // NB: Do not clear channels so our allocations are re-used after the first frame. +} + +void ImDrawList::ClearFreeMemory() +{ + CmdBuffer.clear(); + IdxBuffer.clear(); + VtxBuffer.clear(); + _VtxCurrentIdx = 0; + _VtxWritePtr = NULL; + _IdxWritePtr = NULL; + _ClipRectStack.clear(); + _TextureIdStack.clear(); + _Path.clear(); + _ChannelsCurrent = 0; + _ChannelsCount = 1; + for (int i = 0; i < _Channels.Size; i++) + { + if (i == 0) memset(&_Channels[0], 0, sizeof(_Channels[0])); // channel 0 is a copy of CmdBuffer/IdxBuffer, don't destruct again + _Channels[i].CmdBuffer.clear(); + _Channels[i].IdxBuffer.clear(); + } + _Channels.clear(); +} + +// Using macros because C++ is a terrible language, we want guaranteed inline, no code in header, and no overhead in Debug builds +#define GetCurrentClipRect() (_ClipRectStack.Size ? _ClipRectStack.Data[_ClipRectStack.Size-1] : _Data->ClipRectFullscreen) +#define GetCurrentTextureId() (_TextureIdStack.Size ? _TextureIdStack.Data[_TextureIdStack.Size-1] : NULL) + +void ImDrawList::AddDrawCmd() +{ + ImDrawCmd draw_cmd; + draw_cmd.ClipRect = GetCurrentClipRect(); + draw_cmd.TextureId = GetCurrentTextureId(); + + IM_ASSERT(draw_cmd.ClipRect.x <= draw_cmd.ClipRect.z && draw_cmd.ClipRect.y <= draw_cmd.ClipRect.w); + CmdBuffer.push_back(draw_cmd); +} + +void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data) +{ + ImDrawCmd* current_cmd = CmdBuffer.Size ? &CmdBuffer.back() : NULL; + if (!current_cmd || current_cmd->ElemCount != 0 || current_cmd->UserCallback != NULL) + { + AddDrawCmd(); + current_cmd = &CmdBuffer.back(); + } + current_cmd->UserCallback = callback; + current_cmd->UserCallbackData = callback_data; + + AddDrawCmd(); // Force a new command after us (see comment below) +} + +// Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack. +// The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only. +void ImDrawList::UpdateClipRect() +{ + // If current command is used with different settings we need to add a new command + const ImVec4 curr_clip_rect = GetCurrentClipRect(); + ImDrawCmd* curr_cmd = CmdBuffer.Size > 0 ? &CmdBuffer.Data[CmdBuffer.Size-1] : NULL; + if (!curr_cmd || (curr_cmd->ElemCount != 0 && memcmp(&curr_cmd->ClipRect, &curr_clip_rect, sizeof(ImVec4)) != 0) || curr_cmd->UserCallback != NULL) + { + AddDrawCmd(); + return; + } + + // Try to merge with previous command if it matches, else use current command + ImDrawCmd* prev_cmd = CmdBuffer.Size > 1 ? curr_cmd - 1 : NULL; + if (curr_cmd->ElemCount == 0 && prev_cmd && memcmp(&prev_cmd->ClipRect, &curr_clip_rect, sizeof(ImVec4)) == 0 && prev_cmd->TextureId == GetCurrentTextureId() && prev_cmd->UserCallback == NULL) + CmdBuffer.pop_back(); + else + curr_cmd->ClipRect = curr_clip_rect; +} + +void ImDrawList::UpdateTextureID() +{ + // If current command is used with different settings we need to add a new command + const ImTextureID curr_texture_id = GetCurrentTextureId(); + ImDrawCmd* curr_cmd = CmdBuffer.Size ? &CmdBuffer.back() : NULL; + if (!curr_cmd || (curr_cmd->ElemCount != 0 && curr_cmd->TextureId != curr_texture_id) || curr_cmd->UserCallback != NULL) + { + AddDrawCmd(); + return; + } + + // Try to merge with previous command if it matches, else use current command + ImDrawCmd* prev_cmd = CmdBuffer.Size > 1 ? curr_cmd - 1 : NULL; + if (curr_cmd->ElemCount == 0 && prev_cmd && prev_cmd->TextureId == curr_texture_id && memcmp(&prev_cmd->ClipRect, &GetCurrentClipRect(), sizeof(ImVec4)) == 0 && prev_cmd->UserCallback == NULL) + CmdBuffer.pop_back(); + else + curr_cmd->TextureId = curr_texture_id; +} + +#undef GetCurrentClipRect +#undef GetCurrentTextureId + +// Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) +void ImDrawList::PushClipRect(ImVec2 cr_min, ImVec2 cr_max, bool intersect_with_current_clip_rect) +{ + ImVec4 cr(cr_min.x, cr_min.y, cr_max.x, cr_max.y); + if (intersect_with_current_clip_rect && _ClipRectStack.Size) + { + ImVec4 current = _ClipRectStack.Data[_ClipRectStack.Size-1]; + if (cr.x < current.x) cr.x = current.x; + if (cr.y < current.y) cr.y = current.y; + if (cr.z > current.z) cr.z = current.z; + if (cr.w > current.w) cr.w = current.w; + } + cr.z = ImMax(cr.x, cr.z); + cr.w = ImMax(cr.y, cr.w); + + _ClipRectStack.push_back(cr); + UpdateClipRect(); +} + +void ImDrawList::PushClipRectFullScreen() +{ + PushClipRect(ImVec2(_Data->ClipRectFullscreen.x, _Data->ClipRectFullscreen.y), ImVec2(_Data->ClipRectFullscreen.z, _Data->ClipRectFullscreen.w)); +} + +void ImDrawList::PopClipRect() +{ + IM_ASSERT(_ClipRectStack.Size > 0); + _ClipRectStack.pop_back(); + UpdateClipRect(); +} + +void ImDrawList::PushTextureID(const ImTextureID& texture_id) +{ + _TextureIdStack.push_back(texture_id); + UpdateTextureID(); +} + +void ImDrawList::PopTextureID() +{ + IM_ASSERT(_TextureIdStack.Size > 0); + _TextureIdStack.pop_back(); + UpdateTextureID(); +} + +void ImDrawList::ChannelsSplit(int channels_count) +{ + IM_ASSERT(_ChannelsCurrent == 0 && _ChannelsCount == 1); + int old_channels_count = _Channels.Size; + if (old_channels_count < channels_count) + _Channels.resize(channels_count); + _ChannelsCount = channels_count; + + // _Channels[] (24/32 bytes each) hold storage that we'll swap with this->_CmdBuffer/_IdxBuffer + // The content of _Channels[0] at this point doesn't matter. We clear it to make state tidy in a debugger but we don't strictly need to. + // When we switch to the next channel, we'll copy _CmdBuffer/_IdxBuffer into _Channels[0] and then _Channels[1] into _CmdBuffer/_IdxBuffer + memset(&_Channels[0], 0, sizeof(ImDrawChannel)); + for (int i = 1; i < channels_count; i++) + { + if (i >= old_channels_count) + { + IM_PLACEMENT_NEW(&_Channels[i]) ImDrawChannel(); + } + else + { + _Channels[i].CmdBuffer.resize(0); + _Channels[i].IdxBuffer.resize(0); + } + if (_Channels[i].CmdBuffer.Size == 0) + { + ImDrawCmd draw_cmd; + draw_cmd.ClipRect = _ClipRectStack.back(); + draw_cmd.TextureId = _TextureIdStack.back(); + _Channels[i].CmdBuffer.push_back(draw_cmd); + } + } +} + +void ImDrawList::ChannelsMerge() +{ + // Note that we never use or rely on channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use. + if (_ChannelsCount <= 1) + return; + + ChannelsSetCurrent(0); + if (CmdBuffer.Size && CmdBuffer.back().ElemCount == 0) + CmdBuffer.pop_back(); + + int new_cmd_buffer_count = 0, new_idx_buffer_count = 0; + for (int i = 1; i < _ChannelsCount; i++) + { + ImDrawChannel& ch = _Channels[i]; + if (ch.CmdBuffer.Size && ch.CmdBuffer.back().ElemCount == 0) + ch.CmdBuffer.pop_back(); + new_cmd_buffer_count += ch.CmdBuffer.Size; + new_idx_buffer_count += ch.IdxBuffer.Size; + } + CmdBuffer.resize(CmdBuffer.Size + new_cmd_buffer_count); + IdxBuffer.resize(IdxBuffer.Size + new_idx_buffer_count); + + ImDrawCmd* cmd_write = CmdBuffer.Data + CmdBuffer.Size - new_cmd_buffer_count; + _IdxWritePtr = IdxBuffer.Data + IdxBuffer.Size - new_idx_buffer_count; + for (int i = 1; i < _ChannelsCount; i++) + { + ImDrawChannel& ch = _Channels[i]; + if (int sz = ch.CmdBuffer.Size) { memcpy(cmd_write, ch.CmdBuffer.Data, sz * sizeof(ImDrawCmd)); cmd_write += sz; } + if (int sz = ch.IdxBuffer.Size) { memcpy(_IdxWritePtr, ch.IdxBuffer.Data, sz * sizeof(ImDrawIdx)); _IdxWritePtr += sz; } + } + UpdateClipRect(); // We call this instead of AddDrawCmd(), so that empty channels won't produce an extra draw call. + _ChannelsCount = 1; +} + +void ImDrawList::ChannelsSetCurrent(int idx) +{ + IM_ASSERT(idx < _ChannelsCount); + if (_ChannelsCurrent == idx) return; + memcpy(&_Channels.Data[_ChannelsCurrent].CmdBuffer, &CmdBuffer, sizeof(CmdBuffer)); // copy 12 bytes, four times + memcpy(&_Channels.Data[_ChannelsCurrent].IdxBuffer, &IdxBuffer, sizeof(IdxBuffer)); + _ChannelsCurrent = idx; + memcpy(&CmdBuffer, &_Channels.Data[_ChannelsCurrent].CmdBuffer, sizeof(CmdBuffer)); + memcpy(&IdxBuffer, &_Channels.Data[_ChannelsCurrent].IdxBuffer, sizeof(IdxBuffer)); + _IdxWritePtr = IdxBuffer.Data + IdxBuffer.Size; +} + +// NB: this can be called with negative count for removing primitives (as long as the result does not underflow) +void ImDrawList::PrimReserve(int idx_count, int vtx_count) +{ + ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size-1]; + draw_cmd.ElemCount += idx_count; + + int vtx_buffer_old_size = VtxBuffer.Size; + VtxBuffer.resize(vtx_buffer_old_size + vtx_count); + _VtxWritePtr = VtxBuffer.Data + vtx_buffer_old_size; + + int idx_buffer_old_size = IdxBuffer.Size; + IdxBuffer.resize(idx_buffer_old_size + idx_count); + _IdxWritePtr = IdxBuffer.Data + idx_buffer_old_size; +} + +// Fully unrolled with inline call to keep our debug builds decently fast. +void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col) +{ + ImVec2 b(c.x, a.y), d(a.x, c.y), uv(_Data->TexUvWhitePixel); + ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx; + _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2); + _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3); + _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; + _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col; + _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv; _VtxWritePtr[2].col = col; + _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv; _VtxWritePtr[3].col = col; + _VtxWritePtr += 4; + _VtxCurrentIdx += 4; + _IdxWritePtr += 6; +} + +void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a, const ImVec2& uv_c, ImU32 col) +{ + ImVec2 b(c.x, a.y), d(a.x, c.y), uv_b(uv_c.x, uv_a.y), uv_d(uv_a.x, uv_c.y); + ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx; + _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2); + _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3); + _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv_a; _VtxWritePtr[0].col = col; + _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv_b; _VtxWritePtr[1].col = col; + _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv_c; _VtxWritePtr[2].col = col; + _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv_d; _VtxWritePtr[3].col = col; + _VtxWritePtr += 4; + _VtxCurrentIdx += 4; + _IdxWritePtr += 6; +} + +void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col) +{ + ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx; + _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2); + _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3); + _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv_a; _VtxWritePtr[0].col = col; + _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv_b; _VtxWritePtr[1].col = col; + _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv_c; _VtxWritePtr[2].col = col; + _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv_d; _VtxWritePtr[3].col = col; + _VtxWritePtr += 4; + _VtxCurrentIdx += 4; + _IdxWritePtr += 6; +} + +// TODO: Thickness anti-aliased lines cap are missing their AA fringe. +void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, bool closed, float thickness) +{ + if (points_count < 2) + return; + + const ImVec2 uv = _Data->TexUvWhitePixel; + + int count = points_count; + if (!closed) + count = points_count-1; + + const bool thick_line = thickness > 1.0f; + if (Flags & ImDrawListFlags_AntiAliasedLines) + { + // Anti-aliased stroke + const float AA_SIZE = 1.0f; + const ImU32 col_trans = col & ~IM_COL32_A_MASK; + + const int idx_count = thick_line ? count*18 : count*12; + const int vtx_count = thick_line ? points_count*4 : points_count*3; + PrimReserve(idx_count, vtx_count); + + // Temporary buffer + ImVec2* temp_normals = (ImVec2*)alloca(points_count * (thick_line ? 5 : 3) * sizeof(ImVec2)); + ImVec2* temp_points = temp_normals + points_count; + + for (int i1 = 0; i1 < count; i1++) + { + const int i2 = (i1+1) == points_count ? 0 : i1+1; + ImVec2 diff = points[i2] - points[i1]; + diff *= ImInvLength(diff, 1.0f); + temp_normals[i1].x = diff.y; + temp_normals[i1].y = -diff.x; + } + if (!closed) + temp_normals[points_count-1] = temp_normals[points_count-2]; + + if (!thick_line) + { + if (!closed) + { + temp_points[0] = points[0] + temp_normals[0] * AA_SIZE; + temp_points[1] = points[0] - temp_normals[0] * AA_SIZE; + temp_points[(points_count-1)*2+0] = points[points_count-1] + temp_normals[points_count-1] * AA_SIZE; + temp_points[(points_count-1)*2+1] = points[points_count-1] - temp_normals[points_count-1] * AA_SIZE; + } + + // FIXME-OPT: Merge the different loops, possibly remove the temporary buffer. + unsigned int idx1 = _VtxCurrentIdx; + for (int i1 = 0; i1 < count; i1++) + { + const int i2 = (i1+1) == points_count ? 0 : i1+1; + unsigned int idx2 = (i1+1) == points_count ? _VtxCurrentIdx : idx1+3; + + // Average normals + ImVec2 dm = (temp_normals[i1] + temp_normals[i2]) * 0.5f; + float dmr2 = dm.x*dm.x + dm.y*dm.y; + if (dmr2 > 0.000001f) + { + float scale = 1.0f / dmr2; + if (scale > 100.0f) scale = 100.0f; + dm *= scale; + } + dm *= AA_SIZE; + temp_points[i2*2+0] = points[i2] + dm; + temp_points[i2*2+1] = points[i2] - dm; + + // Add indexes + _IdxWritePtr[0] = (ImDrawIdx)(idx2+0); _IdxWritePtr[1] = (ImDrawIdx)(idx1+0); _IdxWritePtr[2] = (ImDrawIdx)(idx1+2); + _IdxWritePtr[3] = (ImDrawIdx)(idx1+2); _IdxWritePtr[4] = (ImDrawIdx)(idx2+2); _IdxWritePtr[5] = (ImDrawIdx)(idx2+0); + _IdxWritePtr[6] = (ImDrawIdx)(idx2+1); _IdxWritePtr[7] = (ImDrawIdx)(idx1+1); _IdxWritePtr[8] = (ImDrawIdx)(idx1+0); + _IdxWritePtr[9] = (ImDrawIdx)(idx1+0); _IdxWritePtr[10]= (ImDrawIdx)(idx2+0); _IdxWritePtr[11]= (ImDrawIdx)(idx2+1); + _IdxWritePtr += 12; + + idx1 = idx2; + } + + // Add vertexes + for (int i = 0; i < points_count; i++) + { + _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; + _VtxWritePtr[1].pos = temp_points[i*2+0]; _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col_trans; + _VtxWritePtr[2].pos = temp_points[i*2+1]; _VtxWritePtr[2].uv = uv; _VtxWritePtr[2].col = col_trans; + _VtxWritePtr += 3; + } + } + else + { + const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f; + if (!closed) + { + temp_points[0] = points[0] + temp_normals[0] * (half_inner_thickness + AA_SIZE); + temp_points[1] = points[0] + temp_normals[0] * (half_inner_thickness); + temp_points[2] = points[0] - temp_normals[0] * (half_inner_thickness); + temp_points[3] = points[0] - temp_normals[0] * (half_inner_thickness + AA_SIZE); + temp_points[(points_count-1)*4+0] = points[points_count-1] + temp_normals[points_count-1] * (half_inner_thickness + AA_SIZE); + temp_points[(points_count-1)*4+1] = points[points_count-1] + temp_normals[points_count-1] * (half_inner_thickness); + temp_points[(points_count-1)*4+2] = points[points_count-1] - temp_normals[points_count-1] * (half_inner_thickness); + temp_points[(points_count-1)*4+3] = points[points_count-1] - temp_normals[points_count-1] * (half_inner_thickness + AA_SIZE); + } + + // FIXME-OPT: Merge the different loops, possibly remove the temporary buffer. + unsigned int idx1 = _VtxCurrentIdx; + for (int i1 = 0; i1 < count; i1++) + { + const int i2 = (i1+1) == points_count ? 0 : i1+1; + unsigned int idx2 = (i1+1) == points_count ? _VtxCurrentIdx : idx1+4; + + // Average normals + ImVec2 dm = (temp_normals[i1] + temp_normals[i2]) * 0.5f; + float dmr2 = dm.x*dm.x + dm.y*dm.y; + if (dmr2 > 0.000001f) + { + float scale = 1.0f / dmr2; + if (scale > 100.0f) scale = 100.0f; + dm *= scale; + } + ImVec2 dm_out = dm * (half_inner_thickness + AA_SIZE); + ImVec2 dm_in = dm * half_inner_thickness; + temp_points[i2*4+0] = points[i2] + dm_out; + temp_points[i2*4+1] = points[i2] + dm_in; + temp_points[i2*4+2] = points[i2] - dm_in; + temp_points[i2*4+3] = points[i2] - dm_out; + + // Add indexes + _IdxWritePtr[0] = (ImDrawIdx)(idx2+1); _IdxWritePtr[1] = (ImDrawIdx)(idx1+1); _IdxWritePtr[2] = (ImDrawIdx)(idx1+2); + _IdxWritePtr[3] = (ImDrawIdx)(idx1+2); _IdxWritePtr[4] = (ImDrawIdx)(idx2+2); _IdxWritePtr[5] = (ImDrawIdx)(idx2+1); + _IdxWritePtr[6] = (ImDrawIdx)(idx2+1); _IdxWritePtr[7] = (ImDrawIdx)(idx1+1); _IdxWritePtr[8] = (ImDrawIdx)(idx1+0); + _IdxWritePtr[9] = (ImDrawIdx)(idx1+0); _IdxWritePtr[10] = (ImDrawIdx)(idx2+0); _IdxWritePtr[11] = (ImDrawIdx)(idx2+1); + _IdxWritePtr[12] = (ImDrawIdx)(idx2+2); _IdxWritePtr[13] = (ImDrawIdx)(idx1+2); _IdxWritePtr[14] = (ImDrawIdx)(idx1+3); + _IdxWritePtr[15] = (ImDrawIdx)(idx1+3); _IdxWritePtr[16] = (ImDrawIdx)(idx2+3); _IdxWritePtr[17] = (ImDrawIdx)(idx2+2); + _IdxWritePtr += 18; + + idx1 = idx2; + } + + // Add vertexes + for (int i = 0; i < points_count; i++) + { + _VtxWritePtr[0].pos = temp_points[i*4+0]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col_trans; + _VtxWritePtr[1].pos = temp_points[i*4+1]; _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col; + _VtxWritePtr[2].pos = temp_points[i*4+2]; _VtxWritePtr[2].uv = uv; _VtxWritePtr[2].col = col; + _VtxWritePtr[3].pos = temp_points[i*4+3]; _VtxWritePtr[3].uv = uv; _VtxWritePtr[3].col = col_trans; + _VtxWritePtr += 4; + } + } + _VtxCurrentIdx += (ImDrawIdx)vtx_count; + } + else + { + // Non Anti-aliased Stroke + const int idx_count = count*6; + const int vtx_count = count*4; // FIXME-OPT: Not sharing edges + PrimReserve(idx_count, vtx_count); + + for (int i1 = 0; i1 < count; i1++) + { + const int i2 = (i1+1) == points_count ? 0 : i1+1; + const ImVec2& p1 = points[i1]; + const ImVec2& p2 = points[i2]; + ImVec2 diff = p2 - p1; + diff *= ImInvLength(diff, 1.0f); + + const float dx = diff.x * (thickness * 0.5f); + const float dy = diff.y * (thickness * 0.5f); + _VtxWritePtr[0].pos.x = p1.x + dy; _VtxWritePtr[0].pos.y = p1.y - dx; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; + _VtxWritePtr[1].pos.x = p2.x + dy; _VtxWritePtr[1].pos.y = p2.y - dx; _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col; + _VtxWritePtr[2].pos.x = p2.x - dy; _VtxWritePtr[2].pos.y = p2.y + dx; _VtxWritePtr[2].uv = uv; _VtxWritePtr[2].col = col; + _VtxWritePtr[3].pos.x = p1.x - dy; _VtxWritePtr[3].pos.y = p1.y + dx; _VtxWritePtr[3].uv = uv; _VtxWritePtr[3].col = col; + _VtxWritePtr += 4; + + _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx+1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx+2); + _IdxWritePtr[3] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[4] = (ImDrawIdx)(_VtxCurrentIdx+2); _IdxWritePtr[5] = (ImDrawIdx)(_VtxCurrentIdx+3); + _IdxWritePtr += 6; + _VtxCurrentIdx += 4; + } + } +} + +void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col) +{ + const ImVec2 uv = _Data->TexUvWhitePixel; + + if (Flags & ImDrawListFlags_AntiAliasedFill) + { + // Anti-aliased Fill + const float AA_SIZE = 1.0f; + const ImU32 col_trans = col & ~IM_COL32_A_MASK; + const int idx_count = (points_count-2)*3 + points_count*6; + const int vtx_count = (points_count*2); + PrimReserve(idx_count, vtx_count); + + // Add indexes for fill + unsigned int vtx_inner_idx = _VtxCurrentIdx; + unsigned int vtx_outer_idx = _VtxCurrentIdx+1; + for (int i = 2; i < points_count; i++) + { + _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx+((i-1)<<1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_inner_idx+(i<<1)); + _IdxWritePtr += 3; + } + + // Compute normals + ImVec2* temp_normals = (ImVec2*)alloca(points_count * sizeof(ImVec2)); + for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) + { + const ImVec2& p0 = points[i0]; + const ImVec2& p1 = points[i1]; + ImVec2 diff = p1 - p0; + diff *= ImInvLength(diff, 1.0f); + temp_normals[i0].x = diff.y; + temp_normals[i0].y = -diff.x; + } + + for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) + { + // Average normals + const ImVec2& n0 = temp_normals[i0]; + const ImVec2& n1 = temp_normals[i1]; + ImVec2 dm = (n0 + n1) * 0.5f; + float dmr2 = dm.x*dm.x + dm.y*dm.y; + if (dmr2 > 0.000001f) + { + float scale = 1.0f / dmr2; + if (scale > 100.0f) scale = 100.0f; + dm *= scale; + } + dm *= AA_SIZE * 0.5f; + + // Add vertices + _VtxWritePtr[0].pos = (points[i1] - dm); _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; // Inner + _VtxWritePtr[1].pos = (points[i1] + dm); _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col_trans; // Outer + _VtxWritePtr += 2; + + // Add indexes for fringes + _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx+(i1<<1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx+(i0<<1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx+(i0<<1)); + _IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx+(i0<<1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx+(i1<<1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx+(i1<<1)); + _IdxWritePtr += 6; + } + _VtxCurrentIdx += (ImDrawIdx)vtx_count; + } + else + { + // Non Anti-aliased Fill + const int idx_count = (points_count-2)*3; + const int vtx_count = points_count; + PrimReserve(idx_count, vtx_count); + for (int i = 0; i < vtx_count; i++) + { + _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; + _VtxWritePtr++; + } + for (int i = 2; i < points_count; i++) + { + _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx+i-1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx+i); + _IdxWritePtr += 3; + } + _VtxCurrentIdx += (ImDrawIdx)vtx_count; + } +} + +void ImDrawList::PathArcToFast(const ImVec2& centre, float radius, int a_min_of_12, int a_max_of_12) +{ + if (radius == 0.0f || a_min_of_12 > a_max_of_12) + { + _Path.push_back(centre); + return; + } + _Path.reserve(_Path.Size + (a_max_of_12 - a_min_of_12 + 1)); + for (int a = a_min_of_12; a <= a_max_of_12; a++) + { + const ImVec2& c = _Data->CircleVtx12[a % IM_ARRAYSIZE(_Data->CircleVtx12)]; + _Path.push_back(ImVec2(centre.x + c.x * radius, centre.y + c.y * radius)); + } +} + +void ImDrawList::PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments) +{ + if (radius == 0.0f) + { + _Path.push_back(centre); + return; + } + _Path.reserve(_Path.Size + (num_segments + 1)); + for (int i = 0; i <= num_segments; i++) + { + const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min); + _Path.push_back(ImVec2(centre.x + cosf(a) * radius, centre.y + sinf(a) * radius)); + } +} + +static void PathBezierToCasteljau(ImVector* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) +{ + float dx = x4 - x1; + float dy = y4 - y1; + float d2 = ((x2 - x4) * dy - (y2 - y4) * dx); + float d3 = ((x3 - x4) * dy - (y3 - y4) * dx); + d2 = (d2 >= 0) ? d2 : -d2; + d3 = (d3 >= 0) ? d3 : -d3; + if ((d2+d3) * (d2+d3) < tess_tol * (dx*dx + dy*dy)) + { + path->push_back(ImVec2(x4, y4)); + } + else if (level < 10) + { + float x12 = (x1+x2)*0.5f, y12 = (y1+y2)*0.5f; + float x23 = (x2+x3)*0.5f, y23 = (y2+y3)*0.5f; + float x34 = (x3+x4)*0.5f, y34 = (y3+y4)*0.5f; + float x123 = (x12+x23)*0.5f, y123 = (y12+y23)*0.5f; + float x234 = (x23+x34)*0.5f, y234 = (y23+y34)*0.5f; + float x1234 = (x123+x234)*0.5f, y1234 = (y123+y234)*0.5f; + + PathBezierToCasteljau(path, x1,y1, x12,y12, x123,y123, x1234,y1234, tess_tol, level+1); + PathBezierToCasteljau(path, x1234,y1234, x234,y234, x34,y34, x4,y4, tess_tol, level+1); + } +} + +void ImDrawList::PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments) +{ + ImVec2 p1 = _Path.back(); + if (num_segments == 0) + { + // Auto-tessellated + PathBezierToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, _Data->CurveTessellationTol, 0); + } + else + { + float t_step = 1.0f / (float)num_segments; + for (int i_step = 1; i_step <= num_segments; i_step++) + { + float t = t_step * i_step; + float u = 1.0f - t; + float w1 = u*u*u; + float w2 = 3*u*u*t; + float w3 = 3*u*t*t; + float w4 = t*t*t; + _Path.push_back(ImVec2(w1*p1.x + w2*p2.x + w3*p3.x + w4*p4.x, w1*p1.y + w2*p2.y + w3*p3.y + w4*p4.y)); + } + } +} + +void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, int rounding_corners) +{ + rounding = ImMin(rounding, fabsf(b.x - a.x) * ( ((rounding_corners & ImDrawCornerFlags_Top) == ImDrawCornerFlags_Top) || ((rounding_corners & ImDrawCornerFlags_Bot) == ImDrawCornerFlags_Bot) ? 0.5f : 1.0f ) - 1.0f); + rounding = ImMin(rounding, fabsf(b.y - a.y) * ( ((rounding_corners & ImDrawCornerFlags_Left) == ImDrawCornerFlags_Left) || ((rounding_corners & ImDrawCornerFlags_Right) == ImDrawCornerFlags_Right) ? 0.5f : 1.0f ) - 1.0f); + + if (rounding <= 0.0f || rounding_corners == 0) + { + PathLineTo(a); + PathLineTo(ImVec2(b.x, a.y)); + PathLineTo(b); + PathLineTo(ImVec2(a.x, b.y)); + } + else + { + const float rounding_tl = (rounding_corners & ImDrawCornerFlags_TopLeft) ? rounding : 0.0f; + const float rounding_tr = (rounding_corners & ImDrawCornerFlags_TopRight) ? rounding : 0.0f; + const float rounding_br = (rounding_corners & ImDrawCornerFlags_BotRight) ? rounding : 0.0f; + const float rounding_bl = (rounding_corners & ImDrawCornerFlags_BotLeft) ? rounding : 0.0f; + PathArcToFast(ImVec2(a.x + rounding_tl, a.y + rounding_tl), rounding_tl, 6, 9); + PathArcToFast(ImVec2(b.x - rounding_tr, a.y + rounding_tr), rounding_tr, 9, 12); + PathArcToFast(ImVec2(b.x - rounding_br, b.y - rounding_br), rounding_br, 0, 3); + PathArcToFast(ImVec2(a.x + rounding_bl, b.y - rounding_bl), rounding_bl, 3, 6); + } +} + +void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + PathLineTo(a + ImVec2(0.5f,0.5f)); + PathLineTo(b + ImVec2(0.5f,0.5f)); + PathStroke(col, false, thickness); +} + +// a: upper-left, b: lower-right. we don't render 1 px sized rectangles properly. +void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners_flags, float thickness) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.5f,0.5f), rounding, rounding_corners_flags); + PathStroke(col, true, thickness); +} + +void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners_flags) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + if (rounding > 0.0f) + { + PathRect(a, b, rounding, rounding_corners_flags); + PathFillConvex(col); + } + else + { + PrimReserve(6, 4); + PrimRect(a, b, col); + } +} + +void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left) +{ + if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0) + return; + + const ImVec2 uv = _Data->TexUvWhitePixel; + PrimReserve(6, 4); + PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+1)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+2)); + PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+2)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+3)); + PrimWriteVtx(a, uv, col_upr_left); + PrimWriteVtx(ImVec2(c.x, a.y), uv, col_upr_right); + PrimWriteVtx(c, uv, col_bot_right); + PrimWriteVtx(ImVec2(a.x, c.y), uv, col_bot_left); +} + +void ImDrawList::AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col, float thickness) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + PathLineTo(a); + PathLineTo(b); + PathLineTo(c); + PathLineTo(d); + PathStroke(col, true, thickness); +} + +void ImDrawList::AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + PathLineTo(a); + PathLineTo(b); + PathLineTo(c); + PathLineTo(d); + PathFillConvex(col); +} + +void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + PathLineTo(a); + PathLineTo(b); + PathLineTo(c); + PathStroke(col, true, thickness); +} + +void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + PathLineTo(a); + PathLineTo(b); + PathLineTo(c); + PathFillConvex(col); +} + +void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments, float thickness) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments; + PathArcTo(centre, radius-0.5f, 0.0f, a_max, num_segments); + PathStroke(col, true, thickness); +} + +void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments; + PathArcTo(centre, radius, 0.0f, a_max, num_segments); + PathFillConvex(col); +} + +void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + PathLineTo(pos0); + PathBezierCurveTo(cp0, cp1, pos1, num_segments); + PathStroke(col, false, thickness); +} + +void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + if (text_end == NULL) + text_end = text_begin + strlen(text_begin); + if (text_begin == text_end) + return; + + // Pull default font/size from the shared ImDrawListSharedData instance + if (font == NULL) + font = _Data->Font; + if (font_size == 0.0f) + font_size = _Data->FontSize; + + IM_ASSERT(font->ContainerAtlas->TexID == _TextureIdStack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font. + + ImVec4 clip_rect = _ClipRectStack.back(); + if (cpu_fine_clip_rect) + { + clip_rect.x = ImMax(clip_rect.x, cpu_fine_clip_rect->x); + clip_rect.y = ImMax(clip_rect.y, cpu_fine_clip_rect->y); + clip_rect.z = ImMin(clip_rect.z, cpu_fine_clip_rect->z); + clip_rect.w = ImMin(clip_rect.w, cpu_fine_clip_rect->w); + } + font->RenderText(this, font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip_rect != NULL); +} + +void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end) +{ + AddText(NULL, 0.0f, pos, col, text_begin, text_end); +} + +void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + const bool push_texture_id = _TextureIdStack.empty() || user_texture_id != _TextureIdStack.back(); + if (push_texture_id) + PushTextureID(user_texture_id); + + PrimReserve(6, 4); + PrimRectUV(a, b, uv_a, uv_b, col); + + if (push_texture_id) + PopTextureID(); +} + +void ImDrawList::AddImageQuad(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + const bool push_texture_id = _TextureIdStack.empty() || user_texture_id != _TextureIdStack.back(); + if (push_texture_id) + PushTextureID(user_texture_id); + + PrimReserve(6, 4); + PrimQuadUV(a, b, c, d, uv_a, uv_b, uv_c, uv_d, col); + + if (push_texture_id) + PopTextureID(); +} + +void ImDrawList::AddImageRounded(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col, float rounding, int rounding_corners) +{ + if ((col & IM_COL32_A_MASK) == 0) + return; + + if (rounding <= 0.0f || (rounding_corners & ImDrawCornerFlags_All) == 0) + { + AddImage(user_texture_id, a, b, uv_a, uv_b, col); + return; + } + + const bool push_texture_id = _TextureIdStack.empty() || user_texture_id != _TextureIdStack.back(); + if (push_texture_id) + PushTextureID(user_texture_id); + + int vert_start_idx = VtxBuffer.Size; + PathRect(a, b, rounding, rounding_corners); + PathFillConvex(col); + int vert_end_idx = VtxBuffer.Size; + ImGui::ShadeVertsLinearUV(VtxBuffer.Data + vert_start_idx, VtxBuffer.Data + vert_end_idx, a, b, uv_a, uv_b, true); + + if (push_texture_id) + PopTextureID(); +} + +//----------------------------------------------------------------------------- +// ImDrawData +//----------------------------------------------------------------------------- + +// For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering! +void ImDrawData::DeIndexAllBuffers() +{ + ImVector new_vtx_buffer; + TotalVtxCount = TotalIdxCount = 0; + for (int i = 0; i < CmdListsCount; i++) + { + ImDrawList* cmd_list = CmdLists[i]; + if (cmd_list->IdxBuffer.empty()) + continue; + new_vtx_buffer.resize(cmd_list->IdxBuffer.Size); + for (int j = 0; j < cmd_list->IdxBuffer.Size; j++) + new_vtx_buffer[j] = cmd_list->VtxBuffer[cmd_list->IdxBuffer[j]]; + cmd_list->VtxBuffer.swap(new_vtx_buffer); + cmd_list->IdxBuffer.resize(0); + TotalVtxCount += cmd_list->VtxBuffer.Size; + } +} + +// Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution. +void ImDrawData::ScaleClipRects(const ImVec2& scale) +{ + for (int i = 0; i < CmdListsCount; i++) + { + ImDrawList* cmd_list = CmdLists[i]; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + ImDrawCmd* cmd = &cmd_list->CmdBuffer[cmd_i]; + cmd->ClipRect = ImVec4(cmd->ClipRect.x * scale.x, cmd->ClipRect.y * scale.y, cmd->ClipRect.z * scale.x, cmd->ClipRect.w * scale.y); + } + } +} + +//----------------------------------------------------------------------------- +// Shade functions +//----------------------------------------------------------------------------- + +// Generic linear color gradient, write to RGB fields, leave A untouched. +void ImGui::ShadeVertsLinearColorGradientKeepAlpha(ImDrawVert* vert_start, ImDrawVert* vert_end, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1) +{ + ImVec2 gradient_extent = gradient_p1 - gradient_p0; + float gradient_inv_length2 = 1.0f / ImLengthSqr(gradient_extent); + for (ImDrawVert* vert = vert_start; vert < vert_end; vert++) + { + float d = ImDot(vert->pos - gradient_p0, gradient_extent); + float t = ImClamp(d * gradient_inv_length2, 0.0f, 1.0f); + int r = ImLerp((int)(col0 >> IM_COL32_R_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_R_SHIFT) & 0xFF, t); + int g = ImLerp((int)(col0 >> IM_COL32_G_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_G_SHIFT) & 0xFF, t); + int b = ImLerp((int)(col0 >> IM_COL32_B_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_B_SHIFT) & 0xFF, t); + vert->col = (r << IM_COL32_R_SHIFT) | (g << IM_COL32_G_SHIFT) | (b << IM_COL32_B_SHIFT) | (vert->col & IM_COL32_A_MASK); + } +} + +// Scan and shade backward from the end of given vertices. Assume vertices are text only (= vert_start..vert_end going left to right) so we can break as soon as we are out the gradient bounds. +void ImGui::ShadeVertsLinearAlphaGradientForLeftToRightText(ImDrawVert* vert_start, ImDrawVert* vert_end, float gradient_p0_x, float gradient_p1_x) +{ + float gradient_extent_x = gradient_p1_x - gradient_p0_x; + float gradient_inv_length2 = 1.0f / (gradient_extent_x * gradient_extent_x); + int full_alpha_count = 0; + for (ImDrawVert* vert = vert_end - 1; vert >= vert_start; vert--) + { + float d = (vert->pos.x - gradient_p0_x) * (gradient_extent_x); + float alpha_mul = 1.0f - ImClamp(d * gradient_inv_length2, 0.0f, 1.0f); + if (alpha_mul >= 1.0f && ++full_alpha_count > 2) + return; // Early out + int a = (int)(((vert->col >> IM_COL32_A_SHIFT) & 0xFF) * alpha_mul); + vert->col = (vert->col & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT); + } +} + +// Distribute UV over (a, b) rectangle +void ImGui::ShadeVertsLinearUV(ImDrawVert* vert_start, ImDrawVert* vert_end, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp) +{ + const ImVec2 size = b - a; + const ImVec2 uv_size = uv_b - uv_a; + const ImVec2 scale = ImVec2( + size.x != 0.0f ? (uv_size.x / size.x) : 0.0f, + size.y != 0.0f ? (uv_size.y / size.y) : 0.0f); + + if (clamp) + { + const ImVec2 min = ImMin(uv_a, uv_b); + const ImVec2 max = ImMax(uv_a, uv_b); + + for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex) + vertex->uv = ImClamp(uv_a + ImMul(ImVec2(vertex->pos.x, vertex->pos.y) - a, scale), min, max); + } + else + { + for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex) + vertex->uv = uv_a + ImMul(ImVec2(vertex->pos.x, vertex->pos.y) - a, scale); + } +} + +//----------------------------------------------------------------------------- +// ImFontConfig +//----------------------------------------------------------------------------- + +ImFontConfig::ImFontConfig() +{ + FontData = NULL; + FontDataSize = 0; + FontDataOwnedByAtlas = true; + FontNo = 0; + SizePixels = 0.0f; + OversampleH = 3; + OversampleV = 1; + PixelSnapH = false; + GlyphExtraSpacing = ImVec2(0.0f, 0.0f); + GlyphOffset = ImVec2(0.0f, 0.0f); + GlyphRanges = NULL; + MergeMode = false; + RasterizerFlags = 0x00; + RasterizerMultiply = 1.0f; + memset(Name, 0, sizeof(Name)); + DstFont = NULL; +} + +//----------------------------------------------------------------------------- +// ImFontAtlas +//----------------------------------------------------------------------------- + +// A work of art lies ahead! (. = white layer, X = black layer, others are blank) +// The white texels on the top left are the ones we'll use everywhere in ImGui to render filled shapes. +const int FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF = 90; +const int FONT_ATLAS_DEFAULT_TEX_DATA_H = 27; +const unsigned int FONT_ATLAS_DEFAULT_TEX_DATA_ID = 0x80000000; +static const char FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS[FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF * FONT_ATLAS_DEFAULT_TEX_DATA_H + 1] = +{ + "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX" + "..- -X.....X- X.X - X.X -X.....X - X.....X" + "--- -XXX.XXX- X...X - X...X -X....X - X....X" + "X - X.X - X.....X - X.....X -X...X - X...X" + "XX - X.X -X.......X- X.......X -X..X.X - X.X..X" + "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X" + "X..X - X.X - X.X - X.X -XX X.X - X.X XX" + "X...X - X.X - X.X - XX X.X XX - X.X - X.X " + "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X " + "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X " + "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X " + "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X " + "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X " + "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X " + "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X " + "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X " + "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX " + "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------" + "X.X X..X - -X.......X- X.......X - XX XX - " + "XX X..X - - X.....X - X.....X - X.X X.X - " + " X..X - X...X - X...X - X..X X..X - " + " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - " + "------------ - X - X -X.....................X- " + " ----------------------------------- X...XXXXXXXXXXXXX...X - " + " - X..X X..X - " + " - X.X X.X - " + " - XX XX - " +}; + +static const ImVec2 FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[ImGuiMouseCursor_Count_][3] = +{ + // Pos ........ Size ......... Offset ...... + { ImVec2(0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow + { ImVec2(13,0), ImVec2(7,16), ImVec2( 4, 8) }, // ImGuiMouseCursor_TextInput + { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_Move + { ImVec2(21,0), ImVec2( 9,23), ImVec2( 5,11) }, // ImGuiMouseCursor_ResizeNS + { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 5) }, // ImGuiMouseCursor_ResizeEW + { ImVec2(73,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNESW + { ImVec2(55,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNWSE +}; + + +ImFontAtlas::ImFontAtlas() +{ + TexID = NULL; + TexDesiredWidth = 0; + TexGlyphPadding = 1; + TexPixelsAlpha8 = NULL; + TexPixelsRGBA32 = NULL; + TexWidth = TexHeight = 0; + TexUvWhitePixel = ImVec2(0, 0); + for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++) + CustomRectIds[n] = -1; +} + +ImFontAtlas::~ImFontAtlas() +{ + Clear(); +} + +void ImFontAtlas::ClearInputData() +{ + for (int i = 0; i < ConfigData.Size; i++) + if (ConfigData[i].FontData && ConfigData[i].FontDataOwnedByAtlas) + { + ImGui::MemFree(ConfigData[i].FontData); + ConfigData[i].FontData = NULL; + } + + // When clearing this we lose access to the font name and other information used to build the font. + for (int i = 0; i < Fonts.Size; i++) + if (Fonts[i]->ConfigData >= ConfigData.Data && Fonts[i]->ConfigData < ConfigData.Data + ConfigData.Size) + { + Fonts[i]->ConfigData = NULL; + Fonts[i]->ConfigDataCount = 0; + } + ConfigData.clear(); + CustomRects.clear(); + for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++) + CustomRectIds[n] = -1; +} + +void ImFontAtlas::ClearTexData() +{ + if (TexPixelsAlpha8) + ImGui::MemFree(TexPixelsAlpha8); + if (TexPixelsRGBA32) + ImGui::MemFree(TexPixelsRGBA32); + TexPixelsAlpha8 = NULL; + TexPixelsRGBA32 = NULL; +} + +void ImFontAtlas::ClearFonts() +{ + for (int i = 0; i < Fonts.Size; i++) + IM_DELETE(Fonts[i]); + Fonts.clear(); +} + +void ImFontAtlas::Clear() +{ + ClearInputData(); + ClearTexData(); + ClearFonts(); +} + +void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel) +{ + // Build atlas on demand + if (TexPixelsAlpha8 == NULL) + { + if (ConfigData.empty()) + AddFontDefault(); + Build(); + } + + *out_pixels = TexPixelsAlpha8; + if (out_width) *out_width = TexWidth; + if (out_height) *out_height = TexHeight; + if (out_bytes_per_pixel) *out_bytes_per_pixel = 1; +} + +void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel) +{ + // Convert to RGBA32 format on demand + // Although it is likely to be the most commonly used format, our font rendering is 1 channel / 8 bpp + if (!TexPixelsRGBA32) + { + unsigned char* pixels; + GetTexDataAsAlpha8(&pixels, NULL, NULL); + TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4)); + const unsigned char* src = pixels; + unsigned int* dst = TexPixelsRGBA32; + for (int n = TexWidth * TexHeight; n > 0; n--) + *dst++ = IM_COL32(255, 255, 255, (unsigned int)(*src++)); + } + + *out_pixels = (unsigned char*)TexPixelsRGBA32; + if (out_width) *out_width = TexWidth; + if (out_height) *out_height = TexHeight; + if (out_bytes_per_pixel) *out_bytes_per_pixel = 4; +} + +ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg) +{ + IM_ASSERT(font_cfg->FontData != NULL && font_cfg->FontDataSize > 0); + IM_ASSERT(font_cfg->SizePixels > 0.0f); + + // Create new font + if (!font_cfg->MergeMode) + Fonts.push_back(IM_NEW(ImFont)); + else + IM_ASSERT(!Fonts.empty()); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font. + + ConfigData.push_back(*font_cfg); + ImFontConfig& new_font_cfg = ConfigData.back(); + if (!new_font_cfg.DstFont) + new_font_cfg.DstFont = Fonts.back(); + if (!new_font_cfg.FontDataOwnedByAtlas) + { + new_font_cfg.FontData = ImGui::MemAlloc(new_font_cfg.FontDataSize); + new_font_cfg.FontDataOwnedByAtlas = true; + memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize); + } + + // Invalidate texture + ClearTexData(); + return new_font_cfg.DstFont; +} + +// Default font TTF is compressed with stb_compress then base85 encoded (see extra_fonts/binary_to_compressed_c.cpp for encoder) +static unsigned int stb_decompress_length(unsigned char *input); +static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length); +static const char* GetDefaultCompressedFontDataTTFBase85(); +static unsigned int Decode85Byte(char c) { return c >= '\\' ? c-36 : c-35; } +static void Decode85(const unsigned char* src, unsigned char* dst) +{ + while (*src) + { + unsigned int tmp = Decode85Byte(src[0]) + 85*(Decode85Byte(src[1]) + 85*(Decode85Byte(src[2]) + 85*(Decode85Byte(src[3]) + 85*Decode85Byte(src[4])))); + dst[0] = ((tmp >> 0) & 0xFF); dst[1] = ((tmp >> 8) & 0xFF); dst[2] = ((tmp >> 16) & 0xFF); dst[3] = ((tmp >> 24) & 0xFF); // We can't assume little-endianness. + src += 5; + dst += 4; + } +} + +// Load embedded ProggyClean.ttf at size 13, disable oversampling +ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template) +{ + ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); + if (!font_cfg_template) + { + font_cfg.OversampleH = font_cfg.OversampleV = 1; + font_cfg.PixelSnapH = true; + } + if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, "ProggyClean.ttf, 13px"); + if (font_cfg.SizePixels <= 0.0f) font_cfg.SizePixels = 13.0f; + + const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85(); + ImFont* font = AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_cfg.SizePixels, &font_cfg, GetGlyphRangesDefault()); + return font; +} + +ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) +{ + int data_size = 0; + void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); + if (!data) + { + IM_ASSERT(0); // Could not load file. + return NULL; + } + ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); + if (font_cfg.Name[0] == '\0') + { + // Store a short copy of filename into into the font name for convenience + const char* p; + for (p = filename + strlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {} + snprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", p, size_pixels); + } + return AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg, glyph_ranges); +} + +// NB: Transfer ownership of 'ttf_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build(). +ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) +{ + ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); + IM_ASSERT(font_cfg.FontData == NULL); + font_cfg.FontData = ttf_data; + font_cfg.FontDataSize = ttf_size; + font_cfg.SizePixels = size_pixels; + if (glyph_ranges) + font_cfg.GlyphRanges = glyph_ranges; + return AddFont(&font_cfg); +} + +ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) +{ + const unsigned int buf_decompressed_size = stb_decompress_length((unsigned char*)compressed_ttf_data); + unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size); + stb_decompress(buf_decompressed_data, (unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size); + + ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); + IM_ASSERT(font_cfg.FontData == NULL); + font_cfg.FontDataOwnedByAtlas = true; + return AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, &font_cfg, glyph_ranges); +} + +ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges) +{ + int compressed_ttf_size = (((int)strlen(compressed_ttf_data_base85) + 4) / 5) * 4; + void* compressed_ttf = ImGui::MemAlloc((size_t)compressed_ttf_size); + Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned char*)compressed_ttf); + ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges); + ImGui::MemFree(compressed_ttf); + return font; +} + +int ImFontAtlas::AddCustomRectRegular(unsigned int id, int width, int height) +{ + IM_ASSERT(id >= 0x10000); + IM_ASSERT(width > 0 && width <= 0xFFFF); + IM_ASSERT(height > 0 && height <= 0xFFFF); + CustomRect r; + r.ID = id; + r.Width = (unsigned short)width; + r.Height = (unsigned short)height; + CustomRects.push_back(r); + return CustomRects.Size - 1; // Return index +} + +int ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset) +{ + IM_ASSERT(font != NULL); + IM_ASSERT(width > 0 && width <= 0xFFFF); + IM_ASSERT(height > 0 && height <= 0xFFFF); + CustomRect r; + r.ID = id; + r.Width = (unsigned short)width; + r.Height = (unsigned short)height; + r.GlyphAdvanceX = advance_x; + r.GlyphOffset = offset; + r.Font = font; + CustomRects.push_back(r); + return CustomRects.Size - 1; // Return index +} + +void ImFontAtlas::CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) +{ + IM_ASSERT(TexWidth > 0 && TexHeight > 0); // Font atlas needs to be built before we can calculate UV coordinates + IM_ASSERT(rect->IsPacked()); // Make sure the rectangle has been packed + *out_uv_min = ImVec2((float)rect->X / TexWidth, (float)rect->Y / TexHeight); + *out_uv_max = ImVec2((float)(rect->X + rect->Width) / TexWidth, (float)(rect->Y + rect->Height) / TexHeight); +} + +bool ImFontAtlas::Build() +{ + return ImFontAtlasBuildWithStbTruetype(this); +} + +void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_brighten_factor) +{ + for (unsigned int i = 0; i < 256; i++) + { + unsigned int value = (unsigned int)(i * in_brighten_factor); + out_table[i] = value > 255 ? 255 : (value & 0xFF); + } +} + +void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride) +{ + unsigned char* data = pixels + x + y * stride; + for (int j = h; j > 0; j--, data += stride) + for (int i = 0; i < w; i++) + data[i] = table[data[i]]; +} + +bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) +{ + IM_ASSERT(atlas->ConfigData.Size > 0); + + ImFontAtlasBuildRegisterDefaultCustomRects(atlas); + + atlas->TexID = NULL; + atlas->TexWidth = atlas->TexHeight = 0; + atlas->TexUvWhitePixel = ImVec2(0, 0); + atlas->ClearTexData(); + + // Count glyphs/ranges + int total_glyphs_count = 0; + int total_ranges_count = 0; + for (int input_i = 0; input_i < atlas->ConfigData.Size; input_i++) + { + ImFontConfig& cfg = atlas->ConfigData[input_i]; + if (!cfg.GlyphRanges) + cfg.GlyphRanges = atlas->GetGlyphRangesDefault(); + for (const ImWchar* in_range = cfg.GlyphRanges; in_range[0] && in_range[1]; in_range += 2, total_ranges_count++) + total_glyphs_count += (in_range[1] - in_range[0]) + 1; + } + + // We need a width for the skyline algorithm. Using a dumb heuristic here to decide of width. User can override TexDesiredWidth and TexGlyphPadding if they wish. + // Width doesn't really matter much, but some API/GPU have texture size limitations and increasing width can decrease height. + atlas->TexWidth = (atlas->TexDesiredWidth > 0) ? atlas->TexDesiredWidth : (total_glyphs_count > 4000) ? 4096 : (total_glyphs_count > 2000) ? 2048 : (total_glyphs_count > 1000) ? 1024 : 512; + atlas->TexHeight = 0; + + // Start packing + const int max_tex_height = 1024*32; + stbtt_pack_context spc = {}; + stbtt_PackBegin(&spc, NULL, atlas->TexWidth, max_tex_height, 0, atlas->TexGlyphPadding, NULL); + stbtt_PackSetOversampling(&spc, 1, 1); + + // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values). + ImFontAtlasBuildPackCustomRects(atlas, spc.pack_info); + + // Initialize font information (so we can error without any cleanup) + struct ImFontTempBuildData + { + stbtt_fontinfo FontInfo; + stbrp_rect* Rects; + int RectsCount; + stbtt_pack_range* Ranges; + int RangesCount; + }; + ImFontTempBuildData* tmp_array = (ImFontTempBuildData*)ImGui::MemAlloc((size_t)atlas->ConfigData.Size * sizeof(ImFontTempBuildData)); + for (int input_i = 0; input_i < atlas->ConfigData.Size; input_i++) + { + ImFontConfig& cfg = atlas->ConfigData[input_i]; + ImFontTempBuildData& tmp = tmp_array[input_i]; + IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas)); + + const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)cfg.FontData, cfg.FontNo); + IM_ASSERT(font_offset >= 0); + if (!stbtt_InitFont(&tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset)) + { + ImGui::MemFree(tmp_array); + return false; + } + } + + // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0) + int buf_packedchars_n = 0, buf_rects_n = 0, buf_ranges_n = 0; + stbtt_packedchar* buf_packedchars = (stbtt_packedchar*)ImGui::MemAlloc(total_glyphs_count * sizeof(stbtt_packedchar)); + stbrp_rect* buf_rects = (stbrp_rect*)ImGui::MemAlloc(total_glyphs_count * sizeof(stbrp_rect)); + stbtt_pack_range* buf_ranges = (stbtt_pack_range*)ImGui::MemAlloc(total_ranges_count * sizeof(stbtt_pack_range)); + memset(buf_packedchars, 0, total_glyphs_count * sizeof(stbtt_packedchar)); + memset(buf_rects, 0, total_glyphs_count * sizeof(stbrp_rect)); // Unnecessary but let's clear this for the sake of sanity. + memset(buf_ranges, 0, total_ranges_count * sizeof(stbtt_pack_range)); + + // First font pass: pack all glyphs (no rendering at this point, we are working with rectangles in an infinitely tall texture at this point) + for (int input_i = 0; input_i < atlas->ConfigData.Size; input_i++) + { + ImFontConfig& cfg = atlas->ConfigData[input_i]; + ImFontTempBuildData& tmp = tmp_array[input_i]; + + // Setup ranges + int font_glyphs_count = 0; + int font_ranges_count = 0; + for (const ImWchar* in_range = cfg.GlyphRanges; in_range[0] && in_range[1]; in_range += 2, font_ranges_count++) + font_glyphs_count += (in_range[1] - in_range[0]) + 1; + tmp.Ranges = buf_ranges + buf_ranges_n; + tmp.RangesCount = font_ranges_count; + buf_ranges_n += font_ranges_count; + for (int i = 0; i < font_ranges_count; i++) + { + const ImWchar* in_range = &cfg.GlyphRanges[i * 2]; + stbtt_pack_range& range = tmp.Ranges[i]; + range.font_size = cfg.SizePixels; + range.first_unicode_codepoint_in_range = in_range[0]; + range.num_chars = (in_range[1] - in_range[0]) + 1; + range.chardata_for_range = buf_packedchars + buf_packedchars_n; + buf_packedchars_n += range.num_chars; + } + + // Pack + tmp.Rects = buf_rects + buf_rects_n; + tmp.RectsCount = font_glyphs_count; + buf_rects_n += font_glyphs_count; + stbtt_PackSetOversampling(&spc, cfg.OversampleH, cfg.OversampleV); + int n = stbtt_PackFontRangesGatherRects(&spc, &tmp.FontInfo, tmp.Ranges, tmp.RangesCount, tmp.Rects); + IM_ASSERT(n == font_glyphs_count); + stbrp_pack_rects((stbrp_context*)spc.pack_info, tmp.Rects, n); + + // Extend texture height + for (int i = 0; i < n; i++) + if (tmp.Rects[i].was_packed) + atlas->TexHeight = ImMax(atlas->TexHeight, tmp.Rects[i].y + tmp.Rects[i].h); + } + IM_ASSERT(buf_rects_n == total_glyphs_count); + IM_ASSERT(buf_packedchars_n == total_glyphs_count); + IM_ASSERT(buf_ranges_n == total_ranges_count); + + // Create texture + atlas->TexHeight = ImUpperPowerOfTwo(atlas->TexHeight); + atlas->TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(atlas->TexWidth * atlas->TexHeight); + memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight); + spc.pixels = atlas->TexPixelsAlpha8; + spc.height = atlas->TexHeight; + + // Second pass: render font characters + for (int input_i = 0; input_i < atlas->ConfigData.Size; input_i++) + { + ImFontConfig& cfg = atlas->ConfigData[input_i]; + ImFontTempBuildData& tmp = tmp_array[input_i]; + stbtt_PackSetOversampling(&spc, cfg.OversampleH, cfg.OversampleV); + stbtt_PackFontRangesRenderIntoRects(&spc, &tmp.FontInfo, tmp.Ranges, tmp.RangesCount, tmp.Rects); + if (cfg.RasterizerMultiply != 1.0f) + { + unsigned char multiply_table[256]; + ImFontAtlasBuildMultiplyCalcLookupTable(multiply_table, cfg.RasterizerMultiply); + for (const stbrp_rect* r = tmp.Rects; r != tmp.Rects + tmp.RectsCount; r++) + if (r->was_packed) + ImFontAtlasBuildMultiplyRectAlpha8(multiply_table, spc.pixels, r->x, r->y, r->w, r->h, spc.stride_in_bytes); + } + tmp.Rects = NULL; + } + + // End packing + stbtt_PackEnd(&spc); + ImGui::MemFree(buf_rects); + buf_rects = NULL; + + // Third pass: setup ImFont and glyphs for runtime + for (int input_i = 0; input_i < atlas->ConfigData.Size; input_i++) + { + ImFontConfig& cfg = atlas->ConfigData[input_i]; + ImFontTempBuildData& tmp = tmp_array[input_i]; + ImFont* dst_font = cfg.DstFont; // We can have multiple input fonts writing into a same destination font (when using MergeMode=true) + + const float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels); + int unscaled_ascent, unscaled_descent, unscaled_line_gap; + stbtt_GetFontVMetrics(&tmp.FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap); + + const float ascent = unscaled_ascent * font_scale; + const float descent = unscaled_descent * font_scale; + ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent); + const float off_x = cfg.GlyphOffset.x; + const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f); + + for (int i = 0; i < tmp.RangesCount; i++) + { + stbtt_pack_range& range = tmp.Ranges[i]; + for (int char_idx = 0; char_idx < range.num_chars; char_idx += 1) + { + const stbtt_packedchar& pc = range.chardata_for_range[char_idx]; + if (!pc.x0 && !pc.x1 && !pc.y0 && !pc.y1) + continue; + + const int codepoint = range.first_unicode_codepoint_in_range + char_idx; + if (cfg.MergeMode && dst_font->FindGlyph((unsigned short)codepoint)) + continue; + + stbtt_aligned_quad q; + float dummy_x = 0.0f, dummy_y = 0.0f; + stbtt_GetPackedQuad(range.chardata_for_range, atlas->TexWidth, atlas->TexHeight, char_idx, &dummy_x, &dummy_y, &q, 0); + dst_font->AddGlyph((ImWchar)codepoint, q.x0 + off_x, q.y0 + off_y, q.x1 + off_x, q.y1 + off_y, q.s0, q.t0, q.s1, q.t1, pc.xadvance); + } + } + } + + // Cleanup temporaries + ImGui::MemFree(buf_packedchars); + ImGui::MemFree(buf_ranges); + ImGui::MemFree(tmp_array); + + ImFontAtlasBuildFinish(atlas); + + return true; +} + +void ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas) +{ + if (atlas->CustomRectIds[0] < 0) + atlas->CustomRectIds[0] = atlas->AddCustomRectRegular(FONT_ATLAS_DEFAULT_TEX_DATA_ID, FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF*2+1, FONT_ATLAS_DEFAULT_TEX_DATA_H); +} + +void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent) +{ + if (!font_config->MergeMode) + { + font->ClearOutputData(); + font->FontSize = font_config->SizePixels; + font->ConfigData = font_config; + font->ContainerAtlas = atlas; + font->Ascent = ascent; + font->Descent = descent; + } + font->ConfigDataCount++; +} + +void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* pack_context_opaque) +{ + stbrp_context* pack_context = (stbrp_context*)pack_context_opaque; + + ImVector& user_rects = atlas->CustomRects; + IM_ASSERT(user_rects.Size >= 1); // We expect at least the default custom rects to be registered, else something went wrong. + + ImVector pack_rects; + pack_rects.resize(user_rects.Size); + memset(pack_rects.Data, 0, sizeof(stbrp_rect) * user_rects.Size); + for (int i = 0; i < user_rects.Size; i++) + { + pack_rects[i].w = user_rects[i].Width; + pack_rects[i].h = user_rects[i].Height; + } + stbrp_pack_rects(pack_context, &pack_rects[0], pack_rects.Size); + for (int i = 0; i < pack_rects.Size; i++) + if (pack_rects[i].was_packed) + { + user_rects[i].X = pack_rects[i].x; + user_rects[i].Y = pack_rects[i].y; + IM_ASSERT(pack_rects[i].w == user_rects[i].Width && pack_rects[i].h == user_rects[i].Height); + atlas->TexHeight = ImMax(atlas->TexHeight, pack_rects[i].y + pack_rects[i].h); + } +} + +static void ImFontAtlasBuildRenderDefaultTexData(ImFontAtlas* atlas) +{ + IM_ASSERT(atlas->CustomRectIds[0] >= 0); + ImFontAtlas::CustomRect& r = atlas->CustomRects[atlas->CustomRectIds[0]]; + IM_ASSERT(r.ID == FONT_ATLAS_DEFAULT_TEX_DATA_ID); + IM_ASSERT(r.Width == FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF*2+1); + IM_ASSERT(r.Height == FONT_ATLAS_DEFAULT_TEX_DATA_H); + IM_ASSERT(r.IsPacked()); + IM_ASSERT(atlas->TexPixelsAlpha8 != NULL); + + // Render/copy pixels + for (int y = 0, n = 0; y < FONT_ATLAS_DEFAULT_TEX_DATA_H; y++) + for (int x = 0; x < FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF; x++, n++) + { + const int offset0 = (int)(r.X + x) + (int)(r.Y + y) * atlas->TexWidth; + const int offset1 = offset0 + FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF + 1; + atlas->TexPixelsAlpha8[offset0] = FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS[n] == '.' ? 0xFF : 0x00; + atlas->TexPixelsAlpha8[offset1] = FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS[n] == 'X' ? 0xFF : 0x00; + } + const ImVec2 tex_uv_scale(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight); + atlas->TexUvWhitePixel = ImVec2((r.X + 0.5f) * tex_uv_scale.x, (r.Y + 0.5f) * tex_uv_scale.y); + + // Setup mouse cursors + for (int type = 0; type < ImGuiMouseCursor_Count_; type++) + { + ImGuiMouseCursorData& cursor_data = GImGui->MouseCursorData[type]; + ImVec2 pos = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[type][0] + ImVec2((float)r.X, (float)r.Y); + const ImVec2 size = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[type][1]; + cursor_data.Type = type; + cursor_data.Size = size; + cursor_data.HotOffset = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[type][2]; + cursor_data.TexUvMin[0] = (pos) * tex_uv_scale; + cursor_data.TexUvMax[0] = (pos + size) * tex_uv_scale; + pos.x += FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF + 1; + cursor_data.TexUvMin[1] = (pos) * tex_uv_scale; + cursor_data.TexUvMax[1] = (pos + size) * tex_uv_scale; + } +} + +void ImFontAtlasBuildFinish(ImFontAtlas* atlas) +{ + // Render into our custom data block + ImFontAtlasBuildRenderDefaultTexData(atlas); + + // Register custom rectangle glyphs + for (int i = 0; i < atlas->CustomRects.Size; i++) + { + const ImFontAtlas::CustomRect& r = atlas->CustomRects[i]; + if (r.Font == NULL || r.ID > 0x10000) + continue; + + IM_ASSERT(r.Font->ContainerAtlas == atlas); + ImVec2 uv0, uv1; + atlas->CalcCustomRectUV(&r, &uv0, &uv1); + r.Font->AddGlyph((ImWchar)r.ID, r.GlyphOffset.x, r.GlyphOffset.y, r.GlyphOffset.x + r.Width, r.GlyphOffset.y + r.Height, uv0.x, uv0.y, uv1.x, uv1.y, r.GlyphAdvanceX); + } + + // Build all fonts lookup tables + for (int i = 0; i < atlas->Fonts.Size; i++) + atlas->Fonts[i]->BuildLookupTable(); +} + +// Retrieve list of range (2 int per range, values are inclusive) +const ImWchar* ImFontAtlas::GetGlyphRangesDefault() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0, + }; + return &ranges[0]; +} + +const ImWchar* ImFontAtlas::GetGlyphRangesKorean() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x3131, 0x3163, // Korean alphabets + 0xAC00, 0xD79D, // Korean characters + 0, + }; + return &ranges[0]; +} + +const ImWchar* ImFontAtlas::GetGlyphRangesChinese() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana + 0x31F0, 0x31FF, // Katakana Phonetic Extensions + 0xFF00, 0xFFEF, // Half-width characters + 0x4e00, 0x9FAF, // CJK Ideograms + 0, + }; + return &ranges[0]; +} + +const ImWchar* ImFontAtlas::GetGlyphRangesJapanese() +{ + // Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1. + // This encoding is designed to helps us reduce the source code size. + // FIXME: Source a list of the revised 2136 joyo kanji list from 2010 and rebuild this. + // The current list was sourced from http://theinstructionlimit.com/author/renaudbedardrenaudbedard/page/3 + // Note that you may use ImFontAtlas::GlyphRangesBuilder to create your own ranges, by merging existing ranges or adding new characters. + static const short offsets_from_0x4E00[] = + { + -1,0,1,3,0,0,0,0,1,0,5,1,1,0,7,4,6,10,0,1,9,9,7,1,3,19,1,10,7,1,0,1,0,5,1,0,6,4,2,6,0,0,12,6,8,0,3,5,0,1,0,9,0,0,8,1,1,3,4,5,13,0,0,8,2,17, + 4,3,1,1,9,6,0,0,0,2,1,3,2,22,1,9,11,1,13,1,3,12,0,5,9,2,0,6,12,5,3,12,4,1,2,16,1,1,4,6,5,3,0,6,13,15,5,12,8,14,0,0,6,15,3,6,0,18,8,1,6,14,1, + 5,4,12,24,3,13,12,10,24,0,0,0,1,0,1,1,2,9,10,2,2,0,0,3,3,1,0,3,8,0,3,2,4,4,1,6,11,10,14,6,15,3,4,15,1,0,0,5,2,2,0,0,1,6,5,5,6,0,3,6,5,0,0,1,0, + 11,2,2,8,4,7,0,10,0,1,2,17,19,3,0,2,5,0,6,2,4,4,6,1,1,11,2,0,3,1,2,1,2,10,7,6,3,16,0,8,24,0,0,3,1,1,3,0,1,6,0,0,0,2,0,1,5,15,0,1,0,0,2,11,19, + 1,4,19,7,6,5,1,0,0,0,0,5,1,0,1,9,0,0,5,0,2,0,1,0,3,0,11,3,0,2,0,0,0,0,0,9,3,6,4,12,0,14,0,0,29,10,8,0,14,37,13,0,31,16,19,0,8,30,1,20,8,3,48, + 21,1,0,12,0,10,44,34,42,54,11,18,82,0,2,1,2,12,1,0,6,2,17,2,12,7,0,7,17,4,2,6,24,23,8,23,39,2,16,23,1,0,5,1,2,15,14,5,6,2,11,0,8,6,2,2,2,14, + 20,4,15,3,4,11,10,10,2,5,2,1,30,2,1,0,0,22,5,5,0,3,1,5,4,1,0,0,2,2,21,1,5,1,2,16,2,1,3,4,0,8,4,0,0,5,14,11,2,16,1,13,1,7,0,22,15,3,1,22,7,14, + 22,19,11,24,18,46,10,20,64,45,3,2,0,4,5,0,1,4,25,1,0,0,2,10,0,0,0,1,0,1,2,0,0,9,1,2,0,0,0,2,5,2,1,1,5,5,8,1,1,1,5,1,4,9,1,3,0,1,0,1,1,2,0,0, + 2,0,1,8,22,8,1,0,0,0,0,4,2,1,0,9,8,5,0,9,1,30,24,2,6,4,39,0,14,5,16,6,26,179,0,2,1,1,0,0,0,5,2,9,6,0,2,5,16,7,5,1,1,0,2,4,4,7,15,13,14,0,0, + 3,0,1,0,0,0,2,1,6,4,5,1,4,9,0,3,1,8,0,0,10,5,0,43,0,2,6,8,4,0,2,0,0,9,6,0,9,3,1,6,20,14,6,1,4,0,7,2,3,0,2,0,5,0,3,1,0,3,9,7,0,3,4,0,4,9,1,6,0, + 9,0,0,2,3,10,9,28,3,6,2,4,1,2,32,4,1,18,2,0,3,1,5,30,10,0,2,2,2,0,7,9,8,11,10,11,7,2,13,7,5,10,0,3,40,2,0,1,6,12,0,4,5,1,5,11,11,21,4,8,3,7, + 8,8,33,5,23,0,0,19,8,8,2,3,0,6,1,1,1,5,1,27,4,2,5,0,3,5,6,3,1,0,3,1,12,5,3,3,2,0,7,7,2,1,0,4,0,1,1,2,0,10,10,6,2,5,9,7,5,15,15,21,6,11,5,20, + 4,3,5,5,2,5,0,2,1,0,1,7,28,0,9,0,5,12,5,5,18,30,0,12,3,3,21,16,25,32,9,3,14,11,24,5,66,9,1,2,0,5,9,1,5,1,8,0,8,3,3,0,1,15,1,4,8,1,2,7,0,7,2, + 8,3,7,5,3,7,10,2,1,0,0,2,25,0,6,4,0,10,0,4,2,4,1,12,5,38,4,0,4,1,10,5,9,4,0,14,4,2,5,18,20,21,1,3,0,5,0,7,0,3,7,1,3,1,1,8,1,0,0,0,3,2,5,2,11, + 6,0,13,1,3,9,1,12,0,16,6,2,1,0,2,1,12,6,13,11,2,0,28,1,7,8,14,13,8,13,0,2,0,5,4,8,10,2,37,42,19,6,6,7,4,14,11,18,14,80,7,6,0,4,72,12,36,27, + 7,7,0,14,17,19,164,27,0,5,10,7,3,13,6,14,0,2,2,5,3,0,6,13,0,0,10,29,0,4,0,3,13,0,3,1,6,51,1,5,28,2,0,8,0,20,2,4,0,25,2,10,13,10,0,16,4,0,1,0, + 2,1,7,0,1,8,11,0,0,1,2,7,2,23,11,6,6,4,16,2,2,2,0,22,9,3,3,5,2,0,15,16,21,2,9,20,15,15,5,3,9,1,0,0,1,7,7,5,4,2,2,2,38,24,14,0,0,15,5,6,24,14, + 5,5,11,0,21,12,0,3,8,4,11,1,8,0,11,27,7,2,4,9,21,59,0,1,39,3,60,62,3,0,12,11,0,3,30,11,0,13,88,4,15,5,28,13,1,4,48,17,17,4,28,32,46,0,16,0, + 18,11,1,8,6,38,11,2,6,11,38,2,0,45,3,11,2,7,8,4,30,14,17,2,1,1,65,18,12,16,4,2,45,123,12,56,33,1,4,3,4,7,0,0,0,3,2,0,16,4,2,4,2,0,7,4,5,2,26, + 2,25,6,11,6,1,16,2,6,17,77,15,3,35,0,1,0,5,1,0,38,16,6,3,12,3,3,3,0,9,3,1,3,5,2,9,0,18,0,25,1,3,32,1,72,46,6,2,7,1,3,14,17,0,28,1,40,13,0,20, + 15,40,6,38,24,12,43,1,1,9,0,12,6,0,6,2,4,19,3,7,1,48,0,9,5,0,5,6,9,6,10,15,2,11,19,3,9,2,0,1,10,1,27,8,1,3,6,1,14,0,26,0,27,16,3,4,9,6,2,23, + 9,10,5,25,2,1,6,1,1,48,15,9,15,14,3,4,26,60,29,13,37,21,1,6,4,0,2,11,22,23,16,16,2,2,1,3,0,5,1,6,4,0,0,4,0,0,8,3,0,2,5,0,7,1,7,3,13,2,4,10, + 3,0,2,31,0,18,3,0,12,10,4,1,0,7,5,7,0,5,4,12,2,22,10,4,2,15,2,8,9,0,23,2,197,51,3,1,1,4,13,4,3,21,4,19,3,10,5,40,0,4,1,1,10,4,1,27,34,7,21, + 2,17,2,9,6,4,2,3,0,4,2,7,8,2,5,1,15,21,3,4,4,2,2,17,22,1,5,22,4,26,7,0,32,1,11,42,15,4,1,2,5,0,19,3,1,8,6,0,10,1,9,2,13,30,8,2,24,17,19,1,4, + 4,25,13,0,10,16,11,39,18,8,5,30,82,1,6,8,18,77,11,13,20,75,11,112,78,33,3,0,0,60,17,84,9,1,1,12,30,10,49,5,32,158,178,5,5,6,3,3,1,3,1,4,7,6, + 19,31,21,0,2,9,5,6,27,4,9,8,1,76,18,12,1,4,0,3,3,6,3,12,2,8,30,16,2,25,1,5,5,4,3,0,6,10,2,3,1,0,5,1,19,3,0,8,1,5,2,6,0,0,0,19,1,2,0,5,1,2,5, + 1,3,7,0,4,12,7,3,10,22,0,9,5,1,0,2,20,1,1,3,23,30,3,9,9,1,4,191,14,3,15,6,8,50,0,1,0,0,4,0,0,1,0,2,4,2,0,2,3,0,2,0,2,2,8,7,0,1,1,1,3,3,17,11, + 91,1,9,3,2,13,4,24,15,41,3,13,3,1,20,4,125,29,30,1,0,4,12,2,21,4,5,5,19,11,0,13,11,86,2,18,0,7,1,8,8,2,2,22,1,2,6,5,2,0,1,2,8,0,2,0,5,2,1,0, + 2,10,2,0,5,9,2,1,2,0,1,0,4,0,0,10,2,5,3,0,6,1,0,1,4,4,33,3,13,17,3,18,6,4,7,1,5,78,0,4,1,13,7,1,8,1,0,35,27,15,3,0,0,0,1,11,5,41,38,15,22,6, + 14,14,2,1,11,6,20,63,5,8,27,7,11,2,2,40,58,23,50,54,56,293,8,8,1,5,1,14,0,1,12,37,89,8,8,8,2,10,6,0,0,0,4,5,2,1,0,1,1,2,7,0,3,3,0,4,6,0,3,2, + 19,3,8,0,0,0,4,4,16,0,4,1,5,1,3,0,3,4,6,2,17,10,10,31,6,4,3,6,10,126,7,3,2,2,0,9,0,0,5,20,13,0,15,0,6,0,2,5,8,64,50,3,2,12,2,9,0,0,11,8,20, + 109,2,18,23,0,0,9,61,3,0,28,41,77,27,19,17,81,5,2,14,5,83,57,252,14,154,263,14,20,8,13,6,57,39,38, + }; + static ImWchar base_ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana + 0x31F0, 0x31FF, // Katakana Phonetic Extensions + 0xFF00, 0xFFEF, // Half-width characters + }; + static bool full_ranges_unpacked = false; + static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1]; + if (!full_ranges_unpacked) + { + // Unpack + int codepoint = 0x4e00; + memcpy(full_ranges, base_ranges, sizeof(base_ranges)); + ImWchar* dst = full_ranges + IM_ARRAYSIZE(base_ranges);; + for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2) + dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1)); + dst[0] = 0; + full_ranges_unpacked = true; + } + return &full_ranges[0]; +} + +const ImWchar* ImFontAtlas::GetGlyphRangesCyrillic() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x0400, 0x052F, // Cyrillic + Cyrillic Supplement + 0x2DE0, 0x2DFF, // Cyrillic Extended-A + 0xA640, 0xA69F, // Cyrillic Extended-B + 0, + }; + return &ranges[0]; +} + +const ImWchar* ImFontAtlas::GetGlyphRangesThai() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + 0x2010, 0x205E, // Punctuations + 0x0E00, 0x0E7F, // Thai + 0, + }; + return &ranges[0]; +} + +//----------------------------------------------------------------------------- +// ImFontAtlas::GlyphRangesBuilder +//----------------------------------------------------------------------------- + +void ImFontAtlas::GlyphRangesBuilder::AddText(const char* text, const char* text_end) +{ + while (text_end ? (text < text_end) : *text) + { + unsigned int c = 0; + int c_len = ImTextCharFromUtf8(&c, text, text_end); + text += c_len; + if (c_len == 0) + break; + if (c < 0x10000) + AddChar((ImWchar)c); + } +} + +void ImFontAtlas::GlyphRangesBuilder::AddRanges(const ImWchar* ranges) +{ + for (; ranges[0]; ranges += 2) + for (ImWchar c = ranges[0]; c <= ranges[1]; c++) + AddChar(c); +} + +void ImFontAtlas::GlyphRangesBuilder::BuildRanges(ImVector* out_ranges) +{ + for (int n = 0; n < 0x10000; n++) + if (GetBit(n)) + { + out_ranges->push_back((ImWchar)n); + while (n < 0x10000 && GetBit(n + 1)) + n++; + out_ranges->push_back((ImWchar)n); + } + out_ranges->push_back(0); +} + +//----------------------------------------------------------------------------- +// ImFont +//----------------------------------------------------------------------------- + +ImFont::ImFont() +{ + Scale = 1.0f; + FallbackChar = (ImWchar)'?'; + DisplayOffset = ImVec2(0.0f, 1.0f); + ClearOutputData(); +} + +ImFont::~ImFont() +{ + // Invalidate active font so that the user gets a clear crash instead of a dangling pointer. + // If you want to delete fonts you need to do it between Render() and NewFrame(). + // FIXME-CLEANUP + /* + ImGuiContext& g = *GImGui; + if (g.Font == this) + g.Font = NULL; + */ + ClearOutputData(); +} + +void ImFont::ClearOutputData() +{ + FontSize = 0.0f; + Glyphs.clear(); + IndexAdvanceX.clear(); + IndexLookup.clear(); + FallbackGlyph = NULL; + FallbackAdvanceX = 0.0f; + ConfigDataCount = 0; + ConfigData = NULL; + ContainerAtlas = NULL; + Ascent = Descent = 0.0f; + MetricsTotalSurface = 0; +} + +void ImFont::BuildLookupTable() +{ + int max_codepoint = 0; + for (int i = 0; i != Glyphs.Size; i++) + max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint); + + IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved + IndexAdvanceX.clear(); + IndexLookup.clear(); + GrowIndex(max_codepoint + 1); + for (int i = 0; i < Glyphs.Size; i++) + { + int codepoint = (int)Glyphs[i].Codepoint; + IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX; + IndexLookup[codepoint] = (unsigned short)i; + } + + // Create a glyph to handle TAB + // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?) + if (FindGlyph((unsigned short)' ')) + { + if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times + Glyphs.resize(Glyphs.Size + 1); + ImFontGlyph& tab_glyph = Glyphs.back(); + tab_glyph = *FindGlyph((unsigned short)' '); + tab_glyph.Codepoint = '\t'; + tab_glyph.AdvanceX *= 4; + IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX; + IndexLookup[(int)tab_glyph.Codepoint] = (unsigned short)(Glyphs.Size-1); + } + + FallbackGlyph = NULL; + FallbackGlyph = FindGlyph(FallbackChar); + FallbackAdvanceX = FallbackGlyph ? FallbackGlyph->AdvanceX : 0.0f; + for (int i = 0; i < max_codepoint + 1; i++) + if (IndexAdvanceX[i] < 0.0f) + IndexAdvanceX[i] = FallbackAdvanceX; +} + +void ImFont::SetFallbackChar(ImWchar c) +{ + FallbackChar = c; + BuildLookupTable(); +} + +void ImFont::GrowIndex(int new_size) +{ + IM_ASSERT(IndexAdvanceX.Size == IndexLookup.Size); + if (new_size <= IndexLookup.Size) + return; + IndexAdvanceX.resize(new_size, -1.0f); + IndexLookup.resize(new_size, (unsigned short)-1); +} + +void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x) +{ + Glyphs.resize(Glyphs.Size + 1); + ImFontGlyph& glyph = Glyphs.back(); + glyph.Codepoint = (ImWchar)codepoint; + glyph.X0 = x0; + glyph.Y0 = y0; + glyph.X1 = x1; + glyph.Y1 = y1; + glyph.U0 = u0; + glyph.V0 = v0; + glyph.U1 = u1; + glyph.V1 = v1; + glyph.AdvanceX = advance_x + ConfigData->GlyphExtraSpacing.x; // Bake spacing into AdvanceX + + if (ConfigData->PixelSnapH) + glyph.AdvanceX = (float)(int)(glyph.AdvanceX + 0.5f); + + // Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round) + MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + 1.99f) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + 1.99f); +} + +void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst) +{ + IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function. + int index_size = IndexLookup.Size; + + if (dst < index_size && IndexLookup.Data[dst] == (unsigned short)-1 && !overwrite_dst) // 'dst' already exists + return; + if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op + return; + + GrowIndex(dst + 1); + IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (unsigned short)-1; + IndexAdvanceX[dst] = (src < index_size) ? IndexAdvanceX.Data[src] : 1.0f; +} + +const ImFontGlyph* ImFont::FindGlyph(ImWchar c) const +{ + if (c < IndexLookup.Size) + { + const unsigned short i = IndexLookup[c]; + if (i != (unsigned short)-1) + return &Glyphs.Data[i]; + } + return FallbackGlyph; +} + +const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const +{ + // Simple word-wrapping for English, not full-featured. Please submit failing cases! + // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.) + + // For references, possible wrap point marked with ^ + // "aaa bbb, ccc,ddd. eee fff. ggg!" + // ^ ^ ^ ^ ^__ ^ ^ + + // List of hardcoded separators: .,;!?'" + + // Skip extra blanks after a line returns (that includes not counting them in width computation) + // e.g. "Hello world" --> "Hello" "World" + + // Cut words that cannot possibly fit within one line. + // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish" + + float line_width = 0.0f; + float word_width = 0.0f; + float blank_width = 0.0f; + wrap_width /= scale; // We work with unscaled widths to avoid scaling every characters + + const char* word_end = text; + const char* prev_word_end = NULL; + bool inside_word = true; + + const char* s = text; + while (s < text_end) + { + unsigned int c = (unsigned int)*s; + const char* next_s; + if (c < 0x80) + next_s = s + 1; + else + next_s = s + ImTextCharFromUtf8(&c, s, text_end); + if (c == 0) + break; + + if (c < 32) + { + if (c == '\n') + { + line_width = word_width = blank_width = 0.0f; + inside_word = true; + s = next_s; + continue; + } + if (c == '\r') + { + s = next_s; + continue; + } + } + + const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX[(int)c] : FallbackAdvanceX); + if (ImCharIsSpace(c)) + { + if (inside_word) + { + line_width += blank_width; + blank_width = 0.0f; + word_end = s; + } + blank_width += char_width; + inside_word = false; + } + else + { + word_width += char_width; + if (inside_word) + { + word_end = next_s; + } + else + { + prev_word_end = word_end; + line_width += word_width + blank_width; + word_width = blank_width = 0.0f; + } + + // Allow wrapping after punctuation. + inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"'); + } + + // We ignore blank width at the end of the line (they can be skipped) + if (line_width + word_width >= wrap_width) + { + // Words that cannot possibly fit within an entire line will be cut anywhere. + if (word_width < wrap_width) + s = prev_word_end ? prev_word_end : word_end; + break; + } + + s = next_s; + } + + return s; +} + +ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const +{ + if (!text_end) + text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this. + + const float line_height = size; + const float scale = size / FontSize; + + ImVec2 text_size = ImVec2(0,0); + float line_width = 0.0f; + + const bool word_wrap_enabled = (wrap_width > 0.0f); + const char* word_wrap_eol = NULL; + + const char* s = text_begin; + while (s < text_end) + { + if (word_wrap_enabled) + { + // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. + if (!word_wrap_eol) + { + word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width); + if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. + word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below + } + + if (s >= word_wrap_eol) + { + if (text_size.x < line_width) + text_size.x = line_width; + text_size.y += line_height; + line_width = 0.0f; + word_wrap_eol = NULL; + + // Wrapping skips upcoming blanks + while (s < text_end) + { + const char c = *s; + if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; } + } + continue; + } + } + + // Decode and advance source + const char* prev_s = s; + unsigned int c = (unsigned int)*s; + if (c < 0x80) + { + s += 1; + } + else + { + s += ImTextCharFromUtf8(&c, s, text_end); + if (c == 0) // Malformed UTF-8? + break; + } + + if (c < 32) + { + if (c == '\n') + { + text_size.x = ImMax(text_size.x, line_width); + text_size.y += line_height; + line_width = 0.0f; + continue; + } + if (c == '\r') + continue; + } + + const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX[(int)c] : FallbackAdvanceX) * scale; + if (line_width + char_width >= max_width) + { + s = prev_s; + break; + } + + line_width += char_width; + } + + if (text_size.x < line_width) + text_size.x = line_width; + + if (line_width > 0 || text_size.y == 0.0f) + text_size.y += line_height; + + if (remaining) + *remaining = s; + + return text_size; +} + +void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, unsigned short c) const +{ + if (c == ' ' || c == '\t' || c == '\n' || c == '\r') // Match behavior of RenderText(), those 4 codepoints are hard-coded. + return; + if (const ImFontGlyph* glyph = FindGlyph(c)) + { + float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f; + pos.x = (float)(int)pos.x + DisplayOffset.x; + pos.y = (float)(int)pos.y + DisplayOffset.y; + draw_list->PrimReserve(6, 4); + draw_list->PrimRectUV(ImVec2(pos.x + glyph->X0 * scale, pos.y + glyph->Y0 * scale), ImVec2(pos.x + glyph->X1 * scale, pos.y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col); + } +} + +void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const +{ + if (!text_end) + text_end = text_begin + strlen(text_begin); // ImGui functions generally already provides a valid text_end, so this is merely to handle direct calls. + + // Align to be pixel perfect + pos.x = (float)(int)pos.x + DisplayOffset.x; + pos.y = (float)(int)pos.y + DisplayOffset.y; + float x = pos.x; + float y = pos.y; + if (y > clip_rect.w) + return; + + const float scale = size / FontSize; + const float line_height = FontSize * scale; + const bool word_wrap_enabled = (wrap_width > 0.0f); + const char* word_wrap_eol = NULL; + + // Skip non-visible lines + const char* s = text_begin; + if (!word_wrap_enabled && y + line_height < clip_rect.y) + while (s < text_end && *s != '\n') // Fast-forward to next line + s++; + + // Reserve vertices for remaining worse case (over-reserving is useful and easily amortized) + const int vtx_count_max = (int)(text_end - s) * 4; + const int idx_count_max = (int)(text_end - s) * 6; + const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max; + draw_list->PrimReserve(idx_count_max, vtx_count_max); + + ImDrawVert* vtx_write = draw_list->_VtxWritePtr; + ImDrawIdx* idx_write = draw_list->_IdxWritePtr; + unsigned int vtx_current_idx = draw_list->_VtxCurrentIdx; + + while (s < text_end) + { + if (word_wrap_enabled) + { + // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. + if (!word_wrap_eol) + { + word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x)); + if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. + word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below + } + + if (s >= word_wrap_eol) + { + x = pos.x; + y += line_height; + word_wrap_eol = NULL; + + // Wrapping skips upcoming blanks + while (s < text_end) + { + const char c = *s; + if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; } + } + continue; + } + } + + // Decode and advance source + unsigned int c = (unsigned int)*s; + if (c < 0x80) + { + s += 1; + } + else + { + s += ImTextCharFromUtf8(&c, s, text_end); + if (c == 0) // Malformed UTF-8? + break; + } + + if (c < 32) + { + if (c == '\n') + { + x = pos.x; + y += line_height; + + if (y > clip_rect.w) + break; + if (!word_wrap_enabled && y + line_height < clip_rect.y) + while (s < text_end && *s != '\n') // Fast-forward to next line + s++; + continue; + } + if (c == '\r') + continue; + } + + float char_width = 0.0f; + if (const ImFontGlyph* glyph = FindGlyph((unsigned short)c)) + { + char_width = glyph->AdvanceX * scale; + + // Arbitrarily assume that both space and tabs are empty glyphs as an optimization + if (c != ' ' && c != '\t') + { + // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w + float x1 = x + glyph->X0 * scale; + float x2 = x + glyph->X1 * scale; + float y1 = y + glyph->Y0 * scale; + float y2 = y + glyph->Y1 * scale; + if (x1 <= clip_rect.z && x2 >= clip_rect.x) + { + // Render a character + float u1 = glyph->U0; + float v1 = glyph->V0; + float u2 = glyph->U1; + float v2 = glyph->V1; + + // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads. + if (cpu_fine_clip) + { + if (x1 < clip_rect.x) + { + u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1); + x1 = clip_rect.x; + } + if (y1 < clip_rect.y) + { + v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1); + y1 = clip_rect.y; + } + if (x2 > clip_rect.z) + { + u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1); + x2 = clip_rect.z; + } + if (y2 > clip_rect.w) + { + v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1); + y2 = clip_rect.w; + } + if (y1 >= y2) + { + x += char_width; + continue; + } + } + + // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here: + { + idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2); + idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3); + vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1; + vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1; + vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2; + vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2; + vtx_write += 4; + vtx_current_idx += 4; + idx_write += 6; + } + } + } + } + + x += char_width; + } + + // Give back unused vertices + draw_list->VtxBuffer.resize((int)(vtx_write - draw_list->VtxBuffer.Data)); + draw_list->IdxBuffer.resize((int)(idx_write - draw_list->IdxBuffer.Data)); + draw_list->CmdBuffer[draw_list->CmdBuffer.Size-1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size); + draw_list->_VtxWritePtr = vtx_write; + draw_list->_IdxWritePtr = idx_write; + draw_list->_VtxCurrentIdx = (unsigned int)draw_list->VtxBuffer.Size; +} + +//----------------------------------------------------------------------------- +// Internals Drawing Helpers +//----------------------------------------------------------------------------- + +static inline float ImAcos01(float x) +{ + if (x <= 0.0f) return IM_PI * 0.5f; + if (x >= 1.0f) return 0.0f; + return acosf(x); + //return (-0.69813170079773212f * x * x - 0.87266462599716477f) * x + 1.5707963267948966f; // Cheap approximation, may be enough for what we do. +} + +// FIXME: Cleanup and move code to ImDrawList. +void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding) +{ + if (x_end_norm == x_start_norm) + return; + if (x_start_norm > x_end_norm) + ImSwap(x_start_norm, x_end_norm); + + ImVec2 p0 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_start_norm), rect.Min.y); + ImVec2 p1 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_end_norm), rect.Max.y); + if (rounding == 0.0f) + { + draw_list->AddRectFilled(p0, p1, col, 0.0f); + return; + } + + rounding = ImClamp(ImMin((rect.Max.x - rect.Min.x) * 0.5f, (rect.Max.y - rect.Min.y) * 0.5f) - 1.0f, 0.0f, rounding); + const float inv_rounding = 1.0f / rounding; + const float arc0_b = ImAcos01(1.0f - (p0.x - rect.Min.x) * inv_rounding); + const float arc0_e = ImAcos01(1.0f - (p1.x - rect.Min.x) * inv_rounding); + const float x0 = ImMax(p0.x, rect.Min.x + rounding); + if (arc0_b == arc0_e) + { + draw_list->PathLineTo(ImVec2(x0, p1.y)); + draw_list->PathLineTo(ImVec2(x0, p0.y)); + } + else if (arc0_b == 0.0f && arc0_e == IM_PI*0.5f) + { + draw_list->PathArcToFast(ImVec2(x0, p1.y - rounding), rounding, 3, 6); // BL + draw_list->PathArcToFast(ImVec2(x0, p0.y + rounding), rounding, 6, 9); // TR + } + else + { + draw_list->PathArcTo(ImVec2(x0, p1.y - rounding), rounding, IM_PI - arc0_e, IM_PI - arc0_b, 3); // BL + draw_list->PathArcTo(ImVec2(x0, p0.y + rounding), rounding, IM_PI + arc0_b, IM_PI + arc0_e, 3); // TR + } + if (p1.x > rect.Min.x + rounding) + { + const float arc1_b = ImAcos01(1.0f - (rect.Max.x - p1.x) * inv_rounding); + const float arc1_e = ImAcos01(1.0f - (rect.Max.x - p0.x) * inv_rounding); + const float x1 = ImMin(p1.x, rect.Max.x - rounding); + if (arc1_b == arc1_e) + { + draw_list->PathLineTo(ImVec2(x1, p0.y)); + draw_list->PathLineTo(ImVec2(x1, p1.y)); + } + else if (arc1_b == 0.0f && arc1_e == IM_PI*0.5f) + { + draw_list->PathArcToFast(ImVec2(x1, p0.y + rounding), rounding, 9, 12); // TR + draw_list->PathArcToFast(ImVec2(x1, p1.y - rounding), rounding, 0, 3); // BR + } + else + { + draw_list->PathArcTo(ImVec2(x1, p0.y + rounding), rounding, -arc1_e, -arc1_b, 3); // TR + draw_list->PathArcTo(ImVec2(x1, p1.y - rounding), rounding, +arc1_b, +arc1_e, 3); // BR + } + } + draw_list->PathFillConvex(col); +} + +//----------------------------------------------------------------------------- +// DEFAULT FONT DATA +//----------------------------------------------------------------------------- +// Compressed with stb_compress() then converted to a C array. +// Use the program in extra_fonts/binary_to_compressed_c.cpp to create the array from a TTF file. +// Decompression from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h +//----------------------------------------------------------------------------- + +static unsigned int stb_decompress_length(unsigned char *input) +{ + return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11]; +} + +static unsigned char *stb__barrier, *stb__barrier2, *stb__barrier3, *stb__barrier4; +static unsigned char *stb__dout; +static void stb__match(unsigned char *data, unsigned int length) +{ + // INVERSE of memmove... write each byte before copying the next... + IM_ASSERT (stb__dout + length <= stb__barrier); + if (stb__dout + length > stb__barrier) { stb__dout += length; return; } + if (data < stb__barrier4) { stb__dout = stb__barrier+1; return; } + while (length--) *stb__dout++ = *data++; +} + +static void stb__lit(unsigned char *data, unsigned int length) +{ + IM_ASSERT (stb__dout + length <= stb__barrier); + if (stb__dout + length > stb__barrier) { stb__dout += length; return; } + if (data < stb__barrier2) { stb__dout = stb__barrier+1; return; } + memcpy(stb__dout, data, length); + stb__dout += length; +} + +#define stb__in2(x) ((i[x] << 8) + i[(x)+1]) +#define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1)) +#define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1)) + +static unsigned char *stb_decompress_token(unsigned char *i) +{ + if (*i >= 0x20) { // use fewer if's for cases that expand small + if (*i >= 0x80) stb__match(stb__dout-i[1]-1, i[0] - 0x80 + 1), i += 2; + else if (*i >= 0x40) stb__match(stb__dout-(stb__in2(0) - 0x4000 + 1), i[2]+1), i += 3; + else /* *i >= 0x20 */ stb__lit(i+1, i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1); + } else { // more ifs for cases that expand large, since overhead is amortized + if (*i >= 0x18) stb__match(stb__dout-(stb__in3(0) - 0x180000 + 1), i[3]+1), i += 4; + else if (*i >= 0x10) stb__match(stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5; + else if (*i >= 0x08) stb__lit(i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1); + else if (*i == 0x07) stb__lit(i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1); + else if (*i == 0x06) stb__match(stb__dout-(stb__in3(1)+1), i[4]+1), i += 5; + else if (*i == 0x04) stb__match(stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6; + } + return i; +} + +static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen) +{ + const unsigned long ADLER_MOD = 65521; + unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16; + unsigned long blocklen, i; + + blocklen = buflen % 5552; + while (buflen) { + for (i=0; i + 7 < blocklen; i += 8) { + s1 += buffer[0], s2 += s1; + s1 += buffer[1], s2 += s1; + s1 += buffer[2], s2 += s1; + s1 += buffer[3], s2 += s1; + s1 += buffer[4], s2 += s1; + s1 += buffer[5], s2 += s1; + s1 += buffer[6], s2 += s1; + s1 += buffer[7], s2 += s1; + + buffer += 8; + } + + for (; i < blocklen; ++i) + s1 += *buffer++, s2 += s1; + + s1 %= ADLER_MOD, s2 %= ADLER_MOD; + buflen -= blocklen; + blocklen = 5552; + } + return (unsigned int)(s2 << 16) + (unsigned int)s1; +} + +static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length) +{ + unsigned int olen; + if (stb__in4(0) != 0x57bC0000) return 0; + if (stb__in4(4) != 0) return 0; // error! stream is > 4GB + olen = stb_decompress_length(i); + stb__barrier2 = i; + stb__barrier3 = i+length; + stb__barrier = output + olen; + stb__barrier4 = output; + i += 16; + + stb__dout = output; + for (;;) { + unsigned char *old_i = i; + i = stb_decompress_token(i); + if (i == old_i) { + if (*i == 0x05 && i[1] == 0xfa) { + IM_ASSERT(stb__dout == output + olen); + if (stb__dout != output + olen) return 0; + if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2)) + return 0; + return olen; + } else { + IM_ASSERT(0); /* NOTREACHED */ + return 0; + } + } + IM_ASSERT(stb__dout <= output + olen); + if (stb__dout > output + olen) + return 0; + } +} + +//----------------------------------------------------------------------------- +// ProggyClean.ttf +// Copyright (c) 2004, 2005 Tristan Grimmer +// MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip) +// Download and more information at http://upperbounds.net +//----------------------------------------------------------------------------- +// File: 'ProggyClean.ttf' (41208 bytes) +// Exported using binary_to_compressed_c.cpp +//----------------------------------------------------------------------------- +static const char proggy_clean_ttf_compressed_data_base85[11980+1] = + "7])#######hV0qs'/###[),##/l:$#Q6>##5[n42>c-TH`->>#/e>11NNV=Bv(*:.F?uu#(gRU.o0XGH`$vhLG1hxt9?W`#,5LsCp#-i>.r$<$6pD>Lb';9Crc6tgXmKVeU2cD4Eo3R/" + "2*>]b(MC;$jPfY.;h^`IWM9Qo#t'X#(v#Y9w0#1D$CIf;W'#pWUPXOuxXuU(H9M(1=Ke$$'5F%)]0^#0X@U.a$FBjVQTSDgEKnIS7EM9>ZY9w0#L;>>#Mx&4Mvt//L[MkA#W@lK.N'[0#7RL_&#w+F%HtG9M#XL`N&.,GM4Pg;--VsM.M0rJfLH2eTM`*oJMHRC`N" + "kfimM2J,W-jXS:)r0wK#@Fge$U>`w'N7G#$#fB#$E^$#:9:hk+eOe--6x)F7*E%?76%^GMHePW-Z5l'&GiF#$956:rS?dA#fiK:)Yr+`�j@'DbG&#^$PG.Ll+DNa&VZ>1i%h1S9u5o@YaaW$e+bROPOpxTO7Stwi1::iB1q)C_=dV26J;2,]7op$]uQr@_V7$q^%lQwtuHY]=DX,n3L#0PHDO4f9>dC@O>HBuKPpP*E,N+b3L#l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mC#;v)D#?,)4kMYD4lVu`4m`:&5niUA5@(A5BA1]PBB:xlBCC=2CDLXMCEUtiCf&0g2'tN?PGT4CPGT4CPGT4CPGT4CPGT4CPGT4CPGT4CP" + "GT4CPGT4CPGT4CPGT4CPGT4CPGT4CP-qekC`.9kEg^+F$kwViFJTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5o,^<-28ZI'O?;xp" + "O?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xp;7q-#lLYI:xvD=#"; + +static const char* GetDefaultCompressedFontDataTTFBase85() +{ + return proggy_clean_ttf_compressed_data_base85; +} diff --git a/lib/cimgui-1.53.1/imgui-1.53/imgui_internal.h b/lib/cimgui-1.53.1/imgui-1.53/imgui_internal.h new file mode 100644 index 0000000..8043539 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/imgui_internal.h @@ -0,0 +1,985 @@ +// dear imgui, v1.53 +// (internals) + +// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! +// Set: +// #define IMGUI_DEFINE_MATH_OPERATORS +// To implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators) + +#pragma once + +#ifndef IMGUI_VERSION +#error Must include imgui.h before imgui_internal.h +#endif + +#include // FILE* +#include // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf + +#ifdef _MSC_VER +#pragma warning (push) +#pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport) +#endif + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h +#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h +#pragma clang diagnostic ignored "-Wold-style-cast" +#endif + +//----------------------------------------------------------------------------- +// Forward Declarations +//----------------------------------------------------------------------------- + +struct ImRect; +struct ImGuiColMod; +struct ImGuiStyleMod; +struct ImGuiGroupData; +struct ImGuiSimpleColumns; +struct ImGuiDrawContext; +struct ImGuiTextEditState; +struct ImGuiMouseCursorData; +struct ImGuiPopupRef; +struct ImGuiWindow; +struct ImGuiWindowSettings; + +typedef int ImGuiLayoutType; // enum: horizontal or vertical // enum ImGuiLayoutType_ +typedef int ImGuiButtonFlags; // flags: for ButtonEx(), ButtonBehavior() // enum ImGuiButtonFlags_ +typedef int ImGuiItemFlags; // flags: for PushItemFlag() // enum ImGuiItemFlags_ +typedef int ImGuiSeparatorFlags; // flags: for Separator() - internal // enum ImGuiSeparatorFlags_ +typedef int ImGuiSliderFlags; // flags: for SliderBehavior() // enum ImGuiSliderFlags_ + +//------------------------------------------------------------------------- +// STB libraries +//------------------------------------------------------------------------- + +namespace ImGuiStb +{ + +#undef STB_TEXTEDIT_STRING +#undef STB_TEXTEDIT_CHARTYPE +#define STB_TEXTEDIT_STRING ImGuiTextEditState +#define STB_TEXTEDIT_CHARTYPE ImWchar +#define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f +#include "stb_textedit.h" + +} // namespace ImGuiStb + +//----------------------------------------------------------------------------- +// Context +//----------------------------------------------------------------------------- + +#ifndef GImGui +extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointer +#endif + +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- + +#define IM_PI 3.14159265358979323846f +#define IM_OFFSETOF(_TYPE,_ELM) ((size_t)&(((_TYPE*)0)->_ELM)) + +// Helpers: UTF-8 <> wchar +IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count +IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count +IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count +IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) +IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points + +// Helpers: Misc +IMGUI_API ImU32 ImHash(const void* data, int data_size, ImU32 seed = 0); // Pass data_size==0 for zero-terminated strings +IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0); +IMGUI_API FILE* ImFileOpen(const char* filename, const char* file_open_mode); +static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; } +static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } +static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } + +// Helpers: Geometry +IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); +IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); +IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); +IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); + +// Helpers: String +IMGUI_API int ImStricmp(const char* str1, const char* str2); +IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); +IMGUI_API void ImStrncpy(char* dst, const char* src, size_t count); +IMGUI_API char* ImStrdup(const char* str); +IMGUI_API char* ImStrchrRange(const char* str_begin, const char* str_end, char c); +IMGUI_API int ImStrlenW(const ImWchar* str); +IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line +IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end); +IMGUI_API int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) IM_FMTARGS(3); +IMGUI_API int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) IM_FMTLIST(3); + +// Helpers: Math +// We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined) +#ifdef IMGUI_DEFINE_MATH_OPERATORS +static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); } +static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); } +static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); } +static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); } +static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } +static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); } +static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } +static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } +static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } +static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } +static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x+rhs.x, lhs.y+rhs.y, lhs.z+rhs.z, lhs.w+rhs.w); } +static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); } +static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); } +#endif + +static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; } +static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; } +static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; } +static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; } +static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); } +static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); } +static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } +static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } +static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); } +static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } +static inline void ImSwap(int& a, int& b) { int tmp = a; a = b; b = tmp; } +static inline void ImSwap(float& a, float& b) { float tmp = a; a = b; b = tmp; } +static inline int ImLerp(int a, int b, float t) { return (int)(a + (b - a) * t); } +static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; } +static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return ImVec2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); } +static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } +static inline ImVec4 ImLerp(const ImVec4& a, const ImVec4& b, float t) { return ImVec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); } +static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; } +static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; } +static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / sqrtf(d); return fail_value; } +static inline float ImFloor(float f) { return (float)(int)f; } +static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)v.x, (float)(int)v.y); } +static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; } +static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); } +static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; } +static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } + +// We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax. +// Defining a custom placement new() with a dummy parameter allows us to bypass including which on some platforms complains when user has disabled exceptions. +struct ImNewPlacementDummy {}; +inline void* operator new(size_t, ImNewPlacementDummy, void* ptr) { return ptr; } +inline void operator delete(void*, ImNewPlacementDummy, void*) {} // This is only required so we can use the symetrical new() +#define IM_PLACEMENT_NEW(_PTR) new(ImNewPlacementDummy(), _PTR) +#define IM_NEW(_TYPE) new(ImNewPlacementDummy(), ImGui::MemAlloc(sizeof(_TYPE))) _TYPE +template void IM_DELETE(T*& p) { if (p) { p->~T(); ImGui::MemFree(p); p = NULL; } } + +//----------------------------------------------------------------------------- +// Types +//----------------------------------------------------------------------------- + +// Internal Drag and Drop payload types. String starting with '_' are reserved for Dear ImGui. +#define IMGUI_PAYLOAD_TYPE_DOCKABLE "_IMDOCK" // ImGuiWindow* // [Internal] Docking/tabs + +enum ImGuiButtonFlags_ +{ + ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat + ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // return true on click + release on same item [DEFAULT if no PressedOn* flag is set] + ImGuiButtonFlags_PressedOnClick = 1 << 2, // return true on click (default requires click+release) + ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return true on release (default requires click+release) + ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return true on double-click (default requires click+release) + ImGuiButtonFlags_FlattenChildren = 1 << 5, // allow interactions even if a child window is overlapping + ImGuiButtonFlags_AllowItemOverlap = 1 << 6, // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap() + ImGuiButtonFlags_DontClosePopups = 1 << 7, // disable automatically closing parent popup on press // [UNUSED] + ImGuiButtonFlags_Disabled = 1 << 8, // disable interactions + ImGuiButtonFlags_AlignTextBaseLine = 1 << 9, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine + ImGuiButtonFlags_NoKeyModifiers = 1 << 10, // disable interaction if a key modifier is held + ImGuiButtonFlags_NoHoldingActiveID = 1 << 11, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) + ImGuiButtonFlags_PressedOnDragDropHold = 1 << 12 // press when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers) +}; + +enum ImGuiSliderFlags_ +{ + ImGuiSliderFlags_Vertical = 1 << 0 +}; + +enum ImGuiColumnsFlags_ +{ + // Default: 0 + ImGuiColumnsFlags_NoBorder = 1 << 0, // Disable column dividers + ImGuiColumnsFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers + ImGuiColumnsFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns + ImGuiColumnsFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window + ImGuiColumnsFlags_GrowParentContentsSize= 1 << 4 // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove. +}; + +enum ImGuiSelectableFlagsPrivate_ +{ + // NB: need to be in sync with last value of ImGuiSelectableFlags_ + ImGuiSelectableFlags_Menu = 1 << 3, // -> PressedOnClick + ImGuiSelectableFlags_MenuItem = 1 << 4, // -> PressedOnRelease + ImGuiSelectableFlags_Disabled = 1 << 5, + ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 +}; + +enum ImGuiSeparatorFlags_ +{ + ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar + ImGuiSeparatorFlags_Vertical = 1 << 1 +}; + +// FIXME: this is in development, not exposed/functional as a generic feature yet. +enum ImGuiLayoutType_ +{ + ImGuiLayoutType_Vertical, + ImGuiLayoutType_Horizontal +}; + +enum ImGuiAxis +{ + ImGuiAxis_None = -1, + ImGuiAxis_X = 0, + ImGuiAxis_Y = 1 +}; + +enum ImGuiPlotType +{ + ImGuiPlotType_Lines, + ImGuiPlotType_Histogram +}; + +enum ImGuiDataType +{ + ImGuiDataType_Int, + ImGuiDataType_Float, + ImGuiDataType_Float2 +}; + +enum ImGuiDir +{ + ImGuiDir_None = -1, + ImGuiDir_Left = 0, + ImGuiDir_Right = 1, + ImGuiDir_Up = 2, + ImGuiDir_Down = 3, + ImGuiDir_Count_ +}; + +// 2D axis aligned bounding-box +// NB: we can't rely on ImVec2 math operators being available here +struct IMGUI_API ImRect +{ + ImVec2 Min; // Upper-left + ImVec2 Max; // Lower-right + + ImRect() : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX) {} + ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} + ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} + ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} + + ImVec2 GetCenter() const { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); } + ImVec2 GetSize() const { return ImVec2(Max.x-Min.x, Max.y-Min.y); } + float GetWidth() const { return Max.x-Min.x; } + float GetHeight() const { return Max.y-Min.y; } + ImVec2 GetTL() const { return Min; } // Top-left + ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right + ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left + ImVec2 GetBR() const { return Max; } // Bottom-right + bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; } + bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; } + bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; } + void Add(const ImVec2& rhs) { if (Min.x > rhs.x) Min.x = rhs.x; if (Min.y > rhs.y) Min.y = rhs.y; if (Max.x < rhs.x) Max.x = rhs.x; if (Max.y < rhs.y) Max.y = rhs.y; } + void Add(const ImRect& rhs) { if (Min.x > rhs.Min.x) Min.x = rhs.Min.x; if (Min.y > rhs.Min.y) Min.y = rhs.Min.y; if (Max.x < rhs.Max.x) Max.x = rhs.Max.x; if (Max.y < rhs.Max.y) Max.y = rhs.Max.y; } + void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; } + void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; } + void Translate(const ImVec2& v) { Min.x += v.x; Min.y += v.y; Max.x += v.x; Max.y += v.y; } + void ClipWith(const ImRect& clip) { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; } + void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; } + void FixInverted() { if (Min.x > Max.x) ImSwap(Min.x, Max.x); if (Min.y > Max.y) ImSwap(Min.y, Max.y); } + bool IsFinite() const { return Min.x != FLT_MAX; } + ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const + { + if (!on_edge && Contains(p)) + return p; + if (p.x > Max.x) p.x = Max.x; + else if (p.x < Min.x) p.x = Min.x; + if (p.y > Max.y) p.y = Max.y; + else if (p.y < Min.y) p.y = Min.y; + return p; + } +}; + +// Stacked color modifier, backup of modified data so we can restore it +struct ImGuiColMod +{ + ImGuiCol Col; + ImVec4 BackupValue; +}; + +// Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable. +struct ImGuiStyleMod +{ + ImGuiStyleVar VarIdx; + union { int BackupInt[2]; float BackupFloat[2]; }; + ImGuiStyleMod(ImGuiStyleVar idx, int v) { VarIdx = idx; BackupInt[0] = v; } + ImGuiStyleMod(ImGuiStyleVar idx, float v) { VarIdx = idx; BackupFloat[0] = v; } + ImGuiStyleMod(ImGuiStyleVar idx, ImVec2 v) { VarIdx = idx; BackupFloat[0] = v.x; BackupFloat[1] = v.y; } +}; + +// Stacked data for BeginGroup()/EndGroup() +struct ImGuiGroupData +{ + ImVec2 BackupCursorPos; + ImVec2 BackupCursorMaxPos; + float BackupIndentX; + float BackupGroupOffsetX; + float BackupCurrentLineHeight; + float BackupCurrentLineTextBaseOffset; + float BackupLogLinePosY; + bool BackupActiveIdIsAlive; + bool AdvanceCursor; +}; + +// Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper. +struct IMGUI_API ImGuiSimpleColumns +{ + int Count; + float Spacing; + float Width, NextWidth; + float Pos[8], NextWidths[8]; + + ImGuiSimpleColumns(); + void Update(int count, float spacing, bool clear); + float DeclColumns(float w0, float w1, float w2); + float CalcExtraSpace(float avail_w); +}; + +// Internal state of the currently focused/edited text input box +struct IMGUI_API ImGuiTextEditState +{ + ImGuiID Id; // widget id owning the text state + ImVector Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. + ImVector InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) + ImVector TempTextBuffer; + int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format. + int BufSizeA; // end-user buffer size + float ScrollX; + ImGuiStb::STB_TexteditState StbState; + float CursorAnim; + bool CursorFollow; + bool SelectedAllMouseLock; + + ImGuiTextEditState() { memset(this, 0, sizeof(*this)); } + void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking + void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); } + bool HasSelection() const { return StbState.select_start != StbState.select_end; } + void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; } + void SelectAll() { StbState.select_start = 0; StbState.select_end = CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; } + void OnKeyPressed(int key); +}; + +// Data saved in imgui.ini file +struct ImGuiWindowSettings +{ + char* Name; + ImGuiID Id; + ImVec2 Pos; + ImVec2 Size; + bool Collapsed; + + ImGuiWindowSettings() { Name = NULL; Id = 0; Pos = Size = ImVec2(0,0); Collapsed = false; } +}; + +struct ImGuiSettingsHandler +{ + const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']' + ImGuiID TypeHash; // == ImHash(TypeName, 0, 0) + void* (*ReadOpenFn)(ImGuiContext& ctx, const char* name); + void (*ReadLineFn)(ImGuiContext& ctx, void* entry, const char* line); + void (*WriteAllFn)(ImGuiContext& ctx, ImGuiTextBuffer* out_buf); +}; + +// Mouse cursor data (used when io.MouseDrawCursor is set) +struct ImGuiMouseCursorData +{ + ImGuiMouseCursor Type; + ImVec2 HotOffset; + ImVec2 Size; + ImVec2 TexUvMin[2]; + ImVec2 TexUvMax[2]; +}; + +// Storage for current popup stack +struct ImGuiPopupRef +{ + ImGuiID PopupId; // Set on OpenPopup() + ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() + ImGuiWindow* ParentWindow; // Set on OpenPopup() + ImGuiID ParentMenuSet; // Set on OpenPopup() + ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup + + ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; } +}; + +struct ImGuiColumnData +{ + float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) + float OffsetNormBeforeResize; + ImGuiColumnsFlags Flags; // Not exposed + ImRect ClipRect; + + ImGuiColumnData() { OffsetNorm = OffsetNormBeforeResize = 0.0f; Flags = 0; } +}; + +struct ImGuiColumnsSet +{ + ImGuiID ID; + ImGuiColumnsFlags Flags; + bool IsFirstFrame; + bool IsBeingResized; + int Current; + int Count; + float MinX, MaxX; + float StartPosY; + float StartMaxPosX; // Backup of CursorMaxPos + float CellMinY, CellMaxY; + ImVector Columns; + + ImGuiColumnsSet() { Clear(); } + void Clear() + { + ID = 0; + Flags = 0; + IsFirstFrame = false; + IsBeingResized = false; + Current = 0; + Count = 1; + MinX = MaxX = 0.0f; + StartPosY = 0.0f; + StartMaxPosX = 0.0f; + CellMinY = CellMaxY = 0.0f; + Columns.clear(); + } +}; + +struct ImDrawListSharedData +{ + ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas + ImFont* Font; // Current/default font (optional, for simplified AddText overload) + float FontSize; // Current/default font size (optional, for simplified AddText overload) + float CurveTessellationTol; + ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() + + // Const data + // FIXME: Bake rounded corners fill/borders in atlas + ImVec2 CircleVtx12[12]; + + ImDrawListSharedData(); +}; + +// Main state for ImGui +struct ImGuiContext +{ + bool Initialized; + ImGuiIO IO; + ImGuiStyle Style; + ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() + float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window. + float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height. + ImDrawListSharedData DrawListSharedData; + + float Time; + int FrameCount; + int FrameCountEnded; + int FrameCountRendered; + ImVector Windows; + ImVector WindowsSortBuffer; + ImVector CurrentWindowStack; + ImGuiStorage WindowsById; + int WindowsActiveCount; + ImGuiWindow* CurrentWindow; // Being drawn into + ImGuiWindow* NavWindow; // Nav/focused window for navigation + ImGuiWindow* HoveredWindow; // Will catch mouse inputs + ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only) + ImGuiID HoveredId; // Hovered widget + bool HoveredIdAllowOverlap; + ImGuiID HoveredIdPreviousFrame; + float HoveredIdTimer; + ImGuiID ActiveId; // Active widget + ImGuiID ActiveIdPreviousFrame; + float ActiveIdTimer; + bool ActiveIdIsAlive; // Active widget has been seen this frame + bool ActiveIdIsJustActivated; // Set at the time of activation for one frame + bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always) + ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) + ImGuiWindow* ActiveIdWindow; + ImGuiWindow* MovingWindow; // Track the child window we clicked on to move a window. + ImGuiID MovingWindowMoveId; // == MovingWindow->MoveId + ImVector ColorModifiers; // Stack for PushStyleColor()/PopStyleColor() + ImVector StyleModifiers; // Stack for PushStyleVar()/PopStyleVar() + ImVector FontStack; // Stack for PushFont()/PopFont() + ImVector OpenPopupStack; // Which popups are open (persistent) + ImVector CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame) + + // Storage for SetNexWindow** and SetNextTreeNode*** functions + ImVec2 SetNextWindowPosVal; + ImVec2 SetNextWindowPosPivot; + ImVec2 SetNextWindowSizeVal; + ImVec2 SetNextWindowContentSizeVal; + bool SetNextWindowCollapsedVal; + ImGuiCond SetNextWindowPosCond; + ImGuiCond SetNextWindowSizeCond; + ImGuiCond SetNextWindowContentSizeCond; + ImGuiCond SetNextWindowCollapsedCond; + ImRect SetNextWindowSizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true + ImGuiSizeConstraintCallback SetNextWindowSizeConstraintCallback; + void* SetNextWindowSizeConstraintCallbackUserData; + bool SetNextWindowSizeConstraint; + bool SetNextWindowFocus; + bool SetNextTreeNodeOpenVal; + ImGuiCond SetNextTreeNodeOpenCond; + + // Render + ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user + ImVector RenderDrawLists[3]; + float ModalWindowDarkeningRatio; + ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays + ImGuiMouseCursor MouseCursor; + ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_]; + + // Drag and Drop + bool DragDropActive; + ImGuiDragDropFlags DragDropSourceFlags; + int DragDropMouseButton; + ImGuiPayload DragDropPayload; + ImRect DragDropTargetRect; + ImGuiID DragDropTargetId; + float DragDropAcceptIdCurrRectSurface; + ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) + ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) + int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source + ImVector DragDropPayloadBufHeap; // We don't expose the ImVector<> directly + unsigned char DragDropPayloadBufLocal[8]; + + // Widget state + ImGuiTextEditState InputTextState; + ImFont InputTextPasswordFont; + ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. + ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets + ImVec4 ColorPickerRef; + float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings + ImVec2 DragLastMouseDelta; + float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio + float DragSpeedScaleSlow; + float DragSpeedScaleFast; + ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? + int TooltipOverrideCount; + ImVector PrivateClipboard; // If no custom clipboard handler is defined + ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor + + // Settings + float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero + ImVector SettingsWindows; // .ini settings for ImGuiWindow + ImVector SettingsHandlers; // List of .ini settings handlers + + // Logging + bool LogEnabled; + FILE* LogFile; // If != NULL log to stdout/ file + ImGuiTextBuffer* LogClipboard; // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators. + int LogStartDepth; + int LogAutoExpandMaxDepth; + + // Misc + float FramerateSecPerFrame[120]; // calculate estimate of framerate for user + int FramerateSecPerFrameIdx; + float FramerateSecPerFrameAccum; + int WantCaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags + int WantCaptureKeyboardNextFrame; + int WantTextInputNextFrame; + char TempBuffer[1024*3+1]; // temporary text buffer + + ImGuiContext() : OverlayDrawList(NULL) + { + Initialized = false; + Font = NULL; + FontSize = FontBaseSize = 0.0f; + + Time = 0.0f; + FrameCount = 0; + FrameCountEnded = FrameCountRendered = -1; + WindowsActiveCount = 0; + CurrentWindow = NULL; + NavWindow = NULL; + HoveredWindow = NULL; + HoveredRootWindow = NULL; + HoveredId = 0; + HoveredIdAllowOverlap = false; + HoveredIdPreviousFrame = 0; + HoveredIdTimer = 0.0f; + ActiveId = 0; + ActiveIdPreviousFrame = 0; + ActiveIdTimer = 0.0f; + ActiveIdIsAlive = false; + ActiveIdIsJustActivated = false; + ActiveIdAllowOverlap = false; + ActiveIdClickOffset = ImVec2(-1,-1); + ActiveIdWindow = NULL; + MovingWindow = NULL; + MovingWindowMoveId = 0; + + SetNextWindowPosVal = ImVec2(0.0f, 0.0f); + SetNextWindowSizeVal = ImVec2(0.0f, 0.0f); + SetNextWindowCollapsedVal = false; + SetNextWindowPosCond = 0; + SetNextWindowSizeCond = 0; + SetNextWindowContentSizeCond = 0; + SetNextWindowCollapsedCond = 0; + SetNextWindowSizeConstraintRect = ImRect(); + SetNextWindowSizeConstraintCallback = NULL; + SetNextWindowSizeConstraintCallbackUserData = NULL; + SetNextWindowSizeConstraint = false; + SetNextWindowFocus = false; + SetNextTreeNodeOpenVal = false; + SetNextTreeNodeOpenCond = 0; + + DragDropActive = false; + DragDropSourceFlags = 0; + DragDropMouseButton = -1; + DragDropTargetId = 0; + DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; + DragDropAcceptFrameCount = -1; + memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal)); + + ScalarAsInputTextId = 0; + ColorEditOptions = ImGuiColorEditFlags__OptionsDefault; + DragCurrentValue = 0.0f; + DragLastMouseDelta = ImVec2(0.0f, 0.0f); + DragSpeedDefaultRatio = 1.0f / 100.0f; + DragSpeedScaleSlow = 1.0f / 100.0f; + DragSpeedScaleFast = 10.0f; + ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f); + TooltipOverrideCount = 0; + OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f); + + ModalWindowDarkeningRatio = 0.0f; + OverlayDrawList._Data = &DrawListSharedData; + OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging + MouseCursor = ImGuiMouseCursor_Arrow; + memset(MouseCursorData, 0, sizeof(MouseCursorData)); + + SettingsDirtyTimer = 0.0f; + + LogEnabled = false; + LogFile = NULL; + LogClipboard = NULL; + LogStartDepth = 0; + LogAutoExpandMaxDepth = 2; + + memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); + FramerateSecPerFrameIdx = 0; + FramerateSecPerFrameAccum = 0.0f; + WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1; + memset(TempBuffer, 0, sizeof(TempBuffer)); + } +}; + +// Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin(). +enum ImGuiItemFlags_ +{ + ImGuiItemFlags_AllowKeyboardFocus = 1 << 0, // true + ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. + ImGuiItemFlags_Disabled = 1 << 2, // false // FIXME-WIP: Disable interactions but doesn't affect visuals. Should be: grey out and disable interactions with widgets that affect data + view widgets (WIP) + //ImGuiItemFlags_NoNav = 1 << 3, // false + //ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false + ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window + ImGuiItemFlags_Default_ = ImGuiItemFlags_AllowKeyboardFocus +}; + +// Transient per-window data, reset at the beginning of the frame +// FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered. +struct IMGUI_API ImGuiDrawContext +{ + ImVec2 CursorPos; + ImVec2 CursorPosPrevLine; + ImVec2 CursorStartPos; + ImVec2 CursorMaxPos; // Used to implicitly calculate the size of our contents, always growing during the frame. Turned into window->SizeContents at the beginning of next frame + float CurrentLineHeight; + float CurrentLineTextBaseOffset; + float PrevLineHeight; + float PrevLineTextBaseOffset; + float LogLinePosY; + int TreeDepth; + ImGuiID LastItemId; + ImRect LastItemRect; + bool LastItemRectHoveredRect; + bool MenuBarAppending; + float MenuBarOffsetX; + ImVector ChildWindows; + ImGuiStorage* StateStorage; + ImGuiLayoutType LayoutType; + + // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings. + ImGuiItemFlags ItemFlags; // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default] + float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window + float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f] + ImVectorItemFlagsStack; + ImVector ItemWidthStack; + ImVector TextWrapPosStack; + ImVectorGroupStack; + int StackSizesBackup[6]; // Store size of various stacks for asserting + + float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) + float GroupOffsetX; + float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. + ImGuiColumnsSet* ColumnsSet; // Current columns set + + ImGuiDrawContext() + { + CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f); + CurrentLineHeight = PrevLineHeight = 0.0f; + CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; + LogLinePosY = -1.0f; + TreeDepth = 0; + LastItemId = 0; + LastItemRect = ImRect(); + LastItemRectHoveredRect = false; + MenuBarAppending = false; + MenuBarOffsetX = 0.0f; + StateStorage = NULL; + LayoutType = ImGuiLayoutType_Vertical; + ItemWidth = 0.0f; + ItemFlags = ImGuiItemFlags_Default_; + TextWrapPos = -1.0f; + memset(StackSizesBackup, 0, sizeof(StackSizesBackup)); + + IndentX = 0.0f; + GroupOffsetX = 0.0f; + ColumnsOffsetX = 0.0f; + ColumnsSet = NULL; + } +}; + +// Windows data +struct IMGUI_API ImGuiWindow +{ + char* Name; + ImGuiID ID; // == ImHash(Name) + ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ + ImVec2 PosFloat; + ImVec2 Pos; // Position rounded-up to nearest pixel + ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) + ImVec2 SizeFull; // Size when non collapsed + ImVec2 SizeFullAtLastBegin; // Copy of SizeFull at the end of Begin. This is the reference value we'll use on the next frame to decide if we need scrollbars. + ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame. Include decoration, window title, border, menu, etc. + ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize() + ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis + ImVec2 WindowPadding; // Window padding at the time of begin. + float WindowRounding; // Window rounding at the time of begin. + float WindowBorderSize; // Window border size at the time of begin. + ImGuiID MoveId; // == window->GetID("#MOVE") + ImVec2 Scroll; + ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change) + ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered + bool ScrollbarX, ScrollbarY; + ImVec2 ScrollbarSizes; + bool Active; // Set to true on Begin() + bool WasActive; + bool WriteAccessed; // Set to true when any widget access the current window + bool Collapsed; // Set when collapsing window to become only title-bar + bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) + bool Appearing; // Set during the frame where the window is appearing (or re-appearing) + bool CloseButton; // Set when the window has a close button (p_open != NULL) + int BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0. + int BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues. + int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) + ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling) + int AutoFitFramesX, AutoFitFramesY; + bool AutoFitOnlyGrows; + int AutoFitChildAxises; + ImGuiDir AutoPosLastDirection; + int HiddenFrames; + ImGuiCond SetWindowPosAllowFlags; // store condition flags for next SetWindowPos() call. + ImGuiCond SetWindowSizeAllowFlags; // store condition flags for next SetWindowSize() call. + ImGuiCond SetWindowCollapsedAllowFlags; // store condition flags for next SetWindowCollapsed() call. + ImVec2 SetWindowPosVal; // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size) + ImVec2 SetWindowPosPivot; // store window pivot for positioning. ImVec2(0,0) when positioning from top-left corner; ImVec2(0.5f,0.5f) for centering; ImVec2(1,1) for bottom right. + + ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame + ImVector IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack + ImRect ClipRect; // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2. + ImRect WindowRectClipped; // = WindowRect just after setup in Begin(). == window->Rect() for root window. + ImRect InnerRect; + int LastFrameActive; + float ItemWidthDefault; + ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items + ImGuiStorage StateStorage; + ImVector ColumnsStorage; + float FontWindowScale; // Scale multiplier per-window + ImDrawList* DrawList; + ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL. + ImGuiWindow* RootWindow; // Generally point to ourself. If we are a child window, this is pointing to the first non-child parent window. + ImGuiWindow* RootNonPopupWindow; // Generally point to ourself. Used to display TitleBgActive color and for selecting which window to use for NavWindowing + + // Navigation / Focus + int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister() + int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through) + int FocusIdxAllRequestCurrent; // Item being requested for focus + int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus + int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame) + int FocusIdxTabRequestNext; // " + +public: + ImGuiWindow(ImGuiContext* context, const char* name); + ~ImGuiWindow(); + + ImGuiID GetID(const char* str, const char* str_end = NULL); + ImGuiID GetID(const void* ptr); + ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); + ImGuiID GetIDFromRectangle(const ImRect& r_abs); + + // We don't use g.FontSize because the window may be != g.CurrentWidow. + ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); } + float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; } + float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; } + ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } + float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; } + ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); } +}; + +// Backup and restore just enough data to be able to use IsItemHovered() on item A after another B in the same window has overwritten the data. +struct ImGuiItemHoveredDataBackup +{ + ImGuiID LastItemId; + ImRect LastItemRect; + bool LastItemRectHoveredRect; + + ImGuiItemHoveredDataBackup() { Backup(); } + void Backup() { ImGuiWindow* window = GImGui->CurrentWindow; LastItemId = window->DC.LastItemId; LastItemRect = window->DC.LastItemRect; LastItemRectHoveredRect = window->DC.LastItemRectHoveredRect; } + void Restore() const { ImGuiWindow* window = GImGui->CurrentWindow; window->DC.LastItemId = LastItemId; window->DC.LastItemRect = LastItemRect; window->DC.LastItemRectHoveredRect = LastItemRectHoveredRect; } +}; + +//----------------------------------------------------------------------------- +// Internal API +// No guarantee of forward compatibility here. +//----------------------------------------------------------------------------- + +namespace ImGui +{ + // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window) + // If this ever crash because g.CurrentWindow is NULL it means that either + // - ImGui::NewFrame() has never been called, which is illegal. + // - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. + inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } + inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } + IMGUI_API ImGuiWindow* FindWindowByName(const char* name); + IMGUI_API void FocusWindow(ImGuiWindow* window); + IMGUI_API void BringWindowToFront(ImGuiWindow* window); + IMGUI_API void BringWindowToBack(ImGuiWindow* window); + IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent); + + IMGUI_API void Initialize(); + + IMGUI_API void MarkIniSettingsDirty(); + IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(ImGuiID type_id); + IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); + + IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); + IMGUI_API void ClearActiveID(); + IMGUI_API void SetHoveredID(ImGuiID id); + IMGUI_API void KeepAliveID(ImGuiID id); + + IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f); + IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f); + IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id); + IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); + IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged); + IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop = true); // Return true if focus is requested + IMGUI_API void FocusableItemUnregister(ImGuiWindow* window); + IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y); + IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x); + IMGUI_API void PushMultiItemsWidths(int components, float width_full = 0.0f); + IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); + IMGUI_API void PopItemFlag(); + + IMGUI_API void OpenPopupEx(ImGuiID id, bool reopen_existing); + IMGUI_API void ClosePopup(ImGuiID id); + IMGUI_API bool IsPopupOpen(ImGuiID id); + IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags); + IMGUI_API void BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip = true); + + IMGUI_API int CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate); + + IMGUI_API void Scrollbar(ImGuiLayoutType direction); + IMGUI_API void VerticalSeparator(); // Vertical separator, for menu bars (use current line height). not exposed because it is misleading what it doesn't have an effect on regular layout. + IMGUI_API bool SplitterBehavior(ImGuiID id, const ImRect& bb, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f); + + IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); + IMGUI_API void ClearDragDrop(); + IMGUI_API bool IsDragDropPayloadBeingAccepted(); + + // FIXME-WIP: New Columns API + IMGUI_API void BeginColumns(const char* str_id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns(). + IMGUI_API void EndColumns(); // close columns + IMGUI_API void PushColumnClipRect(int column_index = -1); + + // NB: All position are in absolute pixels coordinates (never using window coordinates internally) + // AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT. + IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); + IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); + IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL); + IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); + IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); + IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); + IMGUI_API void RenderTriangle(ImVec2 pos, ImGuiDir dir, float scale = 1.0f); + IMGUI_API void RenderBullet(ImVec2 pos); + IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col, float sz); + IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); + IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. + + IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); + IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0); + IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius); + IMGUI_API bool ArrowButton(ImGuiID id, ImGuiDir dir, ImVec2 padding, ImGuiButtonFlags flags = 0); + + IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags = 0); + IMGUI_API bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power); + IMGUI_API bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format); + + IMGUI_API bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power); + IMGUI_API bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power); + IMGUI_API bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format); + + IMGUI_API bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); + IMGUI_API bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags); + IMGUI_API bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags); + IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags); + IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision); + + IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); + IMGUI_API void ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags); + + IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); + IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging + IMGUI_API void TreePushRawID(ImGuiID id); + + IMGUI_API void PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size); + + IMGUI_API int ParseFormatPrecision(const char* fmt, int default_value); + IMGUI_API float RoundScalar(float value, int decimal_precision); + + // Shade functions + IMGUI_API void ShadeVertsLinearColorGradientKeepAlpha(ImDrawVert* vert_start, ImDrawVert* vert_end, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1); + IMGUI_API void ShadeVertsLinearAlphaGradientForLeftToRightText(ImDrawVert* vert_start, ImDrawVert* vert_end, float gradient_p0_x, float gradient_p1_x); + IMGUI_API void ShadeVertsLinearUV(ImDrawVert* vert_start, ImDrawVert* vert_end, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp); + +} // namespace ImGui + +// ImFontAtlas internals +IMGUI_API bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas); +IMGUI_API void ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas); +IMGUI_API void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent); +IMGUI_API void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* spc); +IMGUI_API void ImFontAtlasBuildFinish(ImFontAtlas* atlas); +IMGUI_API void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_multiply_factor); +IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride); + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#ifdef _MSC_VER +#pragma warning (pop) +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/stb_rect_pack.h b/lib/cimgui-1.53.1/imgui-1.53/stb_rect_pack.h new file mode 100644 index 0000000..c75527d --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/stb_rect_pack.h @@ -0,0 +1,583 @@ +// stb_rect_pack.h - v0.10 - public domain - rectangle packing +// Sean Barrett 2014 +// +// Useful for e.g. packing rectangular textures into an atlas. +// Does not do rotation. +// +// Not necessarily the awesomest packing method, but better than +// the totally naive one in stb_truetype (which is primarily what +// this is meant to replace). +// +// Has only had a few tests run, may have issues. +// +// More docs to come. +// +// No memory allocations; uses qsort() and assert() from stdlib. +// Can override those by defining STBRP_SORT and STBRP_ASSERT. +// +// This library currently uses the Skyline Bottom-Left algorithm. +// +// Please note: better rectangle packers are welcome! Please +// implement them to the same API, but with a different init +// function. +// +// Credits +// +// Library +// Sean Barrett +// Minor features +// Martins Mozeiko +// Bugfixes / warning fixes +// Jeremy Jaussaud +// +// Version history: +// +// 0.10 (2016-10-25) remove cast-away-const to avoid warnings +// 0.09 (2016-08-27) fix compiler warnings +// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) +// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) +// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort +// 0.05: added STBRP_ASSERT to allow replacing assert +// 0.04: fixed minor bug in STBRP_LARGE_RECTS support +// 0.01: initial release +// +// LICENSE +// +// This software is dual-licensed to the public domain and under the following +// license: you are granted a perpetual, irrevocable license to copy, modify, +// publish, and distribute this file as you see fit. + +////////////////////////////////////////////////////////////////////////////// +// +// INCLUDE SECTION +// + +#ifndef STB_INCLUDE_STB_RECT_PACK_H +#define STB_INCLUDE_STB_RECT_PACK_H + +#define STB_RECT_PACK_VERSION 1 + +#ifdef STBRP_STATIC +#define STBRP_DEF static +#else +#define STBRP_DEF extern +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct stbrp_context stbrp_context; +typedef struct stbrp_node stbrp_node; +typedef struct stbrp_rect stbrp_rect; + +#ifdef STBRP_LARGE_RECTS +typedef int stbrp_coord; +#else +typedef unsigned short stbrp_coord; +#endif + +STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); +// Assign packed locations to rectangles. The rectangles are of type +// 'stbrp_rect' defined below, stored in the array 'rects', and there +// are 'num_rects' many of them. +// +// Rectangles which are successfully packed have the 'was_packed' flag +// set to a non-zero value and 'x' and 'y' store the minimum location +// on each axis (i.e. bottom-left in cartesian coordinates, top-left +// if you imagine y increasing downwards). Rectangles which do not fit +// have the 'was_packed' flag set to 0. +// +// You should not try to access the 'rects' array from another thread +// while this function is running, as the function temporarily reorders +// the array while it executes. +// +// To pack into another rectangle, you need to call stbrp_init_target +// again. To continue packing into the same rectangle, you can call +// this function again. Calling this multiple times with multiple rect +// arrays will probably produce worse packing results than calling it +// a single time with the full rectangle array, but the option is +// available. + +struct stbrp_rect +{ + // reserved for your use: + int id; + + // input: + stbrp_coord w, h; + + // output: + stbrp_coord x, y; + int was_packed; // non-zero if valid packing + +}; // 16 bytes, nominally + + +STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); +// Initialize a rectangle packer to: +// pack a rectangle that is 'width' by 'height' in dimensions +// using temporary storage provided by the array 'nodes', which is 'num_nodes' long +// +// You must call this function every time you start packing into a new target. +// +// There is no "shutdown" function. The 'nodes' memory must stay valid for +// the following stbrp_pack_rects() call (or calls), but can be freed after +// the call (or calls) finish. +// +// Note: to guarantee best results, either: +// 1. make sure 'num_nodes' >= 'width' +// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' +// +// If you don't do either of the above things, widths will be quantized to multiples +// of small integers to guarantee the algorithm doesn't run out of temporary storage. +// +// If you do #2, then the non-quantized algorithm will be used, but the algorithm +// may run out of temporary storage and be unable to pack some rectangles. + +STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); +// Optionally call this function after init but before doing any packing to +// change the handling of the out-of-temp-memory scenario, described above. +// If you call init again, this will be reset to the default (false). + + +STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); +// Optionally select which packing heuristic the library should use. Different +// heuristics will produce better/worse results for different data sets. +// If you call init again, this will be reset to the default. + +enum +{ + STBRP_HEURISTIC_Skyline_default=0, + STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, + STBRP_HEURISTIC_Skyline_BF_sortHeight +}; + + +////////////////////////////////////////////////////////////////////////////// +// +// the details of the following structures don't matter to you, but they must +// be visible so you can handle the memory allocations for them + +struct stbrp_node +{ + stbrp_coord x,y; + stbrp_node *next; +}; + +struct stbrp_context +{ + int width; + int height; + int align; + int init_mode; + int heuristic; + int num_nodes; + stbrp_node *active_head; + stbrp_node *free_head; + stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' +}; + +#ifdef __cplusplus +} +#endif + +#endif + +////////////////////////////////////////////////////////////////////////////// +// +// IMPLEMENTATION SECTION +// + +#ifdef STB_RECT_PACK_IMPLEMENTATION +#ifndef STBRP_SORT +#include +#define STBRP_SORT qsort +#endif + +#ifndef STBRP_ASSERT +#include +#define STBRP_ASSERT assert +#endif + +#ifdef _MSC_VER +#define STBRP__NOTUSED(v) (void)(v) +#else +#define STBRP__NOTUSED(v) (void)sizeof(v) +#endif + +enum +{ + STBRP__INIT_skyline = 1 +}; + +STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) +{ + switch (context->init_mode) { + case STBRP__INIT_skyline: + STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); + context->heuristic = heuristic; + break; + default: + STBRP_ASSERT(0); + } +} + +STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) +{ + if (allow_out_of_mem) + // if it's ok to run out of memory, then don't bother aligning them; + // this gives better packing, but may fail due to OOM (even though + // the rectangles easily fit). @TODO a smarter approach would be to only + // quantize once we've hit OOM, then we could get rid of this parameter. + context->align = 1; + else { + // if it's not ok to run out of memory, then quantize the widths + // so that num_nodes is always enough nodes. + // + // I.e. num_nodes * align >= width + // align >= width / num_nodes + // align = ceil(width/num_nodes) + + context->align = (context->width + context->num_nodes-1) / context->num_nodes; + } +} + +STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) +{ + int i; +#ifndef STBRP_LARGE_RECTS + STBRP_ASSERT(width <= 0xffff && height <= 0xffff); +#endif + + for (i=0; i < num_nodes-1; ++i) + nodes[i].next = &nodes[i+1]; + nodes[i].next = NULL; + context->init_mode = STBRP__INIT_skyline; + context->heuristic = STBRP_HEURISTIC_Skyline_default; + context->free_head = &nodes[0]; + context->active_head = &context->extra[0]; + context->width = width; + context->height = height; + context->num_nodes = num_nodes; + stbrp_setup_allow_out_of_mem(context, 0); + + // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) + context->extra[0].x = 0; + context->extra[0].y = 0; + context->extra[0].next = &context->extra[1]; + context->extra[1].x = (stbrp_coord) width; +#ifdef STBRP_LARGE_RECTS + context->extra[1].y = (1<<30); +#else + context->extra[1].y = 65535; +#endif + context->extra[1].next = NULL; +} + +// find minimum y position if it starts at x1 +static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste) +{ + stbrp_node *node = first; + int x1 = x0 + width; + int min_y, visited_width, waste_area; + + STBRP__NOTUSED(c); + + STBRP_ASSERT(first->x <= x0); + + #if 0 + // skip in case we're past the node + while (node->next->x <= x0) + ++node; + #else + STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency + #endif + + STBRP_ASSERT(node->x <= x0); + + min_y = 0; + waste_area = 0; + visited_width = 0; + while (node->x < x1) { + if (node->y > min_y) { + // raise min_y higher. + // we've accounted for all waste up to min_y, + // but we'll now add more waste for everything we've visted + waste_area += visited_width * (node->y - min_y); + min_y = node->y; + // the first time through, visited_width might be reduced + if (node->x < x0) + visited_width += node->next->x - x0; + else + visited_width += node->next->x - node->x; + } else { + // add waste area + int under_width = node->next->x - node->x; + if (under_width + visited_width > width) + under_width = width - visited_width; + waste_area += under_width * (min_y - node->y); + visited_width += under_width; + } + node = node->next; + } + + *pwaste = waste_area; + return min_y; +} + +typedef struct +{ + int x,y; + stbrp_node **prev_link; +} stbrp__findresult; + +static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) +{ + int best_waste = (1<<30), best_x, best_y = (1 << 30); + stbrp__findresult fr; + stbrp_node **prev, *node, *tail, **best = NULL; + + // align to multiple of c->align + width = (width + c->align - 1); + width -= width % c->align; + STBRP_ASSERT(width % c->align == 0); + + node = c->active_head; + prev = &c->active_head; + while (node->x + width <= c->width) { + int y,waste; + y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); + if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL + // bottom left + if (y < best_y) { + best_y = y; + best = prev; + } + } else { + // best-fit + if (y + height <= c->height) { + // can only use it if it first vertically + if (y < best_y || (y == best_y && waste < best_waste)) { + best_y = y; + best_waste = waste; + best = prev; + } + } + } + prev = &node->next; + node = node->next; + } + + best_x = (best == NULL) ? 0 : (*best)->x; + + // if doing best-fit (BF), we also have to try aligning right edge to each node position + // + // e.g, if fitting + // + // ____________________ + // |____________________| + // + // into + // + // | | + // | ____________| + // |____________| + // + // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned + // + // This makes BF take about 2x the time + + if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { + tail = c->active_head; + node = c->active_head; + prev = &c->active_head; + // find first node that's admissible + while (tail->x < width) + tail = tail->next; + while (tail) { + int xpos = tail->x - width; + int y,waste; + STBRP_ASSERT(xpos >= 0); + // find the left position that matches this + while (node->next->x <= xpos) { + prev = &node->next; + node = node->next; + } + STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); + y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); + if (y + height < c->height) { + if (y <= best_y) { + if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { + best_x = xpos; + STBRP_ASSERT(y <= best_y); + best_y = y; + best_waste = waste; + best = prev; + } + } + } + tail = tail->next; + } + } + + fr.prev_link = best; + fr.x = best_x; + fr.y = best_y; + return fr; +} + +static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) +{ + // find best position according to heuristic + stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); + stbrp_node *node, *cur; + + // bail if: + // 1. it failed + // 2. the best node doesn't fit (we don't always check this) + // 3. we're out of memory + if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { + res.prev_link = NULL; + return res; + } + + // on success, create new node + node = context->free_head; + node->x = (stbrp_coord) res.x; + node->y = (stbrp_coord) (res.y + height); + + context->free_head = node->next; + + // insert the new node into the right starting point, and + // let 'cur' point to the remaining nodes needing to be + // stiched back in + + cur = *res.prev_link; + if (cur->x < res.x) { + // preserve the existing one, so start testing with the next one + stbrp_node *next = cur->next; + cur->next = node; + cur = next; + } else { + *res.prev_link = node; + } + + // from here, traverse cur and free the nodes, until we get to one + // that shouldn't be freed + while (cur->next && cur->next->x <= res.x + width) { + stbrp_node *next = cur->next; + // move the current node to the free list + cur->next = context->free_head; + context->free_head = cur; + cur = next; + } + + // stitch the list back in + node->next = cur; + + if (cur->x < res.x + width) + cur->x = (stbrp_coord) (res.x + width); + +#ifdef _DEBUG + cur = context->active_head; + while (cur->x < context->width) { + STBRP_ASSERT(cur->x < cur->next->x); + cur = cur->next; + } + STBRP_ASSERT(cur->next == NULL); + + { + stbrp_node *L1 = NULL, *L2 = NULL; + int count=0; + cur = context->active_head; + while (cur) { + L1 = cur; + cur = cur->next; + ++count; + } + cur = context->free_head; + while (cur) { + L2 = cur; + cur = cur->next; + ++count; + } + STBRP_ASSERT(count == context->num_nodes+2); + } +#endif + + return res; +} + +static int rect_height_compare(const void *a, const void *b) +{ + const stbrp_rect *p = (const stbrp_rect *) a; + const stbrp_rect *q = (const stbrp_rect *) b; + if (p->h > q->h) + return -1; + if (p->h < q->h) + return 1; + return (p->w > q->w) ? -1 : (p->w < q->w); +} + +static int rect_width_compare(const void *a, const void *b) +{ + const stbrp_rect *p = (const stbrp_rect *) a; + const stbrp_rect *q = (const stbrp_rect *) b; + if (p->w > q->w) + return -1; + if (p->w < q->w) + return 1; + return (p->h > q->h) ? -1 : (p->h < q->h); +} + +static int rect_original_order(const void *a, const void *b) +{ + const stbrp_rect *p = (const stbrp_rect *) a; + const stbrp_rect *q = (const stbrp_rect *) b; + return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); +} + +#ifdef STBRP_LARGE_RECTS +#define STBRP__MAXVAL 0xffffffff +#else +#define STBRP__MAXVAL 0xffff +#endif + +STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) +{ + int i; + + // we use the 'was_packed' field internally to allow sorting/unsorting + for (i=0; i < num_rects; ++i) { + rects[i].was_packed = i; + #ifndef STBRP_LARGE_RECTS + STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff); + #endif + } + + // sort according to heuristic + STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); + + for (i=0; i < num_rects; ++i) { + if (rects[i].w == 0 || rects[i].h == 0) { + rects[i].x = rects[i].y = 0; // empty rect needs no space + } else { + stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); + if (fr.prev_link) { + rects[i].x = (stbrp_coord) fr.x; + rects[i].y = (stbrp_coord) fr.y; + } else { + rects[i].x = rects[i].y = STBRP__MAXVAL; + } + } + } + + // unsort + STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); + + // set was_packed flags + for (i=0; i < num_rects; ++i) + rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); +} +#endif diff --git a/lib/cimgui-1.53.1/imgui-1.53/stb_textedit.h b/lib/cimgui-1.53.1/imgui-1.53/stb_textedit.h new file mode 100644 index 0000000..4b731a0 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/stb_textedit.h @@ -0,0 +1,1322 @@ +// [ImGui] this is a slightly modified version of stb_truetype.h 1.9. Those changes would need to be pushed into nothings/sb +// [ImGui] - fixed linestart handler when over last character of multi-line buffer + simplified existing code (#588, #815) +// [ImGui] - fixed a state corruption/crash bug in stb_text_redo and stb_textedit_discard_redo (#715) +// [ImGui] - fixed a crash bug in stb_textedit_discard_redo (#681) +// [ImGui] - fixed some minor warnings + +// stb_textedit.h - v1.9 - public domain - Sean Barrett +// Development of this library was sponsored by RAD Game Tools +// +// This C header file implements the guts of a multi-line text-editing +// widget; you implement display, word-wrapping, and low-level string +// insertion/deletion, and stb_textedit will map user inputs into +// insertions & deletions, plus updates to the cursor position, +// selection state, and undo state. +// +// It is intended for use in games and other systems that need to build +// their own custom widgets and which do not have heavy text-editing +// requirements (this library is not recommended for use for editing large +// texts, as its performance does not scale and it has limited undo). +// +// Non-trivial behaviors are modelled after Windows text controls. +// +// +// LICENSE +// +// This software is dual-licensed to the public domain and under the following +// license: you are granted a perpetual, irrevocable license to copy, modify, +// publish, and distribute this file as you see fit. +// +// +// DEPENDENCIES +// +// Uses the C runtime function 'memmove', which you can override +// by defining STB_TEXTEDIT_memmove before the implementation. +// Uses no other functions. Performs no runtime allocations. +// +// +// VERSION HISTORY +// +// 1.9 (2016-08-27) customizable move-by-word +// 1.8 (2016-04-02) better keyboard handling when mouse button is down +// 1.7 (2015-09-13) change y range handling in case baseline is non-0 +// 1.6 (2015-04-15) allow STB_TEXTEDIT_memmove +// 1.5 (2014-09-10) add support for secondary keys for OS X +// 1.4 (2014-08-17) fix signed/unsigned warnings +// 1.3 (2014-06-19) fix mouse clicking to round to nearest char boundary +// 1.2 (2014-05-27) fix some RAD types that had crept into the new code +// 1.1 (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE ) +// 1.0 (2012-07-26) improve documentation, initial public release +// 0.3 (2012-02-24) bugfixes, single-line mode; insert mode +// 0.2 (2011-11-28) fixes to undo/redo +// 0.1 (2010-07-08) initial version +// +// ADDITIONAL CONTRIBUTORS +// +// Ulf Winklemann: move-by-word in 1.1 +// Fabian Giesen: secondary key inputs in 1.5 +// Martins Mozeiko: STB_TEXTEDIT_memmove +// +// Bugfixes: +// Scott Graham +// Daniel Keller +// Omar Cornut +// +// USAGE +// +// This file behaves differently depending on what symbols you define +// before including it. +// +// +// Header-file mode: +// +// If you do not define STB_TEXTEDIT_IMPLEMENTATION before including this, +// it will operate in "header file" mode. In this mode, it declares a +// single public symbol, STB_TexteditState, which encapsulates the current +// state of a text widget (except for the string, which you will store +// separately). +// +// To compile in this mode, you must define STB_TEXTEDIT_CHARTYPE to a +// primitive type that defines a single character (e.g. char, wchar_t, etc). +// +// To save space or increase undo-ability, you can optionally define the +// following things that are used by the undo system: +// +// STB_TEXTEDIT_POSITIONTYPE small int type encoding a valid cursor position +// STB_TEXTEDIT_UNDOSTATECOUNT the number of undo states to allow +// STB_TEXTEDIT_UNDOCHARCOUNT the number of characters to store in the undo buffer +// +// If you don't define these, they are set to permissive types and +// moderate sizes. The undo system does no memory allocations, so +// it grows STB_TexteditState by the worst-case storage which is (in bytes): +// +// [4 + sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATE_COUNT +// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHAR_COUNT +// +// +// Implementation mode: +// +// If you define STB_TEXTEDIT_IMPLEMENTATION before including this, it +// will compile the implementation of the text edit widget, depending +// on a large number of symbols which must be defined before the include. +// +// The implementation is defined only as static functions. You will then +// need to provide your own APIs in the same file which will access the +// static functions. +// +// The basic concept is that you provide a "string" object which +// behaves like an array of characters. stb_textedit uses indices to +// refer to positions in the string, implicitly representing positions +// in the displayed textedit. This is true for both plain text and +// rich text; even with rich text stb_truetype interacts with your +// code as if there was an array of all the displayed characters. +// +// Symbols that must be the same in header-file and implementation mode: +// +// STB_TEXTEDIT_CHARTYPE the character type +// STB_TEXTEDIT_POSITIONTYPE small type that a valid cursor position +// STB_TEXTEDIT_UNDOSTATECOUNT the number of undo states to allow +// STB_TEXTEDIT_UNDOCHARCOUNT the number of characters to store in the undo buffer +// +// Symbols you must define for implementation mode: +// +// STB_TEXTEDIT_STRING the type of object representing a string being edited, +// typically this is a wrapper object with other data you need +// +// STB_TEXTEDIT_STRINGLEN(obj) the length of the string (ideally O(1)) +// STB_TEXTEDIT_LAYOUTROW(&r,obj,n) returns the results of laying out a line of characters +// starting from character #n (see discussion below) +// STB_TEXTEDIT_GETWIDTH(obj,n,i) returns the pixel delta from the xpos of the i'th character +// to the xpos of the i+1'th char for a line of characters +// starting at character #n (i.e. accounts for kerning +// with previous char) +// STB_TEXTEDIT_KEYTOTEXT(k) maps a keyboard input to an insertable character +// (return type is int, -1 means not valid to insert) +// STB_TEXTEDIT_GETCHAR(obj,i) returns the i'th character of obj, 0-based +// STB_TEXTEDIT_NEWLINE the character returned by _GETCHAR() we recognize +// as manually wordwrapping for end-of-line positioning +// +// STB_TEXTEDIT_DELETECHARS(obj,i,n) delete n characters starting at i +// STB_TEXTEDIT_INSERTCHARS(obj,i,c*,n) insert n characters at i (pointed to by STB_TEXTEDIT_CHARTYPE*) +// +// STB_TEXTEDIT_K_SHIFT a power of two that is or'd in to a keyboard input to represent the shift key +// +// STB_TEXTEDIT_K_LEFT keyboard input to move cursor left +// STB_TEXTEDIT_K_RIGHT keyboard input to move cursor right +// STB_TEXTEDIT_K_UP keyboard input to move cursor up +// STB_TEXTEDIT_K_DOWN keyboard input to move cursor down +// STB_TEXTEDIT_K_LINESTART keyboard input to move cursor to start of line // e.g. HOME +// STB_TEXTEDIT_K_LINEEND keyboard input to move cursor to end of line // e.g. END +// STB_TEXTEDIT_K_TEXTSTART keyboard input to move cursor to start of text // e.g. ctrl-HOME +// STB_TEXTEDIT_K_TEXTEND keyboard input to move cursor to end of text // e.g. ctrl-END +// STB_TEXTEDIT_K_DELETE keyboard input to delete selection or character under cursor +// STB_TEXTEDIT_K_BACKSPACE keyboard input to delete selection or character left of cursor +// STB_TEXTEDIT_K_UNDO keyboard input to perform undo +// STB_TEXTEDIT_K_REDO keyboard input to perform redo +// +// Optional: +// STB_TEXTEDIT_K_INSERT keyboard input to toggle insert mode +// STB_TEXTEDIT_IS_SPACE(ch) true if character is whitespace (e.g. 'isspace'), +// required for default WORDLEFT/WORDRIGHT handlers +// STB_TEXTEDIT_MOVEWORDLEFT(obj,i) custom handler for WORDLEFT, returns index to move cursor to +// STB_TEXTEDIT_MOVEWORDRIGHT(obj,i) custom handler for WORDRIGHT, returns index to move cursor to +// STB_TEXTEDIT_K_WORDLEFT keyboard input to move cursor left one word // e.g. ctrl-LEFT +// STB_TEXTEDIT_K_WORDRIGHT keyboard input to move cursor right one word // e.g. ctrl-RIGHT +// STB_TEXTEDIT_K_LINESTART2 secondary keyboard input to move cursor to start of line +// STB_TEXTEDIT_K_LINEEND2 secondary keyboard input to move cursor to end of line +// STB_TEXTEDIT_K_TEXTSTART2 secondary keyboard input to move cursor to start of text +// STB_TEXTEDIT_K_TEXTEND2 secondary keyboard input to move cursor to end of text +// +// Todo: +// STB_TEXTEDIT_K_PGUP keyboard input to move cursor up a page +// STB_TEXTEDIT_K_PGDOWN keyboard input to move cursor down a page +// +// Keyboard input must be encoded as a single integer value; e.g. a character code +// and some bitflags that represent shift states. to simplify the interface, SHIFT must +// be a bitflag, so we can test the shifted state of cursor movements to allow selection, +// i.e. (STB_TEXTED_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow. +// +// You can encode other things, such as CONTROL or ALT, in additional bits, and +// then test for their presence in e.g. STB_TEXTEDIT_K_WORDLEFT. For example, +// my Windows implementations add an additional CONTROL bit, and an additional KEYDOWN +// bit. Then all of the STB_TEXTEDIT_K_ values bitwise-or in the KEYDOWN bit, +// and I pass both WM_KEYDOWN and WM_CHAR events to the "key" function in the +// API below. The control keys will only match WM_KEYDOWN events because of the +// keydown bit I add, and STB_TEXTEDIT_KEYTOTEXT only tests for the KEYDOWN +// bit so it only decodes WM_CHAR events. +// +// STB_TEXTEDIT_LAYOUTROW returns information about the shape of one displayed +// row of characters assuming they start on the i'th character--the width and +// the height and the number of characters consumed. This allows this library +// to traverse the entire layout incrementally. You need to compute word-wrapping +// here. +// +// Each textfield keeps its own insert mode state, which is not how normal +// applications work. To keep an app-wide insert mode, update/copy the +// "insert_mode" field of STB_TexteditState before/after calling API functions. +// +// API +// +// void stb_textedit_initialize_state(STB_TexteditState *state, int is_single_line) +// +// void stb_textedit_click(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y) +// void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y) +// int stb_textedit_cut(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +// int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, STB_TEXTEDIT_CHARTYPE *text, int len) +// void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int key) +// +// Each of these functions potentially updates the string and updates the +// state. +// +// initialize_state: +// set the textedit state to a known good default state when initially +// constructing the textedit. +// +// click: +// call this with the mouse x,y on a mouse down; it will update the cursor +// and reset the selection start/end to the cursor point. the x,y must +// be relative to the text widget, with (0,0) being the top left. +// +// drag: +// call this with the mouse x,y on a mouse drag/up; it will update the +// cursor and the selection end point +// +// cut: +// call this to delete the current selection; returns true if there was +// one. you should FIRST copy the current selection to the system paste buffer. +// (To copy, just copy the current selection out of the string yourself.) +// +// paste: +// call this to paste text at the current cursor point or over the current +// selection if there is one. +// +// key: +// call this for keyboard inputs sent to the textfield. you can use it +// for "key down" events or for "translated" key events. if you need to +// do both (as in Win32), or distinguish Unicode characters from control +// inputs, set a high bit to distinguish the two; then you can define the +// various definitions like STB_TEXTEDIT_K_LEFT have the is-key-event bit +// set, and make STB_TEXTEDIT_KEYTOCHAR check that the is-key-event bit is +// clear. +// +// When rendering, you can read the cursor position and selection state from +// the STB_TexteditState. +// +// +// Notes: +// +// This is designed to be usable in IMGUI, so it allows for the possibility of +// running in an IMGUI that has NOT cached the multi-line layout. For this +// reason, it provides an interface that is compatible with computing the +// layout incrementally--we try to make sure we make as few passes through +// as possible. (For example, to locate the mouse pointer in the text, we +// could define functions that return the X and Y positions of characters +// and binary search Y and then X, but if we're doing dynamic layout this +// will run the layout algorithm many times, so instead we manually search +// forward in one pass. Similar logic applies to e.g. up-arrow and +// down-arrow movement.) +// +// If it's run in a widget that *has* cached the layout, then this is less +// efficient, but it's not horrible on modern computers. But you wouldn't +// want to edit million-line files with it. + + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//// +//// Header-file mode +//// +//// + +#ifndef INCLUDE_STB_TEXTEDIT_H +#define INCLUDE_STB_TEXTEDIT_H + +//////////////////////////////////////////////////////////////////////// +// +// STB_TexteditState +// +// Definition of STB_TexteditState which you should store +// per-textfield; it includes cursor position, selection state, +// and undo state. +// + +#ifndef STB_TEXTEDIT_UNDOSTATECOUNT +#define STB_TEXTEDIT_UNDOSTATECOUNT 99 +#endif +#ifndef STB_TEXTEDIT_UNDOCHARCOUNT +#define STB_TEXTEDIT_UNDOCHARCOUNT 999 +#endif +#ifndef STB_TEXTEDIT_CHARTYPE +#define STB_TEXTEDIT_CHARTYPE int +#endif +#ifndef STB_TEXTEDIT_POSITIONTYPE +#define STB_TEXTEDIT_POSITIONTYPE int +#endif + +typedef struct +{ + // private data + STB_TEXTEDIT_POSITIONTYPE where; + short insert_length; + short delete_length; + short char_storage; +} StbUndoRecord; + +typedef struct +{ + // private data + StbUndoRecord undo_rec [STB_TEXTEDIT_UNDOSTATECOUNT]; + STB_TEXTEDIT_CHARTYPE undo_char[STB_TEXTEDIT_UNDOCHARCOUNT]; + short undo_point, redo_point; + short undo_char_point, redo_char_point; +} StbUndoState; + +typedef struct +{ + ///////////////////// + // + // public data + // + + int cursor; + // position of the text cursor within the string + + int select_start; // selection start point + int select_end; + // selection start and end point in characters; if equal, no selection. + // note that start may be less than or greater than end (e.g. when + // dragging the mouse, start is where the initial click was, and you + // can drag in either direction) + + unsigned char insert_mode; + // each textfield keeps its own insert mode state. to keep an app-wide + // insert mode, copy this value in/out of the app state + + ///////////////////// + // + // private data + // + unsigned char cursor_at_end_of_line; // not implemented yet + unsigned char initialized; + unsigned char has_preferred_x; + unsigned char single_line; + unsigned char padding1, padding2, padding3; + float preferred_x; // this determines where the cursor up/down tries to seek to along x + StbUndoState undostate; +} STB_TexteditState; + + +//////////////////////////////////////////////////////////////////////// +// +// StbTexteditRow +// +// Result of layout query, used by stb_textedit to determine where +// the text in each row is. + +// result of layout query +typedef struct +{ + float x0,x1; // starting x location, end x location (allows for align=right, etc) + float baseline_y_delta; // position of baseline relative to previous row's baseline + float ymin,ymax; // height of row above and below baseline + int num_chars; +} StbTexteditRow; +#endif //INCLUDE_STB_TEXTEDIT_H + + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//// +//// Implementation mode +//// +//// + + +// implementation isn't include-guarded, since it might have indirectly +// included just the "header" portion +#ifdef STB_TEXTEDIT_IMPLEMENTATION + +#ifndef STB_TEXTEDIT_memmove +#include +#define STB_TEXTEDIT_memmove memmove +#endif + + +///////////////////////////////////////////////////////////////////////////// +// +// Mouse input handling +// + +// traverse the layout to locate the nearest character to a display position +static int stb_text_locate_coord(STB_TEXTEDIT_STRING *str, float x, float y) +{ + StbTexteditRow r; + int n = STB_TEXTEDIT_STRINGLEN(str); + float base_y = 0, prev_x; + int i=0, k; + + r.x0 = r.x1 = 0; + r.ymin = r.ymax = 0; + r.num_chars = 0; + + // search rows to find one that straddles 'y' + while (i < n) { + STB_TEXTEDIT_LAYOUTROW(&r, str, i); + if (r.num_chars <= 0) + return n; + + if (i==0 && y < base_y + r.ymin) + return 0; + + if (y < base_y + r.ymax) + break; + + i += r.num_chars; + base_y += r.baseline_y_delta; + } + + // below all text, return 'after' last character + if (i >= n) + return n; + + // check if it's before the beginning of the line + if (x < r.x0) + return i; + + // check if it's before the end of the line + if (x < r.x1) { + // search characters in row for one that straddles 'x' + prev_x = r.x0; + for (k=0; k < r.num_chars; ++k) { + float w = STB_TEXTEDIT_GETWIDTH(str, i, k); + if (x < prev_x+w) { + if (x < prev_x+w/2) + return k+i; + else + return k+i+1; + } + prev_x += w; + } + // shouldn't happen, but if it does, fall through to end-of-line case + } + + // if the last character is a newline, return that. otherwise return 'after' the last character + if (STB_TEXTEDIT_GETCHAR(str, i+r.num_chars-1) == STB_TEXTEDIT_NEWLINE) + return i+r.num_chars-1; + else + return i+r.num_chars; +} + +// API click: on mouse down, move the cursor to the clicked location, and reset the selection +static void stb_textedit_click(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y) +{ + state->cursor = stb_text_locate_coord(str, x, y); + state->select_start = state->cursor; + state->select_end = state->cursor; + state->has_preferred_x = 0; +} + +// API drag: on mouse drag, move the cursor and selection endpoint to the clicked location +static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y) +{ + int p = stb_text_locate_coord(str, x, y); + if (state->select_start == state->select_end) + state->select_start = state->cursor; + state->cursor = state->select_end = p; +} + +///////////////////////////////////////////////////////////////////////////// +// +// Keyboard input handling +// + +// forward declarations +static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state); +static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state); +static void stb_text_makeundo_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length); +static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length); +static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length); + +typedef struct +{ + float x,y; // position of n'th character + float height; // height of line + int first_char, length; // first char of row, and length + int prev_first; // first char of previous row +} StbFindState; + +// find the x/y location of a character, and remember info about the previous row in +// case we get a move-up event (for page up, we'll have to rescan) +static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *str, int n, int single_line) +{ + StbTexteditRow r; + int prev_start = 0; + int z = STB_TEXTEDIT_STRINGLEN(str); + int i=0, first; + + if (n == z) { + // if it's at the end, then find the last line -- simpler than trying to + // explicitly handle this case in the regular code + if (single_line) { + STB_TEXTEDIT_LAYOUTROW(&r, str, 0); + find->y = 0; + find->first_char = 0; + find->length = z; + find->height = r.ymax - r.ymin; + find->x = r.x1; + } else { + find->y = 0; + find->x = 0; + find->height = 1; + while (i < z) { + STB_TEXTEDIT_LAYOUTROW(&r, str, i); + prev_start = i; + i += r.num_chars; + } + find->first_char = i; + find->length = 0; + find->prev_first = prev_start; + } + return; + } + + // search rows to find the one that straddles character n + find->y = 0; + + for(;;) { + STB_TEXTEDIT_LAYOUTROW(&r, str, i); + if (n < i + r.num_chars) + break; + prev_start = i; + i += r.num_chars; + find->y += r.baseline_y_delta; + } + + find->first_char = first = i; + find->length = r.num_chars; + find->height = r.ymax - r.ymin; + find->prev_first = prev_start; + + // now scan to find xpos + find->x = r.x0; + i = 0; + for (i=0; first+i < n; ++i) + find->x += STB_TEXTEDIT_GETWIDTH(str, first, i); +} + +#define STB_TEXT_HAS_SELECTION(s) ((s)->select_start != (s)->select_end) + +// make the selection/cursor state valid if client altered the string +static void stb_textedit_clamp(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +{ + int n = STB_TEXTEDIT_STRINGLEN(str); + if (STB_TEXT_HAS_SELECTION(state)) { + if (state->select_start > n) state->select_start = n; + if (state->select_end > n) state->select_end = n; + // if clamping forced them to be equal, move the cursor to match + if (state->select_start == state->select_end) + state->cursor = state->select_start; + } + if (state->cursor > n) state->cursor = n; +} + +// delete characters while updating undo +static void stb_textedit_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int len) +{ + stb_text_makeundo_delete(str, state, where, len); + STB_TEXTEDIT_DELETECHARS(str, where, len); + state->has_preferred_x = 0; +} + +// delete the section +static void stb_textedit_delete_selection(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +{ + stb_textedit_clamp(str, state); + if (STB_TEXT_HAS_SELECTION(state)) { + if (state->select_start < state->select_end) { + stb_textedit_delete(str, state, state->select_start, state->select_end - state->select_start); + state->select_end = state->cursor = state->select_start; + } else { + stb_textedit_delete(str, state, state->select_end, state->select_start - state->select_end); + state->select_start = state->cursor = state->select_end; + } + state->has_preferred_x = 0; + } +} + +// canoncialize the selection so start <= end +static void stb_textedit_sortselection(STB_TexteditState *state) +{ + if (state->select_end < state->select_start) { + int temp = state->select_end; + state->select_end = state->select_start; + state->select_start = temp; + } +} + +// move cursor to first character of selection +static void stb_textedit_move_to_first(STB_TexteditState *state) +{ + if (STB_TEXT_HAS_SELECTION(state)) { + stb_textedit_sortselection(state); + state->cursor = state->select_start; + state->select_end = state->select_start; + state->has_preferred_x = 0; + } +} + +// move cursor to last character of selection +static void stb_textedit_move_to_last(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +{ + if (STB_TEXT_HAS_SELECTION(state)) { + stb_textedit_sortselection(state); + stb_textedit_clamp(str, state); + state->cursor = state->select_end; + state->select_start = state->select_end; + state->has_preferred_x = 0; + } +} + +#ifdef STB_TEXTEDIT_IS_SPACE +static int is_word_boundary( STB_TEXTEDIT_STRING *str, int idx ) +{ + return idx > 0 ? (STB_TEXTEDIT_IS_SPACE( STB_TEXTEDIT_GETCHAR(str,idx-1) ) && !STB_TEXTEDIT_IS_SPACE( STB_TEXTEDIT_GETCHAR(str, idx) ) ) : 1; +} + +#ifndef STB_TEXTEDIT_MOVEWORDLEFT +static int stb_textedit_move_to_word_previous( STB_TEXTEDIT_STRING *str, int c ) +{ + --c; // always move at least one character + while( c >= 0 && !is_word_boundary( str, c ) ) + --c; + + if( c < 0 ) + c = 0; + + return c; +} +#define STB_TEXTEDIT_MOVEWORDLEFT stb_textedit_move_to_word_previous +#endif + +#ifndef STB_TEXTEDIT_MOVEWORDRIGHT +static int stb_textedit_move_to_word_next( STB_TEXTEDIT_STRING *str, int c ) +{ + const int len = STB_TEXTEDIT_STRINGLEN(str); + ++c; // always move at least one character + while( c < len && !is_word_boundary( str, c ) ) + ++c; + + if( c > len ) + c = len; + + return c; +} +#define STB_TEXTEDIT_MOVEWORDRIGHT stb_textedit_move_to_word_next +#endif + +#endif + +// update selection and cursor to match each other +static void stb_textedit_prep_selection_at_cursor(STB_TexteditState *state) +{ + if (!STB_TEXT_HAS_SELECTION(state)) + state->select_start = state->select_end = state->cursor; + else + state->cursor = state->select_end; +} + +// API cut: delete selection +static int stb_textedit_cut(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +{ + if (STB_TEXT_HAS_SELECTION(state)) { + stb_textedit_delete_selection(str,state); // implicity clamps + state->has_preferred_x = 0; + return 1; + } + return 0; +} + +// API paste: replace existing selection with passed-in text +static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, STB_TEXTEDIT_CHARTYPE const *ctext, int len) +{ + STB_TEXTEDIT_CHARTYPE *text = (STB_TEXTEDIT_CHARTYPE *) ctext; + // if there's a selection, the paste should delete it + stb_textedit_clamp(str, state); + stb_textedit_delete_selection(str,state); + // try to insert the characters + if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) { + stb_text_makeundo_insert(state, state->cursor, len); + state->cursor += len; + state->has_preferred_x = 0; + return 1; + } + // remove the undo since we didn't actually insert the characters + if (state->undostate.undo_point) + --state->undostate.undo_point; + return 0; +} + +// API key: process a keyboard input +static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int key) +{ +retry: + switch (key) { + default: { + int c = STB_TEXTEDIT_KEYTOTEXT(key); + if (c > 0) { + STB_TEXTEDIT_CHARTYPE ch = (STB_TEXTEDIT_CHARTYPE) c; + + // can't add newline in single-line mode + if (c == '\n' && state->single_line) + break; + + if (state->insert_mode && !STB_TEXT_HAS_SELECTION(state) && state->cursor < STB_TEXTEDIT_STRINGLEN(str)) { + stb_text_makeundo_replace(str, state, state->cursor, 1, 1); + STB_TEXTEDIT_DELETECHARS(str, state->cursor, 1); + if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) { + ++state->cursor; + state->has_preferred_x = 0; + } + } else { + stb_textedit_delete_selection(str,state); // implicity clamps + if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) { + stb_text_makeundo_insert(state, state->cursor, 1); + ++state->cursor; + state->has_preferred_x = 0; + } + } + } + break; + } + +#ifdef STB_TEXTEDIT_K_INSERT + case STB_TEXTEDIT_K_INSERT: + state->insert_mode = !state->insert_mode; + break; +#endif + + case STB_TEXTEDIT_K_UNDO: + stb_text_undo(str, state); + state->has_preferred_x = 0; + break; + + case STB_TEXTEDIT_K_REDO: + stb_text_redo(str, state); + state->has_preferred_x = 0; + break; + + case STB_TEXTEDIT_K_LEFT: + // if currently there's a selection, move cursor to start of selection + if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_move_to_first(state); + else + if (state->cursor > 0) + --state->cursor; + state->has_preferred_x = 0; + break; + + case STB_TEXTEDIT_K_RIGHT: + // if currently there's a selection, move cursor to end of selection + if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_move_to_last(str, state); + else + ++state->cursor; + stb_textedit_clamp(str, state); + state->has_preferred_x = 0; + break; + + case STB_TEXTEDIT_K_LEFT | STB_TEXTEDIT_K_SHIFT: + stb_textedit_clamp(str, state); + stb_textedit_prep_selection_at_cursor(state); + // move selection left + if (state->select_end > 0) + --state->select_end; + state->cursor = state->select_end; + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_MOVEWORDLEFT + case STB_TEXTEDIT_K_WORDLEFT: + if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_move_to_first(state); + else { + state->cursor = STB_TEXTEDIT_MOVEWORDLEFT(str, state->cursor); + stb_textedit_clamp( str, state ); + } + break; + + case STB_TEXTEDIT_K_WORDLEFT | STB_TEXTEDIT_K_SHIFT: + if( !STB_TEXT_HAS_SELECTION( state ) ) + stb_textedit_prep_selection_at_cursor(state); + + state->cursor = STB_TEXTEDIT_MOVEWORDLEFT(str, state->cursor); + state->select_end = state->cursor; + + stb_textedit_clamp( str, state ); + break; +#endif + +#ifdef STB_TEXTEDIT_MOVEWORDRIGHT + case STB_TEXTEDIT_K_WORDRIGHT: + if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_move_to_last(str, state); + else { + state->cursor = STB_TEXTEDIT_MOVEWORDRIGHT(str, state->cursor); + stb_textedit_clamp( str, state ); + } + break; + + case STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT: + if( !STB_TEXT_HAS_SELECTION( state ) ) + stb_textedit_prep_selection_at_cursor(state); + + state->cursor = STB_TEXTEDIT_MOVEWORDRIGHT(str, state->cursor); + state->select_end = state->cursor; + + stb_textedit_clamp( str, state ); + break; +#endif + + case STB_TEXTEDIT_K_RIGHT | STB_TEXTEDIT_K_SHIFT: + stb_textedit_prep_selection_at_cursor(state); + // move selection right + ++state->select_end; + stb_textedit_clamp(str, state); + state->cursor = state->select_end; + state->has_preferred_x = 0; + break; + + case STB_TEXTEDIT_K_DOWN: + case STB_TEXTEDIT_K_DOWN | STB_TEXTEDIT_K_SHIFT: { + StbFindState find; + StbTexteditRow row; + int i, sel = (key & STB_TEXTEDIT_K_SHIFT) != 0; + + if (state->single_line) { + // on windows, up&down in single-line behave like left&right + key = STB_TEXTEDIT_K_RIGHT | (key & STB_TEXTEDIT_K_SHIFT); + goto retry; + } + + if (sel) + stb_textedit_prep_selection_at_cursor(state); + else if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_move_to_last(str,state); + + // compute current position of cursor point + stb_textedit_clamp(str, state); + stb_textedit_find_charpos(&find, str, state->cursor, state->single_line); + + // now find character position down a row + if (find.length) { + float goal_x = state->has_preferred_x ? state->preferred_x : find.x; + float x; + int start = find.first_char + find.length; + state->cursor = start; + STB_TEXTEDIT_LAYOUTROW(&row, str, state->cursor); + x = row.x0; + for (i=0; i < row.num_chars; ++i) { + float dx = STB_TEXTEDIT_GETWIDTH(str, start, i); + #ifdef STB_TEXTEDIT_GETWIDTH_NEWLINE + if (dx == STB_TEXTEDIT_GETWIDTH_NEWLINE) + break; + #endif + x += dx; + if (x > goal_x) + break; + ++state->cursor; + } + stb_textedit_clamp(str, state); + + state->has_preferred_x = 1; + state->preferred_x = goal_x; + + if (sel) + state->select_end = state->cursor; + } + break; + } + + case STB_TEXTEDIT_K_UP: + case STB_TEXTEDIT_K_UP | STB_TEXTEDIT_K_SHIFT: { + StbFindState find; + StbTexteditRow row; + int i, sel = (key & STB_TEXTEDIT_K_SHIFT) != 0; + + if (state->single_line) { + // on windows, up&down become left&right + key = STB_TEXTEDIT_K_LEFT | (key & STB_TEXTEDIT_K_SHIFT); + goto retry; + } + + if (sel) + stb_textedit_prep_selection_at_cursor(state); + else if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_move_to_first(state); + + // compute current position of cursor point + stb_textedit_clamp(str, state); + stb_textedit_find_charpos(&find, str, state->cursor, state->single_line); + + // can only go up if there's a previous row + if (find.prev_first != find.first_char) { + // now find character position up a row + float goal_x = state->has_preferred_x ? state->preferred_x : find.x; + float x; + state->cursor = find.prev_first; + STB_TEXTEDIT_LAYOUTROW(&row, str, state->cursor); + x = row.x0; + for (i=0; i < row.num_chars; ++i) { + float dx = STB_TEXTEDIT_GETWIDTH(str, find.prev_first, i); + #ifdef STB_TEXTEDIT_GETWIDTH_NEWLINE + if (dx == STB_TEXTEDIT_GETWIDTH_NEWLINE) + break; + #endif + x += dx; + if (x > goal_x) + break; + ++state->cursor; + } + stb_textedit_clamp(str, state); + + state->has_preferred_x = 1; + state->preferred_x = goal_x; + + if (sel) + state->select_end = state->cursor; + } + break; + } + + case STB_TEXTEDIT_K_DELETE: + case STB_TEXTEDIT_K_DELETE | STB_TEXTEDIT_K_SHIFT: + if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_delete_selection(str, state); + else { + int n = STB_TEXTEDIT_STRINGLEN(str); + if (state->cursor < n) + stb_textedit_delete(str, state, state->cursor, 1); + } + state->has_preferred_x = 0; + break; + + case STB_TEXTEDIT_K_BACKSPACE: + case STB_TEXTEDIT_K_BACKSPACE | STB_TEXTEDIT_K_SHIFT: + if (STB_TEXT_HAS_SELECTION(state)) + stb_textedit_delete_selection(str, state); + else { + stb_textedit_clamp(str, state); + if (state->cursor > 0) { + stb_textedit_delete(str, state, state->cursor-1, 1); + --state->cursor; + } + } + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_K_TEXTSTART2 + case STB_TEXTEDIT_K_TEXTSTART2: +#endif + case STB_TEXTEDIT_K_TEXTSTART: + state->cursor = state->select_start = state->select_end = 0; + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_K_TEXTEND2 + case STB_TEXTEDIT_K_TEXTEND2: +#endif + case STB_TEXTEDIT_K_TEXTEND: + state->cursor = STB_TEXTEDIT_STRINGLEN(str); + state->select_start = state->select_end = 0; + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_K_TEXTSTART2 + case STB_TEXTEDIT_K_TEXTSTART2 | STB_TEXTEDIT_K_SHIFT: +#endif + case STB_TEXTEDIT_K_TEXTSTART | STB_TEXTEDIT_K_SHIFT: + stb_textedit_prep_selection_at_cursor(state); + state->cursor = state->select_end = 0; + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_K_TEXTEND2 + case STB_TEXTEDIT_K_TEXTEND2 | STB_TEXTEDIT_K_SHIFT: +#endif + case STB_TEXTEDIT_K_TEXTEND | STB_TEXTEDIT_K_SHIFT: + stb_textedit_prep_selection_at_cursor(state); + state->cursor = state->select_end = STB_TEXTEDIT_STRINGLEN(str); + state->has_preferred_x = 0; + break; + + +#ifdef STB_TEXTEDIT_K_LINESTART2 + case STB_TEXTEDIT_K_LINESTART2: +#endif + case STB_TEXTEDIT_K_LINESTART: + stb_textedit_clamp(str, state); + stb_textedit_move_to_first(state); + if (state->single_line) + state->cursor = 0; + else while (state->cursor > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) != STB_TEXTEDIT_NEWLINE) + --state->cursor; + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_K_LINEEND2 + case STB_TEXTEDIT_K_LINEEND2: +#endif + case STB_TEXTEDIT_K_LINEEND: { + int n = STB_TEXTEDIT_STRINGLEN(str); + stb_textedit_clamp(str, state); + stb_textedit_move_to_first(state); + if (state->single_line) + state->cursor = n; + else while (state->cursor < n && STB_TEXTEDIT_GETCHAR(str, state->cursor) != STB_TEXTEDIT_NEWLINE) + ++state->cursor; + state->has_preferred_x = 0; + break; + } + +#ifdef STB_TEXTEDIT_K_LINESTART2 + case STB_TEXTEDIT_K_LINESTART2 | STB_TEXTEDIT_K_SHIFT: +#endif + case STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_SHIFT: + stb_textedit_clamp(str, state); + stb_textedit_prep_selection_at_cursor(state); + if (state->single_line) + state->cursor = 0; + else while (state->cursor > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) != STB_TEXTEDIT_NEWLINE) + --state->cursor; + state->select_end = state->cursor; + state->has_preferred_x = 0; + break; + +#ifdef STB_TEXTEDIT_K_LINEEND2 + case STB_TEXTEDIT_K_LINEEND2 | STB_TEXTEDIT_K_SHIFT: +#endif + case STB_TEXTEDIT_K_LINEEND | STB_TEXTEDIT_K_SHIFT: { + int n = STB_TEXTEDIT_STRINGLEN(str); + stb_textedit_clamp(str, state); + stb_textedit_prep_selection_at_cursor(state); + if (state->single_line) + state->cursor = n; + else while (state->cursor < n && STB_TEXTEDIT_GETCHAR(str, state->cursor) != STB_TEXTEDIT_NEWLINE) + ++state->cursor; + state->select_end = state->cursor; + state->has_preferred_x = 0; + break; + } + +// @TODO: +// STB_TEXTEDIT_K_PGUP - move cursor up a page +// STB_TEXTEDIT_K_PGDOWN - move cursor down a page + } +} + +///////////////////////////////////////////////////////////////////////////// +// +// Undo processing +// +// @OPTIMIZE: the undo/redo buffer should be circular + +static void stb_textedit_flush_redo(StbUndoState *state) +{ + state->redo_point = STB_TEXTEDIT_UNDOSTATECOUNT; + state->redo_char_point = STB_TEXTEDIT_UNDOCHARCOUNT; +} + +// discard the oldest entry in the undo list +static void stb_textedit_discard_undo(StbUndoState *state) +{ + if (state->undo_point > 0) { + // if the 0th undo state has characters, clean those up + if (state->undo_rec[0].char_storage >= 0) { + int n = state->undo_rec[0].insert_length, i; + // delete n characters from all other records + state->undo_char_point = state->undo_char_point - (short) n; // vsnet05 + STB_TEXTEDIT_memmove(state->undo_char, state->undo_char + n, (size_t) ((size_t)state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); + for (i=0; i < state->undo_point; ++i) + if (state->undo_rec[i].char_storage >= 0) + state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it + } + --state->undo_point; + STB_TEXTEDIT_memmove(state->undo_rec, state->undo_rec+1, (size_t) ((size_t)state->undo_point*sizeof(state->undo_rec[0]))); + } +} + +// discard the oldest entry in the redo list--it's bad if this +// ever happens, but because undo & redo have to store the actual +// characters in different cases, the redo character buffer can +// fill up even though the undo buffer didn't +static void stb_textedit_discard_redo(StbUndoState *state) +{ + int k = STB_TEXTEDIT_UNDOSTATECOUNT-1; + + if (state->redo_point <= k) { + // if the k'th undo state has characters, clean those up + if (state->undo_rec[k].char_storage >= 0) { + int n = state->undo_rec[k].insert_length, i; + // delete n characters from all other records + state->redo_char_point = state->redo_char_point + (short) n; // vsnet05 + STB_TEXTEDIT_memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((size_t)(STB_TEXTEDIT_UNDOCHARCOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); + for (i=state->redo_point; i < k; ++i) + if (state->undo_rec[i].char_storage >= 0) + state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05 + } + STB_TEXTEDIT_memmove(state->undo_rec + state->redo_point, state->undo_rec + state->redo_point-1, (size_t) ((size_t)(STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); + ++state->redo_point; + } +} + +static StbUndoRecord *stb_text_create_undo_record(StbUndoState *state, int numchars) +{ + // any time we create a new undo record, we discard redo + stb_textedit_flush_redo(state); + + // if we have no free records, we have to make room, by sliding the + // existing records down + if (state->undo_point == STB_TEXTEDIT_UNDOSTATECOUNT) + stb_textedit_discard_undo(state); + + // if the characters to store won't possibly fit in the buffer, we can't undo + if (numchars > STB_TEXTEDIT_UNDOCHARCOUNT) { + state->undo_point = 0; + state->undo_char_point = 0; + return NULL; + } + + // if we don't have enough free characters in the buffer, we have to make room + while (state->undo_char_point + numchars > STB_TEXTEDIT_UNDOCHARCOUNT) + stb_textedit_discard_undo(state); + + return &state->undo_rec[state->undo_point++]; +} + +static STB_TEXTEDIT_CHARTYPE *stb_text_createundo(StbUndoState *state, int pos, int insert_len, int delete_len) +{ + StbUndoRecord *r = stb_text_create_undo_record(state, insert_len); + if (r == NULL) + return NULL; + + r->where = pos; + r->insert_length = (short) insert_len; + r->delete_length = (short) delete_len; + + if (insert_len == 0) { + r->char_storage = -1; + return NULL; + } else { + r->char_storage = state->undo_char_point; + state->undo_char_point = state->undo_char_point + (short) insert_len; + return &state->undo_char[r->char_storage]; + } +} + +static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +{ + StbUndoState *s = &state->undostate; + StbUndoRecord u, *r; + if (s->undo_point == 0) + return; + + // we need to do two things: apply the undo record, and create a redo record + u = s->undo_rec[s->undo_point-1]; + r = &s->undo_rec[s->redo_point-1]; + r->char_storage = -1; + + r->insert_length = u.delete_length; + r->delete_length = u.insert_length; + r->where = u.where; + + if (u.delete_length) { + // if the undo record says to delete characters, then the redo record will + // need to re-insert the characters that get deleted, so we need to store + // them. + + // there are three cases: + // there's enough room to store the characters + // characters stored for *redoing* don't leave room for redo + // characters stored for *undoing* don't leave room for redo + // if the last is true, we have to bail + + if (s->undo_char_point + u.delete_length >= STB_TEXTEDIT_UNDOCHARCOUNT) { + // the undo records take up too much character space; there's no space to store the redo characters + r->insert_length = 0; + } else { + int i; + + // there's definitely room to store the characters eventually + while (s->undo_char_point + u.delete_length > s->redo_char_point) { + // there's currently not enough room, so discard a redo record + stb_textedit_discard_redo(s); + // should never happen: + if (s->redo_point == STB_TEXTEDIT_UNDOSTATECOUNT) + return; + } + r = &s->undo_rec[s->redo_point-1]; + + r->char_storage = s->redo_char_point - u.delete_length; + s->redo_char_point = s->redo_char_point - (short) u.delete_length; + + // now save the characters + for (i=0; i < u.delete_length; ++i) + s->undo_char[r->char_storage + i] = STB_TEXTEDIT_GETCHAR(str, u.where + i); + } + + // now we can carry out the deletion + STB_TEXTEDIT_DELETECHARS(str, u.where, u.delete_length); + } + + // check type of recorded action: + if (u.insert_length) { + // easy case: was a deletion, so we need to insert n characters + STB_TEXTEDIT_INSERTCHARS(str, u.where, &s->undo_char[u.char_storage], u.insert_length); + s->undo_char_point -= u.insert_length; + } + + state->cursor = u.where + u.insert_length; + + s->undo_point--; + s->redo_point--; +} + +static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) +{ + StbUndoState *s = &state->undostate; + StbUndoRecord *u, r; + if (s->redo_point == STB_TEXTEDIT_UNDOSTATECOUNT) + return; + + // we need to do two things: apply the redo record, and create an undo record + u = &s->undo_rec[s->undo_point]; + r = s->undo_rec[s->redo_point]; + + // we KNOW there must be room for the undo record, because the redo record + // was derived from an undo record + + u->delete_length = r.insert_length; + u->insert_length = r.delete_length; + u->where = r.where; + u->char_storage = -1; + + if (r.delete_length) { + // the redo record requires us to delete characters, so the undo record + // needs to store the characters + + if (s->undo_char_point + u->insert_length > s->redo_char_point) { + u->insert_length = 0; + u->delete_length = 0; + } else { + int i; + u->char_storage = s->undo_char_point; + s->undo_char_point = s->undo_char_point + u->insert_length; + + // now save the characters + for (i=0; i < u->insert_length; ++i) + s->undo_char[u->char_storage + i] = STB_TEXTEDIT_GETCHAR(str, u->where + i); + } + + STB_TEXTEDIT_DELETECHARS(str, r.where, r.delete_length); + } + + if (r.insert_length) { + // easy case: need to insert n characters + STB_TEXTEDIT_INSERTCHARS(str, r.where, &s->undo_char[r.char_storage], r.insert_length); + s->redo_char_point += r.insert_length; + } + + state->cursor = r.where + r.insert_length; + + s->undo_point++; + s->redo_point++; +} + +static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length) +{ + stb_text_createundo(&state->undostate, where, 0, length); +} + +static void stb_text_makeundo_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length) +{ + int i; + STB_TEXTEDIT_CHARTYPE *p = stb_text_createundo(&state->undostate, where, length, 0); + if (p) { + for (i=0; i < length; ++i) + p[i] = STB_TEXTEDIT_GETCHAR(str, where+i); + } +} + +static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length) +{ + int i; + STB_TEXTEDIT_CHARTYPE *p = stb_text_createundo(&state->undostate, where, old_length, new_length); + if (p) { + for (i=0; i < old_length; ++i) + p[i] = STB_TEXTEDIT_GETCHAR(str, where+i); + } +} + +// reset the state to default +static void stb_textedit_clear_state(STB_TexteditState *state, int is_single_line) +{ + state->undostate.undo_point = 0; + state->undostate.undo_char_point = 0; + state->undostate.redo_point = STB_TEXTEDIT_UNDOSTATECOUNT; + state->undostate.redo_char_point = STB_TEXTEDIT_UNDOCHARCOUNT; + state->select_end = state->select_start = 0; + state->cursor = 0; + state->has_preferred_x = 0; + state->preferred_x = 0; + state->cursor_at_end_of_line = 0; + state->initialized = 1; + state->single_line = (unsigned char) is_single_line; + state->insert_mode = 0; +} + +// API initialize +static void stb_textedit_initialize_state(STB_TexteditState *state, int is_single_line) +{ + stb_textedit_clear_state(state, is_single_line); +} +#endif//STB_TEXTEDIT_IMPLEMENTATION diff --git a/lib/cimgui-1.53.1/imgui-1.53/stb_truetype.h b/lib/cimgui-1.53.1/imgui-1.53/stb_truetype.h new file mode 100644 index 0000000..92b9a87 --- /dev/null +++ b/lib/cimgui-1.53.1/imgui-1.53/stb_truetype.h @@ -0,0 +1,4018 @@ +// stb_truetype.h - v1.14 - public domain +// authored from 2009-2016 by Sean Barrett / RAD Game Tools +// +// This library processes TrueType files: +// parse files +// extract glyph metrics +// extract glyph shapes +// render glyphs to one-channel bitmaps with antialiasing (box filter) +// +// 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 +// +// Misc other: +// Ryan Gordon +// Simon Glass +// github:IntellectualKitty +// +// Bug/warning reports/fixes: +// "Zer" on mollyrocket (with fix) +// Cass Everitt +// stoiko (Haemimont Games) +// Brian Hook +// Walter van Niftrik +// David Gow +// David Given +// Ivan-Assen Ivanov +// Anthony Pesch +// Johan Duparc +// Hou Qiming +// Fabian "ryg" Giesen +// Martins Mozeiko +// Cap Petschulat +// Omar Cornut +// github:aloucks +// Peter LaValle +// Sergey Popov +// Giumo X. Clanjor +// Higor Euripedes +// Thomas Fields +// Derek Vinyard +// +// VERSION HISTORY +// +// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts, num-fonts-in-TTC function +// 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 +// +// This software is dual-licensed to the public domain and under the following +// license: you are granted a perpetual, irrevocable license to copy, modify, +// publish, and distribute this file as you see fit. +// +// USAGE +// +// Include this file in whatever places neeed 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_PackSetOversample() -- 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_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 they 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. +// +// ADVANCED USAGE +// +// Quality: +// +// - Use the functions with Subpixel at the end to allow your characters +// to have subpixel positioning. Since the font is anti-aliased, not +// hinted, this is very import for quality. (This is not possible with +// baked fonts.) +// +// - Kerning is now supported, and if you're supporting subpixel rendering +// then kerning is worth using to give your text a polished look. +// +// Performance: +// +// - Convert Unicode codepoints to glyph indexes and operate on the glyphs; +// if you don't do this, stb_truetype is forced to do the conversion on +// every call. +// +// - There are a lot of memory allocations. We should modify it to take +// a temp buffer and allocate from the temp buffer (without freeing), +// should help performance a lot. +// +// NOTES +// +// The system uses the raw data found in the .ttf file without changing it +// and without building auxiliary data structures. This is a bit inefficient +// on little-endian systems (the data is big-endian), but assuming you're +// caching the bitmaps or glyph shapes this shouldn't be a big deal. +// +// It appears to be very hard to programmatically determine what font a +// given file is in a general way. I provide an API for this, but I don't +// recommend it. +// +// +// SOURCE STATISTICS (based on v0.6c, 2050 LOC) +// +// Documentation & header file 520 LOC \___ 660 LOC documentation +// Sample code 140 LOC / +// Truetype parsing 620 LOC ---- 620 LOC TrueType +// Software rasterization 240 LOC \ . +// Curve tesselation 120 LOC \__ 550 LOC Bitmap creation +// Bitmap management 100 LOC / +// Baked bitmap interface 70 LOC / +// Font name matching & access 150 LOC ---- 150 +// C runtime library abstraction 60 LOC ---- 60 +// +// +// PERFORMANCE MEASUREMENTS FOR 1.06: +// +// 32-bit 64-bit +// Previous release: 8.83 s 7.68 s +// Pool allocations: 7.72 s 6.34 s +// Inline sort : 6.54 s 5.65 s +// New rasterizer : 5.63 s 5.00 s + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +//// +//// SAMPLE PROGRAMS +//// +// +// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless +// +#if 0 +#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation +#include "stb_truetype.h" + +unsigned char ttf_buffer[1<<20]; +unsigned char temp_bitmap[512*512]; + +stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs +GLuint ftex; + +void my_stbtt_initfont(void) +{ + fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb")); + stbtt_BakeFontBitmap(ttf_buffer,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits! + // can free ttf_buffer at this point + glGenTextures(1, &ftex); + glBindTexture(GL_TEXTURE_2D, ftex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512,512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap); + // can free temp_bitmap at this point + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); +} + +void my_stbtt_print(float x, float y, char *text) +{ + // assume orthographic projection with units = screen pixels, origin at top left + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, ftex); + glBegin(GL_QUADS); + while (*text) { + if (*text >= 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.t1); glVertex2f(q.x0,q.y0); + glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0); + glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1); + glTexCoord2f(q.s0,q.t0); 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. + +#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]; + + // #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) + #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(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. + + + +////////////////////////////////////////////////////////////////////////////// +// +// 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, 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, 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_GetPackedQuad(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; + 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 publically 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; // 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. + + +////////////////////////////////////////////////////////////////////////////// +// +// 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 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 + + +////////////////////////////////////////////////////////////////////////////// +// +// 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 countours. 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 + +////////////////////////////////////////////////////////////////////////////// +// +// 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_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_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 + +////////////////////////////////////////////////////////////////////////////// +// +// 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); +} + +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 + + 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; + + // 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; + stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1); + + STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item)); + start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); + if (unicode_codepoint < start) + 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 == -1) { + // 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) 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 if (numberOfContours < 0) { + // @TODO other compound variations? + STBTT_assert(0); + } 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 || b0 > 254)) + return STBTT__CSERR("reserved operator"); + + // push immediate + if (b0 == 255) { + f = (float)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; + *y0 = r ? c.min_y : 0; + *x1 = r ? c.max_x : 0; + *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_GetGlyphKernAdvance(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; +} + +STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2) +{ + if (!info->kern) // 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 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); +} + +////////////////////////////////////////////////////////////////////////////// +// +// 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) + 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 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; + STBTT_assert(x >= 0 && x < len); + scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height; + scanline_fill[x] += e->direction * height; // everything right of this pixel is filled + } else { + int x,x1,x2; + float y_crossing, 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; + } + + x1 = (int) x_top; + x2 = (int) x_bottom; + // compute intersection with y axis at x1+1 + y_crossing = (x1+1 - x0) * dy + y_top; + + sign = e->direction; + // area of the rectangle covered from y0..y_crossing + area = sign * (y_crossing-sy0); + // area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing) + scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2); + + step = sign * dy; + for (x = x1+1; x < x2; ++x) { + scanline[x] += area + step/2; + area += step; + } + y_crossing += dy * (x2 - (x1+1)); + + STBTT_assert(STBTT_fabs(area) <= 1.01f); + + scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (sy1-y_crossing); + + 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 + 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 clear pairs + float y0 = y_top; + float x1 = (float) (x); + float x2 = (float) (x+1); + float x3 = xb; + float y3 = y_bottom; + float y1,y2; + + // x = e->x + e->dx * (y-y_top) + // (y-y_top) = (x - e->x) / e->dx + // y = (x - e->x) / e->dx + y_top + y1 = (x - x0) / dx + y_top; + 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) { + STBTT_assert(z->ey >= scan_y_top); + // 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) +{ + /* threshhold 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; +} + +// tesselate until threshhold 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, *winding_lengths; + 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_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(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; + 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; + + 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; +} + +#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; + + 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); + 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); + ++k; + } + } + + return k; +} + +// 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, 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) { + 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; + } 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, 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, 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_GetPackedQuad(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; + 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; +} + + +////////////////////////////////////////////////////////////////////////////// +// +// 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.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 +// diff --git a/lib/cimgui-1.53.1/menus-api.gif b/lib/cimgui-1.53.1/menus-api.gif new file mode 100644 index 0000000000000000000000000000000000000000..eb2d939066e2abc329edcf0c76750acaa2635f64 GIT binary patch literal 199335 zcmeFZWmKH)vMt)U1`8f65L^O;1W9mrfcP2C%C(l(6^JU^{sEO zv+q9p>~Zh7e{TN(2BR5ty;V=uoHeT+QE?FtPTfuDekex(;58UUMp#inkY7%im5CV! z3IO@l11wY$fEU03`5Ex*ZT^t&m;_8OiQnUpa^k-Jgh#PKhufr6fhYQe}fmEz1@O>p>l>ZXN4hecNIG(4?U7q{QU(q!eIsT0v%3 zUQp~-EUwQOELZ*-HXSU$Ty*B?K70(*J;`1<(=1O^3%gocGjL`Fr& z#Ky%ZBqk-NpgX6hr)Fkl=j7()7Zes1mz1UfE54Og*VNY4H#9bZvaniP-77mSntLGj z4GazqyS9yCbtsc-PIp<2EG#Z9udFVOZ@5j7&x&tvOYO{cH;}KLonKsD6>WUqRNOlh z*?IbLWcj@Rkvb^zwQn?hjQ(~6usaZgVy@a4eI46hZ01IgU5GT=gLE9K2U<+Gn~xeP zT`Kt;Q!uHZq^(3z1_r@FEhyhfpUI1=U zotH==G~fL&Kf@0A;?wbe4gyT29w9-ekPN(k3YPJl1Vg78LdER2R!|8W#`zCRvG(RibXlMJhKl14zt;Ig{8dYaovJZNm*u} zOkgQoQveE6`G_)ECnAL(23R0sBw~51R!H5P5oT{j^{klf@ZEOH!=|}a>oPpUc?T@% z;#Z6H5c=}wEoF>OMC7oEPSD`e;Z`kRS@LbggG0+jKbdQ3)xZy2i_1Y8bk}ozB$eY+ zK3q9KCn7+I2pW#*T?<7E5lYcn{|r3$<-|`TDXT$R>ay#p*zy+T;kSEkIU{WI3@l?O z_06{97muH+C-`0xUoL39`+B=*^5yVaOzz8wb-5x8nPU&JT+~gkhAVeP3yJTjW7Lml zO@}2vJWHoU^BPV4NcHwIixrzMnhiWo{ZH=(Tw#tKCn+6I&n7cSnI89Z-z9VKt?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P(2w`enOy_wlzoSoNWt8)fbcED>UDW;RKxLh z)cgr55)Q~8YZUrSO-pXFi0aua0%Tr5$WWWA^QqoPLa>)whx#8?>&1p+IEgfaE(rN! zZj-ujOiCsJt*U?Q+HNF&*qP)E1lDI!V!9JVhVk~NeX6*l;xyfyk}nxt6xW}`%&5uI zv9f$zB|U$sp=NxLG`Gi&r!b=4kifWb?_s*nV6#tdS2*w;v@FnmrcRc40bvfn6T&kF zqqYw7Y0tUusL!n*snJb7Lnj#x~8gug-fJ zaVx^h$(reWNpU4!6?T!KBSFLVGGFy$q}7ahnLyOK@Ij8rHGh~LM%pB)&>L~f?{7a= zEkwF-J3lM@pe?v4iE%^6dV^PZmd)ZS8rSQdc@**&pxzQ zr_fO;C8mtiOThR6#ux6}p;H9?d4Uky(ztqGqxP_C=w z64ia!Q-`jl`=+W=(FZ?(DdP);``)#(n|j<>-pjqc=3q0DyMdhVwb4CaJHu~YlYgrK0tV#M zs@Us9+OuUhwcSm9-Q>MT3G*Q~va_gdq3|Xt+g@$E+y6MXu-=;S_Nna)(lL`QaWWHe z)!z3Ldnpx>(zhaeF$&)i>5G}f1^n`&akJJ}M=Vg=I^lJ!b+z?mrfnW6DY&>&KOx&f z9)W3XI5|(mPmTmlMJfVXBHv~2V83@D7^aSslkd=@yKjt^{>z!nc(fQ5#|UYBV>`X{ zk+&7M=cw}iiEi5k3YQk(rh)|rChNhH^BbQ2&+TOSPTQM_;gn@rrzgS5aeZ_q;k58n H`j`I!rt?f; literal 0 HcmV?d00001 diff --git a/lib/duktape b/lib/duktape new file mode 120000 index 0000000..5124c61 --- /dev/null +++ b/lib/duktape @@ -0,0 +1 @@ +duktape-2.2.1 \ No newline at end of file diff --git a/lib/duktape-2.2.1/AUTHORS.rst b/lib/duktape-2.2.1/AUTHORS.rst new file mode 100644 index 0000000..8147e99 --- /dev/null +++ b/lib/duktape-2.2.1/AUTHORS.rst @@ -0,0 +1,89 @@ +=============== +Duktape authors +=============== + +Copyright +========= + +Duktape copyrights are held by its authors. Each author has a copyright +to their contribution, and agrees to irrevocably license the contribution +under the Duktape ``LICENSE.txt``. + +Authors +======= + +Please include an e-mail address, a link to your GitHub profile, or something +similar to allow your contribution to be identified accurately. + +The following people have contributed code, website contents, or Wiki contents, +and agreed to irrevocably license their contributions under the Duktape +``LICENSE.txt`` (in order of appearance): + +* Sami Vaarala +* Niki Dobrev +* Andreas Öman +* László Langó +* Legimet +* Karl Skomski +* Bruce Pascoe +* René Hollander +* Julien Hamaide (https://github.com/crazyjul) +* Sebastian Götte (https://github.com/jaseg) +* Tomasz Magulski (https://github.com/magul) +* \D. Bohdan (https://github.com/dbohdan) +* Ondřej Jirman (https://github.com/megous) +* Saúl Ibarra Corretgé +* Jeremy HU +* Ole André Vadla Ravnås (https://github.com/oleavr) +* Harold Brenes (https://github.com/harold-b) +* Oliver Crow (https://github.com/ocrow) +* Jakub Chłapiński (https://github.com/jchlapinski) +* Brett Vickers (https://github.com/beevik) +* Dominik Okwieka (https://github.com/okitec) +* Remko Tronçon (https://el-tramo.be) +* Romero Malaquias (rbsm@ic.ufal.br) +* Michael Drake +* Steven Don (https://github.com/shdon) +* Simon Stone (https://github.com/sstone1) +* \J. McC. (https://github.com/jmhmccr) + +Other contributions +=================== + +The following people have contributed something other than code (e.g. reported +bugs, provided ideas, etc; roughly in order of appearance): + +* Greg Burns +* Anthony Rabine +* Carlos Costa +* Aurélien Bouilland +* Preet Desai (Pris Matic) +* judofyr (http://www.reddit.com/user/judofyr) +* Jason Woofenden +* Michał Przybyś +* Anthony Howe +* Conrad Pankoff +* Jim Schimpf +* Rajaran Gaunker (https://github.com/zimbabao) +* Andreas Öman +* Doug Sanden +* Josh Engebretson (https://github.com/JoshEngebretson) +* Remo Eichenberger (https://github.com/remoe) +* Mamod Mehyar (https://github.com/mamod) +* David Demelier (https://github.com/markand) +* Tim Caswell (https://github.com/creationix) +* Mitchell Blank Jr (https://github.com/mitchblank) +* https://github.com/yushli +* Seo Sanghyeon (https://github.com/sanxiyn) +* Han ChoongWoo (https://github.com/tunz) +* Joshua Peek (https://github.com/josh) +* Bruce E. Pascoe (https://github.com/fatcerberus) +* https://github.com/Kelledin +* https://github.com/sstruchtrup +* Michael Drake (https://github.com/tlsa) +* https://github.com/chris-y +* Laurent Zubiaur (https://github.com/lzubiaur) +* Neil Kolban (https://github.com/nkolban) + +If you are accidentally missing from this list, send me an e-mail +(``sami.vaarala@iki.fi``) and I'll fix the omission. diff --git a/lib/duktape-2.2.1/LICENSE.txt b/lib/duktape-2.2.1/LICENSE.txt new file mode 100644 index 0000000..e849731 --- /dev/null +++ b/lib/duktape-2.2.1/LICENSE.txt @@ -0,0 +1,25 @@ +=============== +Duktape license +=============== + +(http://opensource.org/licenses/MIT) + +Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst) + +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. diff --git a/lib/duktape-2.2.1/Makefile.cmdline b/lib/duktape-2.2.1/Makefile.cmdline new file mode 100644 index 0000000..a5fffb7 --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.cmdline @@ -0,0 +1,47 @@ +# +# Example Makefile for building a program with embedded Duktape. +# The example program here is the Duktape command line tool. +# + +DUKTAPE_SOURCES = src/duktape.c + +CMDLINE_SOURCES = \ + examples/cmdline/duk_cmdline.c + +CC = gcc +CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer +CCOPTS += -I./examples/cmdline -I./src # duktape.h and duk_config.h must be in include path +CCLIBS = -lm + +# Enable print() and alert() for command line using an optional extra module. +CCOPTS += -DDUK_CMDLINE_PRINTALERT_SUPPORT -I./extras/print-alert +CMDLINE_SOURCES += extras/print-alert/duk_print_alert.c + +# Enable console object (console.log() etc) for command line. +CCOPTS += -DDUK_CMDLINE_CONSOLE_SUPPORT -I./extras/console +CMDLINE_SOURCES += extras/console/duk_console.c + +# Enable Duktape.Logger for command line. +CCOPTS += -DDUK_CMDLINE_LOGGING_SUPPORT -I./extras/logging +CMDLINE_SOURCES += extras/logging/duk_logging.c + +# Enable Duktape 1.x module loading for command line. +CCOPTS += -DDUK_CMDLINE_MODULE_SUPPORT -I./extras/module-duktape +CMDLINE_SOURCES += extras/module-duktape/duk_module_duktape.c + +# If you want linenoise, you can enable these. At the moment linenoise +# will cause some harmless compilation warnings. +#CCOPTS += -DDUK_CMDLINE_FANCY -I./linenoise +#CMDLINE_SOURCES += linenoise/linenoise.c +#duk: linenoise + +# Use the tools/configure.py utility to modify Duktape default configuration: +# http://duktape.org/guide.html#compiling +# http://wiki.duktape.org/Configuring.html + +duk: $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) + $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) + +linenoise/linenoise.c: linenoise +linenoise: + git clone https://github.com/antirez/linenoise.git diff --git a/lib/duktape-2.2.1/Makefile.codepage b/lib/duktape-2.2.1/Makefile.codepage new file mode 100644 index 0000000..cdce9ab --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.codepage @@ -0,0 +1,4 @@ +codepage: + gcc -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ + src/duktape.c examples/codepage-conv/duk_codepage_conv.c \ + examples/codepage-conv/test.c -lm diff --git a/lib/duktape-2.2.1/Makefile.coffee b/lib/duktape-2.2.1/Makefile.coffee new file mode 100644 index 0000000..b99eea2 --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.coffee @@ -0,0 +1,4 @@ +dummy: + coffee -c examples/coffee/globals.coffee + coffee -c examples/coffee/hello.coffee + coffee -c examples/coffee/mandel.coffee diff --git a/lib/duktape-2.2.1/Makefile.dukdebug b/lib/duktape-2.2.1/Makefile.dukdebug new file mode 100644 index 0000000..dec6459 --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.dukdebug @@ -0,0 +1,41 @@ +# +# Duktape command line tool with debugger support. +# + +DUKTAPE_SOURCES = prep/duktape.c + +# Windows (MinGW): use examples/debug-trans-socket/duk_trans_socket_windows.c +# and link with -lws2_32. +CMDLINE_SOURCES = \ + examples/cmdline/duk_cmdline.c \ + examples/debug-trans-socket/duk_trans_socket_unix.c + +CC = gcc +CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer +CCOPTS += -I./prep -I./examples/cmdline -I./examples/debug-trans-socket +CCOPTS += -DDUK_CMDLINE_DEBUGGER_SUPPORT # enable --debugger in ./duk +CCLIBS = -lm + +# Enable a few optional modules. +CCOPTS += -DDUK_CMDLINE_PRINTALERT_SUPPORT -I./extras/print-alert +CMDLINE_SOURCES += extras/print-alert/duk_print_alert.c +CCOPTS += -DDUK_CMDLINE_CONSOLE_SUPPORT -I./extras/console +CMDLINE_SOURCES += extras/console/duk_console.c +CCOPTS += -DDUK_CMDLINE_LOGGING_SUPPORT -I./extras/logging +CMDLINE_SOURCES += extras/logging/duk_logging.c +CCOPTS += -DDUK_CMDLINE_MODULE_SUPPORT -I./extras/module-duktape +CMDLINE_SOURCES += extras/module-duktape/duk_module_duktape.c + +# Use tools/configure.py to prepare Duktape config header and sources with +# custom configuration. +duk: $(CMDLINE_SOURCES) + @rm -rf prep + python2 tools/configure.py \ + --source-directory src-input \ + --output-directory prep \ + --config-metadata config \ + -DDUK_USE_DEBUGGER_SUPPORT \ + -DDUK_USE_INTERRUPT_COUNTER \ + -DDUK_USE_DEBUGGER_DUMPHEAP \ + -DDUK_USE_DEBUGGER_INSPECT + $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) diff --git a/lib/duktape-2.2.1/Makefile.eval b/lib/duktape-2.2.1/Makefile.eval new file mode 100644 index 0000000..73c5225 --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.eval @@ -0,0 +1,7 @@ +# +# Example Makefile for building the eval example +# + +eval: + gcc -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ + src/duktape.c examples/eval/eval.c -lm diff --git a/lib/duktape-2.2.1/Makefile.eventloop b/lib/duktape-2.2.1/Makefile.eventloop new file mode 100644 index 0000000..14806ac --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.eventloop @@ -0,0 +1,22 @@ +# +# Example Makefile for building the eventloop example +# + +evloop: + @echo "NOTE: The eventloop is example is intended to be used on Linux" + @echo " or other common UNIX variants. It is not fully portable." + @echo "" + + gcc -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ + examples/eventloop/main.c \ + examples/eventloop/c_eventloop.c \ + examples/eventloop/poll.c \ + examples/eventloop/socket.c \ + examples/eventloop/fileio.c \ + examples/eventloop/ncurses.c \ + src/duktape.c \ + -lm -lncurses + + @echo "" + @echo "NOTE: You must 'cd examples/eventloop' before you execute the" + @echo " eventloop binary: it relies on finding .js files in CWD" diff --git a/lib/duktape-2.2.1/Makefile.hello b/lib/duktape-2.2.1/Makefile.hello new file mode 100644 index 0000000..745fd2c --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.hello @@ -0,0 +1,32 @@ +# +# Example Makefile for building a program with embedded Duktape. +# +# There are two source sets in the distribution: (1) combined sources where +# you only need duktape.c, duktape.h, and duk_config.h, and (2) separate +# sources where you have a bunch of source and header files. Whichever +# you use, simply include the relevant sources into your C project. This +# Makefile uses the combined source file. +# + +DUKTAPE_SOURCES = src/duktape.c + +# Compiler options are quite flexible. GCC versions have a significant impact +# on the size of -Os code, e.g. gcc-4.6 is much worse than gcc-4.5. + +CC = gcc +CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer +CCOPTS += -I./src # for combined sources +CCLIBS = -lm +DEFINES = + +# If you want a 32-bit build on a 64-bit host +#CCOPTS += -m32 + +# Use the tools/configure.py utility to modify Duktape default configuration: +# http://duktape.org/guide.html#compiling +# http://wiki.duktape.org/Configuring.html + +# For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer + +hello: $(DUKTAPE_SOURCES) examples/hello/hello.c + $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS) diff --git a/lib/duktape-2.2.1/Makefile.jxpretty b/lib/duktape-2.2.1/Makefile.jxpretty new file mode 100644 index 0000000..199247e --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.jxpretty @@ -0,0 +1,8 @@ +# +# Example Makefile for building the jxpretty example +# + +jxpretty: + gcc -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ + src/duktape.c examples/jxpretty/jxpretty.c \ + -lm diff --git a/lib/duktape-2.2.1/Makefile.sandbox b/lib/duktape-2.2.1/Makefile.sandbox new file mode 100644 index 0000000..acd922a --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.sandbox @@ -0,0 +1,7 @@ +# +# Example Makefile for building the sandbox example +# + +sandbox: + gcc -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ + src/duktape.c examples/sandbox/sandbox.c -lm diff --git a/lib/duktape-2.2.1/Makefile.sharedlibrary b/lib/duktape-2.2.1/Makefile.sharedlibrary new file mode 100644 index 0000000..ff8f826 --- /dev/null +++ b/lib/duktape-2.2.1/Makefile.sharedlibrary @@ -0,0 +1,71 @@ +# +# Example of how to build and install locally as a shared library +# +# Usage: +# +# $ make -f Makefile.sharedlibrary +# $ sudo make -f Makefile.sharedlibrary install +# $ make -f Makefile.sharedlibrary duk # --> example 'duk' linked to shared libduktape +# +# $ ls -l duk +# -rwxrwxr-x 1 duktape duktape 19407 Nov 30 15:48 duk +# +# $ ldd ./duk +# linux-vdso.so.1 => (0x00007ffd5ed3c000) +# libduktape.so.104 => /usr/local/lib/libduktape.so.104 (0x00007fb2f9753000) +# libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb2f944d000) +# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb2f9088000) +# /lib64/ld-linux-x86-64.so.2 (0x00007fb2f9991000) +# +# Based on: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html + +# Soname version must be bumped whenever a binary compatibility change occurs +# (and should not be bumped when the library is compatible). A simple Duktape +# convention is to set soname version to (100*MAJOR + MINOR), e.g. 104 for +# Duktape 1.4.x, so that it gets automatically bumped for major and minor +# releases (potentially binary incompatible), but not for patch releases. +DUK_VERSION=20201 +SONAME_VERSION=202 +REAL_VERSION=$(SONAME_VERSION).$(DUK_VERSION) + +# Change to actual path for actual distribution packaging. +INSTALL_PREFIX=/usr/local + +# The 'noline' variant may be more appropriate for some distributions; it +# doesn't have #line directives in the combined source. +DUKTAPE_SRCDIR=./src +#DUKTAPE_SRCDIR=./src-noline + +.PHONY: all +all: libduktape.so.$(REAL_VERSION) libduktaped.so.$(REAL_VERSION) + +# If the default duk_config.h is not suitable for the distribution, modify it +# before compiling the shared library and copy the same, edited duk_config.h +# to $INSTALL_PREFIX/include on installation. + +libduktape.so.$(REAL_VERSION): + gcc -shared -fPIC -Wall -Wextra -Os -Wl,-soname,libduktape.so.$(SONAME_VERSION) \ + -o $@ $(DUKTAPE_SRCDIR)/duktape.c + +libduktaped.so.$(REAL_VERSION): + gcc -shared -fPIC -g -Wall -Wextra -Os -Wl,-soname,libduktaped.so.$(SONAME_VERSION) \ + -o $@ $(DUKTAPE_SRCDIR)/duktape.c + +# Symlinks depend on platform conventions. +.PHONY: install +install: libduktape.so.$(REAL_VERSION) libduktaped.so.$(REAL_VERSION) + cp $+ $(INSTALL_PREFIX)/lib/ + rm -f $(INSTALL_PREFIX)/lib/libduktape.so $(INSTALL_PREFIX)/lib/libduktape.so.$(SONAME_VERSION) + ln -s libduktape.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktape.so + ln -s libduktape.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktape.so.$(SONAME_VERSION) + rm -f $(INSTALL_PREFIX)/lib/libduktaped.so $(INSTALL_PREFIX)/lib/libduktaped.so.$(SONAME_VERSION) + ln -s libduktaped.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktaped.so + ln -s libduktaped.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktaped.so.$(SONAME_VERSION) + cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(INSTALL_PREFIX)/include/ + +# Note: assumes /usr/local/include/ and /usr/local/lib/ are in include/link +# path which may not be the case for all distributions. +#CCOPTS=-I/usr/local/include -L/usr/local/lib +CCOPTS=-I./examples/cmdline +duk: + gcc $(CCOPTS) -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm diff --git a/lib/duktape-2.2.1/README.rst b/lib/duktape-2.2.1/README.rst new file mode 100644 index 0000000..0fa1c55 --- /dev/null +++ b/lib/duktape-2.2.1/README.rst @@ -0,0 +1,138 @@ +======= +Duktape +======= + +Duktape is a small and portable Ecmascript E5/E5.1 implementation. It is +intended to be easily embeddable into C programs, with a C API similar in +spirit to Lua's. + +Duktape supports the full E5/E5.1 feature set (with some semantics updated +from ES2015+) including errors, Unicode strings, and regular expressions, +a subset of Ecmascript 2015 (E6) and Ecmascript 2016 (E7) features (e.g. +computed property names, Proxy objects, exponentiation operator, Reflect), +ES2015 ArrayBuffer/TypedView, Node.js Buffer, performance.now(), and WHATWG +Encoding API living standard. + +Duktape also provides a number of custom features such as error tracebacks, +additional data types for better C integration, combined reference counting +and mark-and sweep garbage collector, object finalizers, co-operative +threads a.k.a. coroutines, tail calls, a built-in debugger protocol, function +bytecode dump/load, and so on. Bundled extra modules provide functionality +such as CommonJS module loading and a logging framework. + +You can browse Duktape programmer's API and other documentation at: + +* http://duktape.org/ + +In particular, you should read the getting started section: + +* http://duktape.org/guide.html#gettingstarted + +More examples and how-to articles are in the Duktape Wiki: + +* http://wiki.duktape.org/ + +To build an example command line tool with interactive evaluation (REPL) and +the ability to run script files:: + + $ cd + $ make -f Makefile.cmdline + [...] + + $ ./duk + ((o) Duktape + duk> print('Hello world!'); + Hello world! + = undefined + + $ ./duk mandel.js + [...] + +To integrate Duktape into your program: + +* Use ``tools/configure.py`` to prepare Duktape source and header files + for build:: + + # Duktape options can be customized via command line options. + # In this example, enable "fastint" support and disable ES2015 + # Proxy support + + $ python2 tools/configure.py --output-directory duktape-src \ + -DDUK_USE_FASTINT -UDUK_USE_ES6_PROXY + +* The output directory (duktape-src) will then contain ``duktape.c``, + ``duktape.h``, and ``duk_config.h`` which you include in your build. + +For more details, see: + +* http://duktape.org/guide.html#compiling + +* http://wiki.duktape.org/Configuring.html + +This distributable contains: + +* Pre-configured Duktape header and source files using the Duktape default + configuration: + + * ``src/``: main Duktape library in a "single source file" format (duktape.c, + duktape.h, and duk_config.h). + + * ``src-noline/``: contains a variant of ``src/duktape.c`` with no ``#line`` + directives which is preferable for some users. See discussion in + https://github.com/svaarala/duktape/pull/363. + + * ``src-separate/``: main Duktape library in multiple files format. + +* ``src-input/``: raw input source files used by ``configure.py`` which + recreates the combined/separate prepared sources with specific options. + +* ``tools/``: various Python tools, such as ``configure.py`` for preparing + a ``duk_config.h`` header and Duktape source files for compilation, see + http://wiki.duktape.org/Configuring.html. + +* ``config/``: configuration metadata for ``configure.py``. + +* ``examples/``: further examples for using Duktape. Although Duktape + itself is widely portable, some of the examples are Linux only. + For instance the ``eventloop`` example illustrates how ``setTimeout()`` + and other standard timer functions could be implemented on Unix/Linux. + +* ``extras/``: utilities and modules which don't comfortably fit into the + main Duktape library because of footprint or portability concerns. + Extras are maintained and bug fixed code, but don't have the same version + guarantees as the main Duktape library. + +* ``polyfills/``: a few replacement suggestions for non-standard Javascript + functions provided by other implementations. + +* ``debugger/``: a debugger with a web UI, see ``debugger/README.rst`` and + https://github.com/svaarala/duktape/blob/master/doc/debugger.rst for + details on Duktape debugger support. Also contains a JSON debug proxy + (one written in Node.js and another in DukLuv) to make talking to the + debug target easier. + +* ``licenses/``: licensing information. + +You can find release notes at: + +* https://github.com/svaarala/duktape/blob/master/RELEASES.rst + (summary of all versions) + +* https://github.com/svaarala/duktape/blob/master/doc/release-notes-v2-2.rst + (more detailed notes for this version) + +This distributable contains Duktape version 2.2.1, created from git +commit 25420e773c5fbc50d5b46bf487fc45717e35b94f (v2.2.1). + +Duktape is copyrighted by its authors (see ``AUTHORS.rst``) and licensed +under the MIT license (see ``LICENSE.txt``). String hashing algorithms are +based on the algorithm from Lua (MIT license), djb2 hash, and Murmurhash2 +(MIT license). Pseudorandom number generator algorithms are based on +Adi Shamir's three-op algorithm, xoroshiro128+ (public domain), and SplitMix64 +(public domain). Duktape module loader is based on the CommonJS module +loading specification (without sharing any code), CommonJS is under the MIT +license. + +Have fun! + +Sami Vaarala (sami.vaarala@iki.fi) diff --git a/lib/duktape-2.2.1/config/README.rst b/lib/duktape-2.2.1/config/README.rst new file mode 100644 index 0000000..7be861f --- /dev/null +++ b/lib/duktape-2.2.1/config/README.rst @@ -0,0 +1,19 @@ +================= +Duktape genconfig +================= + +``genconfig`` is a helper script for coming up with a ``duk_config.h`` for +compiling Duktape for your platform. + +To support this: + +* It helps to create a ``duk_config.h`` for your platform/compiler + combination. You can give a base configuration and then force certain + values manually based on a YAML configuration file. + +* It autogenerates documentation for config options based on option metadata + files written in YAML. + +NOTE: ``tools/configure.py`` is now the preferred tool for preparing a config +header (using genconfig.py) and Duktape source files (using other tools) for +build. diff --git a/lib/duktape-2.2.1/config/architectures.yaml b/lib/duktape-2.2.1/config/architectures.yaml new file mode 100644 index 0000000..77efc08 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures.yaml @@ -0,0 +1,63 @@ +# Architecture metadata. + +autodetect: + - + name: x86 + check: DUK_F_X86 + include: architecture_x86.h.in + - + name: x64 + check: DUK_F_X64 + include: architecture_x64.h.in + - + name: x32 + check: DUK_F_X32 + include: architecture_x32.h.in + - + name: ARM 32-bit + check: DUK_F_ARM32 + include: architecture_arm32.h.in + - + name: ARM 64-bit + check: DUK_F_ARM64 + include: architecture_arm64.h.in + - + name: MIPS 32-bit + check: DUK_F_MIPS32 + include: architecture_mips32.h.in + - + name: MIPS 64-bit + check: DUK_F_MIPS64 + include: architecture_mips64.h.in + - + name: PowerPC 32-bit + check: DUK_F_PPC32 + include: architecture_powerpc32.h.in + - + name: PowerPC 64-bit + check: DUK_F_PPC64 + include: architecture_powerpc64.h.in + - + name: SPARC 32-bit + check: DUK_F_SPARC32 + include: architecture_sparc32.h.in + - + name: SPARC 64-bit + check: DUK_F_SPARC64 + include: architecture_sparc64.h.in + - + name: SuperH + check: DUK_F_SUPERH + include: architecture_superh.h.in + - + name: Motorola 68k + check: DUK_F_M68K + include: architecture_m68k.h.in + - + name: Emscripten + check: DUK_F_EMSCRIPTEN + include: architecture_emscripten.h.in + - + name: Generic + check: null + include: architecture_generic.h.in diff --git a/lib/duktape-2.2.1/config/architectures/architecture_arm32.h.in b/lib/duktape-2.2.1/config/architectures/architecture_arm32.h.in new file mode 100644 index 0000000..9232d8d --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_arm32.h.in @@ -0,0 +1,6 @@ +#define DUK_USE_ARCH_STRING "arm32" +/* Byte order varies, so rely on autodetect. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 4 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_arm64.h.in b/lib/duktape-2.2.1/config/architectures/architecture_arm64.h.in new file mode 100644 index 0000000..35ce264 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_arm64.h.in @@ -0,0 +1,6 @@ +#define DUK_USE_ARCH_STRING "arm64" +/* Byte order varies, so rely on autodetect. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_emscripten.h.in b/lib/duktape-2.2.1/config/architectures/architecture_emscripten.h.in new file mode 100644 index 0000000..85160a3 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_emscripten.h.in @@ -0,0 +1,8 @@ +#define DUK_USE_ARCH_STRING "emscripten" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_generic.h.in b/lib/duktape-2.2.1/config/architectures/architecture_generic.h.in new file mode 100644 index 0000000..783f58b --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_generic.h.in @@ -0,0 +1,3 @@ +/* These are necessary wild guesses. */ +#define DUK_USE_ARCH_STRING "generic" +/* Rely on autodetection for byte order, alignment, and packed tval. */ diff --git a/lib/duktape-2.2.1/config/architectures/architecture_m68k.h.in b/lib/duktape-2.2.1/config/architectures/architecture_m68k.h.in new file mode 100644 index 0000000..8c5dc8d --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_m68k.h.in @@ -0,0 +1,8 @@ +#define DUK_USE_ARCH_STRING "m68k" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_mips32.h.in b/lib/duktape-2.2.1/config/architectures/architecture_mips32.h.in new file mode 100644 index 0000000..07eff79 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_mips32.h.in @@ -0,0 +1,6 @@ +#define DUK_USE_ARCH_STRING "mips32" +/* MIPS byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_mips64.h.in b/lib/duktape-2.2.1/config/architectures/architecture_mips64.h.in new file mode 100644 index 0000000..71b18f8 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_mips64.h.in @@ -0,0 +1,6 @@ +#define DUK_USE_ARCH_STRING "mips64" +/* MIPS byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_powerpc32.h.in b/lib/duktape-2.2.1/config/architectures/architecture_powerpc32.h.in new file mode 100644 index 0000000..ebe91cd --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_powerpc32.h.in @@ -0,0 +1,8 @@ +#define DUK_USE_ARCH_STRING "ppc32" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_powerpc64.h.in b/lib/duktape-2.2.1/config/architectures/architecture_powerpc64.h.in new file mode 100644 index 0000000..7abe31b --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_powerpc64.h.in @@ -0,0 +1,8 @@ +#define DUK_USE_ARCH_STRING "ppc64" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_sparc32.h.in b/lib/duktape-2.2.1/config/architectures/architecture_sparc32.h.in new file mode 100644 index 0000000..df6263b --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_sparc32.h.in @@ -0,0 +1,6 @@ +#define DUK_USE_ARCH_STRING "sparc32" +/* SPARC byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_sparc64.h.in b/lib/duktape-2.2.1/config/architectures/architecture_sparc64.h.in new file mode 100644 index 0000000..69ef74c --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_sparc64.h.in @@ -0,0 +1,6 @@ +#define DUK_USE_ARCH_STRING "sparc64" +/* SPARC byte order varies so rely on autodetection. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif +#undef DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_superh.h.in b/lib/duktape-2.2.1/config/architectures/architecture_superh.h.in new file mode 100644 index 0000000..14a8e62 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_superh.h.in @@ -0,0 +1,9 @@ +#define DUK_USE_ARCH_STRING "sh" +/* Byte order varies, rely on autodetection. */ +/* Based on 'make checkalign' there are no alignment requirements on + * Linux SH4, but align by 4 is probably a good basic default. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 4 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_x32.h.in b/lib/duktape-2.2.1/config/architectures/architecture_x32.h.in new file mode 100644 index 0000000..e17c6f2 --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_x32.h.in @@ -0,0 +1,11 @@ +#define DUK_USE_ARCH_STRING "x32" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +/* XXX: This is technically not guaranteed because it's possible to configure + * an x86 to require aligned accesses with Alignment Check (AC) flag. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 1 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_x64.h.in b/lib/duktape-2.2.1/config/architectures/architecture_x64.h.in new file mode 100644 index 0000000..8536bfb --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_x64.h.in @@ -0,0 +1,11 @@ +#define DUK_USE_ARCH_STRING "x64" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +/* XXX: This is technically not guaranteed because it's possible to configure + * an x86 to require aligned accesses with Alignment Check (AC) flag. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 1 +#endif +#undef DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/architectures/architecture_x86.h.in b/lib/duktape-2.2.1/config/architectures/architecture_x86.h.in new file mode 100644 index 0000000..4657a1e --- /dev/null +++ b/lib/duktape-2.2.1/config/architectures/architecture_x86.h.in @@ -0,0 +1,11 @@ +#define DUK_USE_ARCH_STRING "x86" +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +/* XXX: This is technically not guaranteed because it's possible to configure + * an x86 to require aligned accesses with Alignment Check (AC) flag. + */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 1 +#endif +#define DUK_USE_PACKED_TVAL diff --git a/lib/duktape-2.2.1/config/compilers.yaml b/lib/duktape-2.2.1/config/compilers.yaml new file mode 100644 index 0000000..4399cc2 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers.yaml @@ -0,0 +1,35 @@ +# Compiler metadata. + +autodetect: + - + name: Clang + check: DUK_F_CLANG + include: compiler_clang.h.in + - + name: GCC + check: DUK_F_GCC + include: compiler_gcc.h.in + - + name: MSVC + check: DUK_F_MSVC + include: compiler_msvc.h.in + - + name: Emscripten + check: DUK_F_EMSCRIPTEN + include: compiler_emscripten.h.in + - + name: TinyC + check: DUK_F_TINYC + include: compiler_tinyc.h.in + - + name: VBCC + check: DUK_F_VBCC + include: compiler_vbcc.h.in + - + name: Bruce's C compiler + check: DUK_F_BCC + include: compiler_bcc.h.in + - + name: Generic + check: null + include: compiler_generic.h.in diff --git a/lib/duktape-2.2.1/config/compilers/compiler_bcc.h.in b/lib/duktape-2.2.1/config/compilers/compiler_bcc.h.in new file mode 100644 index 0000000..a12bf62 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_bcc.h.in @@ -0,0 +1,24 @@ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "bcc++" +#else +#define DUK_USE_COMPILER_STRING "bcc" +#endif + +/* Most portable */ +#undef DUK_USE_VARIADIC_MACROS + +/* Most portable, wastes space */ +#undef DUK_USE_UNION_INITIALIZERS + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER + +/* BCC, assume we're on x86. */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif diff --git a/lib/duktape-2.2.1/config/compilers/compiler_clang.h.in b/lib/duktape-2.2.1/config/compilers/compiler_clang.h.in new file mode 100644 index 0000000..91f8398 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_clang.h.in @@ -0,0 +1,64 @@ +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +/* C99 / C++11 and above: rely on va_copy() which is required. */ +#define DUK_VA_COPY(dest,src) va_copy(dest,src) +#else +/* Clang: assume we have __va_copy() in non-C99 mode. */ +#define DUK_VA_COPY(dest,src) __va_copy(dest,src) +#endif + +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif +#endif + +#define DUK_USE_BRANCH_HINTS +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unpredictable) +#define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x)) +#endif +#endif + +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +/* DUK_HOT */ +/* DUK_COLD */ + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +#snippet "msvc_visibility.h.in" +#else +#snippet "gcc_clang_visibility.h.in" +#endif + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "clang" +#else +#define DUK_USE_COMPILER_STRING "clang" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS +#define DUK_USE_PACK_CLANG_ATTR diff --git a/lib/duktape-2.2.1/config/compilers/compiler_emscripten.h.in b/lib/duktape-2.2.1/config/compilers/compiler_emscripten.h.in new file mode 100644 index 0000000..dd18700 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_emscripten.h.in @@ -0,0 +1,45 @@ +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif +#endif + +#define DUK_USE_BRANCH_HINTS +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unpredictable) +#define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x)) +#endif +#endif + +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#snippet "gcc_clang_visibility.h.in" + +#define DUK_USE_COMPILER_STRING "emscripten" + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS +#define DUK_USE_PACK_CLANG_ATTR diff --git a/lib/duktape-2.2.1/config/compilers/compiler_gcc.h.in b/lib/duktape-2.2.1/config/compilers/compiler_gcc.h.in new file mode 100644 index 0000000..0a9b7d7 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_gcc.h.in @@ -0,0 +1,84 @@ +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +/* C99 / C++11 and above: rely on va_copy() which is required. */ +#define DUK_VA_COPY(dest,src) va_copy(dest,src) +#else +/* GCC: assume we have __va_copy() in non-C99 mode. */ +#define DUK_VA_COPY(dest,src) __va_copy(dest,src) +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L) +/* since gcc-2.5 */ +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L) +/* since gcc-4.5 */ +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif + +#define DUK_USE_BRANCH_HINTS +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L) +/* GCC: test not very accurate; enable only in relatively recent builds + * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html) + */ +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#endif +/* XXX: equivalent of clang __builtin_unpredictable? */ + +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \ + defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \ + defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40300) +#define DUK_HOT __attribute__((hot)) +#define DUK_COLD __attribute__((cold)) +#endif + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +#snippet "msvc_visibility.h.in" +#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000) +#snippet "gcc_clang_visibility.h.in" +#endif + +#if defined(DUK_F_MINGW) +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "mingw++" +#else +#define DUK_USE_COMPILER_STRING "mingw" +#endif +#else +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "g++" +#else +#define DUK_USE_COMPILER_STRING "gcc" +#endif +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__)) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600) +#define DUK_USE_GCC_PRAGMAS +#else +#undef DUK_USE_GCC_PRAGMAS +#endif + +#define DUK_USE_PACK_GCC_ATTR diff --git a/lib/duktape-2.2.1/config/compilers/compiler_generic.h.in b/lib/duktape-2.2.1/config/compilers/compiler_generic.h.in new file mode 100644 index 0000000..011199c --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_generic.h.in @@ -0,0 +1,24 @@ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "generic-c++" +#else +#define DUK_USE_COMPILER_STRING "generic" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */ +#undef DUK_USE_UNION_INITIALIZERS +#if defined(DUK_F_C99) +#define DUK_USE_UNION_INITIALIZERS +#endif + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER diff --git a/lib/duktape-2.2.1/config/compilers/compiler_msvc.h.in b/lib/duktape-2.2.1/config/compilers/compiler_msvc.h.in new file mode 100644 index 0000000..f1666c9 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_msvc.h.in @@ -0,0 +1,84 @@ +/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */ +#define DUK_NORETURN(decl) __declspec(noreturn) decl + +/* XXX: DUK_UNREACHABLE for msvc? */ + +#undef DUK_USE_BRANCH_HINTS + +/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */ +/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */ + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +#snippet "msvc_visibility.h.in" +#endif + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "msvc++" +#else +#define DUK_USE_COMPILER_STRING "msvc" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) +#define DUK_USE_VARIADIC_MACROS +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) +/* VS2005+ should have variadic macros even when they're not C99. */ +#define DUK_USE_VARIADIC_MACROS +#endif + +#undef DUK_USE_UNION_INITIALIZERS +#if defined(_MSC_VER) && (_MSC_VER >= 1800) +/* VS2013+ supports union initializers but there's a bug involving union-inside-struct: + * https://connect.microsoft.com/VisualStudio/feedback/details/805981 + * The bug was fixed (at least) in VS2015 so check for VS2015 for now: + * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/ + * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too. + */ +#define DUK_USE_UNION_INITIALIZERS +#endif + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS + +#define DUK_USE_PACK_MSVC_PRAGMA + +/* These have been tested from VS2008 onwards; may work in older VS versions + * too but not enabled by default. + */ +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +#define DUK_NOINLINE __declspec(noinline) +#define DUK_INLINE __inline +#define DUK_ALWAYS_INLINE __forceinline +#endif + +#if defined(_MSC_VER) && (_MSC_VER >= 1900) +#define DUK_SNPRINTF snprintf +#define DUK_VSNPRINTF vsnprintf +#else +/* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does + * NOT NUL terminate on truncation, but Duktape code never assumes that. + * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 + */ +#define DUK_SNPRINTF _snprintf +#define DUK_VSNPRINTF _vsnprintf +#endif + +/* Avoid warning when doing DUK_UNREF(some_function). */ +#if defined(_MSC_VER) && (_MSC_VER < 1500) +#pragma warning(disable: 4100 4101 4550 4551) +#define DUK_UNREF(x) +#else +#define DUK_UNREF(x) do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0) +#endif + +/* Older versions of MSVC don't support the LL/ULL suffix. */ +#define DUK_U64_CONSTANT(x) x##ui64 +#define DUK_I64_CONSTANT(x) x##i64 diff --git a/lib/duktape-2.2.1/config/compilers/compiler_tinyc.h.in b/lib/duktape-2.2.1/config/compilers/compiler_tinyc.h.in new file mode 100644 index 0000000..2a33010 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_tinyc.h.in @@ -0,0 +1,18 @@ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "tinyc++" +#else +#define DUK_USE_COMPILER_STRING "tinyc" +#endif + +/* http://bellard.org/tcc/tcc-doc.html#SEC7 */ +#define DUK_USE_VARIADIC_MACROS + +#define DUK_USE_UNION_INITIALIZERS + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER diff --git a/lib/duktape-2.2.1/config/compilers/compiler_vbcc.h.in b/lib/duktape-2.2.1/config/compilers/compiler_vbcc.h.in new file mode 100644 index 0000000..d0eae43 --- /dev/null +++ b/lib/duktape-2.2.1/config/compilers/compiler_vbcc.h.in @@ -0,0 +1,23 @@ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "vbcc-c++" +#else +#define DUK_USE_COMPILER_STRING "vbcc" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +/* VBCC supports C99 so check only for C99 for union initializer support. + * Designated union initializers would possibly work even without a C99 check. + */ +#undef DUK_USE_UNION_INITIALIZERS +#if defined(DUK_F_C99) +#define DUK_USE_UNION_INITIALIZERS +#endif + +#define DUK_USE_FLEX_ZEROSIZE +#define DUK_USE_PACK_DUMMY_MEMBER diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_32BIT_PTRS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_32BIT_PTRS.yaml new file mode 100644 index 0000000..d2214e0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_32BIT_PTRS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_32BIT_PTRS +introduced: 1.0.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Pointers are 32-bit integer compatible. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_64BIT_OPS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_64BIT_OPS.yaml new file mode 100644 index 0000000..31fa1d4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_64BIT_OPS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_64BIT_OPS +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Use 64-bit integer operations. On some platforms 64-bit types may be + available but 64-bit operations don't work correctly e.g. in integer/float + casts. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_4.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_4.yaml new file mode 100644 index 0000000..1cce360 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_4.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_ALIGN_4 +introduced: 1.0.0 +removed: 1.3.0 +related: + - DUK_USE_ALIGN_BY +default: false +tags: + - portability +description: > + Use 4-byte alignment for 64-bit integers and IEEE doubles. + Replaced by DUK_USE_ALIGN_BY. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_8.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_8.yaml new file mode 100644 index 0000000..3b3c955 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_8.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_ALIGN_8 +introduced: 1.0.0 +removed: 1.3.0 +related: + - DUK_USE_ALIGN_BY +default: false +tags: + - portability +description: > + Use 8-byte alignment for 64-bit integers and IEEE doubles. + Replaced by DUK_USE_ALIGN_BY. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_BY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_BY.yaml new file mode 100644 index 0000000..bed2f50 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ALIGN_BY.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_ALIGN_BY +introduced: 1.3.0 +default: 8 +tags: + - portability +description: > + Use N-byte alignment for 64-bit integers and IEEE doubles + (supported values are 1, 4, and 8). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ARCH_STRING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARCH_STRING.yaml new file mode 100644 index 0000000..65b22c5 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARCH_STRING.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_ARCH_STRING +introduced: 1.0.0 +default: + string: "unknown" +tags: + - portability +description: > + Human-readable architecture string used in e.g. Duktape.env and debugger + protocol (example: x64). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_BUILTIN.yaml new file mode 100644 index 0000000..0ca01f1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ARRAY_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide an Array built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_FASTPATH.yaml new file mode 100644 index 0000000..d223ab7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_FASTPATH.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_ARRAY_FASTPATH +introduced: 2.0.0 +default: true +tags: + - performance + - fastpath + - lowmemory + - compliance +description: > + Enable fast path for Array.prototype operations like push(), pop(), etc. + The fast path handles dense Array instances which are more common than + sparse arrays or non-array objects (which Array.prototype operations must + also support). The fast path assumes that Array.prototype doesn't contain + inherited index properties; such properties are very rarely used in + practical code. If compliance is critical, disable the fast path. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_PROP_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_PROP_FASTPATH.yaml new file mode 100644 index 0000000..3b74c8a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ARRAY_PROP_FASTPATH.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_ARRAY_PROP_FASTPATH +introduced: 2.0.0 +default: true +tags: + - performance + - fastpath + - lowmemory + - compliance +description: > + Enable a shallow fast path check for Array index property reads and writes. + The fast path assumes Array.prototype doesn't have numeric index properties + which would be inherited and affect read/write behavior. This behavior is + non-compliant (but practical because such inherited properties are very + rare). Disable this option to ensure strict compliance. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ASSERTIONS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ASSERTIONS.yaml new file mode 100644 index 0000000..1f0cfe8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ASSERTIONS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_ASSERTIONS +introduced: 1.0.0 +default: false +tags: + - development + - debug +description: > + Enable internal assert checks. These slow down execution considerably + so only use when debugging. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ATAN2_WORKAROUNDS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ATAN2_WORKAROUNDS.yaml new file mode 100644 index 0000000..8ce15ea --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ATAN2_WORKAROUNDS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_ATAN2_WORKAROUNDS +introduced: 2.0.0 +default: false +tags: + - portability +description: > + Enable workarounds to common atan2() semantics issues. At least Cygwin/MinGW + has such issues, see test-bug-mingw-math-issues.js. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_CREATE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_CREATE.yaml new file mode 100644 index 0000000..84121f3 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_CREATE.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_AUGMENT_ERROR_CREATE +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Augment an Ecmascript error object at creation with tracedata or + fileName/lineNumber, or Duktape.errCreate (if enabled). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_THROW.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_THROW.yaml new file mode 100644 index 0000000..1244197 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_AUGMENT_ERROR_THROW.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_AUGMENT_ERROR_THROW +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Augment an Ecmascript error object at throw time with Duktape.errThrow + (if enabled). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_AVOID_PLATFORM_FUNCPTRS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_AVOID_PLATFORM_FUNCPTRS.yaml new file mode 100644 index 0000000..cbde8c6 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_AVOID_PLATFORM_FUNCPTRS.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_AVOID_PLATFORM_FUNCPTRS +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Don't assume that platform functions (e.g. math functions) are actual + functions. This option is needed if platform functions may be defined + as macros. This is certainly the case with some platform "polyfills" + which provide missing C99/C++11 functions through macros, and may be + the case with VS2013 (see GH-17). + + This is now the default: the cost in footprint is negligible. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BASE64_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BASE64_FASTPATH.yaml new file mode 100644 index 0000000..7c6f48d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BASE64_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_BASE64_FASTPATH +introduced: 1.4.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for base64 encode/decode. The fast path uses a lookup + table at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BOOLEAN_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BOOLEAN_BUILTIN.yaml new file mode 100644 index 0000000..0ac5176 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BOOLEAN_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_BOOLEAN_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide a Boolean built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BRANCH_HINTS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BRANCH_HINTS.yaml new file mode 100644 index 0000000..7a1a5cf --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BRANCH_HINTS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_BRANCH_HINTS +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Use branch hints if the compiler supports them. + +# FIXME: unused now? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BROWSER_LIKE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BROWSER_LIKE.yaml new file mode 100644 index 0000000..79d37ef --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BROWSER_LIKE.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_BROWSER_LIKE +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide browser-like bindings: currently print() and alert(). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BUFFEROBJECT_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BUFFEROBJECT_SUPPORT.yaml new file mode 100644 index 0000000..3674752 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BUFFEROBJECT_SUPPORT.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_BUFFEROBJECT_SUPPORT +introduced: 1.3.0 +default: true +tags: + - ecmascript2015 +description: > + Enable support for Khronos/ES6 typed arrays and Node.js Buffer objects. + + When disabled, Duktape custom plain buffer type is present and functional + in the C API. Plain buffers have virtual properties and you can read/write + buffer contents in Ecmascript code. Plain buffers will still inherit from + ArrayBuffer.prototype, but none of the Ecmascript buffer related bindings + will work. This includes all ArrayBuffer, typed array, and Node.js Buffer + methods. Native bindings which produce plain buffer results (like + Duktape.dec()) will still work. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BUFLEN16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BUFLEN16.yaml new file mode 100644 index 0000000..1e40f4b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BUFLEN16.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_BUFLEN16 +introduced: 1.1.0 +default: false +tags: + - lowmemory + - experimental +description: > + Use a 16-bit buffer length field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BUILTIN_INITJS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BUILTIN_INITJS.yaml new file mode 100644 index 0000000..63d4b61 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BUILTIN_INITJS.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_BUILTIN_INITJS +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - ecmascript +description: > + Use built-in .js init code when creating a new global context. + The .js init code (duk_initjs.js) provides some initialization + code that's nicer to implement in Ecmascript, and is also used + to provide some backwards compatibility bindings which are easy + to remove later. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTECODE_DUMP_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTECODE_DUMP_SUPPORT.yaml new file mode 100644 index 0000000..0662fa3 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTECODE_DUMP_SUPPORT.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_BYTECODE_DUMP_SUPPORT +introduced: 1.3.0 +default: true +tags: + - api +description: > + Enable support for API calls to dump/load function bytecode. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER.yaml new file mode 100644 index 0000000..75a08d7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_BYTEORDER +introduced: 1.4.0 +default: 0 # no reasonable automatic default +tags: + - portability +description: > + Byte order for platform: 1 = little endian, 2 = mixed (arm hybrid) endian, + 3 = big endian. + + ARM mixed endian means integers are little endian but IEEE doubles have + mixed endianness: big endian bytes 12345678 are ordered in memory as + 43218765. + + (This define should be produced by duk_config.h; currently Duktape internals + use automatically derived defines DUK_USE_{INTEGER,DOUBLE}_{LE,BE_ME} + instead of using this define directly.) diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER_FORCED.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER_FORCED.yaml new file mode 100644 index 0000000..c31fe66 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_BYTEORDER_FORCED.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_BYTEORDER_FORCED +introduced: 1.0.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Byte order was forced (instead of being autodetected). This has no + functional impact but the forced status shows up in Duktape.env. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_ACTIVATION.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_ACTIVATION.yaml new file mode 100644 index 0000000..6c22b56 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_ACTIVATION.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_CACHE_ACTIVATION +introduced: 2.2.0 +default: true +tags: + - performance +description: > + Cache duk_activation records. When releasing a duk_activation, place it in + a free list for later reuse. Mark-and-sweep frees the free list to keep + memory usage in check. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_CATCHER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_CATCHER.yaml new file mode 100644 index 0000000..d16627d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_CACHE_CATCHER.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_CACHE_CATCHER +introduced: 2.2.0 +default: true +tags: + - performance +description: > + Cache duk_catcher records. When releasing a duk_catcher, place it in + a free list for later reuse. Mark-and-sweep frees the free list to keep + memory usage in check. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_CALLSTACK_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_CALLSTACK_LIMIT.yaml new file mode 100644 index 0000000..a2c154c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_CALLSTACK_LIMIT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_CALLSTACK_LIMIT +introduced: 2.2.0 +default: 10000 +tags: + - misc +description: > + Maximum call stack size. If call stack would grow beyond this value, reject + the call in progress. This mainly protects against runaway recursion. Note + in particular that this limit is unrelated to the native C stack size which + has a separate limit define. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_COMMONJS_MODULES.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMMONJS_MODULES.yaml new file mode 100644 index 0000000..7972f39 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMMONJS_MODULES.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_COMMONJS_MODULES +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Enable support for CommonJS modules. When enabled, the global require() + function provides a simple module loader facility which depends on the user + providing low level module searching functionality. When disabled, the + global require() function is present but throws an error. + +# FIXME: change so that global is missing if disabled? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_RECLIMIT.yaml new file mode 100644 index 0000000..d6a61df --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_RECLIMIT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_COMPILER_RECLIMIT +introduced: 1.3.0 +default: 2500 +tags: + - portability + - cstackdepth +description: > + Ecmascript compiler native call stack recursion limit. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_STRING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_STRING.yaml new file mode 100644 index 0000000..2f47b01 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPILER_STRING.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_COMPILER_STRING +introduced: 1.0.0 +default: + string: "unknown" +tags: + - portability +description: > + Human-readable compiler string used in e.g. Duktape.env and debugger + protocol (example: gcc). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_INFINITY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_INFINITY.yaml new file mode 100644 index 0000000..c59fd45 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_INFINITY.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_COMPUTED_INFINITY +introduced: 1.0.0 +default: false +tags: + - portability +description: > + The DUK_DOUBLE_INFINITY is not a constant but refers to a global variable + with an IEEE double infinity value computed at run-time. Some compilers + don't provide a constant for infinity, and may incorrectly evaluate + (1 / 0) when doing constant folding. + + When enabled, define DUK_DOUBLE_INFINITY as duk_computed_infinity. + +# FIXME: remove computed infinity from Duktape itself and let user +# provide it instead? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_NAN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_NAN.yaml new file mode 100644 index 0000000..a432744 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_COMPUTED_NAN.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_COMPUTED_NAN +introduced: 1.0.0 +default: false +tags: + - portability +description: > + The DUK_DOUBLE_NAN is not a constant but refers to a global variable with + an IEEE NaN value computed at run-time. Some compilers don't provide a + constant for NaN, and may incorrectly evaluate (0 / 0) when doing + constant folding. + + When enabled, define DUK_DOUBLE_NAN as duk_computed_nan. + +# FIXME: remove computed NaN from Duktape itself and let user provide +# it instead? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_COROUTINE_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_COROUTINE_SUPPORT.yaml new file mode 100644 index 0000000..e608bdf --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_COROUTINE_SUPPORT.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_COROUTINE_SUPPORT +introduced: 2.0.0 +default: true +tags: + - execution +description: > + Enable support for Duktape coroutines, i.e. yield/resume. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_CPP_EXCEPTIONS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_CPP_EXCEPTIONS.yaml new file mode 100644 index 0000000..c735666 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_CPP_EXCEPTIONS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_CPP_EXCEPTIONS +introduced: 1.4.0 +default: false +tags: + - portability +description: > + Use C++ exceptions instead of setjmp/longjmp for long control transfers. + This allows Duktape/C functions written in C++ to use automatic destructors + (RAII or scope-based resource management). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR16.yaml new file mode 100644 index 0000000..5c424ce --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR16.yaml @@ -0,0 +1,21 @@ +define: DUK_USE_DATAPTR16 +introduced: 1.1.0 +related: + - DUK_USE_DATAPTR_ENC16 + - DUK_USE_DATAPTR_DEC16 +default: false +tags: + - lowmemory + - experimental +description: > + Enable "compression" of arbitrary data pointers into an unsigned 16-bit + value. Use together with DUK_USE_DATAPTR_ENC16 and DUK_USE_DATAPTR_DEC16. + + Pointers compressed are any void pointers in C code, not just the Duktape + heap. Also NULL pointer must encode and decode correctly. + + Currently it is required that NULL encodes to integer 0, and integer + 0 decodes to NULL. No other pointer can be encoded to 0. + + NOTE: This feature option is currently unimplemented, i.e. Duktape won't + compress any data pointers at the moment. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_DEC16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_DEC16.yaml new file mode 100644 index 0000000..1cdf2ec --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_DEC16.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_DATAPTR_DEC16 +introduced: 1.1.0 +requires: + - DUK_USE_DATAPTR16 +default: false +tags: + - lowmemory + - experimental +description: > + Use together with DUK_USE_DATAPTR16 for arbitrary data pointer compression. + DUK_USE_DATAPTR_DEC16(udata,x) is a macro with a userdata and duk_uint16_t + argument, and a void ptr return value. The userdata argument is the heap + userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_ENC16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_ENC16.yaml new file mode 100644 index 0000000..988e6b7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATAPTR_ENC16.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_DATAPTR_ENC16 +introduced: 1.1.0 +requires: + - DUK_USE_DATAPTR16 +default: false +tags: + - lowmemory + - experimental +description: > + Use together with DUK_USE_DATAPTR16 for arbitrary data pointer compression. + DUK_USE_DATAPTR_ENC16(udata,p) is a macro with a userdata and void ptr + argument, and a duk_uint16_t return value. The userdata argument is the + heap userdata value given at heap creation. Currently it is required that + NULL encodes to integer 0, and integer 0 decodes to NULL. No other pointer + can be encoded to 0. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_BUILTIN.yaml new file mode 100644 index 0000000..f233b4a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_DATE_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide a Date built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FMT_STRFTIME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FMT_STRFTIME.yaml new file mode 100644 index 0000000..eed38c5 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FMT_STRFTIME.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_DATE_FMT_STRFTIME +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use strftime() to format Date values in native, platform specific format + before falling back into ISO 8601. When enabled, appropriate date/time + headers must be included. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FORMAT_STRING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FORMAT_STRING.yaml new file mode 100644 index 0000000..6146b5e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_FORMAT_STRING.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DATE_FORMAT_STRING +introduced: 1.3.0 +default: false +tags: + - date + - portability +description: > + Optional macro for formatting a date in a platform dependent manner, + see datetime.rst. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_LOCAL_TZOFFSET.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_LOCAL_TZOFFSET.yaml new file mode 100644 index 0000000..572f3c4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_LOCAL_TZOFFSET.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DATE_GET_LOCAL_TZOFFSET +introduced: 1.3.0 +default: false +tags: + - date + - portability +description: > + Mandatory macro for getting the local time offset for a given datetime, + see datetime.rst. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_NOW.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_NOW.yaml new file mode 100644 index 0000000..b89d9b0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_GET_NOW.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_DATE_GET_NOW +introduced: 1.3.0 +default: false +tags: + - date + - portability +description: > + Mandatory macro for getting the current time, see datetime.rst. The macro + is allowed (and recommended) to return millisecond fractions. The fractions + are truncated by the Date built-in, but are available via duk_get_now() C + API call. + + If the time provided experiences time jumps or doesn't advance in realtime + (which is useful in some time virtualization scenarios), consider defining + DUK_USE_GET_MONOTONIC_TIME. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_GETTIMEOFDAY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_GETTIMEOFDAY.yaml new file mode 100644 index 0000000..6d0d7ee --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_GETTIMEOFDAY.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DATE_NOW_GETTIMEOFDAY +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use gettimeofday() to get current datetime. When enabled, appropriate + date/time headers must be included. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_TIME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_TIME.yaml new file mode 100644 index 0000000..107d750 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_TIME.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_DATE_NOW_TIME +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use time() to get current datetime, with the limitation that datetime is + limited to one second resolution. When enabled, appropriate date/time + headers must be included. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS.yaml new file mode 100644 index 0000000..de24e39 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_DATE_NOW_WINDOWS +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use Win32 API calls to get current datetime. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS_SUBMS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS_SUBMS.yaml new file mode 100644 index 0000000..bb5b77f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_NOW_WINDOWS_SUBMS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DATE_NOW_WINDOWS_SUBMS +introduced: 2.2.0 +default: false +tags: + - date + - portability +description: > + Like DUK_USE_DATE_NOW_WINDOWS but use GetSystemTimePreciseAsFileTime(), + available since Windows 8, for sub-millisecond resolution. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PARSE_STRING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PARSE_STRING.yaml new file mode 100644 index 0000000..7fe0ac2 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PARSE_STRING.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DATE_PARSE_STRING +introduced: 1.3.0 +default: false +tags: + - date + - portability +description: > + Optional macro for parsing a date in a platform dependent manner, + see datetime.rst. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_GETDATE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_GETDATE.yaml new file mode 100644 index 0000000..c3d0b11 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_GETDATE.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_DATE_PRS_GETDATE +introduced: 1.3.0 +default: false +tags: + - date + - portability +description: > + Use getdate_r() to parse a platform specific datetime string into Ecmascript + time. getdate_r() depends on DATEMSK being set so this is not always very + convenient for an embedded interpreter. When enabled, appropriate date/time + headers must be included. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_STRPTIME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_STRPTIME.yaml new file mode 100644 index 0000000..6fe041e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_PRS_STRPTIME.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DATE_PRS_STRPTIME +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use strptime() to parse a platform specific datetime string into Ecmascript + time. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME.yaml new file mode 100644 index 0000000..1386e9b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_DATE_TZO_GMTIME +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use gmtime() to get local time offset at a certain time. + When enabled, appropriate date/time headers must be included. + + Since gmtime() is not re-entrant, this is not thread safe. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_R.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_R.yaml new file mode 100644 index 0000000..d1289c2 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_R.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DATE_TZO_GMTIME_R +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use gmtime_r() to get local time offset at a certain time. + When enabled, appropriate date/time headers must be included. + +# FIXME: add an include file metadata entry to cause default #include +# directives to be emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_S.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_S.yaml new file mode 100644 index 0000000..13779e7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_GMTIME_S.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_DATE_TZO_GMTIME_S +introduced: 2.0.0 +default: false +tags: + - date + - portability +description: > + Use gmtime_s() to get local time offset at a certain time. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS.yaml new file mode 100644 index 0000000..dbfa9a8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_DATE_TZO_WINDOWS +introduced: 1.0.0 +default: false +tags: + - date + - portability +description: > + Use Win32 API calls to get local time offset at a certain time. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS_NO_DST.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS_NO_DST.yaml new file mode 100644 index 0000000..f0639da --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DATE_TZO_WINDOWS_NO_DST.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DATE_TZO_WINDOWS_NO_DST +introduced: 2.0.1 +default: false +tags: + - date + - portability +description: > + Use Win32 API calls to get local time offset at a certain time. + Does not take into account daylight savings time. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DDDPRINT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DDDPRINT.yaml new file mode 100644 index 0000000..5dc055d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DDDPRINT.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DDDPRINT +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - debug +description: > + Enable even more debug printouts. Not recommended unless you have + grep handy. Replaced by DUK_USE_DEBUG_LEVEL. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DDPRINT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DDPRINT.yaml new file mode 100644 index 0000000..6406f0f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DDPRINT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_DDPRINT +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - debug +description: > + Enable more debug printouts. Replaced by DUK_USE_DEBUG_LEVEL. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG.yaml new file mode 100644 index 0000000..09b9785 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_DEBUG +introduced: 1.0.0 +default: false +tags: + - debug +description: > + Enable debug code in Duktape internals. Without this option other + debugging options (such as DUK_USE_DEBUG_LEVEL and DUK_USE_DEBUG_WRITE) + have no effect. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_DUMPHEAP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_DUMPHEAP.yaml new file mode 100644 index 0000000..ef9c8d8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_DUMPHEAP.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DEBUGGER_DUMPHEAP +introduced: 1.2.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +default: false +tags: + - debugger +description: > + Support the DumpHeap command. This is optional because the command is not + always needed. The command also has a relatively large footprint (about + 10% of debugger code); in absolute terms it's about 1kB of code footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_LOGGING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_LOGGING.yaml new file mode 100644 index 0000000..66fc0d9 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_LOGGING.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_DEBUGGER_FWD_LOGGING +introduced: 1.2.0 +removed: 2.0.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +default: false +tags: + - debugger +description: > + Forward log writes using the built-in logging framework to the debug client. + Forwarding happens from the Duktape.Logger.prototype.info() etc calls before + the raw() function is called, so that logging is forwarded even if you + replace the backend. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_PRINTALERT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_PRINTALERT.yaml new file mode 100644 index 0000000..842e541 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_FWD_PRINTALERT.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DEBUGGER_FWD_PRINTALERT +introduced: 1.2.0 +removed: 2.0.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +default: false +tags: + - debugger +description: > + Forward calls to the built-in print() and alert() function to the debug + client. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_INSPECT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_INSPECT.yaml new file mode 100644 index 0000000..299e14d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_INSPECT.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_DEBUGGER_INSPECT +introduced: 1.5.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +default: false +tags: + - debugger +description: > + Support debugger heap object inspection commands GetHeapObjInfo, + GetObjPropDesc, GetObjPropDescRange. These are optional because the + commands have a relatively high code footprint (about 3kB) and are not + always needed. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_PAUSE_UNCAUGHT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_PAUSE_UNCAUGHT.yaml new file mode 100644 index 0000000..250d0d1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_PAUSE_UNCAUGHT.yaml @@ -0,0 +1,17 @@ +define: DUK_USE_DEBUGGER_PAUSE_UNCAUGHT +introduced: 1.4.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +related: + - DUK_USE_DEBUGGER_THROW_NOTIFY +default: false +tags: + - debugger +description: > + Pause automatically when an error is about to be thrown and that error is + (most likely) not going to be caught. An error is considered uncaught if + there is no active catch clause in the current thread or in the current + thread's resumer chain. This is not 100% accurate because there may be a + finally clause which neutralizes the throw (e.g. converts it to a "return" + or a "continue"). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_SUPPORT.yaml new file mode 100644 index 0000000..a67ac73 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_SUPPORT.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_DEBUGGER_SUPPORT +introduced: 1.2.0 +requires: + - DUK_USE_INTERRUPT_COUNTER +default: false +tags: + - debugger +description: > + Enable support for Duktape debug protocol (see doc/debugger.rst) and the + debug API calls (duk_debugger_attach(), duk_debugger_detach(), etc). + This adds about 10kB of code footprint at the moment. + + This option requires DUK_USE_INTERRUPT_COUNTER. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_THROW_NOTIFY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_THROW_NOTIFY.yaml new file mode 100644 index 0000000..b323e60 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_THROW_NOTIFY.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_DEBUGGER_THROW_NOTIFY +introduced: 1.4.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +related: + - DUK_USE_DEBUGGER_PAUSE_UNCAUGHT +default: true +tags: + - debugger +description: > + Send a Throw notify when an error is about to be thrown. The Throw notify + also indicates if an error is fatal (most likely not caught) which is very + useful in debugging. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_TRANSPORT_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_TRANSPORT_TORTURE.yaml new file mode 100644 index 0000000..70a0f35 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUGGER_TRANSPORT_TORTURE.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_DEBUGGER_TRANSPORT_TORTURE +introduced: 1.2.0 +# Option is ignored unless debugger support is enabled. +#requires: +# - DUK_USE_DEBUGGER_SUPPORT +default: false +tags: + - debugger + - development + - torture +description: > + Development time option: force debugger transport torture. Concretely this + now causes Duktape to read/write debug protocol data in 1-byte increments, + which stresses message parsing and transport code. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_BUFSIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_BUFSIZE.yaml new file mode 100644 index 0000000..1d93415 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_BUFSIZE.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DEBUG_BUFSIZE +introduced: 1.0.0 +related: # not strictly required, value is defined even when DUK_USE_DEBUG not defined + - DUK_USE_DEBUG +default: 65536 +tags: + - debug +description: > + Debug code uses a static buffer as a formatting temporary to avoid side + effects in debug prints. The static buffer is large by default, which + may be an issue in constrained environments. You can set the buffer size + manually with this option, e.g. set DUK_USE_DEBUG_BUFSIZE to 2048. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_LEVEL.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_LEVEL.yaml new file mode 100644 index 0000000..aa0265e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_LEVEL.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_DEBUG_LEVEL +introduced: 2.0.0 +default: 0 +tags: + - debug +description: > + Set debug print level when DUK_USE_DEBUG is enabled. The level can be + 0 (minimal), 1 (verbose), 2 (very verbose). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_WRITE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_WRITE.yaml new file mode 100644 index 0000000..46599be --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEBUG_WRITE.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_DEBUG_WRITE +introduced: 2.0.0 +default: false +tags: + - debug +description: > + Macro used for Duktape debug log writes (when DUK_USE_DEBUG is enabled). + There's no default provider to avoid a dependency on platform I/O calls. + The macro is called like a function with the following prototype: + "void DUK_USE_DEBUG_WRITE(long level, const char *file, long line, const char *func, const char *msg)". + The "file", "func", and "msg" arguments are non-NULL strings, though NULLs + should be handled as good practice (it's ultimately up to duk_config.h + whether NULL values are possible). + + See http://wiki.duktape.org/HowtoDebugPrints.html for more information + and examples. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DEEP_C_STACK.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEEP_C_STACK.yaml new file mode 100644 index 0000000..82de994 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DEEP_C_STACK.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_DEEP_C_STACK +introduced: 1.0.0 +removed: 1.3.0 +default: true +tags: + - portability +description: > + Assume deep C stacks are not an issue on the target platform; on some + embedded platforms the native C stack is very limited (e.g. 32-64 kB) + and overrunning the stack leads to difficult-to-diagnose problems. + + Removed in Duktape 1.3.0, replaced by explicit recursion limits. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_BE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_BE.yaml new file mode 100644 index 0000000..a63d9d9 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_BE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_DOUBLE_BE +introduced: 1.0.0 +removed: 1.4.0 +default: false +conflicts: + - DUK_USE_DOUBLE_LE + - DUK_USE_DOUBLE_ME +tags: + - portability +description: > + IEEE double memory representation is big endian on the target platform. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LE.yaml new file mode 100644 index 0000000..fcbcbc0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_DOUBLE_LE +introduced: 1.0.0 +removed: 1.4.0 +default: true +conflicts: + - DUK_USE_DOUBLE_BE + - DUK_USE_DOUBLE_ME +tags: + - portability +description: > + IEEE double memory representation is little endian on the target platform. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LINKED_HEAP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LINKED_HEAP.yaml new file mode 100644 index 0000000..eda0052 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_LINKED_HEAP.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_DOUBLE_LINKED_HEAP +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Use a double-linked duk_heaphdr structure. Required when reference + counting is enabled. + +# FIXME: this must currently always match DUK_USE_REFERENCE_COUNTING +# so remove as a separate option? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_ME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_ME.yaml new file mode 100644 index 0000000..61a4cda --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DOUBLE_ME.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_DOUBLE_ME +introduced: 1.0.0 +removed: 1.4.0 +default: false +conflicts: + - DUK_USE_DOUBLE_LE + - DUK_USE_DOUBLE_BE +tags: + - portability +description: > + IEEE double memory representation is mixed endian on the target platform. + In other words the logical bytes ABCDEFGH are represented in memory as + DCBAHGFE. This endianness is used by some ARM platforms. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT.yaml new file mode 100644 index 0000000..0895eb6 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_DPRINT +introduced: 1.0.0 +removed: 2.0.0 +requires: + - DUK_USE_DEBUG +default: false +tags: + - debug +description: > + Enable debug printouts. Replaced by DUK_USE_DEBUG_LEVEL. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_COLORS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_COLORS.yaml new file mode 100644 index 0000000..e1b65f1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_COLORS.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_DPRINT_COLORS +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - debug +description: > + Enable coloring of debug prints with ANSI escape codes + (http://en.wikipedia.org/wiki/ANSI_escape_code). The behavior is not + sensitive to terminal settings. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_RDTSC.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_RDTSC.yaml new file mode 100644 index 0000000..e154585 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DPRINT_RDTSC.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_DPRINT_RDTSC +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - debug +description: > + Print RDTSC cycle count in debug prints if available. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_DUKTAPE_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_DUKTAPE_BUILTIN.yaml new file mode 100644 index 0000000..c36aebf --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_DUKTAPE_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_DUKTAPE_BUILTIN +introduced: 2.0.0 +default: true +tags: + - duktape +description: > + Provide a Duktape built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ENCODING_BUILTINS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ENCODING_BUILTINS.yaml new file mode 100644 index 0000000..8c860e7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ENCODING_BUILTINS.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_ENCODING_BUILTINS +introduced: 2.0.0 +default: true +tags: + - encoding-api +description: > + Provide TextEncoder and TextDecoder built-ins (the Encoding API) which allow + Ecmascript code to encode and decode text stored in a buffer. Only UTF-8 is + currently supported for decoding. + + DUK_USE_BUFFEROBJECT_SUPPORT is recommended but not required: If it is + disabled, TextEncoder will encode to a plain buffer instead of a Uint8Array. + TextDecoder always accepts plain buffers as input. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ERRCREATE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ERRCREATE.yaml new file mode 100644 index 0000000..a25b3b8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ERRCREATE.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_ERRCREATE +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Call Duktape.errCreate() when augmenting an Ecmascript error object + being created. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ERRTHROW.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ERRTHROW.yaml new file mode 100644 index 0000000..f9d5b19 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ERRTHROW.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_ERRTHROW +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Call Duktape.errThrow() when augmenting an Ecmascript error object + about to be thrown. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6.yaml new file mode 100644 index 0000000..886fe9b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES6 +introduced: 2.0.0 +default: true +tags: + - ecmascript2015 +description: > + Enable ES6 functionality not covered by other specific config options. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_PROTO_PROPERTY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_PROTO_PROPERTY.yaml new file mode 100644 index 0000000..d0279d4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_PROTO_PROPERTY.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES6_OBJECT_PROTO_PROPERTY +introduced: 1.0.0 +default: true +tags: + - ecmascript2015 +description: > + Provide the non-standard (ES6) Object.prototype.__proto__ property. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_SETPROTOTYPEOF.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_SETPROTOTYPEOF.yaml new file mode 100644 index 0000000..04b29fb --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_OBJECT_SETPROTOTYPEOF.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES6_OBJECT_SETPROTOTYPEOF +introduced: 1.0.0 +default: true +tags: + - ecmascript2015 +description: > + Provide the non-standard (ES6) Object.setPrototypeOf method. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_PROXY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_PROXY.yaml new file mode 100644 index 0000000..e05952c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_PROXY.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES6_PROXY +introduced: 1.0.0 +default: true +tags: + - ecmascript2015 +description: > + Provide the non-standard (ES6) Proxy object. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_BRACES.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_BRACES.yaml new file mode 100644 index 0000000..ea864f8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_BRACES.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_ES6_REGEXP_BRACES +introduced: 1.5.0 +removed: 2.0.0 +default: true +tags: + - ecmascript2015 +description: > + Replaced by DUK_USE_ES6_REGEXP_SYNTAX. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_SYNTAX.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_SYNTAX.yaml new file mode 100644 index 0000000..f9f1c41 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_REGEXP_SYNTAX.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_ES6_REGEXP_SYNTAX +introduced: 2.0.0 +default: true +tags: + - ecmascript2015 +description: > + Enable support for additional RegExp syntax from E6 Section B.1.4, such as: + (1) dollar escape, (2) unescaped curly braces ('{' and '}'), and (3) + unescaped right bracket (']'). This option does not enable all of the ES6 + syntax because not all of the extra syntax is implemented; rather, the option + enables whatever ES6 extra syntax has been implemented so far. + + This option is recommended because a lot of existing code depends on literal + regexp braces, and other non-ES5 constructs. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_UNICODE_ESCAPE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_UNICODE_ESCAPE.yaml new file mode 100644 index 0000000..5ed1cb4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES6_UNICODE_ESCAPE.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_ES6_UNICODE_ESCAPE +introduced: 2.0.0 +default: true +tags: + - ecmascript2015 +description: > + Enable support for ES6 Unicode escape syntax ("\u{12345}") in source code + and RegExps. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES7.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES7.yaml new file mode 100644 index 0000000..e195be3 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES7.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES7 +introduced: 2.0.0 +default: true +tags: + - ecmascript2016 +description: > + Enable ES7 functionality not covered by other specific config options. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES7_EXP_OPERATOR.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES7_EXP_OPERATOR.yaml new file mode 100644 index 0000000..8cd9fe4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES7_EXP_OPERATOR.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_ES7_EXP_OPERATOR +introduced: 2.0.0 +default: true +tags: + - ecmascript2016 +description: > + Support the ES7 exponentiation operator (** and **=). This is optional + because the operator pulls in pow() which may have a significant footprint + impact on bare metal platforms. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES8.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES8.yaml new file mode 100644 index 0000000..ec10b5c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES8.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES8 +introduced: 2.0.0 +default: true +tags: + - ecmascript2017 +description: > + Enable ES8 functionality not covered by other specific config options. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ES9.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES9.yaml new file mode 100644 index 0000000..541a00d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ES9.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ES9 +introduced: 2.0.0 +default: true +tags: + - ecmascript2018 +description: > + Enable ES9 functionality not covered by other specific config options. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_LIMITS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_LIMITS.yaml new file mode 100644 index 0000000..b96de7a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_LIMITS.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_ESBC_LIMITS +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Impose byte and line number limits for compiled function bytecode. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_BYTES.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_BYTES.yaml new file mode 100644 index 0000000..1230861 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_BYTES.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_ESBC_MAX_BYTES +introduced: 1.0.0 +requires: + - DUK_USE_ESBC_LIMITS +default: 0x7fff0000 +tags: + - ecmascript +description: > + Maximum byte count for compiled function bytecode. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_LINENUMBER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_LINENUMBER.yaml new file mode 100644 index 0000000..6f1da17 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ESBC_MAX_LINENUMBER.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_ESBC_MAX_LINENUMBER +introduced: 1.0.0 +requires: + - DUK_USE_ESBC_LIMITS +default: 0x7fff0000 +tags: + - ecmascript +description: > + Maximum line number for compiled function bytecode. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXAMPLE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXAMPLE.yaml new file mode 100644 index 0000000..94b3225 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXAMPLE.yaml @@ -0,0 +1,74 @@ +# +# Each Duktape option is described as a YAML file named OPTION_NAME.yaml. +# YAML is used because it diffs well and has clean support for multiline +# inline strings. +# + +# C #define name for the option. Must match filename minus extension. +define: DUK_USE_OBJSIZES16 + +# Duktape version number where this option was first introduced. +introduced: 1.1.0 + +# Optional Duktape version number where this option was deprecated, +# i.e. the option is supported but no longer recommended. +# FIXME: automatic #error with some -DDUK_USE_NO_DEPRECATED flag? +#deprecated: 1.2.0 + +# Optional Duktape version number where this option was removed, +# i.e. the option is no longer supported but we may want to issue +# a clear #error for it. +#removed: 1.3.0 + +# Optional indication that config option is defined but currently +# unused, so that it can be omitted from generated header. +#unused: true + +# Optional list of options that must also be defined to use this option. +#requires: +# - DUK_USE_FOO +# - DUK_USE_BAR + +# Optional list of options that this option conflicts with. +#conflicts: +# - DUK_USE_BAZ + +# Optional list of options that are related from a user and documentation +# perspective. +#related: +# - DUK_USE_QUUX + +# Default value for option: +# - false: undefined (#undef DUK_USE_EXAMPLE) +# - true: defined with no value (#define DUK_USE_EXAMPLE) +# - string: defined with string value (#define DUK_USE_EXAMPLE "foo") +# - number: defined with number value (#define DUK_USE_EXAMPLE 123) +# FIXME: verbatim? #define DUK_USE_EXAMPLE do { } while (0) +default: false + +# Tags related to option (required). If present, first tag is used as a +# primary tag for grouping. Use 'misc' if nothing else is appropriate. +tags: + - lowmemory + - experimental + +# When set to true, genconfig.py will warn if no forced value is provided. +# This should be used sparingly, for options which are really strongly +# recommended so that configure.py output should warn about it. +#warn_if_missing: true + +# Description for option, no newlines. Line breaking for e.g. C header +# is automatic. +description: > + Use a 16-bit object entry and array part sizes (for low memory + environments). Also automatically drops support for an object hash + part to further reduce memory usage; there are rarely large objects + in low memory environments simply because there's no memory to store + a lot of properties. + + By default use "description: >" markup which works well for paragraphs + (replacing newlines with spaces) but includes a trailing newline which + is also a good default. + +# Marker to avoid processing this file. +example: true diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_FUN_LOCAL.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_FUN_LOCAL.yaml new file mode 100644 index 0000000..3d66df2 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_FUN_LOCAL.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_EXEC_FUN_LOCAL +introduced: 1.4.0 +default: false +tags: + - performance + - execution +description: > + Use a local variable "fun" pointing to the current function in the bytecode + dispatch loop instead of looking up the current function through "thr" every + time it is needed. On x64 performance is slightly better without a "fun" + local; on x86 performance is slightly better with one. + + You should only tweak this if you're really interested in performance, and + should then do proper testing to see which value works better. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_INDIRECT_BOUND_CHECK.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_INDIRECT_BOUND_CHECK.yaml new file mode 100644 index 0000000..16c30f0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_INDIRECT_BOUND_CHECK.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_EXEC_INDIRECT_BOUND_CHECK +introduced: 1.0.0 +default: false +tags: + - execution + - debug +description: > + For opcodes with indirect indices, check final index against stack size. + Useful for diagnosing problems. Normally this check is not necessary + because the compiler is trusted, and we don't bound check direct indices + either. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_PREFER_SIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_PREFER_SIZE.yaml new file mode 100644 index 0000000..19aa8f1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_PREFER_SIZE.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_EXEC_PREFER_SIZE +introduced: 2.0.0 +default: false +tags: + - lowmemory +description: > + Prefer size over performance in bytecode executor. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_REGCONST_OPTIMIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_REGCONST_OPTIMIZE.yaml new file mode 100644 index 0000000..b7bee88 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_REGCONST_OPTIMIZE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_EXEC_REGCONST_OPTIMIZE +introduced: 2.0.0 +default: true +tags: + - performance + - execution +description: > + Use an internal optimization to access registers and constants in the + bytecode executor. The optimization avoids unnecessary shifts when computing + addresses but assumes sizeof(duk_tval) is 8 or 16. This is almost always the + case, but when it isn't, disable this option. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_TIMEOUT_CHECK.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_TIMEOUT_CHECK.yaml new file mode 100644 index 0000000..e59c7fd --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXEC_TIMEOUT_CHECK.yaml @@ -0,0 +1,31 @@ +define: DUK_USE_EXEC_TIMEOUT_CHECK +introduced: 1.2.0 +requires: + - DUK_USE_INTERRUPT_COUNTER +default: false +tags: + - execution + - sandbox + - experimental +description: > + NOTE: This mechanism is EXPERIMENTAL and the details may change + between releases. + + Provide a hook to check for bytecode execution timeout. The macro gets + a void ptr userdata argument (the userdata given to duk_heap_create()) + and must evaluate to a duk_bool_t. Duktape calls the macro as: + "if (DUK_USE_EXEC_TIMEOUT_CHECK(udata)) { ... }". + + The macro is called occasionally by the Duktape bytecode executor (i.e. + when executing Ecmascript code), typically from a few times per second + to a hundred times per second, but the interval varies a great deal + depending on what kind of code is being executed. + + To indicate an execution timeout, the macro must return a non-zero value. + When that happens, Duktape starts to bubble a ``RangeError`` outwards + until control has been returned to the original protected call made by + the application. Until that happens, the exec timeout macro must always + return non-zero to indicate an execution timeout is still in progress. + + This mechanism and its limitations is described in more detail in + doc/sandboxing.rst. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXPLICIT_NULL_INIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXPLICIT_NULL_INIT.yaml new file mode 100644 index 0000000..0da6c1b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXPLICIT_NULL_INIT.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_EXPLICIT_NULL_INIT +introduced: 1.0.0 +default: false +tags: + - portability +description: > + When zeroing structures, don't rely on memzero initializing pointers to + NULL. Instead, write NULL values explicitly after zeroing. This should + only be necessary when a NULL pointer is not represented by zero bytes in + memory. + + # NOTE: Condition in Duktape 1.2 seems wrong, and is linked to packed tval. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_FREE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_FREE.yaml new file mode 100644 index 0000000..d65fead --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_FREE.yaml @@ -0,0 +1,23 @@ +define: DUK_USE_EXTSTR_FREE +introduced: 1.1.0 +requires: + - DUK_USE_HSTRING_EXTDATA +default: false +tags: + - memory + - experimental +description: > + Optional counterpart to DUK_USE_EXTSTR_INTERN_CHECK. Invoked when an + external string is about to be freed by Duktape. + + The argument "ptr" is a void ptr and points to the external string data. + Concretely, it is the (non-NULL) value returned by + DUK_USE_EXTSTR_INTERN_CHECK. The "udata" argument is the heap userdata + which may be ignored if not needed. + + Also enable DUK_USE_HSTRING_EXTDATA to use this feature. + + NOTE: Right now there is no API to push external strings; external strings + come into being as a resul of DUK_USE_EXTSTR_INTERN_CHECK() only. If/when + this is changed, this hook will get called for every string, even if pushed + by the user using an API call; this may need to be rethought at that time. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_INTERN_CHECK.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_INTERN_CHECK.yaml new file mode 100644 index 0000000..784eb25 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_EXTSTR_INTERN_CHECK.yaml @@ -0,0 +1,39 @@ +define: DUK_USE_EXTSTR_INTERN_CHECK +introduced: 1.1.0 +requires: + - DUK_USE_HSTRING_EXTDATA +default: false +tags: + - memory + - experimental +description: > + Provide a hook for checking if data for a certain string can be used from + external memory (outside of Duktape heap, e.g. memory mapped flash). + The hook is called during string interning with the following semantics: + + The string data with no NUL termination resides at "ptr" and has "len" + bytes. The "udata" argument is the heap userdata which may be ignored + if not needed. If the hook returns NULL, Duktape interns the string + normally, i.e. string data is allocated from Duktape heap. Otherwise the + hook return value must point to a memory area which contains + "len" bytes from "ptr" followed by a NUL byte which is NOT PRESENT + in the input data. Data behind the returned pointer may not change after + the hook returns. + + The hook may be called several times for the same input string. This + happens when a string is interned, garbage collected, and then interned + again. + + The DUK_USE_EXTSTR_FREE() hook allows application code to detect when + an external string is about to be freed. + + In most cases the hook should reject strings whose "len" is less than 4 + because there is no RAM advantage in moving so short strings into external + memory. The ordinary "duk_hstring" header followed by the data (and a + NUL byte) has the same size as "duk_hstring_external" header which hosts + a pointer instead of string data. + + Also enable DUK_USE_HSTRING_EXTDATA to use this feature. + + See doc/low-memory.rst for more discussion how to use this feature option + in practice. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FASTINT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FASTINT.yaml new file mode 100644 index 0000000..8cb4c85 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FASTINT.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_FASTINT +requires: + - DUK_USE_64BIT_OPS +introduced: 1.2.0 +default: false +tags: + - performance + - fastpath +description: > + Enable support for 48-bit signed "fastint" integer values. Fastints are + transparent to user code (both C and Ecmascript) but may be faster than + IEEE doubles on some platforms, especially those using softints. The + downside of fastints is increased code footprint and a small performance + penalty for some kinds of code. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FAST_REFCOUNT_DEFAULT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FAST_REFCOUNT_DEFAULT.yaml new file mode 100644 index 0000000..bc9b2f9 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FAST_REFCOUNT_DEFAULT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_FAST_REFCOUNT_DEFAULT +introduced: 1.2.0 +default: true +tags: + - performance + - fastpath + - experimental +description: > + When enabled, plain refcount macros (e.g. DUK_TVAL_INCREF) default to + fast variants (DUK_TVAL_INCREF_FAST) to improve performance. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_HANDLER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_HANDLER.yaml new file mode 100644 index 0000000..e53c914 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_HANDLER.yaml @@ -0,0 +1,23 @@ +define: DUK_USE_FATAL_HANDLER +introduced: 2.0.0 +default: false +tags: + - portability +warn_if_missing: true +description: > + Provide a custom default fatal error handler to replace the built-in one + (which calls abort() without any error message). The default fatal error + handler gets called when (1) a fatal error occurs and application code + didn't register a fatal error handler in heap creation or (2) a context-free + fatal error happens, concretely e.g. an assertion failure. + + The handler is called like a C function with the prototype + "void fatal_handler(void *udata, const char *msg)". The "msg" argument can + be NULL. The "udata" argument matches the heap-related userdata but is + NULL for fatal errors unrelated to a heap/thread context (this is the case + for e.g. assertions). + + A custom default fatal error handler is recommended for any environment + where recover from fatal errors is important. A custom handler can take + appropriate action to recover, e.g. record the error and reboot the target + device. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_MAXLEN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_MAXLEN.yaml new file mode 100644 index 0000000..2971c20 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FATAL_MAXLEN.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_FATAL_MAXLEN +introduced: 2.2.0 +default: 128 +tags: + - portability +description: > + Maximum length of fatal error message string when error is thrown by + Duktape internals, in particular for uncaught errors. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FILE_IO.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FILE_IO.yaml new file mode 100644 index 0000000..8ff767d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FILE_IO.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_FILE_IO +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - io +description: > + File I/O support. This is now used in a few API calls to e.g. push + a string from file contents or eval a file. For portability it must + be possible to disable I/O altogether. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_SUPPORT.yaml new file mode 100644 index 0000000..1bb8694 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_SUPPORT.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_FINALIZER_SUPPORT +introduced: 2.0.0 +default: true +tags: + - execution +description: > + Enable support for object finalizers (Duktape specific). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_TORTURE.yaml new file mode 100644 index 0000000..30b32b7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FINALIZER_TORTURE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_FINALIZER_TORTURE +introduced: 2.1.0 +default: false +tags: + - gc + - memory + - development + - torture +description: > + Development time option: simulate a fake finalizer call every time when + finalizers might be executed (even if the actual finalize_list is empty). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_C99.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_C99.yaml new file mode 100644 index 0000000..5694b38 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_C99.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_FLEX_C99 +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Use C99 flexible array member for defining variable size structures. + +# FIXME: currently unused, remove or mark unused so doesn't get emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ONESIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ONESIZE.yaml new file mode 100644 index 0000000..5ccc25a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ONESIZE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_FLEX_ONESIZE +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use a single element array to define variable size structures. This is the + most portable alternative: zero-size arrays are not allowed by all compilers + and flexible array member ("char arr[]") is defined in C99. + +# FIXME: currently unused, remove or mark unused so doesn't get emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ZEROSIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ZEROSIZE.yaml new file mode 100644 index 0000000..2d4293f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FLEX_ZEROSIZE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_FLEX_ZEROSIZE +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use a zero element array to define variable size structures. This is not + fully portable but works with some compilers and is preferred over using + a one element array. + +# FIXME: currently unused, remove or mark unused so doesn't get emitted? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FULL_TVAL.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FULL_TVAL.yaml new file mode 100644 index 0000000..796c317 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FULL_TVAL.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_FULL_TVAL +introduced: 1.0.0 +removed: 1.2.0 +default: false +tags: + - misc +description: > + Initialize all bytes of a duk_tval when setting a value into one. + + By default only needed fields are initialized which reduces code size and + improves performance slightly. This should cause no functional issues but + may cause valgrind issues in rare cases, e.g. when debugger code dumps the + constant table of a function (which then reads uninitialized bits). + + Removed in 1.2.0 because the option was never enabled and there was no + feature option to cause it to be used. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR16.yaml new file mode 100644 index 0000000..bf54cdb --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR16.yaml @@ -0,0 +1,21 @@ +define: DUK_USE_FUNCPTR16 +introduced: 1.1.0 +related: + - DUK_USE_FUNCPTR_ENC16 + - DUK_USE_FUNCPTR_DEC16 +default: false +tags: + - lowmemory + - experimental +description: > + Enable "compression" of arbitrary data pointers into an unsigned 16-bit + value. Use together with DUK_USE_DATAPTR_ENC16 and DUK_USE_DATAPTR_DEC16. + + Pointers compressed are any void pointers in C code, not just the Duktape + heap. Also NULL pointer must encode and decode correctly. + + Currently it is required that NULL encodes to integer 0, and integer + 0 decodes to NULL. No other pointer can be encoded to 0. + + NOTE: This feature option is currently unimplemented, i.e. Duktape won't + compress any data pointers at the moment. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_DEC16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_DEC16.yaml new file mode 100644 index 0000000..f1e10c0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_DEC16.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_FUNCPTR_DEC16 +introduced: 1.1.0 +requires: + - DUK_USE_FUNCPTR16 +default: false +tags: + - lowmemory + - experimental +description: > + Use together with DUK_USE_FUNCPTR16 for arbitrary data pointer compression. + DUK_USE_FUNCPTR_ENC16(udata,p) is a macro with a userdata and void ptr + argument, and a duk_uint16_t return value. The userdata argument is the + heap userdata value given at heap creation. Currently it is required that + NULL encodes to integer 0, and integer 0 decodes to NULL. No other pointer + can be encoded to 0. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_ENC16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_ENC16.yaml new file mode 100644 index 0000000..51ff363 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCPTR_ENC16.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_FUNCPTR_ENC16 +introduced: 1.1.0 +requires: + - DUK_USE_FUNCPTR16 +default: false +tags: + - lowmemory + - experimental +description: > + Use together with DUK_USE_FUNCPTR16 for arbitrary data pointer compression. + DUK_USE_FUNCPTR_DEC16(udata,x) is a macro with a userdata and duk_uint16_t + argument, and a void ptr return value. The userdata argument is the heap + userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCTION_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCTION_BUILTIN.yaml new file mode 100644 index 0000000..663cd45 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNCTION_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_FUNCTION_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide a Function built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_FILENAME_PROPERTY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_FILENAME_PROPERTY.yaml new file mode 100644 index 0000000..74e98bd --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_FILENAME_PROPERTY.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_FUNC_FILENAME_PROPERTY +introduced: 2.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + Add a non-standard ".fileName" property to function instances. Disabling + reduces footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_NAME_PROPERTY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_NAME_PROPERTY.yaml new file mode 100644 index 0000000..eb61de3 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_FUNC_NAME_PROPERTY.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_FUNC_NAME_PROPERTY +introduced: 2.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + Add a "name" property to function instances. This is part of Ecmascript + requirements, but low memory devices can sometimes opt to not include the + .name to reduce footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GCC_PRAGMAS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GCC_PRAGMAS.yaml new file mode 100644 index 0000000..9a68e46 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GCC_PRAGMAS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_GCC_PRAGMAS +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use GCC-specific pragmas, e.g. "#pragma GCC diagnostic" to suppress + unnecessary warnings. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GC_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GC_TORTURE.yaml new file mode 100644 index 0000000..7f2968a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GC_TORTURE.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_GC_TORTURE +introduced: 1.0.0 +default: false +tags: + - gc + - memory + - development + - torture +description: > + Development time option: force full mark-and-sweep on every allocation and + in other chosen places to stress test memory management. + + Using a low value (e.g. 3) for DUK_USE_MARK_AND_SWEEP_RECLIMIT is also + recommended. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME.yaml new file mode 100644 index 0000000..d5ed7b3 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME.yaml @@ -0,0 +1,22 @@ +define: DUK_USE_GET_MONOTONIC_TIME +introduced: 2.2.0 +default: false +tags: + - portability +description: > + Optional macro for getting monotonic time in milliseconds from an arbitrary + starting point (device startup, program startup, script startup, etc). + Fractional time values are allowed (and even recommended). The time returned + must increase monotonically, and must not jump discontinuously even if system + date/time is reset. The semantics are similar to POSIX clock_gettime() + CLOCK_MONOTONIC. + + Monotonic time is used by Duktape for its internal needs, such as rate + limiting debugger transport peek callbacks. It is also used to provide + performance.now(). If this option is not provided, Duktape falls back to + using DUK_USE_DATE_GET_NOW() which is usually fine. + + If DUK_USE_DATE_GET_NOW() experiences time jumps or doesn't run in realtime + (which may be useful for some time virtualization cases) it's recommended + to provide this config option so that internals which need a reliable + realtime rate have a reliable time basis. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME.yaml new file mode 100644 index 0000000..8f18392 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME +introduced: 2.2.0 +default: false +tags: + - portability +description: > + Use clock_gettime(CLOCK_MONOTONIC, ...) for monotonic time on POSIX + platforms. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC.yaml new file mode 100644 index 0000000..ca5bc19 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC +introduced: 2.2.0 +default: false +tags: + - portability +description: > + Use QueryPerformanceCounter() for monotonic time on Windows. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_RANDOM_DOUBLE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_RANDOM_DOUBLE.yaml new file mode 100644 index 0000000..2ae1c20 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GET_RANDOM_DOUBLE.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_GET_RANDOM_DOUBLE +introduced: 2.0.0 +default: false +tags: + - portability + - performance +description: > + Override the default internal random number generator which is used for + Math.random() and some other internal call sites (currently, for example, + Array.prototype.sort()). The default random number generator has a very + low footprint but is not suitable for serious statistics algorithms or + cryptography. Overriding the random number generator may thus be useful + in some environments. + + The macro gets a heap userdata argument and must provide an IEEE double + in the range [0,1[. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BINDING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BINDING.yaml new file mode 100644 index 0000000..096bb62 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BINDING.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_GLOBAL_BINDING +introduced: 2.1.0 +default: false +tags: + - ecmascript + - experimental +description: > + Provide a 'global' binding (https://github.com/tc39/proposal-global). + Disabled by default because it's still a proposal and there may be + reasons it won't be widely implemented: https://github.com/tc39/proposal-global/issues/20. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BUILTIN.yaml new file mode 100644 index 0000000..b8ba6e4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_GLOBAL_BUILTIN.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_GLOBAL_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide miscellaneous global built-ins like encodeURIComponent(), escape(), + Infinity, etc. This is a catch-all for globals not covered by other options + (like DUK_USE_ARRAY_BUILTIN). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS.yaml new file mode 100644 index 0000000..fe5e336 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS +introduced: 1.0.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Allow unaligned 32-bit unsigned integer access in hashbytes algorithm. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR16.yaml new file mode 100644 index 0000000..608143f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR16.yaml @@ -0,0 +1,35 @@ +define: DUK_USE_HEAPPTR16 +introduced: 1.1.0 +conflicts: + - DUK_USE_DEBUG +related: + - DUK_USE_HEAPPTR_ENC16 + - DUK_USE_HEAPPTR_DEC16 +default: false +tags: + - lowmemory + - experimental +description: > + Enable "compression" of Duktape heap pointers into an unsigned 16-bit value. + Use together with DUK_USE_HEAPPTR_ENC16 and DUK_USE_HEAPPTR_DEC16. + + Pointers compressed are those allocated from Duktape heap, using the user + provided allocation functions. Also NULL pointer must encode and decode + correctly. + + Currently it is required that NULL encodes to integer 0, and integer + 0 decodes to NULL. No other pointer can be encoded to 0. + + This option reduces memory usage by several kilobytes, but has several + downsides. It can only be applied when Duktape heap is limited in size, + for instance, with 4-byte aligned allocations a 256kB heap (minus one value + for NULL) can be supported. Pointer encoding and decoding may be relatively + complicated as they need to correctly handle NULL pointers and + non-continuous memory maps used by some targets. The macro may need to call + out to a helper function in practice, which is much slower than an inline + implementation. + + Current limitation: Duktape internal debug code enabled with e.g. + DUK_USE_DEBUG and DUK_USE_DEBUG_LEVEL=0 doesn't have enough plumbing to be + able to decode pointers. Debug printing cannot currently be enabled when + pointer compression is active. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_DEC16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_DEC16.yaml new file mode 100644 index 0000000..1262dca --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_DEC16.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_HEAPPTR_DEC16 +introduced: 1.1.0 +requires: + - DUK_USE_HEAPPTR16 +default: false +tags: + - lowmemory + - experimental +description: > + Use together with DUK_USE_HEAPPTR16 for heap pointer compression. + DUK_USE_HEAPPTR_DEC16(udata,x) is a macro with a userdata and duk_uint16_t + argument, and a void ptr return value. The userdata argument is the heap + userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_ENC16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_ENC16.yaml new file mode 100644 index 0000000..7339c49 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEAPPTR_ENC16.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_HEAPPTR_ENC16 +introduced: 1.1.0 +requires: + - DUK_USE_HEAPPTR16 +default: false +tags: + - lowmemory + - experimental +description: > + Use together with DUK_USE_HEAPPTR16 for heap pointer compression. + DUK_USE_HEAPPTR_ENC16(udata,p) is a macro with a userdata and void ptr + argument, and a duk_uint16_t return value. The userdata argument is the + heap userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HEX_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEX_FASTPATH.yaml new file mode 100644 index 0000000..c00bbe4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HEX_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_HEX_FASTPATH +introduced: 1.4.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for hex encode/decode. The fast path uses a lookup + table at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT.yaml new file mode 100644 index 0000000..74b8387 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT +introduced: 2.1.0 +default: 2 +tags: + - performance + - lowmemory +description: > + Abandon array part if its density is below L. The limit L is expressed as + a .3 fixed point point, e.g. 2 means 2/8 = 25%. + + The default limit is quite low: one array entry with packed duk_tval is 8 + bytes whereas one normal entry is 4+1+8 = 13 bytes without a hash entry, + and 17-21 bytes with a hash entry (load factor 0.5-1.0). So the array part + shouldn't be abandoned very easily from a footprint point of view. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT.yaml new file mode 100644 index 0000000..6429d4b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT +introduced: 2.1.0 +default: 9 +tags: + - performance + - lowmemory +description: > + Skip abandon check in object array part resize if new_size < L * old_size. + The limit L is expressed as a .3 fixed point value, e.g. 9 means 9/8 = + 112.5% of current size. + + This is rather technical and you should only change the parameter if you've + looked at the internals. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_ADD.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_ADD.yaml new file mode 100644 index 0000000..82e79f7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_ADD.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_HOBJECT_ARRAY_MINGROW_ADD +introduced: 2.1.0 +default: 16 +tags: + - performance +description: > + Technical internal parameter, see sources for details. Only adjust if + you've looked at the internals. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR.yaml new file mode 100644 index 0000000..98fdb29 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR +introduced: 2.1.0 +default: 8 +tags: + - performance +description: > + Technical internal parameter, see sources for details. Only adjust if + you've looked at the internals. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_ADD.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_ADD.yaml new file mode 100644 index 0000000..c31b111 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_ADD.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR +introduced: 2.1.0 +default: 8 +tags: + - performance +description: > + Technical internal parameter, see sources for details. Only adjust if + you've looked at the internals. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR.yaml new file mode 100644 index 0000000..c38fd8f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_HOBJECT_ENTRY_MINGROW_ADD +introduced: 2.1.0 +default: 16 +tags: + - performance +description: > + Technical internal parameter, see sources for details. Only adjust if + you've looked at the internals. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PART.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PART.yaml new file mode 100644 index 0000000..4e8c82e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PART.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_HOBJECT_HASH_PART +introduced: 1.1.0 +default: true +tags: + - lowmemory + - experimental +description: > + Use a hash table for objects that have enough properties. This should be + enabled unless the target is very low on memory. + + If DUK_USE_OBJSIZES16 is defined, this option must not be defined. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PROP_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PROP_LIMIT.yaml new file mode 100644 index 0000000..008b836 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_HASH_PROP_LIMIT.yaml @@ -0,0 +1,20 @@ +define: DUK_USE_HOBJECT_HASH_PROP_LIMIT +introduced: 2.1.0 +default: 8 +tags: + - performance + - lowmemory +description: > + Minimum number of properties needed for a hash part to be included in the + object property table. This limit is checked whenever an object is resized. + + A hash part improves property lookup performance even for small objects, + starting from roughly 4 properties. However, this ignores the cost of + setting up and managing the hash part, which is offset only if property + lookups made through the hash part can offset the setup cost. A hash part + is worth it for heavily accessed small objects or large objects (even those + accessed quite infrequently). The limit doesn't take into account property + access frequency, so it is necessarily a compromise. + + A lower value improves performance (a value as low a 4-8 can be useful) + while a higher value conserves memory. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_1.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_1.yaml new file mode 100644 index 0000000..23a6883 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_1.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_HOBJECT_LAYOUT_1 +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use layout variant 1 for object properties. Layout 1 can be used when the + target has no alignment restrictions. It is preferable to other layouts + because it produces smaller code and provides direct access to property + keys. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_2.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_2.yaml new file mode 100644 index 0000000..c467e3b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_2.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_HOBJECT_LAYOUT_2 +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Use layout variant 2 for object properties. Layout 2 can be used on any + target (including targets with alignment restrictions). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_3.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_3.yaml new file mode 100644 index 0000000..23ea315 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HOBJECT_LAYOUT_3.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_HOBJECT_LAYOUT_3 +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use layout variant 3 for object properties. Layout 3 can be used on any + target (including targets with alignment restrictions). It's a bit more + packed than layout variant 2 but has a bit slower lookups. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_ARRIDX.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_ARRIDX.yaml new file mode 100644 index 0000000..9b82aab --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_ARRIDX.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_HSTRING_ARRIDX +introduced: 2.0.0 +default: true +tags: + - lowmemory +description: > + When enabled, duk_hstring stores a precomputed array index (or "not an array + index") value related to the string. This reduces code footprint and + improves performance a littl ebit. + + When disabled, duk_hstring has a flag indicating whether it is an array + index or not, but the actual value is computed on-the-fly. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_CLEN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_CLEN.yaml new file mode 100644 index 0000000..6f4b3c8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_CLEN.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_HSTRING_CLEN +introduced: 1.5.0 +default: true +tags: + - lowmemory + - experimental +description: > + When DUK_USE_STRLEN16 enabled, indicates whether the character length + (clen16) field should be actually present (default) or computed on-the-fly. + + When clen is computed on-the-fly the duk_hstring structure will be 4 bytes + smaller (from 10 bytes + 2 bytes padding to 8 bytes) which may be useful for + very low memory targets. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_EXTDATA.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_EXTDATA.yaml new file mode 100644 index 0000000..6598eb8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_EXTDATA.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_HSTRING_EXTDATA +introduced: 1.1.0 +default: false +tags: + - memory +description: > + Enable support for external strings. An external string requires a Duktape + heap allocation to store a minimal string header, with the actual string + data being held behind a pointer (similarly to how dynamic buffers work). + + This option is needed to use DUK_USE_EXTSTR_INTERN_CHECK and/or + DUK_USE_EXTSTR_FREE. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_LAZY_CLEN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_LAZY_CLEN.yaml new file mode 100644 index 0000000..7a49aed --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HSTRING_LAZY_CLEN.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_HSTRING_LAZY_CLEN +introduced: 2.2.0 +default: true +tags: + - performance +description: > + When enabled, duk_hstring charlen is computed only when accessed; because + the charlen of most strings is not accessed during their lifetime, this + reduces unnecessary charlen calculations. When disabled, charlen is computed + during interning which has smaller code footprint at slightly slower charlen + handling. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_HTML_COMMENTS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_HTML_COMMENTS.yaml new file mode 100644 index 0000000..cd39e80 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_HTML_COMMENTS.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_HTML_COMMENTS +introduced: 2.1.0 +default: true +tags: + - ecmascript2015 +description: > + Enable ES2015 Annex B.1.3 HTML comment syntax. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_IDCHAR_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_IDCHAR_FASTPATH.yaml new file mode 100644 index 0000000..4748674 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_IDCHAR_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_IDCHAR_FASTPATH +introduced: 1.5.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for identifier start/part tables, which affect lexing and + JSON performance slightly at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_INJECT_HEAP_ALLOC_ERROR.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_INJECT_HEAP_ALLOC_ERROR.yaml new file mode 100644 index 0000000..a1db4a9 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_INJECT_HEAP_ALLOC_ERROR.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_INJECT_HEAP_ALLOC_ERROR +introduced: 2.1.0 +default: false +tags: + - development +description: > + Force heap allocation to fail, value indicates the desired error position. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_BE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_BE.yaml new file mode 100644 index 0000000..662db0b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_BE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_INTEGER_BE +introduced: 1.0.0 +removed: 1.4.0 +default: false +conflicts: + - DUK_USE_INTEGER_LE + - DUK_USE_INTEGER_ME +tags: + - portability +description: > + Integer memory representation is big endian on the target platform. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_LE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_LE.yaml new file mode 100644 index 0000000..d3efa21 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_LE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_INTEGER_LE +introduced: 1.0.0 +removed: 1.4.0 +default: true +conflicts: + - DUK_USE_INTEGER_BE + - DUK_USE_INTEGER_ME +tags: + - portability +description: > + Integer memory representation is little endian on the target platform. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_ME.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_ME.yaml new file mode 100644 index 0000000..a1fdc91 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTEGER_ME.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_INTEGER_ME +introduced: 1.0.0 +removed: 1.4.0 +default: false +conflicts: + - DUK_USE_INTEGER_LE + - DUK_USE_INTEGER_BE +tags: + - portability +description: > + Integer memory representation is mixed endian on the target platform. + + This option is unused (and unsupported) because no target platform currently + needs this. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_COUNTER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_COUNTER.yaml new file mode 100644 index 0000000..614c7fa --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_COUNTER.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_INTERRUPT_COUNTER +introduced: 1.1.0 +related: + - DUK_USE_DEBUGGER_SUPPORT +default: false +tags: + - execution + - debugger +description: > + Enable the internal bytecode executor periodic interrupt counter. + The mechanism is used to implement e.g. execution step limit, custom + profiling, and debugger interaction. Enabling the interrupt counter + has a small impact on execution performance. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_DEBUG_FIXUP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_DEBUG_FIXUP.yaml new file mode 100644 index 0000000..48d7df9 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_INTERRUPT_DEBUG_FIXUP.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_INTERRUPT_DEBUG_FIXUP +introduced: 1.4.0 +default: false +tags: + - development +description: > + For Duktape development only: enable "interrupt fixup" in call handling + so that heap->inst_count_exec and heap->inst_count_interrupt can be + manually checked to match. Only useful when debugging and/or asserts + are enabled. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JC.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JC.yaml new file mode 100644 index 0000000..0bfc818 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JC.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_JC +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Enable support for the JC custom JSON format. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_BUILTIN.yaml new file mode 100644 index 0000000..e858389 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_JSON_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide a JSON built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECNUMBER_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECNUMBER_FASTPATH.yaml new file mode 100644 index 0000000..fa47c15 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECNUMBER_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_JSON_DECNUMBER_FASTPATH +introduced: 1.3.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for decoding numbers in JSON.parse(). The fast path uses + a lookup table at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECSTRING_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECSTRING_FASTPATH.yaml new file mode 100644 index 0000000..ed0e31b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DECSTRING_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_JSON_DECSTRING_FASTPATH +introduced: 1.3.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for string decoding in JSON.parse(). The fast path uses + a lookup table at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DEC_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DEC_RECLIMIT.yaml new file mode 100644 index 0000000..cd07d3c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_DEC_RECLIMIT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_JSON_DEC_RECLIMIT +introduced: 1.3.0 +default: 1000 +tags: + - portability + - cstackdepth +description: > + Maximum native stack recursion for JSON decoding. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_EATWHITE_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_EATWHITE_FASTPATH.yaml new file mode 100644 index 0000000..49e1b44 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_EATWHITE_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_JSON_EATWHITE_FASTPATH +introduced: 1.3.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for eating whitespace in JSON.parse(). The fast path uses + a lookup table at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_ENC_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_ENC_RECLIMIT.yaml new file mode 100644 index 0000000..1df0e07 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_ENC_RECLIMIT.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_JSON_ENC_RECLIMIT +introduced: 1.3.0 +default: 1000 +tags: + - portability + - cstackdepth +description: > + Maximum native stack recursion for JSON encoding. + + Must be higher than the internal DUK_JSON_ENC_LOOPARRAY define when + DUK_USE_JSON_STRINGIFY_FASTPATH is enabled. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_QUOTESTRING_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_QUOTESTRING_FASTPATH.yaml new file mode 100644 index 0000000..e2ee14e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_QUOTESTRING_FASTPATH.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_JSON_QUOTESTRING_FASTPATH +introduced: 1.3.0 +default: true +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for string quoting in JSON.stringify(). The fast path uses + a lookup table at a small cost in footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_STRINGIFY_FASTPATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_STRINGIFY_FASTPATH.yaml new file mode 100644 index 0000000..4d244f6 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_STRINGIFY_FASTPATH.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_JSON_STRINGIFY_FASTPATH +introduced: 1.3.0 +default: false +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast path for JSON.stringify() serialization. The fast path is used + when there is no "replacer" argument. Indent argument and JX/JC format is + supported since Duktape 1.4.0. The fast path increases code footprint by + roughly 1.5 kB but is up to 4-5x faster than the slow path. + + Current limitation: assumes "long long" type exists (and covers duk_int64_t + range) and that sprintf() format string "%lld" works for "long long". diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_SUPPORT.yaml new file mode 100644 index 0000000..166d993 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JSON_SUPPORT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_JSON_SUPPORT +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Enable JSON functionality, affects both Ecmascript and C APIs. + Note that disabling DUK_USE_JSON_BUILTIN still leaves the C API intact + and pulls in the JSON encoding/decoding functionality; disable this + option to remove that too. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_JX.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_JX.yaml new file mode 100644 index 0000000..f037c96 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_JX.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_JX +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Enable support for the JX custom JSON format. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_LEXER_SLIDING_WINDOW.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_LEXER_SLIDING_WINDOW.yaml new file mode 100644 index 0000000..c213f9f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_LEXER_SLIDING_WINDOW.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_LEXER_SLIDING_WINDOW +introduced: 1.3.0 +default: true +tags: + - lowmemory +description: > + Use a sliding window approach for managing the lexer codepoint lookup window + (recommended). If disabled, the lexer uses a slower algorithm which has a + slightly smaller code and RAM footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_LIGHTFUNC_BUILTINS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_LIGHTFUNC_BUILTINS.yaml new file mode 100644 index 0000000..649bdd0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_LIGHTFUNC_BUILTINS.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_LIGHTFUNC_BUILTINS +introduced: 1.1.0 +default: false +tags: + - lowmemory + - experimental +description: > + Force built-in functions to be lightweight functions. This reduces + memory footprint by around 14 kB at the cost of some non-compliant + behavior. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE.yaml new file mode 100644 index 0000000..5589bd1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE.yaml @@ -0,0 +1,17 @@ +define: DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE +introduced: 1.3.0 +removed: 2.1.0 +related: + - DUK_USE_GC_TORTURE + - DUK_USE_REFZERO_FINALIZER_TORTURE +default: false +tags: + - gc + - memory + - development + - torture +description: > + Development time option: simulate a fake finalizer call during every + mark-and-sweep round. This is useful to detect bugs caused by finalizer + side effects. Most useful when combined with DUK_USE_GC_TORTURE so that + potential finalizer side effects are realized on every allocation. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP.yaml new file mode 100644 index 0000000..534e8d0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP.yaml @@ -0,0 +1,19 @@ +define: DUK_USE_MARK_AND_SWEEP +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - gc + - memory +description: > + Enable mark-and-sweep garbage collection (recommended). + + When disabled, only reference counting is used for garbage collection. + This reduces code footprint and eliminates garbage collection pauses, but + objects participating in unreachable reference cycles won't be collected + until the Duktape heap is destroyed. In particular, function instances + won't be collected because they're always in a reference cycle with their + default prototype object. Unreachable objects are collected if you break + reference cycles manually (and are always freed when a heap is destroyed). + + NOTE: Removed in Duktape 2.0.0 because mark-and-sweep is no longer optional. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP_RECLIMIT.yaml new file mode 100644 index 0000000..c34d924 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MARK_AND_SWEEP_RECLIMIT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_MARK_AND_SWEEP_RECLIMIT +introduced: 1.3.0 +default: 256 +tags: + - portability + - cstackdepth +description: > + Mark-and-sweep C recursion depth for marking phase; if reached, + mark object as a TEMPROOT and use multi-pass marking (slower but + same result). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_BUILTIN.yaml new file mode 100644 index 0000000..35dc0be --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_MATH_BUILTIN +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Provide a Math built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMAX.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMAX.yaml new file mode 100644 index 0000000..bbe8e9a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMAX.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_MATH_FMAX +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - portability +description: > + Assume platform function fmax() is available and works correctly. + Some platforms don't have fmax() (it is defined in C99) and on some + platforms (e.g. some uclibc environments) it may not be provided even + though the compilation environment is nominally C99. + + Removed in Duktape 2.0.0: if the platform doesn't have fmax(), simply + define a replacement for DUK_FMAX(). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMIN.yaml new file mode 100644 index 0000000..dae2d08 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_FMIN.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_MATH_FMIN +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - portability +description: > + Assume platform function fmin() is available and works correctly. + Some platforms don't have fmin() (it is defined in C99) and on some + platforms (e.g. some uclibc environments) it may not be provided even + though the compilation environment is nominally C99. + + Removed in Duktape 2.0.0: if the platform doesn't have fmin(), simply + define a replacement for DUK_FMIN(). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_ROUND.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_ROUND.yaml new file mode 100644 index 0000000..d5af637 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MATH_ROUND.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_MATH_ROUND +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - portability +description: > + Assume platform function round() is available and works correctly. + Some platforms don't have round() (it is defined in C99) and on some + platforms (e.g. some uclibc environments) it may not be provided even + though the compilation environment is nominally C99. + + Removed in Duktape 2.0.0: if the platform doesn't have round(), simply + define a replacement for DUK_ROUND(). Currently DUK_ROUND() isn't used + at all however. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_MS_STRINGTABLE_RESIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_MS_STRINGTABLE_RESIZE.yaml new file mode 100644 index 0000000..bb1b9a4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_MS_STRINGTABLE_RESIZE.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_MS_STRINGTABLE_RESIZE +introduced: 1.0.0 +removed: 2.1.0 +default: true +tags: + - gc + - memory +description: > + Enable forced string intern table resize during mark-and-sweep garbage + collection. This is the recommended behavior. + + It may be useful to disable this option when reference counting is disabled, + as mark-and-sweep collections will be more frequent and thus more expensive. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NATIVE_CALL_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NATIVE_CALL_RECLIMIT.yaml new file mode 100644 index 0000000..ac65550 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NATIVE_CALL_RECLIMIT.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_NATIVE_CALL_RECLIMIT +introduced: 1.3.0 +default: 1000 +tags: + - portability + - cstackdepth +description: > + Maximum duk_handle_call() / duk_handle_safe_call() C recursion limit. + Note that this does not limit bytecode executor internal call depth at + all (e.g. for Ecmascript-to-Ecmascript calls, thread yields/resumes, etc). + There is a separate callstack depth limit for threads which is independent + of this limit. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER.yaml new file mode 100644 index 0000000..450f512 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER +introduced: 1.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + For better compatibility with existing code, enable non-standard + Array.prototype.concat() behavior for trailing non-existent elements of + the concat result, see + https://github.com/svaarala/duktape/blob/master/tests/ecmascript/test-bi-array-proto-concat-nonstd-trailing.js. + + If this option is disabled, concat() will behave in a strictly conforming + fashion, ignoring non-existent trailing elements in the result length. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_MAP_TRAILER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_MAP_TRAILER.yaml new file mode 100644 index 0000000..82cd742 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_MAP_TRAILER.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_NONSTD_ARRAY_MAP_TRAILER +introduced: 1.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + For better compatibility with existing code, enable non-standard + Array.prototype.map() behavior for trailing non-existent elements of + the map result, see + https://github.com/svaarala/duktape/blob/master/tests/ecmascript/test-bi-array-proto-map-nonstd-trailing.js. + + If this option is disabled, map() will behave in a strictly conforming + fashion, ignoring non-existent trailing elements in the result length. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml new file mode 100644 index 0000000..c75a785 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT +introduced: 1.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + For better compatibility with existing code, enable non-standard + Array.prototype.splice() behavior when the second argument (deleteCount) + is not given: the splice operation is extended to the end of the array, see + https://github.com/svaarala/duktape/blob/master/tests/ecmascript/test-bi-array-proto-splice-no-delcount.js. + + If this option is disabled, splice() will behave in a strictly conforming + fashion, treating a missing deleteCount the same as an undefined (or 0) + value. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_CALLER_PROPERTY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_CALLER_PROPERTY.yaml new file mode 100644 index 0000000..86f4d67 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_CALLER_PROPERTY.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_NONSTD_FUNC_CALLER_PROPERTY +introduced: 1.0.0 +default: false +tags: + - ecmascript + - compliance +description: > + Add a non-standard "caller" property to non-strict function instances + for better compatibility with existing code. The semantics of this + property are not standardized and may vary between engines; Duktape tries + to behave close to V8 and Spidermonkey. See + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller + description of the property. This feature disables tail call support. + + This feature conflicts with several other features, so you should use it + only if it's absolutely necessary. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY.yaml new file mode 100644 index 0000000..88ed487 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY +introduced: 1.0.0 +default: false +tags: + - ecmascript + - compliance +description: > + Add a non-standard "source" property to function instances. This allows + function toString() to print out the actual function source. The property + is disabled by default because it increases memory footprint. + + NOTE: Unimplemented as of Duktape 1.3.0. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_STMT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_STMT.yaml new file mode 100644 index 0000000..be0ba88 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_FUNC_STMT.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_NONSTD_FUNC_STMT +introduced: 1.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + Enable support for function declarations outside program or function top + level (also known as "function statements"). Such declarations are + non-standard and the strictly compliant behavior is to treat them as a + SyntaxError. When this option is enabled (recommended), Duktape behavior + is to treat them like ordinary function declarations ("hoist" them to + function top) with V8-like semantics. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_GETTER_KEY_ARGUMENT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_GETTER_KEY_ARGUMENT.yaml new file mode 100644 index 0000000..7ffd48a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_GETTER_KEY_ARGUMENT.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_NONSTD_GETTER_KEY_ARGUMENT +introduced: 1.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + Give getter calls the accessed property name as an additional non-standard + argument. This allows a single getter function to be reused for multiple + properties more easily. See + http://duktape.org/guide.html#propertyvirtualization. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_JSON_ESC_U2028_U2029.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_JSON_ESC_U2028_U2029.yaml new file mode 100644 index 0000000..d82c012 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_JSON_ESC_U2028_U2029.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_NONSTD_JSON_ESC_U2028_U2029 +introduced: 1.1.0 +default: true +tags: + - ecmascript + - compliance +description: > + When enabled, Duktape JSON.stringify() will escape U+2028 and U+2029 which + is non-compliant behavior. This is recommended to make JSON.stringify() + output valid when embedded in a web page or parsed with eval(). + + When disabled, Duktape provides the compliant behavior, i.e. no escaping + for U+2028 and U+2029. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE.yaml new file mode 100644 index 0000000..edfa774 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + Replaced by DUK_USE_ES6_REGEXP_SYNTAX. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_SETTER_KEY_ARGUMENT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_SETTER_KEY_ARGUMENT.yaml new file mode 100644 index 0000000..b517b03 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_SETTER_KEY_ARGUMENT.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_NONSTD_SETTER_KEY_ARGUMENT +introduced: 1.0.0 +default: true +tags: + - ecmascript + - compliance +description: > + Give setter calls the accessed property name as an additional non-standard + argument. This allows a single setter function to be reused for multiple + properties more easily. See + http://duktape.org/guide.html#propertyvirtualization. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT.yaml new file mode 100644 index 0000000..44d0ee3 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT +introduced: 1.2.0 +default: true +tags: + - ecmascript + - compliance +description: > + Allow 32-bit codepoints in String.fromCharCode(). This is non-compliant + (the E5.1 specification has a ToUint16() coercion for the codepoints) but + useful because Duktape supports non-BMP strings. + + When disabled, Duktape provides the compliant behavior. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NO_DOUBLE_ALIASING_SELFTEST.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NO_DOUBLE_ALIASING_SELFTEST.yaml new file mode 100644 index 0000000..6c9ff7e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NO_DOUBLE_ALIASING_SELFTEST.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_NO_DOUBLE_ALIASING_SELFTEST +introduced: 1.0.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Disable double aliasing selftest (if self tests enabled). + + Double aliasing testcase fails when Emscripten-generated code is run. + This is not fatal because it only affects packed duk_tval which we + avoid with Emscripten. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_NUMBER_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_NUMBER_BUILTIN.yaml new file mode 100644 index 0000000..c4b2d87 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_NUMBER_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_NUMBER_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide a Number built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_OBJECT_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_OBJECT_BUILTIN.yaml new file mode 100644 index 0000000..983dd9e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_OBJECT_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_OBJECT_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide an Object built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_OBJSIZES16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_OBJSIZES16.yaml new file mode 100644 index 0000000..a10cf1f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_OBJSIZES16.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_OBJSIZES16 +introduced: 1.1.0 +default: false +tags: + - lowmemory + - experimental +description: > + Use a 16-bit object entry and array part sizes (for low memory + environments). Also automatically drops support for an object hash part + to further reduce memory usage; there are rarely large objects in low + memory environments simply because there's no memory to store a lot of + properties. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_OCTAL_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_OCTAL_SUPPORT.yaml new file mode 100644 index 0000000..2a5d690 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_OCTAL_SUPPORT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_OCTAL_SUPPORT +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - ecmascript +description: > + Enable optional octal number support (Ecmascript E5/E5.1 + Annex B: http://www.ecma-international.org/ecma-262/5.1/#sec-B). + Recommended because existing code bases use octal numbers. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_OS_STRING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_OS_STRING.yaml new file mode 100644 index 0000000..b73aef0 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_OS_STRING.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_OS_STRING +introduced: 1.0.0 +default: + string: "unknown" +tags: + - portability +description: > + Human-readable operating system string used in e.g. Duktape.env and debugger + protocol (example: linux). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL.yaml new file mode 100644 index 0000000..1bda282 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_PACKED_TVAL +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use a packed 8-byte representation for duk_tval. The packed representation + represents non-number values as special IEEE double NaN values, and is only + possible for platforms with 32-bit pointers. When the packed representation + is not available, Duktape uses a 12-16 byte struct/union which is more + portable. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL_POSSIBLE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL_POSSIBLE.yaml new file mode 100644 index 0000000..8061032 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACKED_TVAL_POSSIBLE.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_PACKED_TVAL_POSSIBLE +introduced: 1.0.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Define when packed, 8-byte duk_tval representation is possible. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_CLANG_ATTR.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_CLANG_ATTR.yaml new file mode 100644 index 0000000..2e8e190 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_CLANG_ATTR.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_PACK_CLANG_ATTR +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use clang-specific attribute to force struct packing. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_DUMMY_MEMBER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_DUMMY_MEMBER.yaml new file mode 100644 index 0000000..5362cae --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_DUMMY_MEMBER.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_PACK_DUMMY_MEMBER +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use dummy struct member to force struct packing. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_GCC_ATTR.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_GCC_ATTR.yaml new file mode 100644 index 0000000..3457640 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_GCC_ATTR.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_PACK_GCC_ATTR +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use gcc-specific attribute to force struct packing. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_MSVC_PRAGMA.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_MSVC_PRAGMA.yaml new file mode 100644 index 0000000..b648307 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PACK_MSVC_PRAGMA.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_PACK_MSVC_PRAGMA +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Use msvc-specific attribute to force struct packing. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_ABORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_ABORT.yaml new file mode 100644 index 0000000..c62a4f4 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_ABORT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_PANIC_ABORT +introduced: 1.0.0 +removed: 2.0.0 +default: true +tags: + - portability +description: > + Call abort() when the default panic handler is invoked. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_EXIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_EXIT.yaml new file mode 100644 index 0000000..4909806 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_EXIT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_PANIC_EXIT +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - portability +description: > + Call exit() when the default panic handler is invoked. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_HANDLER.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_HANDLER.yaml new file mode 100644 index 0000000..a6ae86d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_HANDLER.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_PANIC_HANDLER +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - portability +description: > + Provide a custom panic handler. A custom panic handler is recommended for + any environment where recovery from fatal errors is important. A custom + handler can take appropriate action to recover, e.g. record the error and + reboot the target device. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_SEGFAULT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_SEGFAULT.yaml new file mode 100644 index 0000000..4792125 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PANIC_SEGFAULT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_PANIC_SEGFAULT +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - portability +description: > + Cause an intentional segfault when the default panic handler is invoked. + This is useful when debugging with valgrind because a segfault provides + a nice C traceback in valgrind. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_DATE_COMPUTATION.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_DATE_COMPUTATION.yaml new file mode 100644 index 0000000..8fbaa79 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_DATE_COMPUTATION.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_PARANOID_DATE_COMPUTATION +introduced: 1.0.0 +default: false # FIXME: make default detect C99/C++11? +tags: + - portability +description: > + There was a curious bug where test-bi-date-canceling.js would fail e.g. + on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations + using doubles would be optimized which then broke some corner case tests. + The problem goes away by adding 'volatile' to the datetime computations. + Not sure what the actual triggering conditions are, but using this on + non-C99 systems solves the known issues and has relatively little cost + on other platforms. + + Recommended for non-C99 platforms. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_ERRORS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_ERRORS.yaml new file mode 100644 index 0000000..66c613b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_ERRORS.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_PARANOID_ERRORS +introduced: 1.4.0 +default: false +tags: + - ecmascript + - sandbox +description: > + When enabled, error messages won't involve summarization of keys or values. + Summaries may be an issue in some security sensitive environments because + error messages will include e.g. property keys. + + The default is to summarize offending base value and key for property access + errors such as "null.foo = 123;", invalid calls such as "undefined()", etc. + Base values and keys are summarized using duk_push_string_tval_readable(). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_MATH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_MATH.yaml new file mode 100644 index 0000000..3aee135 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PARANOID_MATH.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_PARANOID_MATH +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Rely as little as possible on compiler behavior for NaN comparison, + signed zero handling, etc. Currently never activated but may be needed + for broken compilers. + +# FIXME: mark unused? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PC2LINE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PC2LINE.yaml new file mode 100644 index 0000000..c31b757 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PC2LINE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_PC2LINE +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Record a "pc2line" map into function instances which allows bytecode program + counter values to be mapped into line numbers e.g. in error tracebacks. + + Without this map, exceptions won't have meaningful line numbers but function + instances will have a smaller footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PERFORMANCE_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PERFORMANCE_BUILTIN.yaml new file mode 100644 index 0000000..0b47be6 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PERFORMANCE_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_PERFORMANCE_BUILTIN +introduced: 2.2.0 +default: true +tags: + - performance-api +description: > + Provide a 'performance' global object based on https://www.w3.org/TR/hr-time/. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_POW_NETBSD_WORKAROUND.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_POW_NETBSD_WORKAROUND.yaml new file mode 100644 index 0000000..09803a7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_POW_NETBSD_WORKAROUND.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_POW_NETBSD_WORKAROUND +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - portability +description: > + NetBSD 6.0 x86 (at least) has a few problems with pow() semantics, + see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround. + + (This might be a wider problem; if so, generalize the define name.) diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_POW_WORKAROUNDS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_POW_WORKAROUNDS.yaml new file mode 100644 index 0000000..91a2113 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_POW_WORKAROUNDS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_POW_WORKAROUNDS +introduced: 2.0.0 +default: false +tags: + - portability +description: > + Enable workarounds to common pow() semantics issues. At least NetBSD + 6.0 x86 and Cygwin/MinGW have such issues, see test-bug-netbsd-math-pow.js + and test-bug-mingw-math-issues.js. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PREFER_SIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PREFER_SIZE.yaml new file mode 100644 index 0000000..8113ff2 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PREFER_SIZE.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_PREFER_SIZE +introduced: 1.2.0 +default: false +tags: + - lowmemory +description: > + Catch-all flag which can be used to choose between variant algorithms + where a speed-size tradeoff exists (e.g. lookup tables). When it really + matters, specific use flags may be appropriate. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PROMISE_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PROMISE_BUILTIN.yaml new file mode 100644 index 0000000..8eb4b38 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PROMISE_BUILTIN.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_PROMISE_BUILTIN +introduced: 2.2.0 +default: false # disabled until fully functional +tags: + - ecmascript +description: > + Enable Promise built-in. + + At present entirely non-functional, and disabled by default. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS.yaml new file mode 100644 index 0000000..3afcbec --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Provide default allocation functions. + + At the moment this option should be enabled. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_RDTSC.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_RDTSC.yaml new file mode 100644 index 0000000..04b65b1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_RDTSC.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_RDTSC +introduced: 1.3.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Macro to provide an x86/x64 RDTSC timestamp for debug prints. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT16.yaml new file mode 100644 index 0000000..93d7387 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT16.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_REFCOUNT16 +introduced: 1.1.0 +default: false +tags: + - lowmemory + - experimental + - gc +description: > + Use a 16-bit reference count field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT32.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT32.yaml new file mode 100644 index 0000000..363411f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFCOUNT32.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_REFCOUNT32 +introduced: 2.1.0 +default: true +tags: + - gc +description: > + Use a 32-bit reference count field. + + While on some 64-bit systems it's theoretically possible to wrap a 32-bit + counter field, assuming a 16-byte duk_tval the Duktape heap would have to + be larger than 64GB for that to happen. Because of this the default is to + use a 32-bit refcount field. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REFERENCE_COUNTING.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFERENCE_COUNTING.yaml new file mode 100644 index 0000000..a59bad2 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFERENCE_COUNTING.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_REFERENCE_COUNTING +introduced: 1.0.0 +default: true +tags: + - gc +description: > + Use reference counting for garbage collection. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REFLECT_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFLECT_BUILTIN.yaml new file mode 100644 index 0000000..bedd9c1 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFLECT_BUILTIN.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_REFLECT_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript2015 +description: > + Provide a Reflect built-in. The ES6 Reflect object provides a collection of + methods for examining and manipulating objects at runtime. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REFZERO_FINALIZER_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFZERO_FINALIZER_TORTURE.yaml new file mode 100644 index 0000000..de83dae --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REFZERO_FINALIZER_TORTURE.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_REFZERO_FINALIZER_TORTURE +introduced: 1.3.0 +removed: 2.1.0 +related: + - DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE +default: false +tags: + - gc + - memory + - development + - torture +description: > + Development time option: simulate a fake finalizer call for every object + going through refzero freeing. This is useful to detect bugs caused by + finalizer side effects in e.g. call handling. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_BITMAP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_BITMAP.yaml new file mode 100644 index 0000000..36ca02f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_BITMAP.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_REGEXP_CANON_BITMAP +introduced: 2.2.0 +default: true +tags: + - performance + - unicode +description: > + Use a small lookup table (footprint impact is ~300-400 bytes) to speed up + case insensitive RegExp canonicalization. The result is still much slower + than with DUK_USE_REGEXP_CANON_WORKAROUND but ~50x faster than without the + lookup. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_WORKAROUND.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_WORKAROUND.yaml new file mode 100644 index 0000000..f363840 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_CANON_WORKAROUND.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_REGEXP_CANON_WORKAROUND +introduced: 1.4.0 +default: false +tags: + - performance + - unicode + - experimental +description: > + Use a 128kB lookup table for RegExp codepoint canonicalization to improve + performance of case insensitive RegExp handling. + + This is a temporary workaround until there's better support for faster + Unicode handling. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_COMPILER_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_COMPILER_RECLIMIT.yaml new file mode 100644 index 0000000..ea653d7 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_COMPILER_RECLIMIT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_REGEXP_COMPILER_RECLIMIT +introduced: 1.3.0 +default: 10000 +tags: + - portability + - cstackdepth +description: > + RegExp compiler native call stack recursion limit. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_EXECUTOR_RECLIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_EXECUTOR_RECLIMIT.yaml new file mode 100644 index 0000000..cc1dfca --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_EXECUTOR_RECLIMIT.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_REGEXP_EXECUTOR_RECLIMIT +introduced: 1.3.0 +default: 10000 +tags: + - portability + - cstackdepth +description: > + RegExp executor native call stack recursion limit. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_SUPPORT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_SUPPORT.yaml new file mode 100644 index 0000000..39ed04e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REGEXP_SUPPORT.yaml @@ -0,0 +1,15 @@ +define: DUK_USE_REGEXP_SUPPORT +introduced: 1.0.0 +default: true +tags: + - ecmascript + - lowmemory +description: > + Enable support for regular expressions (recommended). + + When disabled, regexp literals are treated as a SyntaxError, RegExp + constructor and prototype functions throw an error, + String.prototype.replace() throws an error if given a regexp search value, + String.prototype.split() throws an error if given a regexp separator value, + String.prototype.search() and String.prototype.match() throw an error + unconditionally. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_FPCLASSIFY.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_FPCLASSIFY.yaml new file mode 100644 index 0000000..7daa08d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_FPCLASSIFY.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_REPL_FPCLASSIFY +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Provide a built-in replacement for fpclassify(), duk_repl_fpclassify. + + When enabled, define DUK_FPCLASSIFY as duk_repl_fpclassify. + +# FIXME: the dependency between DUK_USE_REPL_FPCLASSIFY and DUK_FPCLASSIFY +# is a bit awkward. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISFINITE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISFINITE.yaml new file mode 100644 index 0000000..9ab6f46 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISFINITE.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_REPL_ISFINITE +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Provide a built-in replacement for isfinite(), duk_repl_isfinite. + + When enabled, define DUK_ISFINITE as duk_repl_isfinite. + +# FIXME: the dependency between DUK_USE_REPL_ISFINITE and DUK_ISFINITE +# is a bit awkward. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISINF.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISINF.yaml new file mode 100644 index 0000000..c7613ba --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISINF.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_REPL_ISINF +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Provide a built-in replacement for isinf(), duk_repl_isinf. + + When enabled, define DUK_ISINF as duk_repl_isinf. + +# FIXME: the dependency between DUK_USE_REPL_ISINF and DUK_ISINF +# is a bit awkward. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISNAN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISNAN.yaml new file mode 100644 index 0000000..862b94d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_ISNAN.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_REPL_ISNAN +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Provide a built-in replacement for isnan(), duk_repl_isnan. + + When enabled, define DUK_ISNAN as duk_repl_isnan. + +# FIXME: the dependency between DUK_USE_REPL_ISNAN and DUK_ISNAN +# is a bit awkward. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_SIGNBIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_SIGNBIT.yaml new file mode 100644 index 0000000..d9f3682 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_REPL_SIGNBIT.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_REPL_SIGNBIT +introduced: 1.0.0 +default: false +tags: + - portability +description: > + Provide a built-in replacement for signbit(), duk_repl_signbit. + + When enabled, define DUK_SIGNBIT as duk_repl_signbit. + +# FIXME: the dependency between DUK_USE_REPL_SIGNBIT and DUK_SIGNBIT +# is a bit awkward. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_CLONE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_CLONE.yaml new file mode 100644 index 0000000..70cdb5f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_CLONE.yaml @@ -0,0 +1,18 @@ +define: DUK_USE_ROM_GLOBAL_CLONE +introduced: 1.5.0 +requires: + - DUK_USE_ROM_STRINGS + - DUK_USE_ROM_OBJECTS +conflicts: + - DUK_USE_ROM_GLOBAL_INHERIT +default: false +tags: + - lowmemory + - experimental +description: > + When using ROM built-in objects, create a RAM-based global object by copying + the properties of the ROM-based global object into a fresh empty object. + + Having a writable global object is usually expected; if the global object is + not writable, it's not possible to e.g. declare functions outside of CommonJS + modules. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_INHERIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_INHERIT.yaml new file mode 100644 index 0000000..fbfec9a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_GLOBAL_INHERIT.yaml @@ -0,0 +1,23 @@ +define: DUK_USE_ROM_GLOBAL_INHERIT +introduced: 1.5.0 +requires: + - DUK_USE_ROM_STRINGS + - DUK_USE_ROM_OBJECTS +conflicts: + - DUK_USE_ROM_GLOBAL_CLONE +default: false +tags: + - lowmemory + - experimental +description: > + When using ROM built-in objects, create a RAM-based global object by creating + a fresh empty object which inherits from the ROM-based global object. This + provides all the standard bindings with a small RAM footprint cost, but still + allows the global object to be extended and existing bindings overwritten + (but not deleted). The downside of this compared to cloning a global object + is that the inheritance is not fully transparent and the result is less + compliant. + + Having a writable global object is usually expected; if the global object is + not writable, it's not possible to e.g. declare functions outside of CommonJS + modules. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_OBJECTS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_OBJECTS.yaml new file mode 100644 index 0000000..6983b82 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_OBJECTS.yaml @@ -0,0 +1,22 @@ +define: DUK_USE_ROM_OBJECTS +introduced: 1.5.0 +requires: + - DUK_USE_ROM_STRINGS # use both DUK_USE_ROM_STRINGS + DUK_USE_ROM_OBJECTS together for now +default: false +tags: + - lowmemory + - experimental +description: > + Enable support for built-in objects compiled as constants and placed in a + read-only data section. This reduces startup RAM usage considerably at the + cost of a larger code footprint and slower performance overall. The built-in + objects will be immutable: the objects will be non-extensible. + + ROM objects will always be non-extensible and properties are forced to be + non-configurable. Other property attributes will have their usual values; + in particular, properties can be "writable" from a property attributes + standpoint, but an attempt to actually change the property value will fail + with a TypeError. This may seem strange, but is necessary to allow a + property value to be overridden in a RAM object inheriting from a ROM object: + if the inherited ROM property was not writable, Ecmascript semantics would + prevent a new property from being established in the RAM object. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_PTRCOMP_FIRST.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_PTRCOMP_FIRST.yaml new file mode 100644 index 0000000..50fa63c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_PTRCOMP_FIRST.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_ROM_PTRCOMP_FIRST +introduced: 1.5.0 +related: + - DUK_USE_ROM_STRINGS + - DUK_USE_ROM_OBJECTS +default: 0xf800 +tags: + - lowmemory + - experimental +description: > + When using ROM pointer compression ROM pointers are compressed to the + integer range [DUK_USE_ROM_PTRCOMP_FIRST,0xffff]. The default value + allows for 2048 ROM pointers, which can point to objects and strings. + + You may need to lower this value to support more pointers if there are + a lot of custom ROM strings/objects. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_STRINGS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_STRINGS.yaml new file mode 100644 index 0000000..bdb8871 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ROM_STRINGS.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_ROM_STRINGS +introduced: 1.5.0 +requires: + - DUK_USE_ROM_OBJECTS # use both DUK_USE_ROM_STRINGS + DUK_USE_ROM_OBJECTS together for now +default: false +tags: + - lowmemory + - experimental +description: > + Enable support for built-in (and optional user-supplied strings) which are + compiled as constants and placed in a read-only data section. This reduces + startup RAM usage considerably at the cost of a larger code footprint and + slower string interning. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SECTION_B.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SECTION_B.yaml new file mode 100644 index 0000000..11f4990 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SECTION_B.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_SECTION_B +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Enable optional features in Ecmascript specification + Annex B: http://www.ecma-international.org/ecma-262/5.1/#sec-B. + + When disabled, escape(), unescape(), and String.prototype.substr() + throw an error. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SELF_TESTS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SELF_TESTS.yaml new file mode 100644 index 0000000..8c9b77c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SELF_TESTS.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_SELF_TESTS +introduced: 1.0.0 +default: false +tags: + - debug +description: > + Perform run-time self tests when a Duktape heap is created. Catches + platform/compiler problems which cannot be reliably detected during + compile time. Not enabled by default because of the extra footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SETJMP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SETJMP.yaml new file mode 100644 index 0000000..5dcca01 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SETJMP.yaml @@ -0,0 +1,17 @@ +define: DUK_USE_SETJMP +introduced: 1.1.0 +removed: 1.5.0 +default: true +tags: + - portability +description: > + Use setjmp/longjmp for long control transfers. This is the most portable + option for long control transfers. + + The downside of setjmp/longjmp is that signal mask saving behavior is not + specified and varies between platforms. Signal mask saving may have a + significant performance impact so you may want to force a specific provider + if performance matters for your application. (This is the case for OSX, + for instance.) + + Removed in Duktape 1.5.0: edit duk_config.h directly. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SHEBANG_COMMENTS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SHEBANG_COMMENTS.yaml new file mode 100644 index 0000000..221b0d6 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SHEBANG_COMMENTS.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_SHEBANG_COMMENTS +introduced: 2.1.0 +default: true +tags: + - ecmascript2015 +description: > + Support parsing of a "shebang" comment ('#!...') on the first line of + source text. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SHUFFLE_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SHUFFLE_TORTURE.yaml new file mode 100644 index 0000000..822ca6e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SHUFFLE_TORTURE.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_SHUFFLE_TORTURE +introduced: 1.2.0 +default: false +tags: + - gc + - memory + - development + - torture +description: > + Development time option: force compiler to shuffle every possible opcode + to stress shuffle behavior which is otherwise difficult to test for + comprehensively. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SIGSETJMP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SIGSETJMP.yaml new file mode 100644 index 0000000..7a9a383 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SIGSETJMP.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_SIGSETJMP +introduced: 1.1.0 +removed: 1.5.0 +default: false +tags: + - portability +description: > + Use sigsetjmp/siglongjmp with savesigs == 0 for long control + transfers (i.e. signal mask not saved/restored). See comments in + DUK_USE_SETJMP. + + Removed in Duktape 1.5.0: edit duk_config.h directly. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SOURCE_NONBMP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SOURCE_NONBMP.yaml new file mode 100644 index 0000000..9682a17 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SOURCE_NONBMP.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_SOURCE_NONBMP +introduced: 1.0.0 +default: true +tags: + - ecmascript + - lowmemory +description: > + Enable accurate Unicode support for non-BMP characters in source code. + + When disabled non-BMP characters are always accepted as identifier + characters. Disabling this option saves a little bit of code footprint. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH16.yaml new file mode 100644 index 0000000..f66e36b --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH16.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_STRHASH16 +introduced: 1.1.0 +default: false +tags: + - lowmemory + - experimental +description: > + Use a 16-bit string hash field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_DENSE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_DENSE.yaml new file mode 100644 index 0000000..af1b28f --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_DENSE.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_STRHASH_DENSE +introduced: 1.4.0 +default: false +tags: + - performance + - sandbox +description: > + Use the slower but more dense string hash algorithm from Duktape 1.3.0 and + prior (based on Murmurhash2). This may be useful if you're experiencing + collision issues with the default hash algorithm. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_SKIP_SHIFT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_SKIP_SHIFT.yaml new file mode 100644 index 0000000..d9a4d04 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRHASH_SKIP_SHIFT.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_STRHASH_SKIP_SHIFT +introduced: 1.4.0 +default: 5 +tags: + - performance +description: > + Shift value to use for string hash skip offset when using the default + (fast) string hash. The skip offset is calculated as: + ((length >> DUK_USE_STRHASH_SKIP_SHIFT) + 1). A higher value will be + slower but sample the string more densely. + + You should only change this if you run into issues with the default value. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_DECL.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_DECL.yaml new file mode 100644 index 0000000..533bf74 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_DECL.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_STRICT_DECL +introduced: 1.1.0 +default: true +tags: + - ecmascript + - experimental +description: > + Enable support for "use strict" declaration (recommended). + + When disabled, Ecmascript code is always executed in non-strict mode. + Duktape/C functions remain strict. This option is useful in some legacy + environments where "use strict" declarations are used in existing code + base but the Javascript engine didn't actually support strict mode. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_UTF8_SOURCE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_UTF8_SOURCE.yaml new file mode 100644 index 0000000..ceac807 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRICT_UTF8_SOURCE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_STRICT_UTF8_SOURCE +introduced: 1.0.0 +default: false +tags: + - ecmascript +description: > + Enable strict UTF-8 parsing of source code. + + When disabled, non-shortest encodings (normally invalid UTF-8) and surrogate + pair codepoints are accepted as valid source code characters. Disabling + this option breaks compatibility with some test262 tests. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRING_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRING_BUILTIN.yaml new file mode 100644 index 0000000..c9d11ed --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRING_BUILTIN.yaml @@ -0,0 +1,7 @@ +define: DUK_USE_STRING_BUILTIN +introduced: 2.0.0 +default: true +tags: + - ecmascript +description: > + Provide a String built-in. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRLEN16.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRLEN16.yaml new file mode 100644 index 0000000..4d8a801 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRLEN16.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_STRLEN16 +introduced: 1.1.0 +default: false +tags: + - lowmemory + - experimental +description: > + Use a 16-bit string length field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN.yaml new file mode 100644 index 0000000..67c3205 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN.yaml @@ -0,0 +1,27 @@ +define: DUK_USE_STRTAB_CHAIN +introduced: 1.1.0 +removed: 2.1.0 +related: + - DUK_USE_STRTAB_CHAIN_SIZE +default: false +tags: + - lowmemory +description: > + Replace the default (open addressing, probing) string table structure with + one based on separate chaining. There is a fixed-size top level hash table + (whose size is defined using DUK_USE_STRTAB_CHAIN_SIZE), with each entry in + the hash table being: (a) NULL, (b) a duk_hstring pointer, or (c) a pointer + to an array of duk_hstring pointers. The pointer arrays are gappy (the gaps + are reused on new inserts) and are never shrunk at the moment. + + This option is intended for low memory environments to make Duktape's memory + behavior match a typical pool-based allocator better as follows: + + The top level fixed structure never changes size, so there is no hash table + resize, and thus no need for resize temporaries. The default string table + algorithm needs resizing from time to time and doesn't resize in place, so + you effectively need twice the string table size temporarily during a resize. + + The pointer arrays vary in size, but their size (typically 8 to 64 bytes, + depending on the load factor) matches that of many other allocations which + works well with a pooled allocator. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN_SIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN_SIZE.yaml new file mode 100644 index 0000000..a1e4f08 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_CHAIN_SIZE.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_STRTAB_CHAIN_SIZE +introduced: 1.1.0 +removed: 2.1.0 +requires: + - DUK_USE_STRTAB_CHAIN +default: false +tags: + - lowmemory +description: > + Define stringtable size for DUK_USE_STRTAB_CHAIN. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_GROW_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_GROW_LIMIT.yaml new file mode 100644 index 0000000..111a1a8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_GROW_LIMIT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_STRTAB_GROW_LIMIT +introduced: 2.1.0 +default: 17 # 17/16 = 1.0625 +tags: + - performance + - lowmemory +description: > + Grow top level strtable allocation when load factor reaches this value. + Expressed as a .4 fixed point; the load factor is computed as + floor((count / size) * 16.0), e.g. 32 means a load factor of 2.0. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MAXSIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MAXSIZE.yaml new file mode 100644 index 0000000..da7feef --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MAXSIZE.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_STRTAB_MAXSIZE +introduced: 2.1.0 +default: 268435456 +tags: + - performance + - lowmemory +description: > + Maximum size for Duktape heap string table, must be 2^N, and small enough + so that if the value is multiplied by sizeof(duk_hstring *) it won't overflow + duk_size_t. + + To avoid resizing the strtable at all, set DUK_USE_STRTAB_MINSIZE and + DUK_USE_STRTAB_MAXSIZE to the same value. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MINSIZE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MINSIZE.yaml new file mode 100644 index 0000000..55ba319 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_MINSIZE.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_STRTAB_MINSIZE +introduced: 2.1.0 +default: 1024 +tags: + - performance + - lowmemory +description: > + Minimum size for Duktape heap string table, must be 2^N, and should never + be lower than 64. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PROBE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PROBE.yaml new file mode 100644 index 0000000..c65ac17 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PROBE.yaml @@ -0,0 +1,8 @@ +define: DUK_USE_STRTAB_PROBE +introduced: 1.1.0 +removed: 2.1.0 +default: true +tags: + - lowmemory +description: > + Use the default open addressing (probing) based string table algorithm. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PTRCOMP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PTRCOMP.yaml new file mode 100644 index 0000000..7b93bff --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_PTRCOMP.yaml @@ -0,0 +1,14 @@ +define: DUK_USE_STRTAB_PTRCOMP +introduced: 2.1.0 +default: false +requires: + - DUK_USE_HEAPPTR16 +tags: + - performance + - lowmemory +description: > + Pointer compress the top level heap->strtable[] string table. On 32-bit + targets this saves 2 bytes per entry, e.g. for 256 entries 0.5kB. However, + the additional pointer compression code increases footprint by 200-300 + bytes. The option also reduces performance a little bit, so this should + be enabled when RAM is much more constrained than ROM. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_RESIZE_CHECK_MASK.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_RESIZE_CHECK_MASK.yaml new file mode 100644 index 0000000..383a434 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_RESIZE_CHECK_MASK.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_STRTAB_RESIZE_CHECK_MASK +introduced: 2.1.0 +default: 255 +tags: + - performance + - lowmemory +description: > + Somewhat technical: bit mask (must be 2^N-1) used against heap->st_count to + determine the interval between string table resize checks. A resize check + is made when heap->st_count & DUK_USE_STRTAB_RESIZE_CHECK_MASK is zero. + + A large value makes string table grow/shrink checks less frequent. Usually + this has very little practical impact on memory performance. There are + corner cases, such as dereferencing a large number of strings simultaneously, + where this parameter affects how many new strings need to be inserted before + the string table shrinks to a more appropriate size. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_SHRINK_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_SHRINK_LIMIT.yaml new file mode 100644 index 0000000..372d916 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_SHRINK_LIMIT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_STRTAB_SHRINK_LIMIT +introduced: 2.1.0 +default: 6 # 6/16 = 0.375 +tags: + - performance + - lowmemory +description: > + Shrink top level strtable allocation when load factor reaches this value. + Expressed as a .4 fixed point; the load factor is computed as + floor((count / size) * 16.0), e.g. 8 means a load factor of 0.5. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_TORTURE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_TORTURE.yaml new file mode 100644 index 0000000..86186e8 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_STRTAB_TORTURE.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_STRTAB_TORTURE +introduced: 2.1.0 +default: false +tags: + - torture +description: > + Resize string table (grow, shrink back) for every intern. Ensures string + table chaining is correct, and resize side effects are exercised on every + resize. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_SYMBOL_BUILTIN.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_SYMBOL_BUILTIN.yaml new file mode 100644 index 0000000..75611ae --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_SYMBOL_BUILTIN.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_SYMBOL_BUILTIN +introduced: 2.0.0 +default: false +tags: + - ecmascript2015 +description: > + Provide ES6 Symbol built-ins (experimental in Duktape 2.0.0). + + Even with the built-ins disabled, symbols created by C code are still + supported. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_TAILCALL.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_TAILCALL.yaml new file mode 100644 index 0000000..55fc5c2 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_TAILCALL.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_TAILCALL +introduced: 1.0.0 +conflicts: + - DUK_USE_NONSTD_FUNC_CALLER_PROPERTY +default: true +tags: + - ecmascript +description: > + Enable tail call support (recommended). + + The non-standard function 'caller' property feature conflicts with + tailcalls quite severely so tailcalls must be disabled if the 'caller' + property is enabled. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_TARGET_INFO.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_TARGET_INFO.yaml new file mode 100644 index 0000000..6ea3305 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_TARGET_INFO.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_TARGET_INFO +introduced: 1.2.0 +default: + string: "unknown" +tags: + - debugger +description: > + Define a freeform human readable string to describe the target device (e.g. + "Arduino Yun"). This string will be sent as part of version/target info in + the debugger protocol and shows up in the debugger UI. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACKS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACKS.yaml new file mode 100644 index 0000000..f9f4bda --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACKS.yaml @@ -0,0 +1,12 @@ +define: DUK_USE_TRACEBACKS +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Record traceback data into Ecmascript error objects. + + When disabled, traceback data is not recorded, but fileName/lineNumber of + the error cause are still recorded as explicit properties. Disabling this + option reduces footprint and makes error handling a bit faster, at the cost + of less informative Ecmascript errors. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACK_DEPTH.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACK_DEPTH.yaml new file mode 100644 index 0000000..6c8093d --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_TRACEBACK_DEPTH.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_TRACEBACK_DEPTH +introduced: 1.0.0 +default: 10 +tags: + - ecmascript +description: > + Define traceback collection depth. A large number causes tracedata to be + larger, taking more time to create and consuming more memory. A small + number makes tracebacks less useful. + + When tracebacks are disabled this option affects .fileName and .lineNumber + blaming. Error augmentation code won't look deeper than this value to find + a function to blame for error .fileName / .lineNumber. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_UNALIGNED_ACCESSES_POSSIBLE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_UNALIGNED_ACCESSES_POSSIBLE.yaml new file mode 100644 index 0000000..ea66754 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_UNALIGNED_ACCESSES_POSSIBLE.yaml @@ -0,0 +1,9 @@ +define: DUK_USE_UNALIGNED_ACCESSES_POSSIBLE +introduced: 1.0.0 +removed: 1.4.0 +default: false +tags: + - portability +description: > + Target architecture unaligned memory accesses (e.g. 32-bit integer access + from an arbitrary address). diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_UNDERSCORE_SETJMP.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_UNDERSCORE_SETJMP.yaml new file mode 100644 index 0000000..39a0420 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_UNDERSCORE_SETJMP.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_UNDERSCORE_SETJMP +introduced: 1.1.0 +removed: 1.5.0 +default: false +tags: + - portability +description: > + Use _setjmp/_longjmp for long control transfers. This ensures signal + mask is not saved which can be a lot faster if setjmp/longjmp saves the + signal mask (this varies between platforms). See comments in + DUK_USE_SETJMP. + + Removed in Duktape 1.5.0: edit duk_config.h directly. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_UNION_INITIALIZERS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_UNION_INITIALIZERS.yaml new file mode 100644 index 0000000..4cd5424 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_UNION_INITIALIZERS.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_UNION_INITIALIZERS +introduced: 1.5.0 +default: false +tags: + - portability +description: > + Compiler supports C99-style designated union initializers, e.g. + { .foo = 123 }. + + When disabled, Duktape sometimes needs to resort to less efficient struct + initializers for portability. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_USER_DECLARE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_USER_DECLARE.yaml new file mode 100644 index 0000000..755ca4e --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_USER_DECLARE.yaml @@ -0,0 +1,18 @@ +define: DUK_USE_USER_DECLARE +introduced: 1.0.0 +default: + verbatim: '#define DUK_USE_USER_DECLARE() /* no user declarations */' +tags: + - portability +description: > + Provide declarations or additional preprocessor include directives to be + used when compiling Duktape. You may need this if you set + DUK_USE_PANIC_HANDLER to call your own panic handler function. You can + also use this option to cause additional files to be included when compiling + Duktape. + + NOTE: This is only needed if using the default autodetecting duk_config.h + header. When providing DUK_USE_xxx flags directly, you should just provide + all the necessary declarations in duk_config.h directly. + +# FIXME: to be removed? diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_USER_INITJS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_USER_INITJS.yaml new file mode 100644 index 0000000..cb39223 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_USER_INITJS.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_USER_INITJS +introduced: 1.0.0 +removed: 2.0.0 +default: false +tags: + - portability +description: > + Provide a string to evaluate when a thread with new built-ins (a new global + environment) is created. This allows you to make minor modifications to the + global environment before any code is executed in it. The value must be a + string, e.g.:: -DDUK_OPT_USER_INITJS='"this.foo = 123"'. + + Errors in the initialization code result in a fatal error. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_GROW_SHIFT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_GROW_SHIFT.yaml new file mode 100644 index 0000000..3f122a5 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_GROW_SHIFT.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_VALSTACK_GROW_SHIFT +introduced: 2.2.0 +default: 2 +tags: + - performance + - lowmemory +description: > + When growing the value stack, shift minimum size right by this amount to + come up with a slack which is allocated on top of the minimum required + size. The slack increases memory usage a bit, but reduces value stack + reallocations when the minimum size grows. A value of 2 means that a + 25% slack is used. Undefine to remove any slack, value stack is then + always grown by the minimum amount possible. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_LIMIT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_LIMIT.yaml new file mode 100644 index 0000000..da9c352 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_LIMIT.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_VALSTACK_LIMIT +introduced: 2.2.0 +default: 1000000 +tags: + - misc +description: > + Maximum value stack size. If value stack is about to be grown beyond this + size (the check includes a possible spare so the check isn't exact) reject + the resize. The limit must be low enough so that when multiplied by + sizeof(duk_tval), typically 8 or 16, the multiplication won't overflow + size_t. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT.yaml new file mode 100644 index 0000000..a06162a --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT.yaml @@ -0,0 +1,13 @@ +define: DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT +introduced: 2.2.0 +default: 2 +tags: + - performance + - lowmemory +description: > + When doing a value stack shrink check, skip shrinking if the difference + between the minimum reserve and allocated size is less than + (curr_size >> DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT) bytes. A value of 2 + means that the difference must be at least 25% for a shrink to happen. + If undefined, value stack is always shrunk to the minimum reserved size + with no slack. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT.yaml new file mode 100644 index 0000000..341e445 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT +introduced: 2.2.0 +default: 4 +tags: + - performance + - lowmemory +description: > + When shrinking, leave (curr_size >> DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT) + bytes as a slack. This shift count must be larger than + DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_UNSAFE.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_UNSAFE.yaml new file mode 100644 index 0000000..4c0f881 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VALSTACK_UNSAFE.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_VALSTACK_UNSAFE +introduced: 1.2.0 +default: false +tags: + - performance + - experimental +description: > + Don't check allocated value stack size in operations like value stack + pushes. Improves performance of API calls but causes unsafe memory + behavior (e.g. a segfault) when user code pushes beyond "checked" value + stack size. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VARIADIC_MACROS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VARIADIC_MACROS.yaml new file mode 100644 index 0000000..be08169 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VARIADIC_MACROS.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_VARIADIC_MACROS +introduced: 1.0.0 +default: true +tags: + - portability +description: > + Compiler supports C99-style variadic macros. Highly recommended to enable + when possible. + + When disabled, Duktape needs to resort to various hacks to work around + missing support for variadic macros. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_ERRORS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_ERRORS.yaml new file mode 100644 index 0000000..1ad9127 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_ERRORS.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_VERBOSE_ERRORS +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Provide error message strings and file/line information for errors generated + by Duktape. + + When disabled, reduces footprint at the cost of much less informative + Ecmascript errors. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_EXECUTOR_ERRORS.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_EXECUTOR_ERRORS.yaml new file mode 100644 index 0000000..a23cc9c --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VERBOSE_EXECUTOR_ERRORS.yaml @@ -0,0 +1,10 @@ +define: DUK_USE_VERBOSE_EXECUTOR_ERRORS +introduced: 1.0.0 +default: true +tags: + - ecmascript +description: > + Use verbose error messages in bytecode executor (recommended). + + When disabled, reduces footprint slightly at the cost of more obscure + error messages. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_VOLUNTARY_GC.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_VOLUNTARY_GC.yaml new file mode 100644 index 0000000..530df47 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_VOLUNTARY_GC.yaml @@ -0,0 +1,16 @@ +define: DUK_USE_VOLUNTARY_GC +introduced: 1.0.0 +default: true +tags: + - gc + - memory +description: > + Enable voluntary periodic mark-and-sweep collection. + + When disabled, a mark-and-sweep collection is still triggered in an + out-of-memory condition (known as "emergency GC". When disabling this + option it's recommended to use reference counting which collects all + non-cyclical garbage. Application code should also request an explicit + garbage collection from time to time when appropriate. When this option + is disabled, Duktape will have no garbage collection pauses in ordinary + use, which is useful for timing sensitive applications like games. diff --git a/lib/duktape-2.2.1/config/config-options/DUK_USE_ZERO_BUFFER_DATA.yaml b/lib/duktape-2.2.1/config/config-options/DUK_USE_ZERO_BUFFER_DATA.yaml new file mode 100644 index 0000000..4015c93 --- /dev/null +++ b/lib/duktape-2.2.1/config/config-options/DUK_USE_ZERO_BUFFER_DATA.yaml @@ -0,0 +1,11 @@ +define: DUK_USE_ZERO_BUFFER_DATA +introduced: 1.0.0 +default: true +tags: + - memory + - ecmascript +description: > + Zero data are of newly allocated buffer values (recommended). + + When disabled, buffers are not zeroed and may contain arbitrary data. + Disabling this option only makes sense for performance reasons. diff --git a/lib/duktape-2.2.1/config/examples/compliance.yaml b/lib/duktape-2.2.1/config/examples/compliance.yaml new file mode 100644 index 0000000..112640d --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/compliance.yaml @@ -0,0 +1,20 @@ +# Enable compliant behavior, defaults favor "real world" compatibility. + +DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER: false +DUK_USE_NONSTD_ARRAY_MAP_TRAILER: false +DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT: false +DUK_USE_NONSTD_FUNC_CALLER_PROPERTY: false +DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY: false +DUK_USE_NONSTD_FUNC_STMT: false +DUK_USE_NONSTD_GETTER_KEY_ARGUMENT: false +DUK_USE_NONSTD_JSON_ESC_U2028_U2029: false +DUK_USE_NONSTD_SETTER_KEY_ARGUMENT: false +DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT: false +DUK_USE_ES6_REGEXP_SYNTAX: false # for ES5 compliance, disable ES6-only regexp extra syntax + +# These Array fast paths assume Array.prototype has no inherited index +# properties which might affect reads/writes. Such properties are very +# rare so this assumption is usually a good one; for strict compliance, +# disable the fast paths. +DUK_USE_ARRAY_PROP_FASTPATH: false +DUK_USE_ARRAY_FASTPATH: false diff --git a/lib/duktape-2.2.1/config/examples/debugger_support.yaml b/lib/duktape-2.2.1/config/examples/debugger_support.yaml new file mode 100644 index 0000000..4986adc --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/debugger_support.yaml @@ -0,0 +1,24 @@ +# Enable debugger support in general, also needs interrupt support. +DUK_USE_INTERRUPT_COUNTER: true +DUK_USE_DEBUGGER_SUPPORT: true + +# Basic set of Notifys. +DUK_USE_DEBUGGER_THROW_NOTIFY: true + +# Automatically pause on an uncaught error about to be thrown. +DUK_USE_DEBUGGER_PAUSE_UNCAUGHT: true + +# Enable DumpHeap command (experimental). +DUK_USE_DEBUGGER_DUMPHEAP: true + +# Enable object inspection commands: GetHeapObjInfo, GetObjPropDesc, +# GetObjPropDescRange. +DUK_USE_DEBUGGER_INSPECT: true + +# Transport torture testing: enable when testing your transport +# implementation. +DUK_USE_DEBUGGER_TRANSPORT_TORTURE: false + +# NOTE: If you're using the Duktape command line utility for debugging +# (duk --debugger ...), remember to enable debugger support for the command +# line tool when compiling it: -DDUK_CMDLINE_DEBUGGER_SUPPORT. diff --git a/lib/duktape-2.2.1/config/examples/disable_bufferobjects.yaml b/lib/duktape-2.2.1/config/examples/disable_bufferobjects.yaml new file mode 100644 index 0000000..23b85a8 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/disable_bufferobjects.yaml @@ -0,0 +1,3 @@ +# Disable support for typed arrays and Node.js Buffer. Duktape will still +# support plain buffers and Duktape.Buffer. +DUK_USE_BUFFEROBJECT_SUPPORT: false diff --git a/lib/duktape-2.2.1/config/examples/disable_es6.yaml b/lib/duktape-2.2.1/config/examples/disable_es6.yaml new file mode 100644 index 0000000..26c3411 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/disable_es6.yaml @@ -0,0 +1,5 @@ +# Disable ES2015 features. + +DUK_USE_ES6_OBJECT_PROTO_PROPERTY: false +DUK_USE_ES6_OBJECT_SETPROTOTYPEOFS: false +DUK_USE_ES6_PROXY: false diff --git a/lib/duktape-2.2.1/config/examples/enable_debug_print0.yaml b/lib/duktape-2.2.1/config/examples/enable_debug_print0.yaml new file mode 100644 index 0000000..1f8392e --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/enable_debug_print0.yaml @@ -0,0 +1,3 @@ +# Enable debug level 0. +DUK_USE_DEBUG: true +DUK_USE_DEBUG_LEVEL: 0 diff --git a/lib/duktape-2.2.1/config/examples/enable_debug_print1.yaml b/lib/duktape-2.2.1/config/examples/enable_debug_print1.yaml new file mode 100644 index 0000000..00f3c7e --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/enable_debug_print1.yaml @@ -0,0 +1,3 @@ +# Enable debug level 1. +DUK_USE_DEBUG: true +DUK_USE_DEBUG_LEVEL: 1 diff --git a/lib/duktape-2.2.1/config/examples/enable_debug_print2.yaml b/lib/duktape-2.2.1/config/examples/enable_debug_print2.yaml new file mode 100644 index 0000000..45ac617 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/enable_debug_print2.yaml @@ -0,0 +1,3 @@ +# Enable debug level 2. +DUK_USE_DEBUG: true +DUK_USE_DEBUG_LEVEL: 2 diff --git a/lib/duktape-2.2.1/config/examples/enable_fastint.yaml b/lib/duktape-2.2.1/config/examples/enable_fastint.yaml new file mode 100644 index 0000000..16ff5c9 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/enable_fastint.yaml @@ -0,0 +1,3 @@ +# Enable fastint support. + +DUK_USE_FASTINT: true diff --git a/lib/duktape-2.2.1/config/examples/low_memory.yaml b/lib/duktape-2.2.1/config/examples/low_memory.yaml new file mode 100644 index 0000000..a10020e --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/low_memory.yaml @@ -0,0 +1,139 @@ +# Base configuration for low memory environments, see +# doc/low-memory.rst: +# +# - Strips verbose errors etc +# - Strips some ES2015 features like Proxy support (re-enable if needed) +# - Strips some Duktape custom feature like JX/JC; keeps e.g. RegExp +# and other standard parts +# - Strips some commonly unnecessary API calls like bytecode dump/load +# - Does not enable pointer compression or external strings: these +# need target specific support code +# - Does not enable ROM string/object support by default, enable manually +# + +DUK_USE_PREFER_SIZE: true +DUK_USE_EXEC_PREFER_SIZE: true +DUK_USE_FAST_REFCOUNT_DEFAULT: false +DUK_USE_AUGMENT_ERROR_CREATE: false +DUK_USE_AUGMENT_ERROR_THROW: false +DUK_USE_TRACEBACKS: false +DUK_USE_ERRCREATE: false +DUK_USE_ERRTHROW: false +DUK_USE_VERBOSE_ERRORS: false +DUK_USE_PARANOID_ERRORS: true +DUK_USE_FATAL_MAXLEN: 64 +DUK_USE_VERBOSE_EXECUTOR_ERRORS: false # <100 bytes footprint +DUK_USE_DEBUGGER_SUPPORT: false # must be disabled if DUK_USE_PC2LINE is disabled +DUK_USE_PC2LINE: false +DUK_USE_LEXER_SLIDING_WINDOW: false +DUK_USE_JSON_STRINGIFY_FASTPATH: false +DUK_USE_JSON_QUOTESTRING_FASTPATH: false +DUK_USE_JSON_DECSTRING_FASTPATH: false +DUK_USE_JSON_DECNUMBER_FASTPATH: false +DUK_USE_JSON_EATWHITE_FASTPATH: false +DUK_USE_BASE64_FASTPATH: false +DUK_USE_HEX_FASTPATH: false +DUK_USE_IDCHAR_FASTPATH: false +DUK_USE_ARRAY_PROP_FASTPATH: false +DUK_USE_ARRAY_FASTPATH: false +DUK_USE_BYTECODE_DUMP_SUPPORT: false +DUK_USE_JX: false +DUK_USE_JC: false +#DUK_USE_REGEXP_SUPPORT: false +DUK_USE_DEBUG_BUFSIZE: 2048 +DUK_USE_LIGHTFUNC_BUILTINS: true + +# Grow value stack without any slack, and shrink to minimum reserved size with +# no slack. Increases allocation traffic but avoids allocating space not +# actually needed. +DUK_USE_VALSTACK_GROW_SHIFT: false +DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT: false +DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT: false + +# Using the same minsize and maxsize drops code footprint by around 400 bytes +# (string table resize code is omitted). Enabling DUK_USE_STRTAB_PTRCOMP +# saves some RAM (two bytes per strtab entry) at the cost of 200-300 bytes of +# code footprint. +DUK_USE_STRTAB_MINSIZE: 128 +DUK_USE_STRTAB_MAXSIZE: 128 +DUK_USE_STRTAB_SHRINK_LIMIT: 0 # doesn't matter if minsize==masize +DUK_USE_STRTAB_GROW_LIMIT: 65536 # -""- +DUK_USE_STRTAB_RESIZE_CHECK_MASK: 255 # -""- +#DUK_USE_STRTAB_PTRCOMP: true # sometimes useful with pointer compression + +DUK_USE_HSTRING_ARRIDX: false +DUK_USE_HSTRING_LAZY_CLEN: false # non-lazy charlen is smaller + +# Only add a hash table for quite large objects to conserve memory. Even +# lower memory targets usually drop hash part support entirely. +DUK_USE_HOBJECT_HASH_PROP_LIMIT: 64 + +# Disable freelist caching. +DUK_USE_CACHE_ACTIVATION: false +DUK_USE_CACHE_CATCHER: false + +# Consider using pointer compression, see doc/low-memory.rst. +#DUK_USE_REFCOUNT16: true +#DUK_USE_REFCOUNT32: false +#DUK_USE_STRHASH16: true +#DUK_USE_STRLEN16: true +#DUK_USE_BUFLEN16: true +#DUK_USE_OBJSIZES16: true +#DUK_USE_HSTRING_CLEN: false +#DUK_USE_HSTRING_LAZY_CLEN: false +#DUK_USE_HOBJECT_HASH_PART: false +#DUK_USE_HEAPPTR16 +#DUK_USE_HEAPPTR_DEC16 +#DUK_USE_HEAPPTR_ENC16 + +# Consider using external strings, see doc/low_memory.rst. +#DUK_USE_EXTERNAL_STRINGS: true +#DUK_USE_EXTSTR_INTERN_CHECK +#DUK_USE_EXTSTR_FREE + +# Consider removing Node.js Buffer and ES2015 typed array support if not +# needed (about 10 kB code footprint difference on x64) +DUK_USE_BUFFEROBJECT_SUPPORT: false + +# Consider to reduce code footprint at the expense of more erratic RAM usage +#DUK_USE_REFERENCE_COUNTING: false +#DUK_USE_DOUBLE_LINKED_HEAP: false + +# Consider to reduce code footprint at the expense of less safeguards against +# bugs in calling C code. +DUK_USE_VALSTACK_UNSAFE: true + +# Disable optimizations for case insensitive regexps. If code involves +# case insensitive regexps with large character classes, consider enabling +# at least DUK_USE_REGEXP_CANON_BITMAP. +DUK_USE_REGEXP_CANON_WORKAROUND: false # very large footprint (~128kB) +DUK_USE_REGEXP_CANON_BITMAP: false # small footprint (~300-400 bytes) + +# Consider using ROM strings/objects to reduce footprint, see doc/low_memory.rst. +# ROM strings/objects reduce startup RAM usage at the expense of code footprint +# and some compliance. +#DUK_USE_ROM_STRINGS: true +#DUK_USE_ROM_OBJECTS: true +#DUK_USE_ROM_GLOBAL_INHERIT: true # select inherit or clone; inherit recommended +#DUK_USE_ROM_GLOBAL_CLONE: false + +# Function footprint size reduction. +DUK_USE_FUNC_NAME_PROPERTY: true # compliance +DUK_USE_FUNC_FILENAME_PROPERTY: false # non-standard, can be removed + +# Consider these; disabled by default because they don't impact E5 compliance. +DUK_USE_ES6: false +DUK_USE_ES7: false +DUK_USE_ES8: false +DUK_USE_ES9: false +DUK_USE_COROUTINE_SUPPORT: false +DUK_USE_SOURCE_NONBMP: false # <300 bytes footprint +DUK_USE_ES6_PROXY: false # roughly 2kB footprint +DUK_USE_ES7_EXP_OPERATOR: false # pulls in pow() +DUK_USE_ENCODING_BUILTINS: false +DUK_USE_PERFORMANCE_BUILTIN: false +DUK_USE_ES6_UNICODE_ESCAPE: false +DUK_USE_HTML_COMMENTS: false +DUK_USE_SHEBANG_COMMENTS: false +DUK_USE_REFLECT_BUILTIN: false +DUK_USE_SYMBOL_BUILTIN: false diff --git a/lib/duktape-2.2.1/config/examples/low_memory_strip.yaml b/lib/duktape-2.2.1/config/examples/low_memory_strip.yaml new file mode 100644 index 0000000..308f938 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/low_memory_strip.yaml @@ -0,0 +1,47 @@ +# More stripping for low memory environments, removing e.g. RegExp support, +# coroutine support, etc. + +DUK_USE_BUFFEROBJECT_SUPPORT: false + +DUK_USE_REGEXP_SUPPORT: false + +DUK_USE_REFERENCE_COUNTING: false +DUK_USE_DOUBLE_LINKED_HEAP: false + +# Consider to reduce code footprint at the expense of less safeguards against +# bugs in calling C code +DUK_USE_VALSTACK_UNSAFE: true + +# Short term workaround with large footprint, disable. +DUK_USE_REGEXP_CANON_WORKAROUND: false + +# Coroutine support has about 2kB footprint. +DUK_USE_COROUTINE_SUPPORT: false + +# Finalizer support has about 0.8kB footprint. +DUK_USE_FINALIZER_SUPPORT: false + +# ES2015 Proxy has about 2kB footprint. +DUK_USE_ES6_PROXY: false + +# Don't support non-BMP characters in source code (UTF-8 otherwise OK). +DUK_USE_SOURCE_NONBMP: false + +# Don't include even .name property for functions. +DUK_USE_FUNC_NAME_PROPERTY: false + +# Remove built-in bindings. +DUK_USE_MATH_BUILTIN: false +DUK_USE_DATE_BUILTIN: false +DUK_USE_ARRAY_BUILTIN: false +DUK_USE_STRING_BUILTIN: false +DUK_USE_BOOLEAN_BUILTIN: false +DUK_USE_NUMBER_BUILTIN: false +DUK_USE_FUNCTION_BUILTIN: false +DUK_USE_OBJECT_BUILTIN: false +DUK_USE_DUKTAPE_BUILTIN: false +DUK_USE_JSON_BUILTIN: false +DUK_USE_ENCODING_BUILTINS: false +DUK_USE_REFLECT_BUILTIN: false +DUK_USE_JSON_SUPPORT: false # also disables JSON support for C API +DUK_USE_GLOBAL_BUILTIN: false diff --git a/lib/duktape-2.2.1/config/examples/performance_sensitive.yaml b/lib/duktape-2.2.1/config/examples/performance_sensitive.yaml new file mode 100644 index 0000000..95eb6bc --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/performance_sensitive.yaml @@ -0,0 +1,26 @@ +# Base configuration for performance sensitive environments, see +# doc/performance-sensitive.rst. + +# You should choose the fastest setjmp/longjmp for your platform. + +DUK_USE_PREFER_SIZE: false +DUK_USE_PACKED_TVAL: false # packed duk_tval slower in most cases +DUK_USE_FASTINT: true +DUK_USE_VALSTACK_UNSAFE: true +DUK_USE_FAST_REFCOUNT_DEFAULT: true +DUK_USE_JSON_STRINGIFY_FASTPATH: true # not fully portable right now +DUK_USE_JSON_QUOTESTRING_FASTPATH: true +DUK_USE_JSON_DECSTRING_FASTPATH: true +DUK_USE_JSON_DECNUMBER_FASTPATH: true +DUK_USE_JSON_EATWHITE_FASTPATH: true +DUK_USE_BASE64_FASTPATH: true +DUK_USE_HEX_FASTPATH: true +DUK_USE_IDCHAR_FASTPATH: true +DUK_USE_ARRAY_PROP_FASTPATH: true +DUK_USE_ARRAY_FASTPATH: true +DUK_USE_INTERRUPT_COUNTER: false +DUK_USE_DEBUGGER_SUPPORT: false +DUK_USE_STRHASH_DENSE: false +DUK_USE_STRHASH_SKIP_SHIFT: 5 # may be able to reduce +#DUK_USE_EXEC_FUN_LOCAL: false # test both values, marginal benefit +DUK_USE_REGEXP_CANON_WORKAROUND: true # high footprint impact (128kB), enabled until a better solution diff --git a/lib/duktape-2.2.1/config/examples/rom_builtins.yaml b/lib/duktape-2.2.1/config/examples/rom_builtins.yaml new file mode 100644 index 0000000..a5ba4a8 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/rom_builtins.yaml @@ -0,0 +1,19 @@ +# Move built-in strings and objects to ROM (read-only data section) to reduce +# RAM usage of Duktape heaps; all heaps will share the same built-in strings +# and objects, except for the global object which is writable. The downside +# is that built-in objects (other than global object) will be read-only. + +# These should be used together. +DUK_USE_ROM_STRINGS: true +DUK_USE_ROM_OBJECTS: true + +# Provide a writable global object: +# - DUK_USE_ROM_GLOBAL_INHERIT: empty RAM global object inherits from ROM +# global object, uses very little RAM. +# - DUK_USE_ROM_GLOBAL_CLONE: ROM global object is cloned into RAM, more +# compliant but uses more RAM. +# +# If both are set to 'false', global object will be non-writable which +# may surprise users. +DUK_USE_ROM_GLOBAL_INHERIT: true +DUK_USE_ROM_GLOBAL_CLONE: false diff --git a/lib/duktape-2.2.1/config/examples/security_sensitive.yaml b/lib/duktape-2.2.1/config/examples/security_sensitive.yaml new file mode 100644 index 0000000..bdcbb81 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/security_sensitive.yaml @@ -0,0 +1,17 @@ +# Base configuration for security sensitive environments. + +# Avoid summary of object/key for rejected property operations. May be +# relevant if keys contain potentially sensitive information. +DUK_USE_PARANOID_ERRORS: true + +# Disable tracebacks, minimizes attacker knowledge of call chains. Access +# to the internal error _Tracedata property provides access to all functions +# in the call chain (even when they're otherwise not visible to sandboxed +# code). +DUK_USE_TRACEBACKS: false + +# Dense string hashing may be useful against accidental string hash collisions. +# This won't prevent an attacker from finding intentional collisions. +DUK_USE_STRHASH_DENSE: true + +# TBD diff --git a/lib/duktape-2.2.1/config/examples/shallow_c_stack.yaml b/lib/duktape-2.2.1/config/examples/shallow_c_stack.yaml new file mode 100644 index 0000000..4bbf8b4 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/shallow_c_stack.yaml @@ -0,0 +1,10 @@ +# Reduce recursion limits for shallow C stack targets. +# These values are based on the (removed) DUK_USE_DEEP_C_STACK option. + +DUK_USE_NATIVE_CALL_RECLIMIT: 60 +DUK_USE_COMPILER_RECLIMIT: 50 +DUK_USE_REGEXP_COMPILER_RECLIMIT: 100 +DUK_USE_REGEXP_EXECUTOR_RECLIMIT: 100 +DUK_USE_JSON_ENC_RECLIMIT: 100 +DUK_USE_JSON_DEC_RECLIMIT: 100 +DUK_USE_MARK_AND_SWEEP_RECLIMIT: 32 diff --git a/lib/duktape-2.2.1/config/examples/timing_sensitive.yaml b/lib/duktape-2.2.1/config/examples/timing_sensitive.yaml new file mode 100644 index 0000000..dd11081 --- /dev/null +++ b/lib/duktape-2.2.1/config/examples/timing_sensitive.yaml @@ -0,0 +1,6 @@ +# Base configuration for timing sensitive environments, see +# doc/timing-sensitive.rst: + +DUK_USE_MARK_AND_SWEEP: true +DUK_USE_REFERENCE_COUNTING: true +DUK_USE_VOLUNTARY_GC: false diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_ASSERTIONS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_ASSERTIONS.yaml new file mode 100644 index 0000000..497c2cc --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_ASSERTIONS.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_ASSERTIONS +introduced: 1.0.0 +tags: + - development + - debug +description: > + Enable internal assert checks. These slow down execution considerably + so only use when debugging. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFFEROBJECT_SUPPORT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFFEROBJECT_SUPPORT.yaml new file mode 100644 index 0000000..1cb1dae --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFFEROBJECT_SUPPORT.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_BUFFEROBJECT_SUPPORT +introduced: 1.3.0 +tags: + - ecmascript6 +description: > + Enable support for Khronos/ES6 typed arrays and Node.js Buffer objects. + This adds about 8-9 kB of code footprint on x64. When disabled, Duktape + custom plain buffers and Duktape.Buffer are still supported. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFLEN16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFLEN16.yaml new file mode 100644 index 0000000..682b1f7 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_BUFLEN16.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_BUFLEN16 +introduced: 1.1.0 +tags: + - lowmemory + - experimental +description: > + Use a 16-bit buffer length field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR16.yaml new file mode 100644 index 0000000..e86d313 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR16.yaml @@ -0,0 +1,20 @@ +define: DUK_OPT_DATAPTR16 +introduced: 1.1.0 +related: + - DUK_OPT_DATAPTR_ENC16 + - DUK_OPT_DATAPTR_DEC16 +tags: + - lowmemory + - experimental +description: > + Enable "compression" of arbitrary data pointers into an unsigned 16-bit + value. Use together with DUK_OPT_DATAPTR_ENC16 and DUK_OPT_DATAPTR_DEC16. + + Pointers compressed are any void pointers in C code, not just the Duktape + heap. Also NULL pointer must encode and decode correctly. + + Currently it is required that NULL encodes to integer 0, and integer + 0 decodes to NULL. No other pointer can be encoded to 0. + + NOTE: This feature option is currently unimplemented, i.e. Duktape won't + compress any data pointers at the moment. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_DEC16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_DEC16.yaml new file mode 100644 index 0000000..9a1c693 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_DEC16.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_DATAPTR_DEC16 +introduced: 1.1.0 +requires: + - DUK_OPT_DATAPTR16 +tags: + - lowmemory + - experimental +description: > + Use together with DUK_OPT_DATAPTR16 for arbitrary data pointer compression. + DUK_OPT_DATAPTR_DEC16(udata,x) is a macro with a userdata and duk_uint16_t + argument, and a void ptr return value. The userdata argument is the heap + userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_ENC16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_ENC16.yaml new file mode 100644 index 0000000..14684bf --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DATAPTR_ENC16.yaml @@ -0,0 +1,14 @@ +define: DUK_OPT_DATAPTR_ENC16 +introduced: 1.1.0 +requires: + - DUK_OPT_DATAPTR16 +tags: + - lowmemory + - experimental +description: > + Use together with DUK_OPT_DATAPTR16 for arbitrary data pointer compression. + DUK_OPT_DATAPTR_ENC16(udata,p) is a macro with a userdata and void ptr + argument, and a duk_uint16_t return value. The userdata argument is the + heap userdata value given at heap creation. Currently it is required that + NULL encodes to integer 0, and integer 0 decodes to NULL. No other pointer + can be encoded to 0. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDDPRINT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDDPRINT.yaml new file mode 100644 index 0000000..ebdc0d5 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDDPRINT.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_DDDPRINT +introduced: 1.0.0 +requires: + - DUK_OPT_DEBUG +tags: + - debug +description: > + Enable even more debug printouts. Not recommended unless you have + grep handy. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDPRINT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDPRINT.yaml new file mode 100644 index 0000000..26b7699 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DDPRINT.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_DDPRINT +introduced: 1.0.0 +requires: + - DUK_OPT_DEBUG +tags: + - debug +description: > + Enable more debug printouts. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG.yaml new file mode 100644 index 0000000..9c68c77 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_DEBUG +introduced: 1.0.0 +tags: + - debug +description: > + Enable debug code in Duktape internals. Without this option other + debugging options (such as DUK_OPT_DPRINT) have no effect. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_DUMPHEAP.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_DUMPHEAP.yaml new file mode 100644 index 0000000..d501ce8 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_DUMPHEAP.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_DEBUGGER_DUMPHEAP +introduced: 1.2.0 +requires: + - DUK_OPT_DEBUGGER_SUPPORT +tags: + - debugger +description: > + Support the DumpHeap command. This is optional because the command is not + always needed. The command also has a relatively large footprint (about + 10% of debugger code); in absolute terms it's about 1kB of code footprint. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_LOGGING.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_LOGGING.yaml new file mode 100644 index 0000000..87497d7 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_LOGGING.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_DEBUGGER_FWD_LOGGING +introduced: 1.2.0 +requires: + - DUK_OPT_DEBUGGER_SUPPORT +tags: + - debugger +description: > + Forward log writes using the built-in logging framework to the debug client. + Forwarding happens from the Duktape.Logger.prototype.info() etc calls before + the raw() function is called, so that logging is forwarded even if you + replace the backend. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_PRINTALERT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_PRINTALERT.yaml new file mode 100644 index 0000000..afb5e64 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_FWD_PRINTALERT.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_DEBUGGER_FWD_PRINTALERT +introduced: 1.2.0 +requires: + - DUK_OPT_DEBUGGER_SUPPORT +tags: + - debugger +description: > + Forward calls to the built-in print() and alert() function to the debug + client. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_SUPPORT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_SUPPORT.yaml new file mode 100644 index 0000000..bf1d79a --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_SUPPORT.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_DEBUGGER_SUPPORT +introduced: 1.2.0 +requires: + - DUK_OPT_INTERRUPT_COUNTER +tags: + - debugger +description: > + Enable support for Duktape debug protocol (see doc/debugger.rst) and the + debug API calls (duk_debugger_attach(), duk_debugger_detach(), etc). + This adds about 10kB of code footprint at the moment. + + This option requires DUK_OPT_INTERRUPT_COUNTER. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_TRANSPORT_TORTURE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_TRANSPORT_TORTURE.yaml new file mode 100644 index 0000000..0d8c858 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUGGER_TRANSPORT_TORTURE.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_DEBUGGER_TRANSPORT_TORTURE +introduced: 1.2.0 +requires: + - DUK_OPT_DEBUGGER_SUPPORT +tags: + - debugger + - development +description: > + Development time option: force debugger transport torture. Concretely this + now causes Duktape to read/write debug protocol data in 1-byte increments, + which stresses message parsing and transport code. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG_BUFSIZE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG_BUFSIZE.yaml new file mode 100644 index 0000000..ae87d23 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEBUG_BUFSIZE.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_DEBUG_BUFSIZE +introduced: 1.0.0 +requires: + - DUK_OPT_DEBUG +tags: + - debug +description: > + Debug code uses a static buffer as a formatting temporary to avoid side + effects in debug prints. The static buffer is large by default, which + may be an issue in constrained environments. You can set the buffer size + manually with this option. Example: -DDUK_OPT_DEBUG_BUFSIZE=2048. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DECLARE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DECLARE.yaml new file mode 100644 index 0000000..e8f766e --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DECLARE.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_DECLARE +introduced: 1.0.0 +tags: + - portability +description: > + Provide declarations or additional preprocessor include directives to be + used when compiling Duktape. You may need this if you set + DUK_OPT_PANIC_HANDLER to call your own panic handler function. You can + also use this option to cause additional files to be included when compiling + Duktape. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEEP_C_STACK.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEEP_C_STACK.yaml new file mode 100644 index 0000000..7de8932 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DEEP_C_STACK.yaml @@ -0,0 +1,15 @@ +define: DUK_OPT_DEEP_C_STACK +introduced: 1.0.0 +removed: 1.3.0 +tags: + - memory + - portability +description: > + By default Duktape imposes a sanity limit on the depth of the C stack + because it is often limited in embedded environments. This option + forces Duktape to use a deep C stack which relaxes e.g. recursion limits. + Automatic feature detection enables deep C stacks on some platforms known + to have them (e.g. Linux, BSD, Windows). + + Removed in Duktape 1.3.0, use explicit config options to control recursion + limits for shallow stack targets. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DLL_BUILD.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DLL_BUILD.yaml new file mode 100644 index 0000000..3ec70b3 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DLL_BUILD.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_DLL_BUILD +introduced: 1.0.0 +tags: + - portability +description: > + Add this define to both Duktape and application build when Duktape is + compiled as a DLL. This is especially critical on Windows: the option + makes Duktape use __declspec(dllexport) and __declspec(dllimport) for + public symbols. + + While this is not currently needed for Unix platforms, it should always + be used if you build as a DLL. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT.yaml new file mode 100644 index 0000000..5da8a46 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_DPRINT +introduced: 1.0.0 +requires: + - DUK_OPT_DEBUG +tags: + - debug +description: > + Enable debug printouts. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_COLORS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_COLORS.yaml new file mode 100644 index 0000000..6308b0b --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_COLORS.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_DPRINT_COLORS +introduced: 1.0.0 +tags: + - debug +description: > + Enable coloring of debug prints with ANSI escape codes + (http://en.wikipedia.org/wiki/ANSI_escape_code). The behavior is not + sensitive to terminal settings. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_RDTSC.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_RDTSC.yaml new file mode 100644 index 0000000..a393d2a --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_DPRINT_RDTSC.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_DPRINT_RDTSC +introduced: 1.0.0 +removed: 1.4.0 +tags: + - debug +description: > + Print RDTSC cycle count in debug prints if available. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXAMPLE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXAMPLE.yaml new file mode 100644 index 0000000..277b837 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXAMPLE.yaml @@ -0,0 +1,52 @@ +# +# Each Duktape option is described as a YAML file named OPTION_NAME.yaml. +# YAML is used because it diffs well and has clean support for multiline +# inline strings. +# +# Metadata for feature options (DUK_OPT_xxx) is sparse, it's needed for +# legacy support. +# + +# C #define name for the option. Must match filename minus extension. +define: DUK_OPT_OBJSIZES16 + +# Duktape version number where this option was first introduced. +introduced: 1.1.0 +#deprecated: 1.2.0 +#removed: 1.3.0 + +# Optional indication that feature option is defined but currently +# unused, so that it can be omitted from generated header. +#unused: true + +# Optional list of options that must also be defined to use this option. +#requires: +# - DUK_OPT_FOO +# - DUK_OPT_BAR + +# Optional list of options that this option conflicts with. +#conflicts: +# - DUK_OPT_BAZ + +# Optional list of options that are related from a user and documentation +# perspective. +#related: +# - DUK_OPT_QUUX + +# Tags related to option (required). If present, first tag is used as a +# primary tag for grouping. Use 'misc' if nothing else is appropriate. +tags: + - lowmemory + - experimental + +# Description for option, no newlines. Line breaking for e.g. C header +# is automatic. +description: > + Use a 16-bit object entry and array part sizes (for low memory + environments). Also automatically drops support for an object hash + part to further reduce memory usage; there are rarely large objects + in low memory environments simply because there's no memory to store + a lot of properties. + +# Marker to avoid processing this file. +example: true diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXEC_TIMEOUT_CHECK.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXEC_TIMEOUT_CHECK.yaml new file mode 100644 index 0000000..1ae3de0 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXEC_TIMEOUT_CHECK.yaml @@ -0,0 +1,30 @@ +define: DUK_OPT_EXEC_TIMEOUT_CHECK +introduced: 1.2.0 +requires: + - DUK_OPT_INTERRUPT_COUNTER +tags: + - execution + - sandbox + - experimental +description: > + NOTE: This mechanism is EXPERIMENTAL and the details may change + between releases. + + Provide a hook to check for bytecode execution timeout. The macro gets + a void ptr userdata argument (the userdata given to duk_heap_create()) + and must evaluate to a duk_bool_t. Duktape calls the macro as: + "if (DUK_OPT_EXEC_TIMEOUT_CHECK(udata)) { ... }". + + The macro is called occasionally by the Duktape bytecode executor (i.e. + when executing Ecmascript code), typically from a few times per second + to a hundred times per second, but the interval varies a great deal + depending on what kind of code is being executed. + + To indicate an execution timeout, the macro must return a non-zero value. + When that happens, Duktape starts to bubble a ``RangeError`` outwards + until control has been returned to the original protected call made by + the application. Until that happens, the exec timeout macro must always + return non-zero to indicate an execution timeout is still in progress. + + This mechanism and its limitations is described in more detail in + doc/sandboxing.rst. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTERNAL_STRINGS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTERNAL_STRINGS.yaml new file mode 100644 index 0000000..dfb44ee --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTERNAL_STRINGS.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_EXTERNAL_STRINGS +introduced: 1.1.0 +tags: + - memory +description: > + Enable support for external strings. An external string requires a Duktape + heap allocation to store a minimal string header, with the actual string + data being held behind a pointer (similarly to how dynamic buffers work). + + This option is needed to use DUK_OPT_EXTSTR_INTERN_CHECK and/or + DUK_OPT_EXTSTR_FREE. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_FREE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_FREE.yaml new file mode 100644 index 0000000..56cbd7a --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_FREE.yaml @@ -0,0 +1,22 @@ +define: DUK_OPT_EXTSTR_FREE +introduced: 1.1.0 +requires: + - DUK_OPT_EXTERNAL_STRINGS +tags: + - memory + - experimental +description: > + Optional counterpart to DUK_OPT_EXTSTR_INTERN_CHECK. Invoked when an + external string is about to be freed by Duktape. + + The argument "ptr" is a void ptr and points to the external string data. + Concretely, it is the (non-NULL) value returned by + DUK_OPT_EXTSTR_INTERN_CHECK. The "udata" argument is the heap userdata + which may be ignored if not needed. + + Also enable DUK_OPT_EXTERNAL_STRINGS to use this feature. + + NOTE: Right now there is no API to push external strings; external strings + come into being as a resul of DUK_OPT_EXTSTR_INTERN_CHECK() only. If/when + this is changed, this hook will get called for every string, even if pushed + by the user using an API call; this may need to be rethought at that time. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_INTERN_CHECK.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_INTERN_CHECK.yaml new file mode 100644 index 0000000..0a3bea1 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_EXTSTR_INTERN_CHECK.yaml @@ -0,0 +1,38 @@ +define: DUK_OPT_EXTSTR_INTERN_CHECK +introduced: 1.1.0 +requires: + - DUK_OPT_EXTERNAL_STRINGS +tags: + - memory + - experimental +description: > + Provide a hook for checking if data for a certain string can be used from + external memory (outside of Duktape heap, e.g. memory mapped flash). + The hook is called during string interning with the following semantics: + + The string data with no NUL termination resides at "ptr" and has "len" + bytes. The "udata" argument is the heap userdata which may be ignored + if not needed. If the hook returns NULL, Duktape interns the string + normally, i.e. string data is allocated from Duktape heap. Otherwise the + hook return value must point to a memory area which contains + "len" bytes from "ptr" followed by a NUL byte which is NOT PRESENT + in the input data. Data behind the returned pointer may not change after + the hook returns. + + The hook may be called several times for the same input string. This + happens when a string is interned, garbage collected, and then interned + again. + + The DUK_OPT_EXTSTR_FREE() hook allows application code to detect when + an external string is about to be freed. + + In most cases the hook should reject strings whose "len" is less than 4 + because there is no RAM advantage in moving so short strings into external + memory. The ordinary "duk_hstring" header followed by the data (and a + NUL byte) has the same size as "duk_hstring_external" header which hosts + a pointer instead of string data. + + Also enable DUK_OPT_EXTERNAL_STRINGS to use this feature. + + See doc/low-memory.rst for more discussion how to use this feature option + in practice. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FASTINT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FASTINT.yaml new file mode 100644 index 0000000..620ae8c --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FASTINT.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_FASTINT +introduced: 1.2.0 +tags: + - performance +description: > + Enable support for 48-bit signed "fastint" integer values. Fastints are + transparent to user code (both C and Ecmascript) but may be faster than + IEEE doubles on some platforms, especially those using softints. The + downside of fastints is increased code footprint and a small performance + penalty for some kinds of code. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_ALIGN.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_ALIGN.yaml new file mode 100644 index 0000000..3682c47 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_ALIGN.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_FORCE_ALIGN +introduced: 1.0.0 +tags: + - portability +description: > + Use -DDUK_OPT_FORCE_ALIGN=4 or -DDUK_OPT_FORCE_ALIGN=8 to force a + specific struct/value alignment instead of relying on Duktape's + automatic detection. This shouldn't normally be needed. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_BYTEORDER.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_BYTEORDER.yaml new file mode 100644 index 0000000..69e9dc0 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FORCE_BYTEORDER.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_FORCE_BYTEORDER +introduced: 1.0.0 +tags: + - portability +description: > + Use this to skip byte order detection and force a specific byte order: + 1 for little endian, 2 for ARM "mixed" endian (integers little endian, + IEEE doubles mixed endian), 3 for big endian. Byte order detection + relies on unstandardized platform specific header files, so this may be + required for custom platforms if compilation fails in endianness detection. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR16.yaml new file mode 100644 index 0000000..aa592b1 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR16.yaml @@ -0,0 +1,21 @@ +define: DUK_OPT_FUNCPTR16 +introduced: 1.1.0 +related: + - DUK_OPT_FUNCPTR_ENC16 + - DUK_OPT_FUNCPTR_DEC16 +tags: + - lowmemory + - experimental +description: > + Enable "compression" of arbitrary C function pointers into an unsigned 16-bit + value. Use together with DUK_OPT_FUNCPTR_ENC16 and DUK_OPT_FUNCPTR_DEC16. + + Pointers compressed are any C function pointers. Also NULL pointer must + encode and decode correctly. + + Currently it is required that NULL encodes to integer 0, and integer + 0 decodes to NULL. No other pointer can be encoded to 0. + + NOTE: This feature option is currently unimplemented, i.e. Duktape won't + compress any function pointers at the moment. It might not be necessary + to support a NULL function pointer (uncertain until taken into use). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_DEC16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_DEC16.yaml new file mode 100644 index 0000000..f91bafd --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_DEC16.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_FUNCPTR_DEC16 +introduced: 1.1.0 +requires: + - DUK_OPT_FUNCPTR16 +tags: + - lowmemory + - experimental +description: > + Use together with DUK_OPT_FUNCPTR16 for function pointer compression. + DUK_OPT_FUNCPTR_DEC16(udata,x) is a macro with a userdata and duk_uint16_t + argument, and a void ptr return value. The userdata argument is the heap + userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_ENC16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_ENC16.yaml new file mode 100644 index 0000000..2304e9e --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNCPTR_ENC16.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_FUNCPTR_ENC16 +introduced: 1.1.0 +requires: + - DUK_OPT_FUNCPTR16 +tags: + - lowmemory + - experimental +description: > + Use together with DUK_OPT_FUNCPTR16 for function pointer compression. + DUK_OPT_FUNCPTR_ENC16(udata,p) is a macro with a userdata and void ptr + argument, and a duk_uint16_t return value. The userdata arguments is the + heap userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY.yaml new file mode 100644 index 0000000..8444dac --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY +tags: + - ecmascript +description: > + Removed, use DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY.yaml new file mode 100644 index 0000000..ba4d7dd --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY +tags: + - ecmascript +description: > + Removed, use DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_GC_TORTURE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_GC_TORTURE.yaml new file mode 100644 index 0000000..5298dd9 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_GC_TORTURE.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_GC_TORTURE +introduced: 1.0.0 +tags: + - gc + - memory + - development +description: > + Development time option: force full mark-and-sweep on every allocation to + stress test memory management. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HAVE_CUSTOM_H.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HAVE_CUSTOM_H.yaml new file mode 100644 index 0000000..1ae881d --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HAVE_CUSTOM_H.yaml @@ -0,0 +1,26 @@ +define: DUK_OPT_HAVE_CUSTOM_H +introduced: 1.0.0 +deprecated: 1.3.0 +tags: + - portability +description: > + Normally you define DUK_OPT_xxx feature options and the autodetecting + duk_config.h (previously internal duk_features.h.in) header resolves + these with platform/compiler constraints to determine effective compilation + options for Duktape internals. The effective options are provided as + DUK_USE_xxx defines which you normally never see. + + If you define DUK_OPT_HAVE_CUSTOM_H, Duktape will include "duk_custom.h" + after determining the appropriate DUK_USE_xxx defines but before compiling + any code. The duk_custom.h header, which you provide, can then tweak the + active DUK_USE_xxx defines freely. See duk_config.h and genconfig option + metadata for the available defines. + + This approach is useful when the DUK_OPT_xxx feature options don't + provide enough flexibility to tweak the build. The downside is that you can + easily create inconsistent DUK_USE_xxx flags, the customization header + will be version specific, and you need to peek into Duktape internals to + know what defines to tweak. + + NOTE: This option is deprecated. The preferred method for customization + starting from Duktape 1.3.0 is to create/modify a "duk_config.h" header. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR16.yaml new file mode 100644 index 0000000..a93a181 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR16.yaml @@ -0,0 +1,34 @@ +define: DUK_OPT_HEAPPTR16 +introduced: 1.1.0 +conflicts: + - DUK_OPT_DEBUG +related: + - DUK_OPT_HEAPPTR_ENC16 + - DUK_OPT_HEAPPTR_DEC16 +tags: + - lowmemory + - experimental +description: > + Enable "compression" of Duktape heap pointers into an unsigned 16-bit value. + Use together with DUK_OPT_HEAPPTR_ENC16 and DUK_OPT_HEAPPTR_DEC16. + + Pointers compressed are those allocated from Duktape heap, using the user + provided allocation functions. Also NULL pointer must encode and decode + correctly. + + Currently it is required that NULL encodes to integer 0, and integer + 0 decodes to NULL. No other pointer can be encoded to 0. + + This option reduces memory usage by several kilobytes, but has several + downsides. It can only be applied when Duktape heap is limited in size, + for instance, with 4-byte aligned allocations a 256kB heap (minus one value + for NULL) can be supported. Pointer encoding and decoding may be relatively + complicated as they need to correctly handle NULL pointers and + non-continuous memory maps used by some targets. The macro may need to call + out to a helper function in practice, which is much slower than an inline + implementation. + + Current limitation: Duktape internal debug code enabled with e.g. + DUK_OPT_DEBUG and DUK_OPT_DPRINT doesn't have enough plumbing to be able to + decode pointers. Debug printing cannot currently be enabled when pointer + compression is active. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_DEC16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_DEC16.yaml new file mode 100644 index 0000000..9428827 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_DEC16.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_HEAPPTR_DEC16 +introduced: 1.1.0 +requires: + - DUK_OPT_HEAPPTR16 +tags: + - lowmemory + - experimental +description: > + Use together with DUK_OPT_HEAPPTR16 for heap pointer compression. + DUK_OPT_HEAPPTR_DEC16(udata,x) is a macro with a userdata and duk_uint16_t + argument, and a void ptr return value. The userdata argument is the heap + userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_ENC16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_ENC16.yaml new file mode 100644 index 0000000..ca64ca1 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_HEAPPTR_ENC16.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_HEAPPTR_ENC16 +introduced: 1.1.0 +requires: + - DUK_OPT_HEAPPTR16 +tags: + - lowmemory + - experimental +description: > + Use together with DUK_OPT_HEAPPTR16 for heap pointer compression. + DUK_OPT_HEAPPTR_ENC16(udata,p) is a macro with a userdata and void ptr + argument, and a duk_uint16_t return value. The userdata argument is the + heap userdata value given at heap creation. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_INTERRUPT_COUNTER.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_INTERRUPT_COUNTER.yaml new file mode 100644 index 0000000..835af64 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_INTERRUPT_COUNTER.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_INTERRUPT_COUNTER +introduced: 1.1.0 +related: + - DUK_OPT_DEBUGGER_SUPPORT +tags: + - execution + - debugger +description: > + Enable the internal bytecode executor periodic interrupt counter. + The mechanism is used to implement e.g. execution step limit, custom + profiling, and debugger interaction. Enabling the interrupt counter + has a small impact on execution performance. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_JSON_STRINGIFY_FASTPATH.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_JSON_STRINGIFY_FASTPATH.yaml new file mode 100644 index 0000000..6d6431c --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_JSON_STRINGIFY_FASTPATH.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_JSON_STRINGIFY_FASTPATH +introduced: 1.3.0 +tags: + - performance + - fastpath + - lowmemory +description: > + Enable fast apth for JSON.stringify() serialization. See + DUK_USE_JSON_STRINGIFY_FASTPATH for details. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_LIGHTFUNC_BUILTINS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_LIGHTFUNC_BUILTINS.yaml new file mode 100644 index 0000000..c28a0e6 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_LIGHTFUNC_BUILTINS.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_LIGHTFUNC_BUILTINS +introduced: 1.1.0 +tags: + - lowmemory + - experimental +description: > + Force built-in functions to be lightweight functions. This reduces + memory footprint by around 14 kB at the cost of some non-compliant + behavior. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY.yaml new file mode 100644 index 0000000..4220071 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY.yaml @@ -0,0 +1,14 @@ +define: DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY +introduced: 1.0.0 +tags: + - ecmascript +description: > + Add a non-standard "caller" property to non-strict function instances + for better compatibility with existing code. The semantics of this + property are not standardized and may vary between engines; Duktape tries + to behave close to V8 and Spidermonkey. See + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller + description of the property. This feature disables tail call support. + + This feature conflicts with several other features, so you should use it + only if it's absolutely necessary. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY.yaml new file mode 100644 index 0000000..e9abe9f --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY +introduced: 1.0.0 +tags: + - ecmascript +description: > + Add a non-standard "source" property to function instances. This allows + function toString() to print out the actual function source. The property + is disabled by default because it increases memory footprint. + + NOTE: Unimplemented as of Duktape 1.2.0. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT.yaml new file mode 100644 index 0000000..9f771e8 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT +tags: + - ecmascript +description: > + Removed, use DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_AUGMENT_ERRORS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_AUGMENT_ERRORS.yaml new file mode 100644 index 0000000..3eae3a7 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_AUGMENT_ERRORS.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NO_AUGMENT_ERRORS +introduced: 1.0.0 +related: + - DUK_OPT_NO_TRACEBACKS +tags: + - ecmascript +description: > + Don't augment Ecmascript error objects with custom fields like fileName, + lineNumber, and traceback data. Also disables Duktape.errCreate and + Duktape.errThrow error handler callbacks. Implies DUK_OPT_NO_TRACEBACKS. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BROWSER_LIKE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BROWSER_LIKE.yaml new file mode 100644 index 0000000..002861e --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BROWSER_LIKE.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_BROWSER_LIKE +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable browser-like functions. Makes print() and alert() throw an error. + + This option is confusing when used with the Duktape command line tool, as + the command like tool will immediately panic on startup. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BUFFEROBJECT_SUPPORT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BUFFEROBJECT_SUPPORT.yaml new file mode 100644 index 0000000..395aaf5 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BUFFEROBJECT_SUPPORT.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_BUFFEROBJECT_SUPPORT +introduced: 1.3.0 +tags: + - ecmascript6 +description: > + Disable support for Khronos/ES6 typed arrays and Node.js Buffer objects + which reduces code footprint. When disabled, Duktape custom plain buffers + and Duktape.Buffer are still supported. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BYTECODE_DUMP_SUPPORT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BYTECODE_DUMP_SUPPORT.yaml new file mode 100644 index 0000000..26c5117 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_BYTECODE_DUMP_SUPPORT.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_NO_BYTECODE_DUMP_SUPPORT +introduced: 1.3.0 +tags: + - api +description: > + Disable API calls to dump/load functions to bytecode (reduces code + footprint). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_COMMONJS_MODULES.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_COMMONJS_MODULES.yaml new file mode 100644 index 0000000..61e8273 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_COMMONJS_MODULES.yaml @@ -0,0 +1,6 @@ +define: DUK_OPT_NO_COMMONJS_MODULES +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable support for CommonJS modules. Causes require() to throw an error. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY.yaml new file mode 100644 index 0000000..e89fbdd --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY +introduced: 1.0.0 +tags: + - ecmascript + - ecmascript6 +description: > + Disable the non-standard (ES6) Object.prototype.__proto__ property + which is enabled by default. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF.yaml new file mode 100644 index 0000000..e1f3cc4 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF +introduced: 1.0.0 +tags: + - ecmascript + - ecmascript6 +description: > + Disable the non-standard (ES6) Object.setPrototypeOf method which + is enabled by default. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_PROXY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_PROXY.yaml new file mode 100644 index 0000000..dcddbd2 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ES6_PROXY.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_ES6_PROXY +introduced: 1.0.0 +tags: + - ecmascript + - ecmascript6 +description: > + Disable the non-standard (ES6) Proxy object which is enabled by + default. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FILE_IO.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FILE_IO.yaml new file mode 100644 index 0000000..52646a5 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FILE_IO.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NO_FILE_IO +introduced: 1.0.0 +tags: + - portability +description: > + Disable use of ANSI C file I/O which might be a portability issue on some + platforms. Causes duk_eval_file() to throw an error, makes built-in + print() and alert() no-ops, and suppresses writing of a panic + message to stderr on panic. This option does not suppress debug + printing so don't enable debug printing if you wish to avoid I/O. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FUNC_STMT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FUNC_STMT.yaml new file mode 100644 index 0000000..5a309a6 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_FUNC_STMT.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_FUNC_STMT +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NO_NONSTD_FUNC_STMT +tags: + - ecmascript +description: > + Removed, use DUK_OPT_NO_NONSTD_FUNC_STMT instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JC.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JC.yaml new file mode 100644 index 0000000..ba7d86f --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JC.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_NO_JC +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable support for the JC format. Reduces code footprint. An attempt + to encode or decode the format causes an error. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONC.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONC.yaml new file mode 100644 index 0000000..8c4e0e7 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONC.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_JSONC +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NO_JC +tags: + - ecmascript +description: > + Removed, use DUK_OPT_NO_JC instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONX.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONX.yaml new file mode 100644 index 0000000..d141a27 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JSONX.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_JSONX +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NO_JX +tags: + - ecmascript +description: > + Removed, use DUK_OPT_NO_JX instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JX.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JX.yaml new file mode 100644 index 0000000..be22edd --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_JX.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_NO_JX +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable support for the JX format. Reduces code footprint. An attempt + to encode or decode the format causes an error. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MARK_AND_SWEEP.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MARK_AND_SWEEP.yaml new file mode 100644 index 0000000..3283488 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MARK_AND_SWEEP.yaml @@ -0,0 +1,14 @@ +define: DUK_OPT_NO_MARK_AND_SWEEP +introduced: 1.0.0 +tags: + - gc + - memory +description: > + Disable mark-and-sweep and use only reference counting for garbage + collection. This reduces code footprint and eliminates garbage collection + pauses, but objects participating in unreachable reference cycles won't be + collected until the Duktape heap is destroyed. In particular, function + instances won't be collected because they're always in a reference cycle + with their default prototype object. Unreachable objects are collected if + you break reference cycles manually (and are always freed when a heap is + destroyed). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MS_STRINGTABLE_RESIZE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MS_STRINGTABLE_RESIZE.yaml new file mode 100644 index 0000000..9b0e6af --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_MS_STRINGTABLE_RESIZE.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_MS_STRINGTABLE_RESIZE +introduced: 1.0.0 +tags: + - gc + - memory +description: > + Disable forced string intern table resize during mark-and-sweep garbage + collection. This may be useful when reference counting is disabled, as + mark-and-sweep collections will be more frequent and thus more expensive. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT.yaml new file mode 100644 index 0000000..df5ecda --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT +introduced: 1.0.0 +tags: + - ecmascript +description: > + Don't give setter/getter calls the property name being accessed as + an additional, non-standard property. See + http://duktape.org/guide.html#propertyvirtualization. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER.yaml new file mode 100644 index 0000000..eb7f322 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER +introduced: 1.0.0 +tags: + - ecmascript +description: > + For better compatibility with existing code, Array.prototype.concat() has + non-standard behavior by default for trailing non-existent elements of + the concat result, see + https://github.com/svaarala/duktape/blob/master/ecmascript-testcases/test-bi-array-proto-concat-nonstd-trailing.js. + + If this option is given, concat() will behave in a strictly conforming + fashion, ignoring non-existent trailing elements in the result length. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER.yaml new file mode 100644 index 0000000..a43a81c --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER.yaml @@ -0,0 +1,12 @@ +define: DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER +introduced: 1.0.0 +tags: + - ecmascript +description: > + For better compatibility with existing code, Array.prototype.map() has + non-standard behavior by default for trailing non-existent elements of + the map result, see + https://github.com/svaarala/duktape/blob/master/ecmascript-testcases/test-bi-array-proto-map-nonstd-trailing.js. + + If this option is given, map() will behave in a strictly conforming + fashion, ignoring non-existent trailing elements in the result length. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml new file mode 100644 index 0000000..308d720 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT.yaml @@ -0,0 +1,13 @@ +define: DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT +introduced: 1.0.0 +tags: + - ecmascript +description: > + For better compatibility with existing code, Array.prototype.splice() has + non-standard behavior by default when the second argument (deleteCount) + is not given: the splice operation is extended to the end of the array, see + https://github.com/svaarala/duktape/blob/master/ecmascript-testcases/test-bi-array-proto-splice-no-delcount.js. + + If this option is given, splice() will behave in a strictly conforming + fashion, treating a missing deleteCount the same as an undefined (or 0) + value. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_FUNC_STMT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_FUNC_STMT.yaml new file mode 100644 index 0000000..b27b4fc --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_FUNC_STMT.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NO_NONSTD_FUNC_STMT +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable support for function declarations outside program or function top + level (also known as "function statements"). Such declarations are + non-standard and the strictly compliant behavior is to treat them as a + SyntaxError. Default behavior is to treat them like ordinary function + declarations ("hoist" them to function top) with V8-like semantics. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029.yaml new file mode 100644 index 0000000..b1d87e4 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029 +introduced: 1.1.0 +tags: + - ecmascript +description: > + By default Duktape JSON.stringify() will escape U+2028 and U+2029 which + is non-compliant behavior. This is the default to make JSON.stringify() + output valid when embedded in a web page or parsed with eval(). This + feature option enables the compliant behavior, i.e. no escaping for U+2028 + and U+2029. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT.yaml new file mode 100644 index 0000000..ed5bfbd --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT +introduced: 1.2.0 +tags: + - ecmascript +description: > + By default Duktape String.fromCharCode() allows 32-bit codepoints which is + non-compliant (the E5.1 specification has a ToUint16() coercion for the + codepoints) but useful because Duktape supports non-BMP strings. This + feature option restores the compliant behavior. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY.yaml new file mode 100644 index 0000000..c25ce8a --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY +tags: + - ecmascript + - ecmascript6 +description: > + Removed, use DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF.yaml new file mode 100644 index 0000000..f2b930e --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF +introduced: 1.0.0 +removed: 1.0.0 +related: + - DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF +tags: + - ecmascript + - ecmascript6 +description: > + Removed, use DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF instead. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OCTAL_SUPPORT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OCTAL_SUPPORT.yaml new file mode 100644 index 0000000..b5f414f --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_OCTAL_SUPPORT.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_NO_OCTAL_SUPPORT +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable optional octal number support (Ecmascript E5/E5.1 + Annex B: http://www.ecma-international.org/ecma-262/5.1/#sec-B). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PACKED_TVAL.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PACKED_TVAL.yaml new file mode 100644 index 0000000..a00e468 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PACKED_TVAL.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_PACKED_TVAL +introduced: 1.0.0 +tags: + - memory + - portability +description: > + Don't use the packed 8-byte internal value representation even if otherwise + possible. The packed representation has more platform/compiler portability + issues than the unpacked one. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PC2LINE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PC2LINE.yaml new file mode 100644 index 0000000..dd46056 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_PC2LINE.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_PC2LINE +introduced: 1.0.0 +tags: + - ecmascript +description: > + Don't record a "pc2line" map into function instances. Without this map, + exceptions won't have meaningful line numbers (virtual machine program + counter values cannot be translated to line numbers) but function instances + will have a smaller footprint. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REFERENCE_COUNTING.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REFERENCE_COUNTING.yaml new file mode 100644 index 0000000..df1a218 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REFERENCE_COUNTING.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_REFERENCE_COUNTING +introduced: 1.0.0 +tags: + - gc + - memory +description: > + Disable reference counting and use only mark-and-sweep for garbage + collection. Although this reduces memory footprint of heap objects, the + downside is much more fluctuation in memory usage. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REGEXP_SUPPORT.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REGEXP_SUPPORT.yaml new file mode 100644 index 0000000..fe20fa1 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_REGEXP_SUPPORT.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_NO_REGEXP_SUPPORT +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable support for regular expressions. Regexp literals are treated as + a SyntaxError, RegExp constructor and prototype functions throw an error, + String.prototype.replace() throws an error if given a regexp search value, + String.prototype.split() throws an error if given a regexp separator value, + String.prototype.search() and String.prototype.match() throw an error + unconditionally. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SECTION_B.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SECTION_B.yaml new file mode 100644 index 0000000..94c94d6 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SECTION_B.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_NO_SECTION_B +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable optional features in Ecmascript specification + Annex B: http://www.ecma-international.org/ecma-262/5.1/#sec-B. + Causes escape(), unescape(), and String.prototype.substr() to throw + an error. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SOURCE_NONBMP.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SOURCE_NONBMP.yaml new file mode 100644 index 0000000..0ddfad3 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_SOURCE_NONBMP.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_NO_SOURCE_NONBMP +introduced: 1.0.0 +tags: + - ecmascript +description: > + Disable accurate Unicode support for non-BMP characters in source code. + Non-BMP characters are then always accepted as identifier characters. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_STRICT_DECL.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_STRICT_DECL.yaml new file mode 100644 index 0000000..b5599a4 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_STRICT_DECL.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_STRICT_DECL +introduced: 1.1.0 +tags: + - ecmascript + - experimental +description: > + Disable support for "use strict" declaration so that Ecmascript code is + always executed in non-strict mode. Duktape/C functions remain strict. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_TRACEBACKS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_TRACEBACKS.yaml new file mode 100644 index 0000000..0af5bf3 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_TRACEBACKS.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_TRACEBACKS +introduced: 1.0.0 +tags: + - ecmascript +description: > + Don't record traceback data into Ecmascript error objects (but still record + fileName and lineNumber). Reduces footprint and makes error handling a bit + faster, at the cost of less informative Ecmascript errors. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VERBOSE_ERRORS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VERBOSE_ERRORS.yaml new file mode 100644 index 0000000..467818f --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VERBOSE_ERRORS.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_VERBOSE_ERRORS +introduced: 1.0.0 +tags: + - ecmascript +description: > + Don't provide error message strings or filename/line information for errors + generated by Duktape. Reduces footprint, at the cost of much less + informative Ecmascript errors. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VOLUNTARY_GC.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VOLUNTARY_GC.yaml new file mode 100644 index 0000000..ff2f0c0 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_VOLUNTARY_GC.yaml @@ -0,0 +1,13 @@ +define: DUK_OPT_NO_VOLUNTARY_GC +introduced: 1.0.0 +tags: + - gc + - memory +description: > + Disable voluntary periodic mark-and-sweep collection. A mark-and-sweep + collection is still triggered in an out-of-memory condition. This option + should usually be combined with reference counting, which collects all + non-cyclical garbage. Application code should also request an explicit + garbage collection from time to time when appropriate. When this option + is used, Duktape will have no garbage collection pauses in ordinary use, + which is useful for timing sensitive applications like games. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ZERO_BUFFER_DATA.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ZERO_BUFFER_DATA.yaml new file mode 100644 index 0000000..4696d49 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_NO_ZERO_BUFFER_DATA.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_NO_ZERO_BUFFER_DATA +introduced: 1.0.0 +tags: + - memory + - ecmascript +description: > + By default Duktape zeroes data allocated for buffer values. Define + this to disable the zeroing (perhaps for performance reasons). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_OBJSIZES16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_OBJSIZES16.yaml new file mode 100644 index 0000000..c0bd3da --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_OBJSIZES16.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_OBJSIZES16 +introduced: 1.1.0 +tags: + - lowmemory + - experimental +description: > + Use a 16-bit object entry and array part sizes (for low memory + environments). Also automatically drops support for an object hash part + to further reduce memory usage; there are rarely large objects in low + memory environments simply because there's no memory to store a lot of + properties. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_PANIC_HANDLER.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_PANIC_HANDLER.yaml new file mode 100644 index 0000000..543061a --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_PANIC_HANDLER.yaml @@ -0,0 +1,6 @@ +define: DUK_OPT_PANIC_HANDLER +introduced: 1.0.0 +tags: + - portability +description: > + Provide a custom panic handler. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_REFCOUNT16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_REFCOUNT16.yaml new file mode 100644 index 0000000..3e824df --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_REFCOUNT16.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_REFCOUNT16 +introduced: 1.1.0 +tags: + - lowmemory + - experimental +description: > + Use a 16-bit reference count field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SEGFAULT_ON_PANIC.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SEGFAULT_ON_PANIC.yaml new file mode 100644 index 0000000..bc2288c --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SEGFAULT_ON_PANIC.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_SEGFAULT_ON_PANIC +introduced: 1.0.0 +tags: + - portability +description: > + Cause the default panic handler to cause a segfault instead of using + abort() or exit(). This is useful when debugging with valgrind, + as a segfault provides a nice C traceback in valgrind. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SELF_TESTS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SELF_TESTS.yaml new file mode 100644 index 0000000..e59c9d5 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SELF_TESTS.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_SELF_TESTS +introduced: 1.0.0 +tags: + - debug +description: > + Perform run-time self tests when a Duktape heap is created. Catches + platform/compiler problems which cannot be reliably detected during + compile time. Not enabled by default because of the extra footprint. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SETJMP.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SETJMP.yaml new file mode 100644 index 0000000..50464b9 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SETJMP.yaml @@ -0,0 +1,18 @@ +define: DUK_OPT_SETJMP +introduced: 1.1.0 +removed: 1.5.0 +tags: + - portability +description: > + Force setjmp/longjmp for long control transfers. + + The default long control transfer provider is setjmp/longjmp because it + is the most portable option. When a better provider is known for a platform, + Duktape may default to that (e.g. _setjmp/_longjmp is the default for + OSX/iPhone, see GH-55). With this feature option you can force Duktape to + explicitly use setjmp/longjmp even in these cases. + + The downside of setjmp/longjmp is that signal mask saving behavior is not + specified and varies between platforms. Signal mask saving may have a + significant performance impact so you may want to force a specific provider + if performance matters for your application. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SHUFFLE_TORTURE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SHUFFLE_TORTURE.yaml new file mode 100644 index 0000000..fb2a5c3 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SHUFFLE_TORTURE.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_SHUFFLE_TORTURE +introduced: 1.2.0 +tags: + - gc + - memory + - development +description: > + Development time option: force compiler to shuffle every possible opcode + to stress shuffle behavior which is otherwise difficult to test for + comprehensively. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SIGSETJMP.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SIGSETJMP.yaml new file mode 100644 index 0000000..fdaede2 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_SIGSETJMP.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_SIGSETJMP +introduced: 1.1.0 +removed: 1.5.0 +tags: + - portability +description: > + Force sigsetjmp/siglongjmp with savesigs == 0 for long control + transfers (i.e. signal mask not saved/restored). See comments in + DUK_OPT_SETJMP. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRHASH16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRHASH16.yaml new file mode 100644 index 0000000..2adeeef --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRHASH16.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_STRHASH16 +introduced: 1.1.0 +tags: + - lowmemory + - experimental +description: > + Use a 16-bit string hash field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRICT_UTF8_SOURCE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRICT_UTF8_SOURCE.yaml new file mode 100644 index 0000000..2d602fa --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRICT_UTF8_SOURCE.yaml @@ -0,0 +1,9 @@ +define: DUK_OPT_STRICT_UTF8_SOURCE +introduced: 1.0.0 +tags: + - ecmascript +description: > + Enable strict UTF-8 parsing of source code. When enabled, non-shortest + encodings (normally invalid UTF-8) and surrogate pair codepoints are + accepted as valid source code characters. This option breaks compatibility + with some test262 tests. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRLEN16.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRLEN16.yaml new file mode 100644 index 0000000..848aa52 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRLEN16.yaml @@ -0,0 +1,7 @@ +define: DUK_OPT_STRLEN16 +introduced: 1.1.0 +tags: + - lowmemory + - experimental +description: > + Use a 16-bit string length field (for low memory environments). diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN.yaml new file mode 100644 index 0000000..cefb795 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN.yaml @@ -0,0 +1,25 @@ +define: DUK_OPT_STRTAB_CHAIN +introduced: 1.1.0 +related: + - DUK_OPT_STRTAB_CHAIN_SIZE +tags: + - lowmemory +description: > + Replace the default (open addressing, probing) string table structure with + one based on separate chaining. There is a fixed-size top level hash table + (whose size is defined using DUK_OPT_STRTAB_CHAIN_SIZE), with each entry in + the hash table being: (a) NULL, (b) a duk_hstring pointer, or (c) a pointer + to an array of duk_hstring pointers. The pointer arrays are gappy (the gaps + are reused on new inserts) and are never shrunk at the moment. + + This option is intended for low memory environments to make Duktape's memory + behavior match a typical pool-based allocator better as follows: + + The top level fixed structure never changes size, so there is no hash table + resize, and thus no need for resize temporaries. The default string table + algorithm needs resizing from time to time and doesn't resize in place, so + you effectively need twice the string table size temporarily during a resize. + + The pointer arrays vary in size, but their size (typically 8 to 64 bytes, + depending on the load factor) matches that of many other allocations which + works well with a pooled allocator. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN_SIZE.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN_SIZE.yaml new file mode 100644 index 0000000..4137a7c --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_STRTAB_CHAIN_SIZE.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_STRTAB_CHAIN_SIZE +introduced: 1.1.0 +requires: + - DUK_OPT_STRTAB_CHAIN +tags: + - lowmemory +description: > + Define stringtable size for DUK_OPT_STRTAB_CHAIN. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_TARGET_INFO.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_TARGET_INFO.yaml new file mode 100644 index 0000000..59d550c --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_TARGET_INFO.yaml @@ -0,0 +1,8 @@ +define: DUK_OPT_TARGET_INFO +introduced: 1.2.0 +tags: + - debugger +description: > + Define a freeform human readable string to describe the target device (e.g. + "Arduino Yun"). This string will be sent as part of version/target info in + the debugger protocol and shows up in the debugger UI. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_TRACEBACK_DEPTH.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_TRACEBACK_DEPTH.yaml new file mode 100644 index 0000000..88e73b8 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_TRACEBACK_DEPTH.yaml @@ -0,0 +1,6 @@ +define: DUK_OPT_TRACEBACK_DEPTH +introduced: 1.0.0 +tags: + - ecmascript +description: > + Override default traceback collection depth. The default is currently 10. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_UNDERSCORE_SETJMP.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_UNDERSCORE_SETJMP.yaml new file mode 100644 index 0000000..eeaf0ca --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_UNDERSCORE_SETJMP.yaml @@ -0,0 +1,10 @@ +define: DUK_OPT_UNDERSCORE_SETJMP +introduced: 1.1.0 +removed: 1.5.0 +tags: + - portability +description: > + Force _setjmp/_longjmp for long control transfers. This ensures signal + mask is not saved which can be a lot faster if setjmp/longjmp saves the + signal mask (this varies between platforms). See comments in + DUK_OPT_SETJMP. diff --git a/lib/duktape-2.2.1/config/feature-options/DUK_OPT_USER_INITJS.yaml b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_USER_INITJS.yaml new file mode 100644 index 0000000..af03442 --- /dev/null +++ b/lib/duktape-2.2.1/config/feature-options/DUK_OPT_USER_INITJS.yaml @@ -0,0 +1,11 @@ +define: DUK_OPT_USER_INITJS +introduced: 1.0.0 +tags: + - portability +description: > + Provide a string to evaluate when a thread with new built-ins (a new global + environment) is created. This allows you to make minor modifications to the + global environment before any code is executed in it. The value must be a + string, e.g.:: -DDUK_OPT_USER_INITJS='"this.foo = 123"'. + + Errors in the initialization code result in a fatal error. diff --git a/lib/duktape-2.2.1/config/header-snippets/64bitops.h.in b/lib/duktape-2.2.1/config/header-snippets/64bitops.h.in new file mode 100644 index 0000000..2dbbf11 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/64bitops.h.in @@ -0,0 +1,11 @@ +/* Check whether we should use 64-bit integers or not. + * + * Quite incomplete now. Use 64-bit types if detected (C99 or other detection) + * unless they are known to be unreliable. For instance, 64-bit types are + * available on VBCC but seem to misbehave. + */ +#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC) +#define DUK_USE_64BIT_OPS +#else +#undef DUK_USE_64BIT_OPS +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/alignment_fillin.h.in b/lib/duktape-2.2.1/config/header-snippets/alignment_fillin.h.in new file mode 100644 index 0000000..7291aa1 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/alignment_fillin.h.in @@ -0,0 +1,23 @@ +/* + * Alignment requirement and support for unaligned accesses + * + * Assume unaligned accesses are not supported unless specifically allowed + * in the target platform. Some platforms may support unaligned accesses + * but alignment to 4 or 8 may still be desirable. + */ + +/* If not provided, use safe default for alignment. */ +#if !defined(DUK_USE_ALIGN_BY) +#define DUK_USE_ALIGN_BY 8 +#endif + +/* Compiler specific hackery needed to force struct size to match aligment, + * see e.g. duk_hbuffer.h. + * + * http://stackoverflow.com/questions/11130109/c-struct-size-alignment + * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment + */ +#if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \ + defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER)) +#define DUK_USE_PACK_DUMMY_MEMBER +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/architecture_fillins.h.in b/lib/duktape-2.2.1/config/header-snippets/architecture_fillins.h.in new file mode 100644 index 0000000..e69de29 diff --git a/lib/duktape-2.2.1/config/header-snippets/byteorder_derived.h.in b/lib/duktape-2.2.1/config/header-snippets/byteorder_derived.h.in new file mode 100644 index 0000000..5284b47 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/byteorder_derived.h.in @@ -0,0 +1,21 @@ +/* + * Convert DUK_USE_BYTEORDER, from whatever source, into currently used + * internal defines. If detection failed, #error out. + */ + +#if defined(DUK_USE_BYTEORDER) +#if (DUK_USE_BYTEORDER == 1) +#define DUK_USE_INTEGER_LE +#define DUK_USE_DOUBLE_LE +#elif (DUK_USE_BYTEORDER == 2) +#define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */ +#define DUK_USE_DOUBLE_ME +#elif (DUK_USE_BYTEORDER == 3) +#define DUK_USE_INTEGER_BE +#define DUK_USE_DOUBLE_BE +#else +#error unsupported: byte order invalid +#endif /* byte order */ +#else +#error unsupported: byte order detection failed +#endif /* defined(DUK_USE_BYTEORDER) */ diff --git a/lib/duktape-2.2.1/config/header-snippets/byteorder_fillin.h.in b/lib/duktape-2.2.1/config/header-snippets/byteorder_fillin.h.in new file mode 100644 index 0000000..4432126 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/byteorder_fillin.h.in @@ -0,0 +1,109 @@ +/* + * Byte order and double memory layout detection + * + * Endianness detection is a major portability hassle because the macros + * and headers are not standardized. There's even variance across UNIX + * platforms. Even with "standard" headers, details like underscore count + * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used + * (Crossbridge has a single underscore, for instance). + * + * The checks below are structured with this in mind: several approaches are + * used, and at the end we check if any of them worked. This allows generic + * approaches to be tried first, and platform/compiler specific hacks tried + * last. As a last resort, the user can force a specific endianness, as it's + * not likely that automatic detection will work on the most exotic platforms. + * + * Duktape supports little and big endian machines. There's also support + * for a hybrid used by some ARM machines where integers are little endian + * but IEEE double values use a mixed order (12345678 -> 43218765). This + * byte order for doubles is referred to as "mixed endian". + */ + +/* GCC and Clang provide endianness defines as built-in predefines, with + * leading and trailing double underscores (e.g. __BYTE_ORDER__). See + * output of "make gccpredefs" and "make clangpredefs". Clang doesn't + * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang. + * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + */ +#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) +#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define DUK_USE_BYTEORDER 1 +#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__) +#define DUK_USE_BYTEORDER 2 +#elif !defined(__FLOAT_WORD_ORDER__) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 1 +#else +/* Byte order is little endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__) +#define DUK_USE_BYTEORDER 3 +#elif !defined(__FLOAT_WORD_ORDER__) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 3 +#else +/* Byte order is big endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#else +/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit + * integer ordering and is not relevant. + */ +#endif /* integer byte order */ +#endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */ + +/* More or less standard endianness predefines provided by header files. + * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER + * will be big endian, see: http://lists.mysql.com/internals/443. + * On some platforms some defines may be present with an empty value which + * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453. + */ +#if !defined(DUK_USE_BYTEORDER) +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \ + defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \ + defined(__LITTLE_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN) +#define DUK_USE_BYTEORDER 1 +#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#define DUK_USE_BYTEORDER 2 +#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 1 +#else +/* Byte order is little endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \ + defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \ + defined(__BIG_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#define DUK_USE_BYTEORDER 3 +#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 3 +#else +/* Byte order is big endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#else +/* Cannot determine byte order. */ +#endif /* integer byte order */ +#endif /* !defined(DUK_USE_BYTEORDER) */ + +/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__: + * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - > 24) | \ + ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \ + ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \ + (((duk_uint32_t) (x)) << 24)) +#endif +#if !defined(DUK_BSWAP16) +#define DUK_BSWAP16(x) \ + ((duk_uint16_t) (x) >> 8) | \ + ((duk_uint16_t) (x) << 8) +#endif + +/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */ +/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */ + +#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE)) +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */ +#endif +#endif + +#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \ + defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER)) +#define DUK_USE_PACK_DUMMY_MEMBER +#endif + +#if 0 /* not defined by default */ +#undef DUK_USE_GCC_PRAGMAS +#endif + +#if !defined(DUK_U64_CONSTANT) +#define DUK_U64_CONSTANT(x) x##ULL +#endif +#if !defined(DUK_I64_CONSTANT) +#define DUK_I64_CONSTANT(x) x##LL +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/cpp_exception_sanity.h.in b/lib/duktape-2.2.1/config/header-snippets/cpp_exception_sanity.h.in new file mode 100644 index 0000000..334f926 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/cpp_exception_sanity.h.in @@ -0,0 +1,3 @@ +#if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus) +#error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/date_provider.h.in b/lib/duktape-2.2.1/config/header-snippets/date_provider.h.in new file mode 100644 index 0000000..15a4ac7 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/date_provider.h.in @@ -0,0 +1,66 @@ +/* + * Date provider selection + * + * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll + * rely on an external provider. If this is not done, revert to previous + * behavior and use Unix/Windows built-in provider. + */ + +#if defined(DUK_COMPILING_DUKTAPE) + +#if defined(DUK_USE_DATE_GET_NOW) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday() +#elif defined(DUK_USE_DATE_NOW_TIME) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time() +#elif defined(DUK_USE_DATE_NOW_WINDOWS) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows() +#elif defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows_subms() +#else +#error no provider for DUK_USE_DATE_GET_NOW() +#endif + +#if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d)) +#elif defined(DUK_USE_DATE_TZO_WINDOWS) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d)) +#elif defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows_no_dst((d)) +#else +#error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET() +#endif + +#if defined(DUK_USE_DATE_PARSE_STRING) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_PRS_STRPTIME) +#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str)) +#elif defined(DUK_USE_DATE_PRS_GETDATE) +#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str)) +#else +/* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */ +#endif + +#if defined(DUK_USE_DATE_FORMAT_STRING) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_FMT_STRFTIME) +#define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \ + duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags)) +#else +/* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */ +#endif + +#if defined(DUK_USE_GET_MONOTONIC_TIME) +/* External provider already defined. */ +#elif defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) +#define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_clock_gettime() +#elif defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) +#define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_windows_qpc() +#else +/* No provider for DUK_USE_GET_MONOTONIC_TIME(), fall back to DUK_USE_DATE_GET_NOW(). */ +#endif + +#endif /* DUK_COMPILING_DUKTAPE */ diff --git a/lib/duktape-2.2.1/config/header-snippets/gcc_clang_visibility.h.in b/lib/duktape-2.2.1/config/header-snippets/gcc_clang_visibility.h.in new file mode 100644 index 0000000..7e806e2 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/gcc_clang_visibility.h.in @@ -0,0 +1,26 @@ +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static diff --git a/lib/duktape-2.2.1/config/header-snippets/inline_workaround.h.in b/lib/duktape-2.2.1/config/header-snippets/inline_workaround.h.in new file mode 100644 index 0000000..75587c9 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/inline_workaround.h.in @@ -0,0 +1,11 @@ +/* Workaround for GH-323: avoid inlining control when compiling from + * multiple sources, as it causes compiler portability trouble. + */ +#if !defined(DUK_SINGLE_FILE) +#undef DUK_NOINLINE +#undef DUK_INLINE +#undef DUK_ALWAYS_INLINE +#define DUK_NOINLINE /*nop*/ +#define DUK_INLINE /*nop*/ +#define DUK_ALWAYS_INLINE /*nop*/ +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/msvc_visibility.h.in b/lib/duktape-2.2.1/config/header-snippets/msvc_visibility.h.in new file mode 100644 index 0000000..332a2b2 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/msvc_visibility.h.in @@ -0,0 +1,19 @@ +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static diff --git a/lib/duktape-2.2.1/config/header-snippets/object_layout.h.in b/lib/duktape-2.2.1/config/header-snippets/object_layout.h.in new file mode 100644 index 0000000..7b01c0a --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/object_layout.h.in @@ -0,0 +1,21 @@ +/* Object property allocation layout has implications for memory and code + * footprint and generated code size/speed. The best layout also depends + * on whether the platform has alignment requirements or benefits from + * having mostly aligned accesses. + */ +#undef DUK_USE_HOBJECT_LAYOUT_1 +#undef DUK_USE_HOBJECT_LAYOUT_2 +#undef DUK_USE_HOBJECT_LAYOUT_3 +#if (DUK_USE_ALIGN_BY == 1) +/* On platforms without any alignment issues, layout 1 is preferable + * because it compiles to slightly less code and provides direct access + * to property keys. + */ +#define DUK_USE_HOBJECT_LAYOUT_1 +#else +/* On other platforms use layout 2, which requires some padding but + * is a bit more natural than layout 3 in ordering the entries. Layout + * 3 is currently not used. + */ +#define DUK_USE_HOBJECT_LAYOUT_2 +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/packed_tval_fillin.h.in b/lib/duktape-2.2.1/config/header-snippets/packed_tval_fillin.h.in new file mode 100644 index 0000000..9b7a65d --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/packed_tval_fillin.h.in @@ -0,0 +1,40 @@ +/* + * Check whether or not a packed duk_tval representation is possible. + * What's basically required is that pointers are 32-bit values + * (sizeof(void *) == 4). Best effort check, not always accurate. + * If guess goes wrong, crashes may result; self tests also verify + * the guess. + */ + +/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */ +#if !defined(DUK_F_PACKED_TVAL_PROVIDED) +#undef DUK_F_PACKED_TVAL_POSSIBLE + +/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) +#if (DUK_UINTPTR_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED) +#if (DUK_UINTPTR_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED) +#if (DUK_SIZE_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +#undef DUK_USE_PACKED_TVAL +#if defined(DUK_F_PACKED_TVAL_POSSIBLE) +#define DUK_USE_PACKED_TVAL +#endif + +#undef DUK_F_PACKED_TVAL_POSSIBLE +#endif /* DUK_F_PACKED_TVAL_PROVIDED */ diff --git a/lib/duktape-2.2.1/config/header-snippets/platform_cppextras.h.in b/lib/duktape-2.2.1/config/header-snippets/platform_cppextras.h.in new file mode 100644 index 0000000..2beccfd --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/platform_cppextras.h.in @@ -0,0 +1,9 @@ +/* Workaround for older C++ compilers before including , + * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366 + */ +#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS) +#define __STDC_LIMIT_MACROS +#endif +#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) +#define __STDC_CONSTANT_MACROS +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/platform_fillins.h.in b/lib/duktape-2.2.1/config/header-snippets/platform_fillins.h.in new file mode 100644 index 0000000..be209b8 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/platform_fillins.h.in @@ -0,0 +1,327 @@ +/* An abort()-like primitive is needed by the default fatal error handler. */ +#if !defined(DUK_ABORT) +#define DUK_ABORT abort +#endif + +#if !defined(DUK_SETJMP) +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) setjmp((jb)) +#define DUK_LONGJMP(jb) longjmp((jb), 1) +#endif + +#if 0 +/* sigsetjmp() alternative */ +#define DUK_JMPBUF_TYPE sigjmp_buf +#define DUK_SETJMP(jb) sigsetjmp((jb)) +#define DUK_LONGJMP(jb) siglongjmp((jb), 1) +#endif + +/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h + * (which is unfortunately named). May sometimes need replacement, e.g. + * some compilers don't handle zero length or NULL correctly in realloc(). + */ +#if !defined(DUK_ANSI_MALLOC) +#define DUK_ANSI_MALLOC malloc +#endif +#if !defined(DUK_ANSI_REALLOC) +#define DUK_ANSI_REALLOC realloc +#endif +#if !defined(DUK_ANSI_CALLOC) +#define DUK_ANSI_CALLOC calloc +#endif +#if !defined(DUK_ANSI_FREE) +#define DUK_ANSI_FREE free +#endif + +/* ANSI C (various versions) and some implementations require that the + * pointer arguments to memset(), memcpy(), and memmove() be valid values + * even when byte size is 0 (even a NULL pointer is considered invalid in + * this context). Zero-size operations as such are allowed, as long as their + * pointer arguments point to a valid memory area. The DUK_MEMSET(), + * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.: + * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be + * allowed. If these are not fulfilled, a macro wrapper is needed. + * + * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0 + * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html + * + * Not sure what's the required behavior when a pointer points just past the + * end of a buffer, which often happens in practice (e.g. zero size memmoves). + * For example, if allocation size is 3, the following pointer would not + * technically point to a valid memory byte: + * + * <-- alloc --> + * | 0 | 1 | 2 | ..... + * ^-- p=3, points after last valid byte (2) + */ +#if !defined(DUK_MEMCPY) +#if defined(DUK_F_UCLIBC) +/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide + * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html + */ +#define DUK_MEMCPY memmove +#else +#define DUK_MEMCPY memcpy +#endif +#endif +#if !defined(DUK_MEMMOVE) +#define DUK_MEMMOVE memmove +#endif +#if !defined(DUK_MEMCMP) +#define DUK_MEMCMP memcmp +#endif +#if !defined(DUK_MEMSET) +#define DUK_MEMSET memset +#endif +#if !defined(DUK_STRLEN) +#define DUK_STRLEN strlen +#endif +#if !defined(DUK_STRCMP) +#define DUK_STRCMP strcmp +#endif +#if !defined(DUK_STRNCMP) +#define DUK_STRNCMP strncmp +#endif +#if !defined(DUK_SPRINTF) +#define DUK_SPRINTF sprintf +#endif +#if !defined(DUK_SNPRINTF) +/* snprintf() is technically not part of C89 but usually available. */ +#define DUK_SNPRINTF snprintf +#endif +#if !defined(DUK_VSPRINTF) +#define DUK_VSPRINTF vsprintf +#endif +#if !defined(DUK_VSNPRINTF) +/* vsnprintf() is technically not part of C89 but usually available. */ +#define DUK_VSNPRINTF vsnprintf +#endif +#if !defined(DUK_SSCANF) +#define DUK_SSCANF sscanf +#endif +#if !defined(DUK_VSSCANF) +#define DUK_VSSCANF vsscanf +#endif +#if !defined(DUK_MEMZERO) +#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n)) +#endif + +#if !defined(DUK_DOUBLE_INFINITY) +#undef DUK_USE_COMPUTED_INFINITY +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600) +/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */ +#define DUK_DOUBLE_INFINITY (__builtin_inf()) +#elif defined(INFINITY) +#define DUK_DOUBLE_INFINITY ((double) INFINITY) +#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \ + !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX) +#define DUK_DOUBLE_INFINITY (1.0 / 0.0) +#else +/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity. + * Use a computed infinity (initialized when a heap is created at the + * latest). + */ +#define DUK_USE_COMPUTED_INFINITY +#define DUK_DOUBLE_INFINITY duk_computed_infinity +#endif +#endif + +#if !defined(DUK_DOUBLE_NAN) +#undef DUK_USE_COMPUTED_NAN +#if defined(NAN) +#define DUK_DOUBLE_NAN NAN +#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \ + !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX) +#define DUK_DOUBLE_NAN (0.0 / 0.0) +#else +/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN. + * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error. + * Use a computed NaN (initialized when a heap is created at the + * latest). + */ +#define DUK_USE_COMPUTED_NAN +#define DUK_DOUBLE_NAN duk_computed_nan +#endif +#endif + +/* Many platforms are missing fpclassify() and friends, so use replacements + * if necessary. The replacement constants (FP_NAN etc) can be anything but + * match Linux constants now. + */ +#undef DUK_USE_REPL_FPCLASSIFY +#undef DUK_USE_REPL_SIGNBIT +#undef DUK_USE_REPL_ISFINITE +#undef DUK_USE_REPL_ISNAN +#undef DUK_USE_REPL_ISINF + +/* Complex condition broken into separate parts. */ +#undef DUK_F_USE_REPL_ALL +#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \ + defined(FP_SUBNORMAL) && defined(FP_NORMAL)) +/* Missing some obvious constants. */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC) +/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K) +/* AmigaOS + M68K seems to have math issues even when using GCC cross + * compilation. Use replacements for all AmigaOS versions on M68K + * regardless of compiler. + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG) +/* Placeholder fix for (detection is wider than necessary): + * http://llvm.org/bugs/show_bug.cgi?id=17788 + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_UCLIBC) +/* At least some uclibc versions have broken floating point math. For + * example, fpclassify() can incorrectly classify certain NaN formats. + * To be safe, use replacements. + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AIX) +/* Older versions may be missing isnan(), etc. */ +#define DUK_F_USE_REPL_ALL +#endif + +#if defined(DUK_F_USE_REPL_ALL) +#define DUK_USE_REPL_FPCLASSIFY +#define DUK_USE_REPL_SIGNBIT +#define DUK_USE_REPL_ISFINITE +#define DUK_USE_REPL_ISNAN +#define DUK_USE_REPL_ISINF +#define DUK_FPCLASSIFY duk_repl_fpclassify +#define DUK_SIGNBIT duk_repl_signbit +#define DUK_ISFINITE duk_repl_isfinite +#define DUK_ISNAN duk_repl_isnan +#define DUK_ISINF duk_repl_isinf +#define DUK_FP_NAN 0 +#define DUK_FP_INFINITE 1 +#define DUK_FP_ZERO 2 +#define DUK_FP_SUBNORMAL 3 +#define DUK_FP_NORMAL 4 +#else +#define DUK_FPCLASSIFY fpclassify +#define DUK_SIGNBIT signbit +#define DUK_ISFINITE isfinite +#define DUK_ISNAN isnan +#define DUK_ISINF isinf +#define DUK_FP_NAN FP_NAN +#define DUK_FP_INFINITE FP_INFINITE +#define DUK_FP_ZERO FP_ZERO +#define DUK_FP_SUBNORMAL FP_SUBNORMAL +#define DUK_FP_NORMAL FP_NORMAL +#endif + +#if defined(DUK_F_USE_REPL_ALL) +#undef DUK_F_USE_REPL_ALL +#endif + +/* These functions don't currently need replacement but are wrapped for + * completeness. Because these are used as function pointers, they need + * to be defined as concrete C functions (not macros). + */ +#if !defined(DUK_FABS) +#define DUK_FABS fabs +#endif +#if !defined(DUK_FLOOR) +#define DUK_FLOOR floor +#endif +#if !defined(DUK_CEIL) +#define DUK_CEIL ceil +#endif +#if !defined(DUK_FMOD) +#define DUK_FMOD fmod +#endif +#if !defined(DUK_POW) +#define DUK_POW pow +#endif +#if !defined(DUK_ACOS) +#define DUK_ACOS acos +#endif +#if !defined(DUK_ASIN) +#define DUK_ASIN asin +#endif +#if !defined(DUK_ATAN) +#define DUK_ATAN atan +#endif +#if !defined(DUK_ATAN2) +#define DUK_ATAN2 atan2 +#endif +#if !defined(DUK_SIN) +#define DUK_SIN sin +#endif +#if !defined(DUK_COS) +#define DUK_COS cos +#endif +#if !defined(DUK_TAN) +#define DUK_TAN tan +#endif +#if !defined(DUK_EXP) +#define DUK_EXP exp +#endif +#if !defined(DUK_LOG) +#define DUK_LOG log +#endif +#if !defined(DUK_SQRT) +#define DUK_SQRT sqrt +#endif + +/* The functions below exist only in C99/C++11 or later and need a workaround + * for platforms that don't include them. MSVC isn't detected as C99, but + * these functions also exist in MSVC 2013 and later so include a clause for + * that too. Android doesn't have log2; disable all of these for Android. + */ +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))) && \ + !defined(DUK_F_ANDROID) && !defined(DUK_F_MINT) +#if !defined(DUK_CBRT) +#define DUK_CBRT cbrt +#endif +#if !defined(DUK_LOG2) +#define DUK_LOG2 log2 +#endif +#if !defined(DUK_LOG10) +#define DUK_LOG10 log10 +#endif +#if !defined(DUK_TRUNC) +#define DUK_TRUNC trunc +#endif +#endif /* DUK_F_C99 etc */ + +/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics, + * see test-bug-netbsd-math-pow.js. MinGW has similar (but different) + * issues, see test-bug-mingw-math-issues.js. Enable pow() workarounds + * for these targets. + */ +#undef DUK_USE_POW_WORKAROUNDS +#if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW) +#define DUK_USE_POW_WORKAROUNDS +#endif + +/* Similar workarounds for atan2() semantics issues. MinGW issues are + * documented in test-bug-mingw-math-issues.js. + */ +#undef DUK_USE_ATAN2_WORKAROUNDS +#if defined(DUK_F_MINGW) +#define DUK_USE_ATAN2_WORKAROUNDS +#endif + +/* Rely as little as possible on compiler behavior for NaN comparison, + * signed zero handling, etc. Currently never activated but may be needed + * for broken compilers. + */ +#undef DUK_USE_PARANOID_MATH + +/* There was a curious bug where test-bi-date-canceling.js would fail e.g. + * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations + * using doubles would be optimized which then broke some corner case tests. + * The problem goes away by adding 'volatile' to the datetime computations. + * Not sure what the actual triggering conditions are, but using this on + * non-C99 systems solves the known issues and has relatively little cost + * on other platforms. + */ +#undef DUK_USE_PARANOID_DATE_COMPUTATION +#if !defined(DUK_F_C99) +#define DUK_USE_PARANOID_DATE_COMPUTATION +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/platform_sharedincludes.h.in b/lib/duktape-2.2.1/config/header-snippets/platform_sharedincludes.h.in new file mode 100644 index 0000000..882752d --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/platform_sharedincludes.h.in @@ -0,0 +1,26 @@ +/* Shared includes: C89 */ +#include +#include +#include +#include /* varargs */ +#include +#include /* e.g. ptrdiff_t */ +#include +#include + +/* date.h is omitted, and included per platform */ + +/* Shared includes: stdint.h is C99 */ +#if defined(DUK_F_NO_STDINT_H) +/* stdint.h not available */ +#else +/* Technically C99 (C++11) but found in many systems. On some systems + * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before + * including stdint.h (see above). + */ +#include +#endif + +#if defined(DUK_F_CPP) +#include /* std::exception */ +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/reject_fast_math.h.in b/lib/duktape-2.2.1/config/header-snippets/reject_fast_math.h.in new file mode 100644 index 0000000..d842023 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/reject_fast_math.h.in @@ -0,0 +1,6 @@ +/* GCC/clang inaccurate math would break compliance and probably duk_tval, + * so refuse to compile. Relax this if -ffast-math is tested to work. + */ +#if defined(__FAST_MATH__) +#error __FAST_MATH__ defined, refusing to compile +#endif diff --git a/lib/duktape-2.2.1/config/header-snippets/types1.h.in b/lib/duktape-2.2.1/config/header-snippets/types1.h.in new file mode 100644 index 0000000..5544dae --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/types1.h.in @@ -0,0 +1,78 @@ +/* + * Wrapper typedefs and constants for integer types, also sanity check types. + * + * C99 typedefs are quite good but not always available, and we want to avoid + * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for + * all C99 typedefs and Duktape code should only use these typedefs. Type + * detection when C99 is not supported is best effort and may end up detecting + * some types incorrectly. + * + * Pointer sizes are a portability problem: pointers to different types may + * have a different size and function pointers are very difficult to manage + * portably. + * + * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types + * + * Note: there's an interesting corner case when trying to define minimum + * signed integer value constants which leads to the current workaround of + * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt + * for a longer discussion. + * + * Note: avoid typecasts and computations in macro integer constants as they + * can then no longer be used in macro relational expressions (such as + * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on + * being able to compare DUK_SIZE_MAX against a limit. + */ + +/* XXX: add feature options to force basic types from outside? */ + +#if !defined(INT_MAX) +#error INT_MAX not defined +#endif + +/* Check that architecture is two's complement, standard C allows e.g. + * INT_MIN to be -2**31+1 (instead of -2**31). + */ +#if defined(INT_MAX) && defined(INT_MIN) +#if INT_MAX != -(INT_MIN + 1) +#error platform does not seem complement of two +#endif +#else +#error cannot check complement of two +#endif + +/* Pointer size determination based on __WORDSIZE or architecture when + * that's not available. + */ +#if defined(DUK_F_X86) || defined(DUK_F_X32) || \ + defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \ + defined(DUK_F_BCC) || \ + (defined(__WORDSIZE) && (__WORDSIZE == 32)) || \ + ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \ + defined(DUK_F_HPUX)) && defined(_ILP32)) || \ + defined(DUK_F_ARM32) +#define DUK_F_32BIT_PTRS +#elif defined(DUK_F_X64) || \ + (defined(__WORDSIZE) && (__WORDSIZE == 64)) || \ + ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \ + defined(DUK_F_HPUX)) && defined(_LP64)) || \ + defined(DUK_F_ARM64) +#define DUK_F_64BIT_PTRS +#else +/* not sure, not needed with C99 anyway */ +#endif + +/* Intermediate define for 'have inttypes.h' */ +#undef DUK_F_HAVE_INTTYPES +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)) +/* vbcc + AmigaOS has C99 but no inttypes.h */ +#define DUK_F_HAVE_INTTYPES +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +/* C++11 apparently ratified stdint.h */ +#define DUK_F_HAVE_INTTYPES +#endif + +/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise + * through automatic detection. + */ diff --git a/lib/duktape-2.2.1/config/header-snippets/types2.h.in b/lib/duktape-2.2.1/config/header-snippets/types2.h.in new file mode 100644 index 0000000..39eaf32 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/types2.h.in @@ -0,0 +1,132 @@ +/* A few types are assumed to always exist. */ +typedef size_t duk_size_t; +typedef ptrdiff_t duk_ptrdiff_t; + +/* The best type for an "all around int" in Duktape internals is "at least + * 32 bit signed integer" which is most convenient. Same for unsigned type. + * Prefer 'int' when large enough, as it is almost always a convenient type. + */ +#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL) +typedef int duk_int_t; +typedef unsigned int duk_uint_t; +#define DUK_INT_MIN INT_MIN +#define DUK_INT_MAX INT_MAX +#define DUK_UINT_MIN 0 +#define DUK_UINT_MAX UINT_MAX +#else +typedef duk_int_fast32_t duk_int_t; +typedef duk_uint_fast32_t duk_uint_t; +#define DUK_INT_MIN DUK_INT_FAST32_MIN +#define DUK_INT_MAX DUK_INT_FAST32_MAX +#define DUK_UINT_MIN DUK_UINT_FAST32_MIN +#define DUK_UINT_MAX DUK_UINT_FAST32_MAX +#endif + +/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this + * distinction matters for the CPU. These types are used mainly in the + * executor where it might really matter. + */ +typedef duk_int_fast32_t duk_int_fast_t; +typedef duk_uint_fast32_t duk_uint_fast_t; +#define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN +#define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX +#define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN +#define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX + +/* Small integers (16 bits or more) can fall back to the 'int' type, but + * have a typedef so they are marked "small" explicitly. + */ +typedef int duk_small_int_t; +typedef unsigned int duk_small_uint_t; +#define DUK_SMALL_INT_MIN INT_MIN +#define DUK_SMALL_INT_MAX INT_MAX +#define DUK_SMALL_UINT_MIN 0 +#define DUK_SMALL_UINT_MAX UINT_MAX + +/* Fast variants of small integers, again for really fast paths like the + * executor. + */ +typedef duk_int_fast16_t duk_small_int_fast_t; +typedef duk_uint_fast16_t duk_small_uint_fast_t; +#define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN +#define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX +#define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN +#define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX + +/* Boolean values are represented with the platform 'unsigned int'. */ +typedef duk_small_uint_t duk_bool_t; +#define DUK_BOOL_MIN DUK_SMALL_UINT_MIN +#define DUK_BOOL_MAX DUK_SMALL_UINT_MAX + +/* Index values must have at least 32-bit signed range. */ +typedef duk_int_t duk_idx_t; +#define DUK_IDX_MIN DUK_INT_MIN +#define DUK_IDX_MAX DUK_INT_MAX + +/* Unsigned index variant. */ +typedef duk_uint_t duk_uidx_t; +#define DUK_UIDX_MIN DUK_UINT_MIN +#define DUK_UIDX_MAX DUK_UINT_MAX + +/* Array index values, could be exact 32 bits. + * Currently no need for signed duk_arridx_t. + */ +typedef duk_uint_t duk_uarridx_t; +#define DUK_UARRIDX_MIN DUK_UINT_MIN +#define DUK_UARRIDX_MAX DUK_UINT_MAX + +/* Duktape/C function return value, platform int is enough for now to + * represent 0, 1, or negative error code. Must be compatible with + * assigning truth values (e.g. duk_ret_t rc = (foo == bar);). + */ +typedef duk_small_int_t duk_ret_t; +#define DUK_RET_MIN DUK_SMALL_INT_MIN +#define DUK_RET_MAX DUK_SMALL_INT_MAX + +/* Error codes are represented with platform int. High bits are used + * for flags and such, so 32 bits are needed. + */ +typedef duk_int_t duk_errcode_t; +#define DUK_ERRCODE_MIN DUK_INT_MIN +#define DUK_ERRCODE_MAX DUK_INT_MAX + +/* Codepoint type. Must be 32 bits or more because it is used also for + * internal codepoints. The type is signed because negative codepoints + * are used as internal markers (e.g. to mark EOF or missing argument). + * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to + * ensure duk_uint32_t casts back and forth nicely. Almost everything + * else uses the signed one. + */ +typedef duk_int_t duk_codepoint_t; +typedef duk_uint_t duk_ucodepoint_t; +#define DUK_CODEPOINT_MIN DUK_INT_MIN +#define DUK_CODEPOINT_MAX DUK_INT_MAX +#define DUK_UCODEPOINT_MIN DUK_UINT_MIN +#define DUK_UCODEPOINT_MAX DUK_UINT_MAX + +/* IEEE float/double typedef. */ +typedef float duk_float_t; +typedef double duk_double_t; + +/* We're generally assuming that we're working on a platform with a 32-bit + * address space. If DUK_SIZE_MAX is a typecast value (which is necessary + * if SIZE_MAX is missing), the check must be avoided because the + * preprocessor can't do a comparison. + */ +#if !defined(DUK_SIZE_MAX) +#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX +#elif !defined(DUK_SIZE_MAX_COMPUTED) +#if DUK_SIZE_MAX < 0xffffffffUL +/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value + * which seems incorrect if size_t is (at least) an unsigned 32-bit type. + * However, it doesn't seem useful to error out compilation if this is the + * case. + */ +#endif +#endif + +/* Type used in public API declarations and user code. Typedef maps to + * 'struct duk_hthread' like the 'duk_hthread' typedef which is used + * exclusively in internals. + */ +typedef struct duk_hthread duk_context; diff --git a/lib/duktape-2.2.1/config/header-snippets/types_c99.h.in b/lib/duktape-2.2.1/config/header-snippets/types_c99.h.in new file mode 100644 index 0000000..433e92b --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/types_c99.h.in @@ -0,0 +1,94 @@ +#define DUK_F_HAVE_64BIT +#include + +typedef uint8_t duk_uint8_t; +typedef int8_t duk_int8_t; +typedef uint16_t duk_uint16_t; +typedef int16_t duk_int16_t; +typedef uint32_t duk_uint32_t; +typedef int32_t duk_int32_t; +typedef uint64_t duk_uint64_t; +typedef int64_t duk_int64_t; +typedef uint_least8_t duk_uint_least8_t; +typedef int_least8_t duk_int_least8_t; +typedef uint_least16_t duk_uint_least16_t; +typedef int_least16_t duk_int_least16_t; +typedef uint_least32_t duk_uint_least32_t; +typedef int_least32_t duk_int_least32_t; +typedef uint_least64_t duk_uint_least64_t; +typedef int_least64_t duk_int_least64_t; +typedef uint_fast8_t duk_uint_fast8_t; +typedef int_fast8_t duk_int_fast8_t; +typedef uint_fast16_t duk_uint_fast16_t; +typedef int_fast16_t duk_int_fast16_t; +typedef uint_fast32_t duk_uint_fast32_t; +typedef int_fast32_t duk_int_fast32_t; +typedef uint_fast64_t duk_uint_fast64_t; +typedef int_fast64_t duk_int_fast64_t; +typedef uintptr_t duk_uintptr_t; +typedef intptr_t duk_intptr_t; +typedef uintmax_t duk_uintmax_t; +typedef intmax_t duk_intmax_t; + +#define DUK_UINT8_MIN 0 +#define DUK_UINT8_MAX UINT8_MAX +#define DUK_INT8_MIN INT8_MIN +#define DUK_INT8_MAX INT8_MAX +#define DUK_UINT_LEAST8_MIN 0 +#define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX +#define DUK_INT_LEAST8_MIN INT_LEAST8_MIN +#define DUK_INT_LEAST8_MAX INT_LEAST8_MAX +#define DUK_UINT_FAST8_MIN 0 +#define DUK_UINT_FAST8_MAX UINT_FAST8_MAX +#define DUK_INT_FAST8_MIN INT_FAST8_MIN +#define DUK_INT_FAST8_MAX INT_FAST8_MAX +#define DUK_UINT16_MIN 0 +#define DUK_UINT16_MAX UINT16_MAX +#define DUK_INT16_MIN INT16_MIN +#define DUK_INT16_MAX INT16_MAX +#define DUK_UINT_LEAST16_MIN 0 +#define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX +#define DUK_INT_LEAST16_MIN INT_LEAST16_MIN +#define DUK_INT_LEAST16_MAX INT_LEAST16_MAX +#define DUK_UINT_FAST16_MIN 0 +#define DUK_UINT_FAST16_MAX UINT_FAST16_MAX +#define DUK_INT_FAST16_MIN INT_FAST16_MIN +#define DUK_INT_FAST16_MAX INT_FAST16_MAX +#define DUK_UINT32_MIN 0 +#define DUK_UINT32_MAX UINT32_MAX +#define DUK_INT32_MIN INT32_MIN +#define DUK_INT32_MAX INT32_MAX +#define DUK_UINT_LEAST32_MIN 0 +#define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX +#define DUK_INT_LEAST32_MIN INT_LEAST32_MIN +#define DUK_INT_LEAST32_MAX INT_LEAST32_MAX +#define DUK_UINT_FAST32_MIN 0 +#define DUK_UINT_FAST32_MAX UINT_FAST32_MAX +#define DUK_INT_FAST32_MIN INT_FAST32_MIN +#define DUK_INT_FAST32_MAX INT_FAST32_MAX +#define DUK_UINT64_MIN 0 +#define DUK_UINT64_MAX UINT64_MAX +#define DUK_INT64_MIN INT64_MIN +#define DUK_INT64_MAX INT64_MAX +#define DUK_UINT_LEAST64_MIN 0 +#define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX +#define DUK_INT_LEAST64_MIN INT_LEAST64_MIN +#define DUK_INT_LEAST64_MAX INT_LEAST64_MAX +#define DUK_UINT_FAST64_MIN 0 +#define DUK_UINT_FAST64_MAX UINT_FAST64_MAX +#define DUK_INT_FAST64_MIN INT_FAST64_MIN +#define DUK_INT_FAST64_MAX INT_FAST64_MAX + +#define DUK_UINTPTR_MIN 0 +#define DUK_UINTPTR_MAX UINTPTR_MAX +#define DUK_INTPTR_MIN INTPTR_MIN +#define DUK_INTPTR_MAX INTPTR_MAX + +#define DUK_UINTMAX_MIN 0 +#define DUK_UINTMAX_MAX UINTMAX_MAX +#define DUK_INTMAX_MIN INTMAX_MIN +#define DUK_INTMAX_MAX INTMAX_MAX + +#define DUK_SIZE_MIN 0 +#define DUK_SIZE_MAX SIZE_MAX +#undef DUK_SIZE_MAX_COMPUTED diff --git a/lib/duktape-2.2.1/config/header-snippets/types_legacy.h.in b/lib/duktape-2.2.1/config/header-snippets/types_legacy.h.in new file mode 100644 index 0000000..45ffbd3 --- /dev/null +++ b/lib/duktape-2.2.1/config/header-snippets/types_legacy.h.in @@ -0,0 +1,242 @@ +/* When C99 types are not available, we use heuristic detection to get + * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least + * types are then assumed to be exactly the same for now: these could + * be improved per platform but C99 types are very often now available. + * 64-bit types are not available on all platforms; this is OK at least + * on 32-bit platforms. + * + * This detection code is necessarily a bit hacky and can provide typedefs + * and defines that won't work correctly on some exotic platform. + */ + +#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \ + (defined(UCHAR_MAX) && (UCHAR_MAX == 255)) +typedef unsigned char duk_uint8_t; +typedef signed char duk_int8_t; +#else +#error cannot detect 8-bit type +#endif + +#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL) +typedef unsigned short duk_uint16_t; +typedef signed short duk_int16_t; +#elif defined(UINT_MAX) && (UINT_MAX == 65535UL) +/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ +typedef unsigned int duk_uint16_t; +typedef signed int duk_int16_t; +#else +#error cannot detect 16-bit type +#endif + +#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL) +typedef unsigned int duk_uint32_t; +typedef signed int duk_int32_t; +#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL) +/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ +typedef unsigned long duk_uint32_t; +typedef signed long duk_int32_t; +#else +#error cannot detect 32-bit type +#endif + +/* 64-bit type detection is a bit tricky. + * + * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__ + * are used by at least GCC (even if system headers don't provide ULLONG_MAX). + * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__. + * + * ULL / LL constants are rejected / warned about by some compilers, even if + * the compiler has a 64-bit type and the compiler/system headers provide an + * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants. + * As a side effect we can only check that e.g. ULONG_MAX is larger than 32 + * bits but can't be sure it is exactly 64 bits. Self tests will catch such + * cases. + */ +#undef DUK_F_HAVE_64BIT +#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX) +#if (ULONG_MAX > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long duk_uint64_t; +typedef signed long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX) +#if (ULLONG_MAX > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__) +#if (__ULONG_LONG_MAX__ > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__) +#if (__LONG_LONG_MAX__ > 2147483647L) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MINGW) +#define DUK_F_HAVE_64BIT +typedef unsigned long duk_uint64_t; +typedef signed long duk_int64_t; +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MSVC) +#define DUK_F_HAVE_64BIT +typedef unsigned __int64 duk_uint64_t; +typedef signed __int64 duk_int64_t; +#endif +#if !defined(DUK_F_HAVE_64BIT) +/* cannot detect 64-bit type, not always needed so don't error */ +#endif + +typedef duk_uint8_t duk_uint_least8_t; +typedef duk_int8_t duk_int_least8_t; +typedef duk_uint16_t duk_uint_least16_t; +typedef duk_int16_t duk_int_least16_t; +typedef duk_uint32_t duk_uint_least32_t; +typedef duk_int32_t duk_int_least32_t; +typedef duk_uint8_t duk_uint_fast8_t; +typedef duk_int8_t duk_int_fast8_t; +typedef duk_uint16_t duk_uint_fast16_t; +typedef duk_int16_t duk_int_fast16_t; +typedef duk_uint32_t duk_uint_fast32_t; +typedef duk_int32_t duk_int_fast32_t; +#if defined(DUK_F_HAVE_64BIT) +typedef duk_uint64_t duk_uint_least64_t; +typedef duk_int64_t duk_int_least64_t; +typedef duk_uint64_t duk_uint_fast64_t; +typedef duk_int64_t duk_int_fast64_t; +#endif +#if defined(DUK_F_HAVE_64BIT) +typedef duk_uint64_t duk_uintmax_t; +typedef duk_int64_t duk_intmax_t; +#else +typedef duk_uint32_t duk_uintmax_t; +typedef duk_int32_t duk_intmax_t; +#endif + +/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and + * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are + * -not- portable. See code-issues.txt for a detailed discussion. + */ +#define DUK_UINT8_MIN 0UL +#define DUK_UINT8_MAX 0xffUL +#define DUK_INT8_MIN (-0x80L) +#define DUK_INT8_MAX 0x7fL +#define DUK_UINT_LEAST8_MIN 0UL +#define DUK_UINT_LEAST8_MAX 0xffUL +#define DUK_INT_LEAST8_MIN (-0x80L) +#define DUK_INT_LEAST8_MAX 0x7fL +#define DUK_UINT_FAST8_MIN 0UL +#define DUK_UINT_FAST8_MAX 0xffUL +#define DUK_INT_FAST8_MIN (-0x80L) +#define DUK_INT_FAST8_MAX 0x7fL +#define DUK_UINT16_MIN 0UL +#define DUK_UINT16_MAX 0xffffUL +#define DUK_INT16_MIN (-0x7fffL - 1L) +#define DUK_INT16_MAX 0x7fffL +#define DUK_UINT_LEAST16_MIN 0UL +#define DUK_UINT_LEAST16_MAX 0xffffUL +#define DUK_INT_LEAST16_MIN (-0x7fffL - 1L) +#define DUK_INT_LEAST16_MAX 0x7fffL +#define DUK_UINT_FAST16_MIN 0UL +#define DUK_UINT_FAST16_MAX 0xffffUL +#define DUK_INT_FAST16_MIN (-0x7fffL - 1L) +#define DUK_INT_FAST16_MAX 0x7fffL +#define DUK_UINT32_MIN 0UL +#define DUK_UINT32_MAX 0xffffffffUL +#define DUK_INT32_MIN (-0x7fffffffL - 1L) +#define DUK_INT32_MAX 0x7fffffffL +#define DUK_UINT_LEAST32_MIN 0UL +#define DUK_UINT_LEAST32_MAX 0xffffffffUL +#define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L) +#define DUK_INT_LEAST32_MAX 0x7fffffffL +#define DUK_UINT_FAST32_MIN 0UL +#define DUK_UINT_FAST32_MAX 0xffffffffUL +#define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L) +#define DUK_INT_FAST32_MAX 0x7fffffffL + +/* 64-bit constants. Since LL / ULL constants are not always available, + * use computed values. These values can't be used in preprocessor + * comparisons; flag them as such. + */ +#if defined(DUK_F_HAVE_64BIT) +#define DUK_UINT64_MIN ((duk_uint64_t) 0) +#define DUK_UINT64_MAX ((duk_uint64_t) -1) +#define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1))) +#define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1)) +#define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN +#define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX +#define DUK_INT_LEAST64_MIN DUK_INT64_MIN +#define DUK_INT_LEAST64_MAX DUK_INT64_MAX +#define DUK_UINT_FAST64_MIN DUK_UINT64_MIN +#define DUK_UINT_FAST64_MAX DUK_UINT64_MAX +#define DUK_INT_FAST64_MIN DUK_INT64_MIN +#define DUK_INT_FAST64_MAX DUK_INT64_MAX +#define DUK_UINT64_MIN_COMPUTED +#define DUK_UINT64_MAX_COMPUTED +#define DUK_INT64_MIN_COMPUTED +#define DUK_INT64_MAX_COMPUTED +#define DUK_UINT_LEAST64_MIN_COMPUTED +#define DUK_UINT_LEAST64_MAX_COMPUTED +#define DUK_INT_LEAST64_MIN_COMPUTED +#define DUK_INT_LEAST64_MAX_COMPUTED +#define DUK_UINT_FAST64_MIN_COMPUTED +#define DUK_UINT_FAST64_MAX_COMPUTED +#define DUK_INT_FAST64_MIN_COMPUTED +#define DUK_INT_FAST64_MAX_COMPUTED +#endif + +#if defined(DUK_F_HAVE_64BIT) +#define DUK_UINTMAX_MIN DUK_UINT64_MIN +#define DUK_UINTMAX_MAX DUK_UINT64_MAX +#define DUK_INTMAX_MIN DUK_INT64_MIN +#define DUK_INTMAX_MAX DUK_INT64_MAX +#define DUK_UINTMAX_MIN_COMPUTED +#define DUK_UINTMAX_MAX_COMPUTED +#define DUK_INTMAX_MIN_COMPUTED +#define DUK_INTMAX_MAX_COMPUTED +#else +#define DUK_UINTMAX_MIN 0UL +#define DUK_UINTMAX_MAX 0xffffffffUL +#define DUK_INTMAX_MIN (-0x7fffffffL - 1L) +#define DUK_INTMAX_MAX 0x7fffffffL +#endif + +/* This detection is not very reliable. */ +#if defined(DUK_F_32BIT_PTRS) +typedef duk_int32_t duk_intptr_t; +typedef duk_uint32_t duk_uintptr_t; +#define DUK_UINTPTR_MIN DUK_UINT32_MIN +#define DUK_UINTPTR_MAX DUK_UINT32_MAX +#define DUK_INTPTR_MIN DUK_INT32_MIN +#define DUK_INTPTR_MAX DUK_INT32_MAX +#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT) +typedef duk_int64_t duk_intptr_t; +typedef duk_uint64_t duk_uintptr_t; +#define DUK_UINTPTR_MIN DUK_UINT64_MIN +#define DUK_UINTPTR_MAX DUK_UINT64_MAX +#define DUK_INTPTR_MIN DUK_INT64_MIN +#define DUK_INTPTR_MAX DUK_INT64_MAX +#define DUK_UINTPTR_MIN_COMPUTED +#define DUK_UINTPTR_MAX_COMPUTED +#define DUK_INTPTR_MIN_COMPUTED +#define DUK_INTPTR_MAX_COMPUTED +#else +#error cannot determine intptr type +#endif + +/* SIZE_MAX may be missing so use an approximate value for it. */ +#undef DUK_SIZE_MAX_COMPUTED +#if !defined(SIZE_MAX) +#define DUK_SIZE_MAX_COMPUTED +#define SIZE_MAX ((size_t) (-1)) +#endif +#define DUK_SIZE_MIN 0 +#define DUK_SIZE_MAX SIZE_MAX diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_AIX.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_AIX.h.in new file mode 100644 index 0000000..d026f18 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_AIX.h.in @@ -0,0 +1,5 @@ +/* AIX */ +#if defined(_AIX) +/* defined(__xlc__) || defined(__IBMC__): works but too wide */ +#define DUK_F_AIX +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_AMIGAOS.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_AMIGAOS.h.in new file mode 100644 index 0000000..6bdc5d6 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_AMIGAOS.h.in @@ -0,0 +1,6 @@ +/* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must + * define 'AMIGA' manually when using VBCC. + */ +#if defined(AMIGA) || defined(__amigaos__) +#define DUK_F_AMIGAOS +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ANDROID.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ANDROID.h.in new file mode 100644 index 0000000..5ebb645 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ANDROID.h.in @@ -0,0 +1,3 @@ +#if defined(ANDROID) || defined(__ANDROID__) +#define DUK_F_ANDROID +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_APPLE.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_APPLE.h.in new file mode 100644 index 0000000..3a3e63a --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_APPLE.h.in @@ -0,0 +1,4 @@ +/* Apple OSX, iOS */ +#if defined(__APPLE__) +#define DUK_F_APPLE +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ARM.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ARM.h.in new file mode 100644 index 0000000..aee0061 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ARM.h.in @@ -0,0 +1,9 @@ +/* ARM */ +#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM) || defined(__aarch64__) +#define DUK_F_ARM +#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) +#define DUK_F_ARM64 +#else +#define DUK_F_ARM32 +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_BCC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_BCC.h.in new file mode 100644 index 0000000..f8442cb --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_BCC.h.in @@ -0,0 +1,4 @@ +/* BCC (Bruce's C compiler): this is a "torture target" for compilation */ +#if defined(__BCC__) || defined(__BCC_VERSION__) +#define DUK_F_BCC +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_BSD.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_BSD.h.in new file mode 100644 index 0000000..b1577e6 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_BSD.h.in @@ -0,0 +1,5 @@ +/* BSD variant */ +#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \ + defined(__bsdi__) || defined(__DragonFly__) +#define DUK_F_BSD +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_C99.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_C99.h.in new file mode 100644 index 0000000..bc44022 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_C99.h.in @@ -0,0 +1,5 @@ +/* C99 or above */ +#undef DUK_F_C99 +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define DUK_F_C99 +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CLANG.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CLANG.h.in new file mode 100644 index 0000000..33f7f65 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CLANG.h.in @@ -0,0 +1,4 @@ +/* Clang */ +#if defined(__clang__) +#define DUK_F_CLANG +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP.h.in new file mode 100644 index 0000000..8489fc1 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP.h.in @@ -0,0 +1,5 @@ +/* C++ */ +#undef DUK_F_CPP +#if defined(__cplusplus) +#define DUK_F_CPP +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP11.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP11.h.in new file mode 100644 index 0000000..015259a --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CPP11.h.in @@ -0,0 +1,5 @@ +/* C++11 or above */ +#undef DUK_F_CPP11 +#if defined(__cplusplus) && (__cplusplus >= 201103L) +#define DUK_F_CPP11 +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CYGWIN.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CYGWIN.h.in new file mode 100644 index 0000000..9d631a7 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_CYGWIN.h.in @@ -0,0 +1,4 @@ +/* Cygwin */ +#if defined(__CYGWIN__) +#define DUK_F_CYGWIN +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_DURANGO.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_DURANGO.h.in new file mode 100644 index 0000000..8e64e98 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_DURANGO.h.in @@ -0,0 +1,4 @@ +/* Durango (Xbox One) */ +#if defined(_DURANGO) || defined(_XBOX_ONE) +#define DUK_F_DURANGO +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_EMSCRIPTEN.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_EMSCRIPTEN.h.in new file mode 100644 index 0000000..ba299cd --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_EMSCRIPTEN.h.in @@ -0,0 +1,4 @@ +/* Emscripten (provided explicitly by user), improve if possible */ +#if defined(EMSCRIPTEN) +#define DUK_F_EMSCRIPTEN +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_FLASHPLAYER.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_FLASHPLAYER.h.in new file mode 100644 index 0000000..39060c1 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_FLASHPLAYER.h.in @@ -0,0 +1,4 @@ +/* Flash player (e.g. Crossbridge) */ +#if defined(__FLASHPLAYER__) +#define DUK_F_FLASHPLAYER +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_FREEBSD.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_FREEBSD.h.in new file mode 100644 index 0000000..621b92e --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_FREEBSD.h.in @@ -0,0 +1,4 @@ +/* FreeBSD */ +#if defined(__FreeBSD__) || defined(__FreeBSD) +#define DUK_F_FREEBSD +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_GCC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_GCC.h.in new file mode 100644 index 0000000..ccb4ffb --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_GCC.h.in @@ -0,0 +1,10 @@ +/* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */ +#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG) +#define DUK_F_GCC +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */ +#define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__) +#else +#error cannot figure out gcc version +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_HPUX.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_HPUX.h.in new file mode 100644 index 0000000..33531c6 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_HPUX.h.in @@ -0,0 +1,7 @@ +/* HPUX */ +#if defined(__hpux) +#define DUK_F_HPUX +#if defined(__ia64) +#define DUK_F_HPUX_ITANIUM +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_LINUX.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_LINUX.h.in new file mode 100644 index 0000000..79ace6f --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_LINUX.h.in @@ -0,0 +1,4 @@ +/* Linux */ +#if defined(__linux) || defined(__linux__) || defined(linux) +#define DUK_F_LINUX +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_M68K.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_M68K.h.in new file mode 100644 index 0000000..f377888 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_M68K.h.in @@ -0,0 +1,6 @@ +/* Motorola 68K. Not defined by VBCC, so user must define one of these + * manually when using VBCC. + */ +#if defined(__m68k__) || defined(M68000) || defined(__MC68K__) +#define DUK_F_M68K +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINGW.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINGW.h.in new file mode 100644 index 0000000..8b8a16d --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINGW.h.in @@ -0,0 +1,4 @@ +/* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */ +#if defined(__MINGW32__) || defined(__MINGW64__) +#define DUK_F_MINGW +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINT.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINT.h.in new file mode 100644 index 0000000..ae269cd --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MINT.h.in @@ -0,0 +1,4 @@ +/* Atari Mint */ +#if defined(__MINT__) +#define DUK_F_MINT +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MIPS.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MIPS.h.in new file mode 100644 index 0000000..1d57239 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MIPS.h.in @@ -0,0 +1,14 @@ +/* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */ +#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \ + defined(_R3000) || defined(_R4000) || defined(_R5900) || \ + defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \ + defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \ + defined(__mips) || defined(__MIPS__) +#define DUK_F_MIPS +#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \ + defined(__mips64__) || defined(__mips_n64) +#define DUK_F_MIPS64 +#else +#define DUK_F_MIPS32 +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MSVC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MSVC.h.in new file mode 100644 index 0000000..2ddd894 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_MSVC.h.in @@ -0,0 +1,15 @@ +/* MSVC */ +#if defined(_MSC_VER) +/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx + * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g. + * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp + */ +#define DUK_F_MSVC +#if defined(_MSC_FULL_VER) +#if (_MSC_FULL_VER > 100000000) +#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER +#else +#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10) +#endif +#endif +#endif /* _MSC_VER */ diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_NETBSD.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_NETBSD.h.in new file mode 100644 index 0000000..2705bc8 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_NETBSD.h.in @@ -0,0 +1,4 @@ +/* NetBSD */ +#if defined(__NetBSD__) || defined(__NetBSD) +#define DUK_F_NETBSD +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_NO_STDINT_H.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_NO_STDINT_H.h.in new file mode 100644 index 0000000..47e16ef --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_NO_STDINT_H.h.in @@ -0,0 +1,10 @@ +/* stdint.h not available */ +#if defined(DUK_F_WINDOWS) && defined(_MSC_VER) +#if (_MSC_VER < 1700) +/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */ +#define DUK_F_NO_STDINT_H +#endif +#endif +#if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC)) +#define DUK_F_NO_STDINT_H +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_OPENBSD.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_OPENBSD.h.in new file mode 100644 index 0000000..e882b6c --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_OPENBSD.h.in @@ -0,0 +1,4 @@ +/* OpenBSD */ +#if defined(__OpenBSD__) || defined(__OpenBSD) +#define DUK_F_OPENBSD +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ORBIS.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ORBIS.h.in new file mode 100644 index 0000000..717918e --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ORBIS.h.in @@ -0,0 +1,4 @@ +/* Orbis (PS4) variant */ +#if defined(DUK_F_FREEBSD) && defined(__ORBIS__) +#define DUK_F_ORBIS +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_POSIX.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_POSIX.h.in new file mode 100644 index 0000000..ea153c6 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_POSIX.h.in @@ -0,0 +1,4 @@ +/* POSIX */ +#if defined(__posix) +#define DUK_F_POSIX +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_PPC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_PPC.h.in new file mode 100644 index 0000000..b1ab82c --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_PPC.h.in @@ -0,0 +1,9 @@ +/* PowerPC */ +#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__) +#define DUK_F_PPC +#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64) +#define DUK_F_PPC64 +#else +#define DUK_F_PPC32 +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_QNX.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_QNX.h.in new file mode 100644 index 0000000..9fe1d01 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_QNX.h.in @@ -0,0 +1,4 @@ +/* QNX */ +#if defined(__QNX__) +#define DUK_F_QNX +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SPARC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SPARC.h.in new file mode 100644 index 0000000..37e1e70 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SPARC.h.in @@ -0,0 +1,9 @@ +/* SPARC */ +#if defined(sparc) || defined(__sparc) || defined(__sparc__) +#define DUK_F_SPARC +#if defined(__LP64__) || defined(_LP64) +#define DUK_F_SPARC64 +#else +#define DUK_F_SPARC32 +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUN.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUN.h.in new file mode 100644 index 0000000..9ae871d --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUN.h.in @@ -0,0 +1,12 @@ +/* illumos / Solaris */ +#if defined(__sun) && defined(__SVR4) +#define DUK_F_SUN +#if defined(__SUNPRO_C) && (__SUNPRO_C < 0x550) +#define DUK_F_OLD_SOLARIS +/* Defines _ILP32 / _LP64 required by DUK_F_X86/DUK_F_X64. Platforms + * are processed before architectures, so this happens before the + * DUK_F_X86/DUK_F_X64 detection is emitted. + */ +#include +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUPERH.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUPERH.h.in new file mode 100644 index 0000000..cd9eca5 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_SUPERH.h.in @@ -0,0 +1,9 @@ +/* SuperH */ +#if defined(__sh__) || \ + defined(__sh1__) || defined(__SH1__) || \ + defined(__sh2__) || defined(__SH2__) || \ + defined(__sh3__) || defined(__SH3__) || \ + defined(__sh4__) || defined(__SH4__) || \ + defined(__sh5__) || defined(__SH5__) +#define DUK_F_SUPERH +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINSPIRE.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINSPIRE.h.in new file mode 100644 index 0000000..7451979 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINSPIRE.h.in @@ -0,0 +1,4 @@ +/* TI-Nspire (using Ndless) */ +#if defined(_TINSPIRE) +#define DUK_F_TINSPIRE +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINYC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINYC.h.in new file mode 100644 index 0000000..43a0cff --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TINYC.h.in @@ -0,0 +1,5 @@ +/* TinyC */ +#if defined(__TINYC__) +/* http://bellard.org/tcc/tcc-doc.html#SEC9 */ +#define DUK_F_TINYC +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TOS.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TOS.h.in new file mode 100644 index 0000000..fcc296d --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_TOS.h.in @@ -0,0 +1,6 @@ +/* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC + * apparently, so to use with VBCC user must define __TOS__ manually. + */ +#if defined(__TOS__) +#define DUK_F_TOS +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_UCLIBC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_UCLIBC.h.in new file mode 100644 index 0000000..7706962 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_UCLIBC.h.in @@ -0,0 +1,4 @@ +/* uclibc */ +#if defined(__UCLIBC__) +#define DUK_F_UCLIBC +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ULL_CONSTS.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ULL_CONSTS.h.in new file mode 100644 index 0000000..188f628 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_ULL_CONSTS.h.in @@ -0,0 +1,9 @@ +/* ULL / LL preprocessor constants should be avoided because they're not + * always available. With suitable options, some compilers will support + * 64-bit integer types but won't support ULL / LL preprocessor constants. + * Assume C99/C++11 environments have these. However, BCC is nominally + * C99 but doesn't support these constants. + */ +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && !defined(DUK_F_BCC) +#define DUK_F_ULL_CONSTS +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_UNIX.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_UNIX.h.in new file mode 100644 index 0000000..ab15b35 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_UNIX.h.in @@ -0,0 +1,5 @@ +/* Generic Unix (includes Cygwin) */ +#if defined(__unix) || defined(__unix__) || defined(unix) || \ + defined(DUK_F_LINUX) || defined(DUK_F_BSD) +#define DUK_F_UNIX +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_VBCC.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_VBCC.h.in new file mode 100644 index 0000000..f50e481 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_VBCC.h.in @@ -0,0 +1,4 @@ +/* VBCC */ +#if defined(__VBCC__) +#define DUK_F_VBCC +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_WINDOWS.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_WINDOWS.h.in new file mode 100644 index 0000000..20aa769 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_WINDOWS.h.in @@ -0,0 +1,10 @@ +/* Windows, both 32-bit and 64-bit */ +#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \ + defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) +#define DUK_F_WINDOWS +#if defined(_WIN64) || defined(WIN64) +#define DUK_F_WIN64 +#else +#define DUK_F_WIN32 +#endif +#endif diff --git a/lib/duktape-2.2.1/config/helper-snippets/DUK_F_X86.h.in b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_X86.h.in new file mode 100644 index 0000000..0df3360 --- /dev/null +++ b/lib/duktape-2.2.1/config/helper-snippets/DUK_F_X86.h.in @@ -0,0 +1,26 @@ +/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers), + * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32. + * https://sites.google.com/site/x32abi/ + * + * With DUK_F_OLD_SOLARIS the header must be included + * before this. + */ +#if defined(__amd64__) || defined(__amd64) || \ + defined(__x86_64__) || defined(__x86_64) || \ + defined(_M_X64) || defined(_M_AMD64) +#if defined(__ILP32__) || defined(_ILP32) +#define DUK_F_X32 +#else +#define DUK_F_X64 +#endif +#elif defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(__i486__) || defined(__i586__) || defined(__i686__) || \ + defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \ + defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) +#if defined(__LP64__) || defined(_LP64) +/* This should not really happen, but would indicate x64. */ +#define DUK_F_X64 +#else +#define DUK_F_X86 +#endif +#endif diff --git a/lib/duktape-2.2.1/config/other-defines/c_types.yaml b/lib/duktape-2.2.1/config/other-defines/c_types.yaml new file mode 100644 index 0000000..d4f92fc --- /dev/null +++ b/lib/duktape-2.2.1/config/other-defines/c_types.yaml @@ -0,0 +1,175 @@ +# These should map to C99 types directly if available. +- typedef: duk_uint8_t +- typedef: duk_int8_t +- typedef: duk_uint16_t +- typedef: duk_int16_t +- typedef: duk_uint32_t +- typedef: duk_int32_t +- typedef: duk_uint64_t +- typedef: duk_int64_t +- typedef: duk_uint_least8_t +- typedef: duk_int_least8_t +- typedef: duk_uint_least16_t +- typedef: duk_int_least16_t +- typedef: duk_uint_least32_t +- typedef: duk_int_least32_t +- typedef: duk_uint_least64_t +- typedef: duk_int_least64_t +- typedef: duk_uint_fast8_t +- typedef: duk_int_fast8_t +- typedef: duk_uint_fast16_t +- typedef: duk_int_fast16_t +- typedef: duk_uint_fast32_t +- typedef: duk_int_fast32_t +- typedef: duk_uint_fast64_t +- typedef: duk_int_fast64_t +- typedef: duk_uintptr_t +- typedef: duk_intptr_t +- typedef: duk_uintmax_t +- typedef: duk_intmax_t +- typedef: duk_size_t +- typedef: duk_ptrdiff_t +- typedef: duk_float_t +- typedef: duk_double_t + +# Limits for above types +- define: DUK_UINT8_MIN +- define: DUK_UINT8_MAX +- define: DUK_INT8_MIN +- define: DUK_INT8_MAX +- define: DUK_UINT_LEAST8_MIN +- define: DUK_UINT_LEAST8_MAX +- define: DUK_INT_LEAST8_MIN +- define: DUK_INT_LEAST8_MAX +- define: DUK_UINT_FAST8_MIN +- define: DUK_UINT_FAST8_MAX +- define: DUK_INT_FAST8_MIN +- define: DUK_INT_FAST8_MAX +- define: DUK_UINT16_MIN +- define: DUK_UINT16_MAX +- define: DUK_INT16_MIN +- define: DUK_INT16_MAX +- define: DUK_UINT_LEAST16_MIN +- define: DUK_UINT_LEAST16_MAX +- define: DUK_INT_LEAST16_MIN +- define: DUK_INT_LEAST16_MAX +- define: DUK_UINT_FAST16_MIN +- define: DUK_UINT_FAST16_MAX +- define: DUK_INT_FAST16_MIN +- define: DUK_INT_FAST16_MAX +- define: DUK_UINT32_MIN +- define: DUK_UINT32_MAX +- define: DUK_INT32_MIN +- define: DUK_INT32_MAX +- define: DUK_UINT_LEAST32_MIN +- define: DUK_UINT_LEAST32_MAX +- define: DUK_INT_LEAST32_MIN +- define: DUK_INT_LEAST32_MAX +- define: DUK_UINT_FAST32_MIN +- define: DUK_UINT_FAST32_MAX +- define: DUK_INT_FAST32_MIN +- define: DUK_INT_FAST32_MAX +- define: DUK_UINT64_MIN +- define: DUK_UINT64_MAX +- define: DUK_INT64_MIN +- define: DUK_INT64_MAX +- define: DUK_UINT_LEAST64_MIN +- define: DUK_UINT_LEAST64_MAX +- define: DUK_INT_LEAST64_MIN +- define: DUK_INT_LEAST64_MAX +- define: DUK_UINT_FAST64_MIN +- define: DUK_UINT_FAST64_MAX +- define: DUK_INT_FAST64_MIN +- define: DUK_INT_FAST64_MAX +- define: DUK_UINTPTR_MIN +- define: DUK_UINTPTR_MAX +- define: DUK_INTPTR_MIN +- define: DUK_INTPTR_MAX +- define: DUK_UINTMAX_MIN +- define: DUK_UINTMAX_MAX +- define: DUK_INTMAX_MIN +- define: DUK_INTMAX_MAX +- define: DUK_SIZE_MIN +- define: DUK_SIZE_MAX +# FIXME: ptrdiff limits + +# Indicate if some limits are computed and can only be used runtime +- define: DUK_UINT64_MIN_COMPUTED +- define: DUK_UINT64_MAX_COMPUTED +- define: DUK_INT64_MIN_COMPUTED +- define: DUK_INT64_MAX_COMPUTED +- define: DUK_UINT_LEAST64_MIN_COMPUTED +- define: DUK_UINT_LEAST64_MAX_COMPUTED +- define: DUK_INT_LEAST64_MIN_COMPUTED +- define: DUK_INT_LEAST64_MAX_COMPUTED +- define: DUK_UINT_FAST64_MIN_COMPUTED +- define: DUK_UINT_FAST64_MAX_COMPUTED +- define: DUK_INT_FAST64_MIN_COMPUTED +- define: DUK_INT_FAST64_MAX_COMPUTED +- define: DUK_UINTMAX_MIN_COMPUTED +- define: DUK_UINTMAX_MAX_COMPUTED +- define: DUK_INTMAX_MIN_COMPUTED +- define: DUK_INTMAX_MAX_COMPUTED +- define: DUK_UINTPTR_MIN_COMPUTED +- define: DUK_UINTPTR_MAX_COMPUTED +- define: DUK_INTPTR_MIN_COMPUTED +- define: DUK_INTPTR_MAX_COMPUTED +- define: DUK_SIZE_MAX_COMPUTED + +# Derived types which typically have a fixed mapping to above types. +# FIXME: add current mapping +- typedef: duk_int_t +- typedef: duk_uint_t +- typedef: duk_int_fast_t +- typedef: duk_uint_fast_t +- typedef: duk_small_int_t +- typedef: duk_small_uint_t +- typedef: duk_small_int_fast_t +- typedef: duk_small_uint_fast_t +- typedef: duk_bool_t +- typedef: duk_idx_t +- typedef: duk_uidx_t +- typedef: duk_uarridx_t +- typedef: duk_ret_t +- typedef: duk_errcode_t +- typedef: duk_codepoint_t +- typedef: duk_ucodepoint_t + +# Limits for derived types +- define: DUK_INT_MIN +- define: DUK_INT_MAX +- define: DUK_UINT_MIN +- define: DUK_UINT_MAX +- define: DUK_INT_FAST_MIN +- define: DUK_INT_FAST_MAX +- define: DUK_UINT_FAST_MIN +- define: DUK_UINT_FAST_MAX +- define: DUK_SMALL_INT_MIN +- define: DUK_SMALL_INT_MAX +- define: DUK_SMALL_UINT_MIN +- define: DUK_SMALL_UINT_MAX +- define: DUK_SMALL_INT_FAST_MIN +- define: DUK_SMALL_INT_FAST_MAX +- define: DUK_SMALL_UINT_FAST_MIN +- define: DUK_SMALL_UINT_FAST_MAX +- define: DUK_BOOL_MIN +- define: DUK_BOOL_MAX +- define: DUK_IDX_MIN +- define: DUK_IDX_MAX +- define: DUK_UARRIDX_MIN +- define: DUK_UARRIDX_MAX +- define: DUK_RET_MIN +- define: DUK_RET_MAX +- define: DUK_ERRCODE_MIN +- define: DUK_ERRCODE_MAX +- define: DUK_CODEPOINT_MIN +- define: DUK_CODEPOINT_MAX +- define: DUK_UCODEPOINT_MIN +- define: DUK_UCODEPOINT_MAX + +# Typedef for public API calls +- typedef: duk_context + +# Double constants +- define: DUK_DOUBLE_NAN # FIXME: document DUK_USE_COMPUTED_NAN +- define: DUK_DOUBLE_INFINITY # FIXME: document DUK_USE_COMPUTED_INFINITY diff --git a/lib/duktape-2.2.1/config/other-defines/other_defines.yaml b/lib/duktape-2.2.1/config/other-defines/other_defines.yaml new file mode 100644 index 0000000..0572781 --- /dev/null +++ b/lib/duktape-2.2.1/config/other-defines/other_defines.yaml @@ -0,0 +1,32 @@ +# Varargs copy, not always provided by platform +- define: DUK_VA_COPY + +# Misc compiler/preprocessor +- define: DUK_MACRO_STRINGIFY +- define: DUK_CAUSE_SEGFAULT +- define: DUK_UNREF +- define: DUK_NORETURN +- define: DUK_UNREACHABLE +- define: DUK_LIKELY +- define: DUK_UNLIKELY + # Inline control macros applied to function definition, not declaration. +- define: DUK_NOINLINE +- define: DUK_INLINE +- define: DUK_ALWAYS_INLINE + +# Symbol visibility +- define: DUK_EXTERNAL_DECL +- define: DUK_EXTERNAL +- define: DUK_INTERNAL_DECL +- define: DUK_INTERNAL +- define: DUK_LOCAL_DECL +- define: DUK_LOCAL + +# File/line/function +- define: DUK_FILE_MACRO +- define: DUK_LINE_MACRO +- define: DUK_FUNC_MACRO + +# Byteswap macros, definable because may want to use asm +- define: DUK_BSWAP32 +- define: DUK_BSWAP16 diff --git a/lib/duktape-2.2.1/config/other-defines/platform_functions.yaml b/lib/duktape-2.2.1/config/other-defines/platform_functions.yaml new file mode 100644 index 0000000..7ab194d --- /dev/null +++ b/lib/duktape-2.2.1/config/other-defines/platform_functions.yaml @@ -0,0 +1,57 @@ +# Math replacements +- define: DUK_FPCLASSIFY +- define: DUK_SIGNBIT +- define: DUK_ISFINITE +- define: DUK_ISNAN +- define: DUK_ISINF +- define: DUK_FABS +- define: DUK_FMIN +- define: DUK_FMAX +- define: DUK_FLOOR +- define: DUK_CEIL +- define: DUK_FMOD +- define: DUK_POW +- define: DUK_ACOS +- define: DUK_ASIN +- define: DUK_ATAN +- define: DUK_ATAN2 +- define: DUK_SIN +- define: DUK_COS +- define: DUK_TAN +- define: DUK_EXP +- define: DUK_LOG +- define: DUK_SQRT +- define: DUK_CBRT +- define: DUK_LOG2 +- define: DUK_LOG10 +- define: DUK_TRUNC + +# Memory allocation +- define: DUK_ANSI_MALLOC +- define: DUK_ANSI_REALLOC +- define: DUK_ANSI_CALLOC +- define: DUK_ANSI_FREE + +# Memory manipulation +- define: DUK_MEMCPY +- define: DUK_MEMMOVE +- define: DUK_MEMCMP +- define: DUK_MEMSET +- define: DUK_MEMZERO + +# String manipulation +- define: DUK_STRLEN +- define: DUK_STRCMP +- define: DUK_STRNCMP + +# String printing and parsing +- define: DUK_SPRINTF +- define: DUK_SNPRINTF +- define: DUK_VSNPRINTF +- define: DUK_SSCANF +- define: DUK_VSSCANF + +# These don't need to save/restore signal mask. +- define: DUK_SETJMP +- define: DUK_LONGJMP +- define: DUK_JMPBUF_TYPE # e.g. jmp_buf diff --git a/lib/duktape-2.2.1/config/platforms.yaml b/lib/duktape-2.2.1/config/platforms.yaml new file mode 100644 index 0000000..00bed2e --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms.yaml @@ -0,0 +1,85 @@ +# Platform metadata. + +autodetect: + # Platforms for autodetect header. Order matters because some defines + # overlap, so rules select for more specific define first. + - + name: Mac OSX, iPhone, Darwin + check: DUK_F_APPLE + include: platform_apple.h.in + - + name: Orbis + check: DUK_F_ORBIS + include: platform_orbis.h.in + - + name: OpenBSD + check: DUK_F_OPENBSD + include: platform_openbsd.h.in + - + name: Generic BSD + check: DUK_F_BSD + include: platform_genericbsd.h.in + - + name: Atari ST TOS + check: DUK_F_TOS + include: platform_tos.h.in + - + name: AmigaOS + check: DUK_F_AMIGAOS + include: platform_amigaos.h.in + - + name: Durango (XboxOne) + check: DUK_F_DURANGO + include: platform_durango.h.in + - + name: Windows + check: DUK_F_WINDOWS + include: platform_windows.h.in + - + name: Flashplayer (Crossbridge) + check: DUK_F_FLASHPLAYER + include: platform_flashplayer.h.in + - + name: QNX + check: DUK_F_QNX + include: platform_qnx.h.in + - + name: TI-Nspire + check: DUK_F_TINSPIRE + include: platform_tinspire.h.in + - + name: Emscripten + check: DUK_F_EMSCRIPTEN + include: platform_emscripten.h.in + - + name: Linux + check: DUK_F_LINUX + include: platform_linux.h.in + - + name: Solaris + check: DUK_F_SUN + include: platform_solaris.h.in + - + name: AIX + check: DUK_F_AIX + include: platform_aix.h.in + - + name: HPUX + check: DUK_F_HPUX + include: platform_hpux.h.in + - + name: Generic POSIX + check: DUK_F_POSIX + include: platform_posix.h.in + - + name: Cygwin + check: DUK_F_CYGWIN + include: platform_cygwin.h.in + - + name: Generic UNIX + check: DUK_F_UNIX + include: platform_genericunix.h.in + - + name: Generic fallback + check: null + include: platform_generic.h.in # if nothing else diff --git a/lib/duktape-2.2.1/config/platforms/platform_aix.h.in b/lib/duktape-2.2.1/config/platforms/platform_aix.h.in new file mode 100644 index 0000000..328f45c --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_aix.h.in @@ -0,0 +1,12 @@ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include + +#define DUK_USE_OS_STRING "aix" diff --git a/lib/duktape-2.2.1/config/platforms/platform_amigaos.h.in b/lib/duktape-2.2.1/config/platforms/platform_amigaos.h.in new file mode 100644 index 0000000..d71192e --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_amigaos.h.in @@ -0,0 +1,26 @@ +#if defined(DUK_F_M68K) +/* AmigaOS on M68k */ +#define DUK_USE_DATE_NOW_TIME +#define DUK_USE_DATE_TZO_GMTIME +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include +#elif defined(DUK_F_PPC) +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#if !defined(UINTPTR_MAX) +#define UINTPTR_MAX UINT_MAX +#endif +#else +#error AmigaOS but not M68K/PPC, not supported now +#endif + +#define DUK_USE_OS_STRING "amigaos" + +/* AmigaOS on M68K or PPC is always big endian. */ +#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC)) +#define DUK_USE_BYTEORDER 3 +#endif diff --git a/lib/duktape-2.2.1/config/platforms/platform_apple.h.in b/lib/duktape-2.2.1/config/platforms/platform_apple.h.in new file mode 100644 index 0000000..59169c5 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_apple.h.in @@ -0,0 +1,25 @@ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */ +#if TARGET_IPHONE_SIMULATOR +#define DUK_USE_OS_STRING "iphone-sim" +#elif TARGET_OS_IPHONE +#define DUK_USE_OS_STRING "iphone" +#elif TARGET_OS_MAC +#define DUK_USE_OS_STRING "osx" +#else +#define DUK_USE_OS_STRING "osx-unknown" +#endif + +/* Use _setjmp() on Apple by default, see GH-55. */ +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) _setjmp((jb)) +#define DUK_LONGJMP(jb) _longjmp((jb), 1) diff --git a/lib/duktape-2.2.1/config/platforms/platform_cygwin.h.in b/lib/duktape-2.2.1/config/platforms/platform_cygwin.h.in new file mode 100644 index 0000000..cfe458b --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_cygwin.h.in @@ -0,0 +1,15 @@ +/* don't use strptime() for now */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) _setjmp((jb)) +#define DUK_LONGJMP(jb) _longjmp((jb), 1) + +#define DUK_USE_OS_STRING "windows" diff --git a/lib/duktape-2.2.1/config/platforms/platform_durango.h.in b/lib/duktape-2.2.1/config/platforms/platform_durango.h.in new file mode 100644 index 0000000..36326d8 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_durango.h.in @@ -0,0 +1,32 @@ +/* Durango = XboxOne + * Configuration is nearly identical to Windows, except for + * DUK_USE_DATE_TZO_WINDOWS. + */ + +/* Initial fix: disable secure CRT related warnings when compiling Duktape + * itself (must be defined before including Windows headers). Don't define + * for user code including duktape.h. + */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +/* MSVC does not have sys/param.h */ +#define DUK_USE_DATE_NOW_WINDOWS +#define DUK_USE_DATE_TZO_WINDOWS_NO_DST +/* Note: PRS and FMT are intentionally left undefined for now. This means + * there is no platform specific date parsing/formatting but there is still + * the ISO 8601 standard format. + */ +#if defined(DUK_COMPILING_DUKTAPE) +/* Only include when compiling Duktape to avoid polluting application build + * with a lot of unnecessary defines. + */ +#include +#endif + +#define DUK_USE_OS_STRING "durango" + +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif diff --git a/lib/duktape-2.2.1/config/platforms/platform_emscripten.h.in b/lib/duktape-2.2.1/config/platforms/platform_emscripten.h.in new file mode 100644 index 0000000..afc559d --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_emscripten.h.in @@ -0,0 +1,29 @@ +#if defined(DUK_COMPILING_DUKTAPE) +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE /* e.g. getdate_r */ +#endif +#if !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif +#endif /* DUK_COMPILING_DUKTAPE */ + +#include +#if defined(DUK_F_BCC) +/* no endian.h */ +#else +#include +#endif /* DUK_F_BCC */ +#include +#include +#include +#include + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#define DUK_USE_OS_STRING "emscripten" diff --git a/lib/duktape-2.2.1/config/platforms/platform_flashplayer.h.in b/lib/duktape-2.2.1/config/platforms/platform_flashplayer.h.in new file mode 100644 index 0000000..fa7f6f6 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_flashplayer.h.in @@ -0,0 +1,14 @@ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "flashplayer" + +#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER) +#define DUK_USE_BYTEORDER 1 +#endif diff --git a/lib/duktape-2.2.1/config/platforms/platform_generic.h.in b/lib/duktape-2.2.1/config/platforms/platform_generic.h.in new file mode 100644 index 0000000..24b552f --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_generic.h.in @@ -0,0 +1,18 @@ +/* The most portable current time provider is time(), but it only has a + * one second resolution. + */ +#define DUK_USE_DATE_NOW_TIME + +/* The most portable way to figure out local time offset is gmtime(), + * but it's not thread safe so use with caution. + */ +#define DUK_USE_DATE_TZO_GMTIME + +/* Avoid custom date parsing and formatting for portability. */ +#undef DUK_USE_DATE_PRS_STRPTIME +#undef DUK_USE_DATE_FMT_STRFTIME + +/* Rely on C89 headers only; time.h must be here. */ +#include + +#define DUK_USE_OS_STRING "unknown" diff --git a/lib/duktape-2.2.1/config/platforms/platform_genericbsd.h.in b/lib/duktape-2.2.1/config/platforms/platform_genericbsd.h.in new file mode 100644 index 0000000..494f7b1 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_genericbsd.h.in @@ -0,0 +1,11 @@ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "bsd" diff --git a/lib/duktape-2.2.1/config/platforms/platform_genericunix.h.in b/lib/duktape-2.2.1/config/platforms/platform_genericunix.h.in new file mode 100644 index 0000000..ff3d4e3 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_genericunix.h.in @@ -0,0 +1,7 @@ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#define DUK_USE_OS_STRING "unknown" diff --git a/lib/duktape-2.2.1/config/platforms/platform_hpux.h.in b/lib/duktape-2.2.1/config/platforms/platform_hpux.h.in new file mode 100644 index 0000000..dac6e19 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_hpux.h.in @@ -0,0 +1,13 @@ +#define DUK_F_NO_STDINT_H +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include + +#define DUK_USE_OS_STRING "hpux" diff --git a/lib/duktape-2.2.1/config/platforms/platform_linux.h.in b/lib/duktape-2.2.1/config/platforms/platform_linux.h.in new file mode 100644 index 0000000..cc3a69c --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_linux.h.in @@ -0,0 +1,33 @@ +#if defined(DUK_COMPILING_DUKTAPE) +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE /* e.g. getdate_r */ +#endif +#if !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif +#endif /* DUK_COMPILING_DUKTAPE */ + +#include +#if defined(DUK_F_BCC) +/* no endian.h or stdint.h */ +#else +#include +#include +#endif /* DUK_F_BCC */ +#include +#include +#include + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#if 0 /* XXX: safe condition? */ +#define DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME +#endif + +#define DUK_USE_OS_STRING "linux" diff --git a/lib/duktape-2.2.1/config/platforms/platform_openbsd.h.in b/lib/duktape-2.2.1/config/platforms/platform_openbsd.h.in new file mode 100644 index 0000000..f4b4977 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_openbsd.h.in @@ -0,0 +1,12 @@ +/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "openbsd" diff --git a/lib/duktape-2.2.1/config/platforms/platform_orbis.h.in b/lib/duktape-2.2.1/config/platforms/platform_orbis.h.in new file mode 100644 index 0000000..684ebfd --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_orbis.h.in @@ -0,0 +1,12 @@ +/* Orbis = PS4 */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_S +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "orbis" diff --git a/lib/duktape-2.2.1/config/platforms/platform_posix.h.in b/lib/duktape-2.2.1/config/platforms/platform_posix.h.in new file mode 100644 index 0000000..fa42b1b --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_posix.h.in @@ -0,0 +1,11 @@ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "posix" diff --git a/lib/duktape-2.2.1/config/platforms/platform_qnx.h.in b/lib/duktape-2.2.1/config/platforms/platform_qnx.h.in new file mode 100644 index 0000000..c4e2ee2 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_qnx.h.in @@ -0,0 +1,16 @@ +#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE) +/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */ +#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200112L +#endif + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "qnx" diff --git a/lib/duktape-2.2.1/config/platforms/platform_solaris.h.in b/lib/duktape-2.2.1/config/platforms/platform_solaris.h.in new file mode 100644 index 0000000..cc76772 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_solaris.h.in @@ -0,0 +1,21 @@ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#include +#if defined(DUK_F_OLD_SOLARIS) +/* Old Solaris with no endian.h, stdint.h */ +#define DUK_F_NO_STDINT_H +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#else /* DUK_F_OLD_SOLARIS */ +#include +#endif /* DUK_F_OLD_SOLARIS */ + +#include +#include +#include + +#define DUK_USE_OS_STRING "solaris" diff --git a/lib/duktape-2.2.1/config/platforms/platform_tinspire.h.in b/lib/duktape-2.2.1/config/platforms/platform_tinspire.h.in new file mode 100644 index 0000000..6c54267 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_tinspire.h.in @@ -0,0 +1,14 @@ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "tinspire" diff --git a/lib/duktape-2.2.1/config/platforms/platform_tos.h.in b/lib/duktape-2.2.1/config/platforms/platform_tos.h.in new file mode 100644 index 0000000..8c810e7 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_tos.h.in @@ -0,0 +1,12 @@ +#define DUK_USE_DATE_NOW_TIME +#define DUK_USE_DATE_TZO_GMTIME +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include + +#define DUK_USE_OS_STRING "tos" + +/* TOS on M68K is always big endian. */ +#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K) +#define DUK_USE_BYTEORDER 3 +#endif diff --git a/lib/duktape-2.2.1/config/platforms/platform_windows.h.in b/lib/duktape-2.2.1/config/platforms/platform_windows.h.in new file mode 100644 index 0000000..9e6fcf9 --- /dev/null +++ b/lib/duktape-2.2.1/config/platforms/platform_windows.h.in @@ -0,0 +1,59 @@ +/* Windows version can't obviously be determined at compile time, + * but _WIN32_WINNT indicates the minimum version targeted: + * - https://msdn.microsoft.com/en-us/library/6sehtctf.aspx + */ + +/* Initial fix: disable secure CRT related warnings when compiling Duktape + * itself (must be defined before including Windows headers). Don't define + * for user code including duktape.h. + */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +/* Windows 32-bit and 64-bit are currently the same. */ +/* MSVC does not have sys/param.h */ + +#if defined(DUK_COMPILING_DUKTAPE) +/* Only include when compiling Duktape to avoid polluting application build + * with a lot of unnecessary defines. + */ +#include +#endif + +/* GetSystemTimePreciseAsFileTime() available from Windows 8: + * https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx + */ +#if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) || defined(DUK_USE_DATE_NOW_WINDOWS) +/* User forced provider. */ +#else +#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602) +#define DUK_USE_DATE_NOW_WINDOWS_SUBMS +#else +#define DUK_USE_DATE_NOW_WINDOWS +#endif +#endif + +#define DUK_USE_DATE_TZO_WINDOWS + +/* Note: PRS and FMT are intentionally left undefined for now. This means + * there is no platform specific date parsing/formatting but there is still + * the ISO 8601 standard format. + */ + +/* QueryPerformanceCounter() may go backwards in Windows XP, so enable for + * Vista and later: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions + */ +#if !defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) && \ + defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) +#define DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC +#endif + +#define DUK_USE_OS_STRING "windows" + +/* On Windows, assume we're little endian. Even Itanium which has a + * configurable endianness runs little endian in Windows. + */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif diff --git a/lib/duktape-2.2.1/config/tags.yaml b/lib/duktape-2.2.1/config/tags.yaml new file mode 100644 index 0000000..86d06c7 --- /dev/null +++ b/lib/duktape-2.2.1/config/tags.yaml @@ -0,0 +1,96 @@ +# Properties for each tag: +# +# - title: title to use in header files +# + +ecmascript: + title: Ecmascript Edition 5 (ES5) options + +ecmascript2015: + title: Ecmascript 2015 (ES6) options + +ecmascript2016: + title: Ecmascript 2016 (ES7) options + +ecmascript2017: + title: Ecmascript 2017 (ES8) options + +ecmascript2018: + title: Ecmascript 2018 (ES9) options + +duktape: + title: Duktape specific options + +compliance: + title: Compliance related options + +debugger: + title: Debugger options + +debug: + title: Debug options + +execution: + title: Execution options + +sandbox: + title: Sandboxing options + +performance: + title: Performance options + +portability: + title: Platform and portability options + +memory: + title: Memory management options + +lowmemory: + title: Low memory options + +gc: + title: Garbage collection options + +misc: + title: Miscellaneous options + +io: + title: I/O options + +development: + title: Developer-only options + description: > + Developer options which are not intended for end users and are not + part of semantic versioning guarantees (e.g. torture options). + +legacy: + title: Backwards compatibility options + description: > + Options for providing backwards compatible behavior. + +date: + title: Date handling options + +experimental: + title: Experimental options + +api: + title: API options + +fastpath: + title: Fast path performance options + +cstackdepth: + title: C stack depth + +torture: + title: Development time torture options + description: > + Development time options to stress test corner case handling by e.g. + causing a garbage collection on every allocation. + +encoding-api: + title: WHATWG Encoding API + +performance-api: + title: Performance API (High Resolution Time) diff --git a/lib/duktape-2.2.1/debugger/Makefile b/lib/duktape-2.2.1/debugger/Makefile new file mode 100644 index 0000000..f142c25 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/Makefile @@ -0,0 +1,101 @@ +NODE:=$(shell { command -v nodejs || command -v node; } 2>/dev/null) +DUKLUV:=$(shell command -v dukluv 2>/dev/null) + +# Try to get a useful default --source-dirs which works both in the Duktape +# repo and in the distributable. We don't want to add '..' because it would +# scan a lot of undesired files in the Duktape repo (e.g. test262 testcases). +ifeq ($(wildcard ../tests/ecmascript/*.js),) +SOURCEDIRS:=../ +else +SOURCEDIRS:=../tests/ecmascript +endif + +.PHONY: all +all: run + +.PHONY: run +run: node_modules static/socket.io-1.2.0.js static/jquery-1.11.1.min.js static/reset.css static/jquery-ui.min.js static/jquery-ui.min.css static/images + "$(NODE)" duk_debug.js --source-dirs=$(SOURCEDIRS) + +rundebug: node_modules static/socket.io-1.2.0.js static/jquery-1.11.1.min.js static/reset.css static/jquery-ui.min.js static/jquery-ui.min.css static/images + "$(NODE)" duk_debug.js --source-dirs=$(SOURCEDIRS) --verbose --log-messages /tmp/dukdebug-messages --dump-debug-pretty /tmp/dukdebug-pretty + +.PHONY: runproxynodejs +runproxynodejs: node_modules static/socket.io-1.2.0.js static/jquery-1.11.1.min.js static/reset.css static/jquery-ui.min.js static/jquery-ui.min.css static/images + @echo "Running Node.js based debug proxy" + "$(NODE)" duk_debug.js --json-proxy + +.PHONY: runproxydukluv +runproxydukluv: duk_debug_meta.json + @echo "Running Dukluv based debug proxy (you may need to edit DUKLUV in the Makefile)" + "$(DUKLUV)" duk_debug_proxy.js --log-level 2 --metadata duk_debug_meta.json --readable-numbers + +.PHONY: runproxy +runproxy: runproxydukluv + +.PHONY: clean +clean: + @rm -f static/socket.io-1.2.0.js + @rm -f static/jquery-1.11.1.min.js + @rm -f static/jquery.syntaxhighlighter.min.js + @rm -f static/jquery.snippet.min.js + @rm -f static/jquery.snippet.min.css + @rm -f static/prefixfree.min.js + @rm -f static/reset.css + @rm -f static/jquery-ui.min.js + @rm -f static/jquery-ui.min.css + @rm -rf static/images + @rm -f jquery-ui-1.11.2.zip + @rm -rf jquery-ui-1.11.2 + @rm -rf node_modules + @rm -f duk_debug_meta.json + +node_modules: + npm install + +duk_debug_meta.json: + python2 ../tools/merge_debug_meta.py --output $@ \ + --class-names duk_classnames.yaml \ + --opcodes duk_opcodes.yaml \ + --debug-commands duk_debugcommands.yaml \ + --debug-errors duk_debugerrors.yaml + +static/socket.io-1.2.0.js: + wget -O $@ http://cdn.socket.io/socket.io-1.2.0.js + +static/jquery-1.11.1.min.js: + wget -O $@ http://code.jquery.com/jquery-1.11.1.min.js + +# http://balupton.github.io/jquery-syntaxhighlighter/demo/ +static/jquery.syntaxhighlighter.min.js: + wget -O $@ http://balupton.github.com/jquery-syntaxhighlighter/scripts/jquery.syntaxhighlighter.min.js + +# http://steamdev.com/snippet/ +static/jquery.snippet.min.js: + wget -O $@ http://steamdev.com/snippet/js/jquery.snippet.min.js +static/jquery.snippet.min.css: + wget -O $@ http://steamdev.com/snippet/css/jquery.snippet.min.css + +# http://prismjs.com/ +# http://prismjs.com/plugins/line-highlight/ +# +# XXX: prism download manually? + +# https://raw.github.com/LeaVerou/prefixfree/gh-pages/prefixfree.min.js +static/prefixfree.min.js: + wget -O $@ https://raw.github.com/LeaVerou/prefixfree/gh-pages/prefixfree.min.js + +# http://meyerweb.com/eric/tools/css/reset/ +static/reset.css: + wget -O $@ http://meyerweb.com/eric/tools/css/reset/reset.css + +jquery-ui-1.11.2.zip: + wget -O $@ http://jqueryui.com/resources/download/jquery-ui-1.11.2.zip +jquery-ui-1.11.2: jquery-ui-1.11.2.zip + unzip $< +static/jquery-ui.min.js: jquery-ui-1.11.2 + cp jquery-ui-1.11.2/jquery-ui.min.js $@ +static/jquery-ui.min.css: jquery-ui-1.11.2 + cp jquery-ui-1.11.2/jquery-ui.min.css $@ +static/images: jquery-ui-1.11.2 + cp -r jquery-ui-1.11.2/images static/ diff --git a/lib/duktape-2.2.1/debugger/README.rst b/lib/duktape-2.2.1/debugger/README.rst new file mode 100644 index 0000000..1d837d5 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/README.rst @@ -0,0 +1,383 @@ +========================================= +Duktape debug client and JSON debug proxy +========================================= + +Overview +======== + +Debugger web UI which connects to the Duktape command line tool or any other +target supporting the example TCP transport (``examples/debug-trans-socket``) +on Unix and Windows. + +Also provides a JSON debug proxy with a JSON mapping for the Duktape debug +protocol. + +For detailed documentation of the debugger internals, see `debugger.rst`__. + +__ https://github.com/svaarala/duktape/blob/master/doc/debugger.rst + +Using the debugger web UI +========================= + +Some prerequisites: + +* You'll need Node.js v0.10.x or newer. Older Node.js versions don't support + the required packages. + +Compile Duktape command line tool with debugger support: + +* Enable ``DUK_USE_DEBUGGER_SUPPORT`` and ``DUK_USE_INTERRUPT_COUNTER`` for + ``tools/configure.py``. + +* Enable ``DUK_CMDLINE_DEBUGGER_SUPPORT`` on compiler command line for Duktape + command line utility. + +The source distributable contains a Makefile to build a "duk" command with +debugger support:: + + $ cd + $ make -f Makefile.dukdebug + +The Duktape Git repo "duk" target has debugger support enabled by default:: + + $ make clean duk + +Start Duktape command line tool so that it waits for a debugger connection:: + + # For now we need to be in the directory containing the source files + # executed so that the 'fileName' properties of functions will match + # that on the debug client. + + # Using source distributable + $ cd + $ ./duk --debugger mandel.js + + # Using Duktape Git repo + $ cd /tests/ecmascript/ + $ ../../duk --debugger test-dev-mandel2-func.js + +Start the web UI:: + + # Must be in 'debugger' directory. + + $ cd debugger/ + $ make # runs 'node duk_debug.js' + +Once the required packages are installed, the NodeJS debug client will be +up and running. Open the following in your browser and start debugging: + +* http://localhost:9092/ + +The debug client automatically attaches to the debug target on startup. +If you start the debug target later, you'll need to click "Attach" in the +web UI. + +Using the JSON debug proxy +========================== + +There are two JSON debug proxy implementations: one implemented in DukLuv +and another in Node.js. + +DukLuv JSON proxy +----------------- + +DukLuv (https://github.com/creationix/dukluv) is a small and portable event +loop based on LibUV and Duktape with MIT license (like Duktape). As such it's +easy to embed in a custom debug client: you just include the DukLuv executable +and the JSON proxy source file in your debug client. + +Install DukLuv: + +* Ensure ``cmake`` is installed + +* ``git clone https://github.com/creationix/dukluv.git`` + +* ``git submodule init; git submodule update`` + +* ``make`` + +* Binary should appear in: + + - ``./build/dukluv`` on Linux + + - ``.\build\Debug\dukluv.exe`` on Windows + +Run the proxy:: + + # Using Makefile; autogenerates duk_debug_meta.json + # (You may need to edit DUKLUV in Makefile to point to your DukLuv) + $ make runproxydukluv + + # Manually: see "dukluv duk_debug_proxy.js --help" for help + $ .../path/to/dukluv duk_debug_proxy.js + +Start Duktape command line (or whatever your target is):: + + $ cd /tests/ecmascript/ + $ ../../duk --debugger test-dev-mandel2-func.js + +Now connect to the proxy using e.g. telnet:: + + $ telnet localhost 9093 + +The proxy will then connect to the target and you can start issuing commands:: + + $ telnet localhost 9093 + Trying 127.0.0.1... + Connected to localhost. + Escape character is '^]'. + {"notify":"_TargetConnecting","args":["127.0.0.1",9091]} + {"notify":"_TargetConnected","args":["1 10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo"]} + {"notify":"Status","command":1,"args":[1,"test-dev-mandel2-func.js","global",58,0]} + {"request":"BasicInfo"} + {"reply":true,"args":[10499,"v1.4.0-140-gc9a6c7c","duk command built from Duktape repo",1]} + {"request":"Eval","args":["print('Hello world!'); 123;"]} + {"notify":"Print","command":2,"args":["Hello world!\n"]} + {"reply":true,"args":[0,{"type":"number","data":"405ec00000000000"}]} + [...] + +The proxy log provides dumps both JSON and dvalue binary traffic which is +quite useful in development:: + + $ make runproxydukluv + Running Dukluv based debug proxy + "dukluv" duk_debug_proxy.js --log-level 2 --metadata duk_debug_meta.json + 2016-02-17T13:59:42.308Z INF Proxy: Read proxy metadata from duk_debug_meta.json + 2016-02-17T13:59:42.325Z INF Proxy: Listening for incoming JSON debug connection on 0.0.0.0:9093, target is 127.0.0.1:9091 + 2016-02-17T13:59:47.994Z INF Proxy: JSON proxy client connected + 2016-02-17T13:59:47.994Z INF Proxy: Connecting to debug target at 127.0.0.1:9091 + 2016-02-17T13:59:47.994Z INF Proxy: PROXY --> CLIENT: {"notify":"_TargetConnecting","args":["127.0.0.1",9091]} + 2016-02-17T13:59:47.994Z INF Proxy: Connected to debug target at 127.0.0.1:9091 + 2016-02-17T13:59:48.003Z INF Proxy: PROXY --> CLIENT: {"notify":"_TargetConnected","args":["1 10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo"]} + 2016-02-17T13:59:48.003Z INF Proxy: Target handshake: {"line":"1 10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo","protocolVersion":1,"text":"10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo","dukVersion":"1","dukGitDescribe":"10499","targetString":"v1.4.0-140-gc9a6c7c"} + 2016-02-17T13:59:48.151Z INF Proxy: PROXY <-- TARGET: |04| + 2016-02-17T13:59:48.152Z INF Proxy: PROXY <-- TARGET: |81| + 2016-02-17T13:59:48.152Z INF Proxy: PROXY <-- TARGET: |81| + 2016-02-17T13:59:48.160Z INF Proxy: PROXY <-- TARGET: |78746573742d6465762d6d616e64656c322d66756e632e6a73| + 2016-02-17T13:59:48.161Z INF Proxy: PROXY <-- TARGET: |66676c6f62616c| + 2016-02-17T13:59:48.165Z INF Proxy: PROXY <-- TARGET: |ba| + 2016-02-17T13:59:48.165Z INF Proxy: PROXY <-- TARGET: |80| + 2016-02-17T13:59:48.165Z INF Proxy: PROXY <-- TARGET: |00| + 2016-02-17T13:59:48.165Z INF Proxy: PROXY --> CLIENT: {"notify":"Status","command":1,"args":[1,"test-dev-mandel2-func.js","global",58,0]} + 2016-02-17T13:59:51.289Z INF Proxy: PROXY <-- CLIENT: {"request":"BasicInfo"} + 2016-02-17T13:59:51.289Z INF Proxy: PROXY --> TARGET: |01| + 2016-02-17T13:59:51.289Z INF Proxy: PROXY --> TARGET: |90| + 2016-02-17T13:59:51.289Z INF Proxy: PROXY --> TARGET: |00| + 2016-02-17T13:59:51.291Z INF Proxy: PROXY <-- TARGET: |02| + 2016-02-17T13:59:51.291Z INF Proxy: PROXY <-- TARGET: |e903| + 2016-02-17T13:59:51.292Z INF Proxy: PROXY <-- TARGET: |7376312e342e302d3134302d6763396136633763| + 2016-02-17T13:59:51.293Z INF Proxy: PROXY <-- TARGET: |12002364756b20636f6d6d616e64206275696c742066726f6d2044756b74617065207265706f| + 2016-02-17T13:59:51.293Z INF Proxy: PROXY <-- TARGET: |81| + 2016-02-17T13:59:51.293Z INF Proxy: PROXY <-- TARGET: |00| + 2016-02-17T13:59:51.293Z INF Proxy: PROXY --> CLIENT: {"reply":true,"args":[10499,"v1.4.0-140-gc9a6c7c","duk command built from Duktape repo",1]} + 2016-02-17T14:00:06.105Z INF Proxy: PROXY <-- CLIENT: {"request":"Eval","args":["print('Hello world!'); 123;"]} + 2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |01| + 2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |9e| + 2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |7b7072696e74282748656c6c6f20776f726c642127293b203132333b| + 2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |00| + 2016-02-17T14:00:06.167Z INF Proxy: PROXY <-- TARGET: |04| + 2016-02-17T14:00:06.167Z INF Proxy: PROXY <-- TARGET: |82| + 2016-02-17T14:00:06.167Z INF Proxy: PROXY <-- TARGET: |6d48656c6c6f20776f726c64210a| + 2016-02-17T14:00:06.168Z INF Proxy: PROXY <-- TARGET: |00| + 2016-02-17T14:00:06.168Z INF Proxy: PROXY --> CLIENT: {"notify":"Print","command":2,"args":["Hello world!\n"]} + 2016-02-17T14:00:06.171Z INF Proxy: PROXY <-- TARGET: |02| + 2016-02-17T14:00:06.171Z INF Proxy: PROXY <-- TARGET: |80| + 2016-02-17T14:00:06.173Z INF Proxy: PROXY <-- TARGET: |1a405ec00000000000| + 2016-02-17T14:00:06.173Z INF Proxy: PROXY <-- TARGET: |00| + 2016-02-17T14:00:06.174Z INF Proxy: PROXY --> CLIENT: {"reply":true,"args":[0,{"type":"number","data":"405ec00000000000"}]} + [...] + +Node.js JSON proxy +------------------ + +A Node.js-based JSON debug proxy is also provided by ``duk_debug.js``:: + + # Same prerequisites as for running the debug client + $ make runproxynodejs + +Start Duktape command line (or whatever your target is):: + + $ cd /tests/ecmascript/ + $ ../../duk --debugger test-dev-mandel2-func.js + +You can then connect to localhost:9093 and interact with the proxy. +Here's an example session using telnet and manually typed in commands +The ``-->`` (send) and ``<--`` (receiver) markers have been added for +readability and are not part of the stream:: + + $ telnet localhost 9093 + Trying 127.0.0.1... + Connected to localhost. + Escape character is '^]'. + <-- {"notify":"_TargetConnected","args":["1 10199 v1.1.0-275-gbd4d610-dirty duk command built from Duktape repo"]} + <-- {"notify":"Status","command":1,"args":[1,"test-dev-mandel2-func.js","global",58,0]} + --> {"request":"BasicInfo"} + <-- {"reply":true,"args":[10199,"v1.1.0-275-gbd4d610-dirty","duk command built from Duktape repo",1]} + --> {"request":"Eval", "args":[ "print(Math.PI)" ]} + <-- {"notify":"Print","command":2,"args":["3.141592653589793\n"]} + <-- {"reply":true,"args":[0,{"type":"undefined"}]} + --> {"request":"Resume"} + <-- {"reply":true,"args":[]} + <-- {"notify":"Status","command":1,"args":[0,"test-dev-mandel2-func.js","global",58,0]} + <-- {"notify":"Status","command":1,"args":[0,"test-dev-mandel2-func.js","global",58,0]} + <-- {"notify":"Print","command":2,"args":["................................................................................\n"]} + <-- {"notify":"Print","command":2,"args":["................................................................................\n"]} + <-- {"notify":"Print","command":2,"args":["................................................................................\n"]} + [...] + <-- {"notify":"_Disconnecting"} + +A telnet connection allows you to experiment with debug commands by simply +copy-pasting debug commands to the telnet session. This is useful even if +you decide to implement the binary protocol directly. + +The debug target used by the proxy can be configured with ``duk_debug.js`` +command line options. + +Source search path +================== + +The NodeJS debug client needs to be able to find source code files matching +code running on the target ("duk" command line). **The filenames used on the +target and on the debug client must match exactly**, because e.g. breakpoints +are targeted based on the 'fileName' property of Function objects. + +The search path can be set using the ``--source-dirs`` option given to +``duk_debug.js``, with the default search paths including only +``../tests/ecmascript/``. + +The default search path means that if a function on the target has fileName +``foo/bar.js`` it would be loaded from (relative to the duk_debug.js working +directory, ``debugger/``):: + + ../tests/ecmascript/foo/bar.js + +Similarly, if the filesystem contained:: + + ../tests/ecmascript/baz/quux.js + +the web UI dropdown would show ``baz/quux.js``. If you selected that file +and added a breakpoint, the breakpoint fileName sent to the debug target +would be ``baz/quux.js``. + +.. note:: There's much to improve in the search path. For instance, it'd + be nice to add a certain path to search but exclude files based + on paths and patterns, etc. + +Architecture +============ + +:: + + +-------------------+ + | Web browser | [debug UI] + +-------------------+ + | + | http (port 9092) + | socket.io + v + +-------------------+ + | duk_debug.js | [debug client] + +-------------------+ + | /\ + | || + +----------||---- [example tcp transport] (port 9091) + | || (application provides concrete transport) + | || + | ||---- [debug protocol stream] + | || (between debug client and Duktape) + | || + + - - | - - - - -|| - - + + : v || : +  : +-------------||-+ : [target] + : | application || | : + : +-------------||-+ : + : ^ || : + : | || : [debug API] + : +----------||-------- debug transport callbacks + : | || : (read, write, peek, read/write flush) + : | || : implemented by application + : | \/ : + : +----------------+ : + : | Duktape | : + : +----------------+ : + + - - - - - - - - - - - + + +The debug transport is application specific: + +* Duktape command line ("duk") and this debug client use an **example** TCP + transport as a concrete example. + +* It is entirely up to the application to come up with the most suitable + transport for its environment. Different mechanisms will be needed for + Wi-Fi, serial, etc. + +The debug protocol running inside the transport is transport independent: + +* The debug protocol is documented in ``doc/debugger.rst``. + +* This debug client provides further concrete examples and clarifications + on how the protocol can be used. + +Using a custom transport +======================== + +Quite possibly your target device cannot use the example TCP transport and +you need to implement your own transport. You'll need to implement your +custom transport both for the target device and for the debug client. + +Target device +------------- + +Implement the debug transport callbacks needed by ``duk_debugger_attach()``. + +See ``doc/debugger.rst`` for details and ``examples/debug-trans-socket`` +for example running code for a TCP transport. + +Debug client alternative 1: duk_debug.js + custom TCP proxy +----------------------------------------------------------- + +If you don't want to change ``duk_debug.js`` you can implement a TCP proxy +which accepts a TCP connection from ``duk_debug.js`` and then uses your +custom transport to talk to the target:: + + +--------------+ TCP +-------+ custom +--------+ + | duk_debug.js | ------> | proxy | ---------> | target | + +--------------+ +-------+ +--------+ + +This is a straightforward option and a proxy can be used with other debug +clients too (perhaps custom scripts talking to the target etc). + +You could also use netcat and implement your proxy so that it talks to +``duk_debug.js`` using stdin/stdout. + +Debug client alternative 2: duk_debug.js + custom NodeJS stream +--------------------------------------------------------------- + +To make ``duk_debug.js`` use a custom transport you need to: + +* Implement your own transport as NodeJS stream. You can add it directly to + ``duk_debug.js`` but it's probably easiest to use a separate module so that + the diff to ``duk_debug.js`` stays minimal. + +* Change ``duk_debug.js`` to use the custom transport instead of a TCP + stream. Search for "CUSTOMTRANSPORT" in ``duk_debug.js``. + +See: + +* http://nodejs.org/api/stream.html + +* https://github.com/substack/stream-handbook + +Debug client alternative 3: custom debug client +----------------------------------------------- + +You can also implement your own debug client and debug UI with support for +your custom transport. + +You'll also need to implement the client part of the Duktape debugger +protocol. See ``doc/debugger.rst`` for the specification and ``duk_debug.js`` +for example running code which should illustrate the protocol in more detail. + +The JSON debug proxy allows you to implement a debug client without needing +to implement the Duktape binary debug protocol. The JSON protocol provides +a roughly 1:1 mapping to the binary protocol but with an easier syntax. diff --git a/lib/duktape-2.2.1/debugger/duk_classnames.yaml b/lib/duktape-2.2.1/debugger/duk_classnames.yaml new file mode 100644 index 0000000..ded0277 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_classnames.yaml @@ -0,0 +1,32 @@ +# Must match C header. +class_names: + - none + - Object + - Array + - Function + - Arguments + - Boolean + - Date + - Error + - JSON + - Math + - Number + - RegExp + - String + - global + - Symbol + - ObjEnv + - DecEnv + - Pointer + - Thread + - ArrayBuffer + - DataView + - Int8Array + - Uint8Array + - Uint8ClampedArray + - Int16Array + - Uint16Array + - Int32Array + - Uint32Array + - Float32Array + - Float64Array diff --git a/lib/duktape-2.2.1/debugger/duk_debug.js b/lib/duktape-2.2.1/debugger/duk_debug.js new file mode 100644 index 0000000..55c9624 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_debug.js @@ -0,0 +1,2491 @@ +/* + * Minimal debug web console for Duktape command line tool + * + * See debugger/README.rst. + * + * The web UI socket.io communication can easily become a bottleneck and + * it's important to ensure that the web UI remains responsive. Basic rate + * limiting mechanisms (token buckets, suppressing identical messages, etc) + * are used here now. Ideally the web UI would pull data on its own terms + * which would provide natural rate limiting. + * + * Promises are used to structure callback chains. + * + * https://github.com/petkaantonov/bluebird + * https://github.com/petkaantonov/bluebird/blob/master/API.md + * https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns + */ + +var Promise = require('bluebird'); +var events = require('events'); +var stream = require('stream'); +var path = require('path'); +var fs = require('fs'); +var net = require('net'); +var byline = require('byline'); +var util = require('util'); +var readline = require('readline'); +var sprintf = require('sprintf').sprintf; +var utf8 = require('utf8'); +var yaml = require('yamljs'); +var recursiveReadSync = require('recursive-readdir-sync'); + +// Command line options (defaults here, overwritten if necessary) +var optTargetHost = '127.0.0.1'; +var optTargetPort = 9091; +var optHttpPort = 9092; +var optJsonProxyPort = 9093; +var optJsonProxy = false; +var optSourceSearchDirs = [ '../tests/ecmascript' ]; +var optDumpDebugRead = null; +var optDumpDebugWrite = null; +var optDumpDebugPretty = null; +var optLogMessages = false; + +// Constants +var UI_MESSAGE_CLIPLEN = 128; +var LOCALS_CLIPLEN = 64; +var EVAL_CLIPLEN = 4096; +var GETVAR_CLIPLEN = 4096; +var SUPPORTED_DEBUG_PROTOCOL_VERSION = 2; + +// Commands initiated by Duktape +var CMD_STATUS = 0x01; +var CMD_UNUSED_2 = 0x02; // Duktape 1.x: print notify +var CMD_UNUSED_3 = 0x03; // Duktape 1.x: alert notify +var CMD_UNUSED_4 = 0x04; // Duktape 1.x: log notify +var CMD_THROW = 0x05; +var CMD_DETACHING = 0x06; + +// Commands initiated by the debug client (= us) +var CMD_BASICINFO = 0x10; +var CMD_TRIGGERSTATUS = 0x11; +var CMD_PAUSE = 0x12; +var CMD_RESUME = 0x13; +var CMD_STEPINTO = 0x14; +var CMD_STEPOVER = 0x15; +var CMD_STEPOUT = 0x16; +var CMD_LISTBREAK = 0x17; +var CMD_ADDBREAK = 0x18; +var CMD_DELBREAK = 0x19; +var CMD_GETVAR = 0x1a; +var CMD_PUTVAR = 0x1b; +var CMD_GETCALLSTACK = 0x1c; +var CMD_GETLOCALS = 0x1d; +var CMD_EVAL = 0x1e; +var CMD_DETACH = 0x1f; +var CMD_DUMPHEAP = 0x20; +var CMD_GETBYTECODE = 0x21; + +// Errors +var ERR_UNKNOWN = 0x00; +var ERR_UNSUPPORTED = 0x01; +var ERR_TOOMANY = 0x02; +var ERR_NOTFOUND = 0x03; + +// Marker objects for special protocol values +var DVAL_EOM = { type: 'eom' }; +var DVAL_REQ = { type: 'req' }; +var DVAL_REP = { type: 'rep' }; +var DVAL_ERR = { type: 'err' }; +var DVAL_NFY = { type: 'nfy' }; + +// String map for commands (debug dumping). A single map works (instead of +// separate maps for each direction) because command numbers don't currently +// overlap. So merge the YAML metadata. +var debugCommandMeta = yaml.load('duk_debugcommands.yaml'); +var debugCommandNames = []; // list of command names, merged client/target +debugCommandMeta.target_commands.forEach(function (k, i) { + debugCommandNames[i] = k; +}); +debugCommandMeta.client_commands.forEach(function (k, i) { // override + debugCommandNames[i] = k; +}); +var debugCommandNumbers = {}; // map from (merged) command name to number +debugCommandNames.forEach(function (k, i) { + debugCommandNumbers[k] = i; +}); + +// Duktape heaphdr type constants, must match C headers +var DUK_HTYPE_STRING = 0; +var DUK_HTYPE_OBJECT = 1; +var DUK_HTYPE_BUFFER = 2; + +// Duktape internal class numbers, must match C headers +var dukClassNameMeta = yaml.load('duk_classnames.yaml'); +var dukClassNames = dukClassNameMeta.class_names; + +// Bytecode opcode/extraop metadata +var dukOpcodes = yaml.load('duk_opcodes.yaml'); +if (dukOpcodes.opcodes.length != 256) { + throw new Error('opcode metadata length incorrect'); +} + +/* + * Miscellaneous helpers + */ + +var nybbles = '0123456789abcdef'; + +/* Convert a buffer into a string using Unicode codepoints U+0000...U+00FF. + * This is the NodeJS 'binary' encoding, but since it's being deprecated, + * reimplement it here. We need to avoid parsing strings as e.g. UTF-8: + * although Duktape strings are usually UTF-8/CESU-8 that's not always the + * case, e.g. for internal strings. Buffer values are also represented as + * strings in the debug protocol, so we must deal accurately with arbitrary + * byte arrays. + */ +function bufferToDebugString(buf) { + var cp = []; + var i, n; + +/* + // This fails with "RangeError: Maximum call stack size exceeded" for some + // reason, so use a much slower variant. + + for (i = 0, n = buf.length; i < n; i++) { + cp[i] = buf[i]; + } + + return String.fromCharCode.apply(String, cp); +*/ + + for (i = 0, n = buf.length; i < n; i++) { + cp[i] = String.fromCharCode(buf[i]); + } + + return cp.join(''); +} + +/* Write a string into a buffer interpreting codepoints U+0000...U+00FF + * as bytes. Drop higher bits. + */ +function writeDebugStringToBuffer(str, buf, off) { + var i, n; + + for (i = 0, n = str.length; i < n; i++) { + buf[off + i] = str.charCodeAt(i) & 0xff; // truncate higher bits + } +} + +/* Encode an ordinary Unicode string into a dvalue compatible format, i.e. + * into a byte array represented as codepoints U+0000...U+00FF. Concretely, + * encode with UTF-8 and then represent the bytes with U+0000...U+00FF. + */ +function stringToDebugString(str) { + return utf8.encode(str); +} + +/* Pretty print a dvalue. Useful for dumping etc. */ +function prettyDebugValue(x) { + if (typeof x === 'object' && x !== null) { + if (x.type === 'eom') { + return 'EOM'; + } else if (x.type === 'req') { + return 'REQ'; + } else if (x.type === 'rep') { + return 'REP'; + } else if (x.type === 'err') { + return 'ERR'; + } else if (x.type === 'nfy') { + return 'NFY'; + } + } + return JSON.stringify(x); +} + +/* Pretty print a number for UI usage. Types and values should be easy to + * read and typing should be obvious. For numbers, support Infinity, NaN, + * and signed zeroes properly. + */ +function prettyUiNumber(x) { + if (x === 1 / 0) { return 'Infinity'; } + if (x === -1 / 0) { return '-Infinity'; } + if (Number.isNaN(x)) { return 'NaN'; } + if (x === 0 && 1 / x > 0) { return '0'; } + if (x === 0 && 1 / x < 0) { return '-0'; } + return x.toString(); +} + +/* Pretty print a dvalue string (bytes represented as U+0000...U+00FF) + * for UI usage. Try UTF-8 decoding to get a nice Unicode string (JSON + * encoded) but if that fails, ensure that bytes are encoded transparently. + * The result is a quoted string with a special quote marker for a "raw" + * string when UTF-8 decoding fails. Very long strings are optionally + * clipped. + */ +function prettyUiString(x, cliplen) { + var ret; + + if (typeof x !== 'string') { + throw new Error('invalid input to prettyUiString: ' + typeof x); + } + try { + // Here utf8.decode() is better than decoding using NodeJS buffer + // operations because we want strict UTF-8 interpretation. + ret = JSON.stringify(utf8.decode(x)); + } catch (e) { + // When we fall back to representing bytes, indicate that the string + // is "raw" with a 'r"' prefix (a somewhat arbitrary convention). + // U+0022 = ", U+0027 = ' + ret = 'r"' + x.replace(/[\u0022\u0027\u0000-\u001f\u0080-\uffff]/g, function (match) { + var cp = match.charCodeAt(0); + return '\\x' + nybbles[(cp >> 4) & 0x0f] + nybbles[cp & 0x0f]; + }) + '"'; + } + + if (cliplen && ret.length > cliplen) { + ret = ret.substring(0, cliplen) + '...'; // trailing '"' intentionally missing + } + return ret; +} + +/* Pretty print a dvalue string (bytes represented as U+0000...U+00FF) + * for UI usage without quotes. + */ +function prettyUiStringUnquoted(x, cliplen) { + var ret; + + if (typeof x !== 'string') { + throw new Error('invalid input to prettyUiStringUnquoted: ' + typeof x); + } + + try { + // Here utf8.decode() is better than decoding using NodeJS buffer + // operations because we want strict UTF-8 interpretation. + + // XXX: unprintable characters etc? In some UI cases we'd want to + // e.g. escape newlines and in others not. + ret = utf8.decode(x); + } catch (e) { + // For the unquoted version we don't need to escape single or double + // quotes. + ret = x.replace(/[\u0000-\u001f\u0080-\uffff]/g, function (match) { + var cp = match.charCodeAt(0); + return '\\x' + nybbles[(cp >> 4) & 0x0f] + nybbles[cp & 0x0f]; + }); + } + + if (cliplen && ret.length > cliplen) { + ret = ret.substring(0, cliplen) + '...'; + } + return ret; +} + +/* Pretty print a dvalue for UI usage. Everything comes out as a ready-to-use + * string. + * + * XXX: Currently the debug client formats all values for UI use. A better + * solution would be to pass values in typed form and let the UI format them, + * so that styling etc. could take typing into account. + */ +function prettyUiDebugValue(x, cliplen) { + if (typeof x === 'object' && x !== null) { + // Note: typeof null === 'object', so null special case explicitly + if (x.type === 'eom') { + return 'EOM'; + } else if (x.type === 'req') { + return 'REQ'; + } else if (x.type === 'rep') { + return 'REP'; + } else if (x.type === 'err') { + return 'ERR'; + } else if (x.type === 'nfy') { + return 'NFY'; + } else if (x.type === 'unused') { + return 'unused'; + } else if (x.type === 'undefined') { + return 'undefined'; + } else if (x.type === 'buffer') { + return '|' + x.data + '|'; + } else if (x.type === 'object') { + return '[object ' + (dukClassNames[x.class] || ('class ' + x.class)) + ' ' + x.pointer + ']'; + } else if (x.type === 'pointer') { + return ''; + } else if (x.type === 'lightfunc') { + return ''; + } else if (x.type === 'number') { + // duk_tval number, any IEEE double + var tmp = new Buffer(x.data, 'hex'); // decode into hex + var val = tmp.readDoubleBE(0); // big endian ieee double + return prettyUiNumber(val); + } + } else if (x === null) { + return 'null'; + } else if (typeof x === 'boolean') { + return x ? 'true' : 'false'; + } else if (typeof x === 'string') { + return prettyUiString(x, cliplen); + } else if (typeof x === 'number') { + // Debug protocol integer + return prettyUiNumber(x); + } + + // We shouldn't come here, but if we do, JSON is a reasonable default. + return JSON.stringify(x); +} + +/* Pretty print a debugger message given as an array of parsed dvalues. + * Result should be a pure ASCII one-liner. + */ +function prettyDebugMessage(msg) { + return msg.map(prettyDebugValue).join(' '); +} + +/* Pretty print a debugger command. */ +function prettyDebugCommand(cmd) { + return debugCommandNames[cmd] || String(cmd); +} + +/* Decode and normalize source file contents: UTF-8, tabs to 8, + * CR LF to LF. + */ +function decodeAndNormalizeSource(data) { + var tmp; + var lines, line, repl; + var i, n; + var j, m; + + try { + tmp = data.toString('utf8'); + } catch (e) { + console.log('Failed to UTF-8 decode source file, ignoring: ' + e); + tmp = String(data); + } + + lines = tmp.split(/\r?\n/); + for (i = 0, n = lines.length; i < n; i++) { + line = lines[i]; + if (/\t/.test(line)) { + repl = ''; + for (j = 0, m = line.length; j < m; j++) { + if (line.charAt(j) === '\t') { + repl += ' '; + while ((repl.length % 8) != 0) { + repl += ' '; + } + } else { + repl += line.charAt(j); + } + } + lines[i] = repl; + } + } + + // XXX: normalize last newline (i.e. force a newline if contents don't + // end with a newline)? + + return lines.join('\n'); +} + +/* Token bucket rate limiter for a given callback. Calling code calls + * trigger() to request 'cb' to be called, and the rate limiter ensures + * that 'cb' is not called too often. + */ +function RateLimited(tokens, rate, cb) { + var _this = this; + this.maxTokens = tokens; + this.tokens = this.maxTokens; + this.rate = rate; + this.cb = cb; + this.delayedCb = false; + + // Right now the implementation is setInterval-based, but could also be + // made timerless. There are so few rate limited resources that this + // doesn't matter in practice. + + this.tokenAdder = setInterval(function () { + if (_this.tokens < _this.maxTokens) { + _this.tokens++; + } + if (_this.delayedCb) { + _this.delayedCb = false; + _this.tokens--; + _this.cb(); + } + }, this.rate); +} +RateLimited.prototype.trigger = function () { + if (this.tokens > 0) { + this.tokens--; + this.cb(); + } else { + this.delayedCb = true; + } +}; + +/* + * Source file manager + * + * Scan the list of search directories for Ecmascript source files and + * build an index of them. Provides a mechanism to find a source file + * based on a raw 'fileName' property provided by the debug target, and + * to provide a file list for the web UI. + * + * NOTE: it's tempting to do loose matching for filenames, but this does + * not work in practice. Filenames must match 1:1 with the debug target + * so that e.g. breakpoints assigned based on filenames found from the + * search paths will match 1:1 on the debug target. If this is not the + * case, breakpoints won't work as expected. + */ + +function SourceFileManager(directories) { + this.directories = directories; + this.extensions = { '.js': true, '.jsm': true }; + this.fileMap = {}; // filename as seen by debug target -> file path + this.files = []; // filenames as seen by debug target +} + +SourceFileManager.prototype.scan = function () { + var _this = this; + var fileMap = {}; // relative path -> file path + var files; + + this.directories.forEach(function (dir) { + console.log('Scanning source files: ' + dir); + try { + recursiveReadSync(dir).forEach(function (fn) { + // Example: dir ../../tests + // normFn ../../tests/foo/bar.js + // relFn foo/bar.js + var normDir = path.normalize(dir); + var normFn = path.normalize(fn); + var relFn = path.relative(normDir, normFn); + + if (fs.existsSync(normFn) && fs.lstatSync(normFn).isFile() && + _this.extensions[path.extname(normFn)]) { + // We want the fileMap to contain the filename relative to + // the search dir root. First directory containing a + // certail relFn wins. + if (relFn in fileMap) { + console.log('Found', relFn, 'multiple times, first match wins'); + } else { + fileMap[relFn] = normFn; + } + } + }); + } catch (e) { + console.log('Failed to scan ' + dir + ': ' + e); + } + }); + + files = Object.keys(fileMap); + files.sort(); + this.files = files; + + this.fileMap = fileMap; + + console.log('Found ' + files.length + ' source files in ' + this.directories.length + ' search directories'); +}; + +SourceFileManager.prototype.getFiles = function () { + return this.files; +}; + +SourceFileManager.prototype.search = function (fileName) { + var _this = this; + + // Loose matching is tempting but counterproductive: filenames must + // match 1:1 between the debug client and the debug target for e.g. + // breakpoints to work as expected. Note that a breakpoint may be + // assigned by selecting a file from a dropdown populated by scanning + // the filesystem for available sources and there's no way of knowing + // if the debug target uses the exact same name. + // + // We intentionally allow any files from the search paths, not just + // those scanned to this.fileMap. + + function tryLookup() { + var i, fn, data; + + for (i = 0; i < _this.directories.length; i++) { + fn = path.join(_this.directories[i], fileName); + if (fs.existsSync(fn) && fs.lstatSync(fn).isFile()) { + data = fs.readFileSync(fn); // Raw bytes + return decodeAndNormalizeSource(data); // Unicode string + } + } + return null; + } + + return tryLookup(fileName); +}; + +/* + * Debug protocol parser + * + * The debug protocol parser is an EventEmitter which parses debug messages + * from an input stream and emits 'debug-message' events for completed + * messages ending in an EOM. The parser also provides debug dumping, stream + * logging functionality, and statistics gathering functionality. + * + * This parser is used to parse both incoming and outgoing messages. For + * outgoing messages the only function is to validate and debug dump the + * messages we're about to send. The downside of dumping at this low level + * is that we can't match request and reply/error messages here. + * + * http://www.sitepoint.com/nodejs-events-and-eventemitter/ + */ + +function DebugProtocolParser(inputStream, + protocolVersion, + rawDumpFileName, + textDumpFileName, + textDumpFilePrefix, + hexDumpConsolePrefix, + textDumpConsolePrefix) { + var _this = this; + this.inputStream = inputStream; + this.closed = false; // stream is closed/broken, don't parse anymore + this.bytes = 0; + this.dvalues = 0; + this.messages = 0; + this.requests = 0; + this.prevBytes = 0; + this.bytesPerSec = 0; + this.statsTimer = null; + this.readableNumberValue = true; + + events.EventEmitter.call(this); + + var buf = new Buffer(0); // accumulate data + var msg = []; // accumulated message until EOM + var versionIdentification; + + var statsInterval = 2000; + var statsIntervalSec = statsInterval / 1000; + this.statsTimer = setInterval(function () { + _this.bytesPerSec = (_this.bytes - _this.prevBytes) / statsIntervalSec; + _this.prevBytes = _this.bytes; + _this.emit('stats-update'); + }, statsInterval); + + function consume(n) { + var tmp = new Buffer(buf.length - n); + buf.copy(tmp, 0, n); + buf = tmp; + } + + inputStream.on('data', function (data) { + var i, n, x, v, gotValue, len, t, tmpbuf, verstr; + var prettyMsg; + + if (_this.closed || !_this.inputStream) { + console.log('Ignoring incoming data from closed input stream, len ' + data.length); + return; + } + + _this.bytes += data.length; + if (rawDumpFileName) { + fs.appendFileSync(rawDumpFileName, data); + } + if (hexDumpConsolePrefix) { + console.log(hexDumpConsolePrefix + data.toString('hex')); + } + + buf = Buffer.concat([ buf, data ]); + + // Protocol version handling. When dumping an output stream, the + // caller gives a non-null protocolVersion so we don't read one here. + if (protocolVersion == null) { + if (buf.length > 1024) { + _this.emit('transport-error', 'Parse error (version identification too long), dropping connection'); + _this.close(); + return; + } + + for (i = 0, n = buf.length; i < n; i++) { + if (buf[i] == 0x0a) { + tmpbuf = new Buffer(i); + buf.copy(tmpbuf, 0, 0, i); + consume(i + 1); + verstr = tmpbuf.toString('utf-8'); + t = verstr.split(' '); + protocolVersion = Number(t[0]); + versionIdentification = verstr; + + _this.emit('protocol-version', { + protocolVersion: protocolVersion, + versionIdentification: versionIdentification + }); + break; + } + } + + if (protocolVersion == null) { + // Still waiting for version identification to complete. + return; + } + } + + // Parse complete dvalues (quite inefficient now) by trial parsing. + // Consume a value only when it's fully present in 'buf'. + // See doc/debugger.rst for format description. + + while (buf.length > 0) { + x = buf[0]; + v = undefined; + gotValue = false; // used to flag special values like undefined + + if (x >= 0xc0) { + // 0xc0...0xff: integers 0-16383 + if (buf.length >= 2) { + v = ((x - 0xc0) << 8) + buf[1]; + consume(2); + } + } else if (x >= 0x80) { + // 0x80...0xbf: integers 0-63 + v = x - 0x80; + consume(1); + } else if (x >= 0x60) { + // 0x60...0x7f: strings with length 0-31 + len = x - 0x60; + if (buf.length >= 1 + len) { + v = new Buffer(len); + buf.copy(v, 0, 1, 1 + len); + v = bufferToDebugString(v); + consume(1 + len); + } + } else { + switch (x) { + case 0x00: v = DVAL_EOM; consume(1); break; + case 0x01: v = DVAL_REQ; consume(1); break; + case 0x02: v = DVAL_REP; consume(1); break; + case 0x03: v = DVAL_ERR; consume(1); break; + case 0x04: v = DVAL_NFY; consume(1); break; + case 0x10: // 4-byte signed integer + if (buf.length >= 5) { + v = buf.readInt32BE(1); + consume(5); + } + break; + case 0x11: // 4-byte string + if (buf.length >= 5) { + len = buf.readUInt32BE(1); + if (buf.length >= 5 + len) { + v = new Buffer(len); + buf.copy(v, 0, 5, 5 + len); + v = bufferToDebugString(v); + consume(5 + len); + } + } + break; + case 0x12: // 2-byte string + if (buf.length >= 3) { + len = buf.readUInt16BE(1); + if (buf.length >= 3 + len) { + v = new Buffer(len); + buf.copy(v, 0, 3, 3 + len); + v = bufferToDebugString(v); + consume(3 + len); + } + } + break; + case 0x13: // 4-byte buffer + if (buf.length >= 5) { + len = buf.readUInt32BE(1); + if (buf.length >= 5 + len) { + v = new Buffer(len); + buf.copy(v, 0, 5, 5 + len); + v = { type: 'buffer', data: v.toString('hex') }; + consume(5 + len); + // Value could be a Node.js buffer directly, but + // we prefer all dvalues to be JSON compatible + } + } + break; + case 0x14: // 2-byte buffer + if (buf.length >= 3) { + len = buf.readUInt16BE(1); + if (buf.length >= 3 + len) { + v = new Buffer(len); + buf.copy(v, 0, 3, 3 + len); + v = { type: 'buffer', data: v.toString('hex') }; + consume(3 + len); + // Value could be a Node.js buffer directly, but + // we prefer all dvalues to be JSON compatible + } + } + break; + case 0x15: // unused/none + v = { type: 'unused' }; + consume(1); + break; + case 0x16: // undefined + v = { type: 'undefined' }; + gotValue = true; // indicate 'v' is actually set + consume(1); + break; + case 0x17: // null + v = null; + gotValue = true; // indicate 'v' is actually set + consume(1); + break; + case 0x18: // true + v = true; + consume(1); + break; + case 0x19: // false + v = false; + consume(1); + break; + case 0x1a: // number (IEEE double), big endian + if (buf.length >= 9) { + v = new Buffer(8); + buf.copy(v, 0, 1, 9); + v = { type: 'number', data: v.toString('hex') }; + + if (_this.readableNumberValue) { + // The value key should not be used programmatically, + // it is just there to make the dumps more readable. + v.value = buf.readDoubleBE(1); + } + consume(9); + } + break; + case 0x1b: // object + if (buf.length >= 3) { + len = buf[2]; + if (buf.length >= 3 + len) { + v = new Buffer(len); + buf.copy(v, 0, 3, 3 + len); + v = { type: 'object', 'class': buf[1], pointer: v.toString('hex') }; + consume(3 + len); + } + } + break; + case 0x1c: // pointer + if (buf.length >= 2) { + len = buf[1]; + if (buf.length >= 2 + len) { + v = new Buffer(len); + buf.copy(v, 0, 2, 2 + len); + v = { type: 'pointer', pointer: v.toString('hex') }; + consume(2 + len); + } + } + break; + case 0x1d: // lightfunc + if (buf.length >= 4) { + len = buf[3]; + if (buf.length >= 4 + len) { + v = new Buffer(len); + buf.copy(v, 0, 4, 4 + len); + v = { type: 'lightfunc', flags: buf.readUInt16BE(1), pointer: v.toString('hex') }; + consume(4 + len); + } + } + break; + case 0x1e: // heapptr + if (buf.length >= 2) { + len = buf[1]; + if (buf.length >= 2 + len) { + v = new Buffer(len); + buf.copy(v, 0, 2, 2 + len); + v = { type: 'heapptr', pointer: v.toString('hex') }; + consume(2 + len); + } + } + break; + default: + _this.emit('transport-error', 'Parse error, dropping connection'); + _this.close(); + } + } + + if (typeof v === 'undefined' && !gotValue) { + break; + } + msg.push(v); + _this.dvalues++; + + // Could emit a 'debug-value' event here, but that's not necessary + // because the receiver will just collect statistics which can also + // be done using the finished message. + + if (v === DVAL_EOM) { + _this.messages++; + + if (textDumpFileName || textDumpConsolePrefix) { + prettyMsg = prettyDebugMessage(msg); + if (textDumpFileName) { + fs.appendFileSync(textDumpFileName, (textDumpFilePrefix || '') + prettyMsg + '\n'); + } + if (textDumpConsolePrefix) { + console.log(textDumpConsolePrefix + prettyMsg); + } + } + + _this.emit('debug-message', msg); + msg = []; // new object, old may be in circulation for a while + } + } + }); + + // Not all streams will emit this. + inputStream.on('error', function (err) { + _this.emit('transport-error', err); + _this.close(); + }); + + // Not all streams will emit this. + inputStream.on('close', function () { + _this.close(); + }); +} +DebugProtocolParser.prototype = Object.create(events.EventEmitter.prototype); + +DebugProtocolParser.prototype.close = function () { + // Although the underlying transport may not have a close() or destroy() + // method or even a 'close' event, this method is always available and + // will generate a 'transport-close'. + // + // The caller is responsible for closing the underlying stream if that + // is necessary. + + if (this.closed) { return; } + + this.closed = true; + if (this.statsTimer) { + clearInterval(this.statsTimer); + this.statsTimer = null; + } + this.emit('transport-close'); +}; + +/* + * Debugger output formatting + */ + +function formatDebugValue(v) { + var buf, dec, len; + + // See doc/debugger.rst for format description. + + if (typeof v === 'object' && v !== null) { + // Note: typeof null === 'object', so null special case explicitly + if (v.type === 'eom') { + return new Buffer([ 0x00 ]); + } else if (v.type === 'req') { + return new Buffer([ 0x01 ]); + } else if (v.type === 'rep') { + return new Buffer([ 0x02 ]); + } else if (v.type === 'err') { + return new Buffer([ 0x03 ]); + } else if (v.type === 'nfy') { + return new Buffer([ 0x04 ]); + } else if (v.type === 'unused') { + return new Buffer([ 0x15 ]); + } else if (v.type === 'undefined') { + return new Buffer([ 0x16 ]); + } else if (v.type === 'number') { + dec = new Buffer(v.data, 'hex'); + len = dec.length; + if (len !== 8) { + throw new TypeError('value cannot be converted to dvalue: ' + JSON.stringify(v)); + } + buf = new Buffer(1 + len); + buf[0] = 0x1a; + dec.copy(buf, 1); + return buf; + } else if (v.type === 'buffer') { + dec = new Buffer(v.data, 'hex'); + len = dec.length; + if (len <= 0xffff) { + buf = new Buffer(3 + len); + buf[0] = 0x14; + buf[1] = (len >> 8) & 0xff; + buf[2] = (len >> 0) & 0xff; + dec.copy(buf, 3); + return buf; + } else { + buf = new Buffer(5 + len); + buf[0] = 0x13; + buf[1] = (len >> 24) & 0xff; + buf[2] = (len >> 16) & 0xff; + buf[3] = (len >> 8) & 0xff; + buf[4] = (len >> 0) & 0xff; + dec.copy(buf, 5); + return buf; + } + } else if (v.type === 'object') { + dec = new Buffer(v.pointer, 'hex'); + len = dec.length; + buf = new Buffer(3 + len); + buf[0] = 0x1b; + buf[1] = v.class; + buf[2] = len; + dec.copy(buf, 3); + return buf; + } else if (v.type === 'pointer') { + dec = new Buffer(v.pointer, 'hex'); + len = dec.length; + buf = new Buffer(2 + len); + buf[0] = 0x1c; + buf[1] = len; + dec.copy(buf, 2); + return buf; + } else if (v.type === 'lightfunc') { + dec = new Buffer(v.pointer, 'hex'); + len = dec.length; + buf = new Buffer(4 + len); + buf[0] = 0x1d; + buf[1] = (v.flags >> 8) & 0xff; + buf[2] = v.flags & 0xff; + buf[3] = len; + dec.copy(buf, 4); + return buf; + } else if (v.type === 'heapptr') { + dec = new Buffer(v.pointer, 'hex'); + len = dec.length; + buf = new Buffer(2 + len); + buf[0] = 0x1e; + buf[1] = len; + dec.copy(buf, 2); + return buf; + } + } else if (v === null) { + return new Buffer([ 0x17 ]); + } else if (typeof v === 'boolean') { + return new Buffer([ v ? 0x18 : 0x19 ]); + } else if (typeof v === 'number') { + if (Math.floor(v) === v && /* whole */ + (v !== 0 || 1 / v > 0) && /* not negative zero */ + v >= -0x80000000 && v <= 0x7fffffff) { + // Represented signed 32-bit integers as plain integers. + // Debugger code expects this for all fields that are not + // duk_tval representations (e.g. command numbers and such). + if (v >= 0x00 && v <= 0x3f) { + return new Buffer([ 0x80 + v ]); + } else if (v >= 0x0000 && v <= 0x3fff) { + return new Buffer([ 0xc0 + (v >> 8), v & 0xff ]); + } else if (v >= -0x80000000 && v <= 0x7fffffff) { + return new Buffer([ 0x10, + (v >> 24) & 0xff, + (v >> 16) & 0xff, + (v >> 8) & 0xff, + (v >> 0) & 0xff ]); + } else { + throw new Error('internal error when encoding integer to dvalue: ' + v); + } + } else { + // Represent non-integers as IEEE double dvalues + buf = new Buffer(1 + 8); + buf[0] = 0x1a; + buf.writeDoubleBE(v, 1); + return buf; + } + } else if (typeof v === 'string') { + if (v.length < 0 || v.length > 0xffffffff) { + // Not possible in practice. + throw new TypeError('cannot convert to dvalue, invalid string length: ' + v.length); + } + if (v.length <= 0x1f) { + buf = new Buffer(1 + v.length); + buf[0] = 0x60 + v.length; + writeDebugStringToBuffer(v, buf, 1); + return buf; + } else if (v.length <= 0xffff) { + buf = new Buffer(3 + v.length); + buf[0] = 0x12; + buf[1] = (v.length >> 8) & 0xff; + buf[2] = (v.length >> 0) & 0xff; + writeDebugStringToBuffer(v, buf, 3); + return buf; + } else { + buf = new Buffer(5 + v.length); + buf[0] = 0x11; + buf[1] = (v.length >> 24) & 0xff; + buf[2] = (v.length >> 16) & 0xff; + buf[3] = (v.length >> 8) & 0xff; + buf[4] = (v.length >> 0) & 0xff; + writeDebugStringToBuffer(v, buf, 5); + return buf; + } + } + + // Shouldn't come here. + throw new TypeError('value cannot be converted to dvalue: ' + JSON.stringify(v)); +} + +/* + * Debugger implementation + * + * A debugger instance communicates with the debug target and maintains + * persistent debug state so that the current state can be resent to the + * socket.io client (web UI) if it reconnects. Whenever the debugger state + * is changed an event is generated. The socket.io handler will listen to + * state change events and push the necessary updates to the web UI, often + * in a rate limited fashion or using a client pull to ensure the web UI + * is not overloaded. + * + * The debugger instance assumes that if the debug protocol connection is + * re-established, it is always to the same target. There is no separate + * abstraction for a debugger session. + */ + +function Debugger() { + events.EventEmitter.call(this); + + this.web = null; // web UI singleton + this.targetStream = null; // transport connection to target + this.outputPassThroughStream = null; // dummy passthrough for message dumping + this.inputParser = null; // parser for incoming debug messages + this.outputParser = null; // parser for outgoing debug messages (stats, dumping) + this.protocolVersion = null; + this.dukVersion = null; + this.dukGitDescribe = null; + this.targetInfo = null; + this.attached = false; + this.handshook = false; + this.reqQueue = null; + this.stats = { // stats for current debug connection + rxBytes: 0, rxDvalues: 0, rxMessages: 0, rxBytesPerSec: 0, + txBytes: 0, txDvalues: 0, txMessages: 0, txBytesPerSec: 0 + }; + this.execStatus = { + attached: false, + state: 'detached', + fileName: '', + funcName: '', + line: 0, + pc: 0 + }; + this.breakpoints = []; + this.callstack = []; + this.locals = []; + this.messageLines = []; + this.messageScrollBack = 100; +} +Debugger.prototype = events.EventEmitter.prototype; + +Debugger.prototype.decodeBytecodeFromBuffer = function (buf, consts, funcs) { + var i, j, n, m, ins, pc; + var res = []; + var op, str, args, comments; + + // XXX: add constants inline to preformatted output (e.g. for strings, + // add a short escaped snippet as a comment on the line after the + // compact argument list). + + for (i = 0, n = buf.length; i < n; i += 4) { + pc = i / 4; + + // shift forces unsigned + if (this.endianness === 'little') { + ins = buf.readInt32LE(i) >>> 0; + } else { + ins = buf.readInt32BE(i) >>> 0; + } + + op = dukOpcodes.opcodes[ins & 0xff]; + + args = []; + comments = []; + if (op.args) { + for (j = 0, m = op.args.length; j < m; j++) { + var A = (ins >>> 8) & 0xff; + var B = (ins >>> 16) & 0xff; + var C = (ins >>> 24) & 0xff; + var BC = (ins >>> 16) & 0xffff; + var ABC = (ins >>> 8) & 0xffffff; + var Bconst = op & 0x01; + var Cconst = op & 0x02; + + switch (op.args[j]) { + case 'A_R': args.push('r' + A); break; + case 'A_RI': args.push('r' + A + '(indirect)'); break; + case 'A_C': args.push('c' + A); break; + case 'A_H': args.push('0x' + A.toString(16)); break; + case 'A_I': args.push(A.toString(10)); break; + case 'A_B': args.push(A ? 'true' : 'false'); break; + case 'B_RC': args.push((Bconst ? 'c' : 'r') + B); break; + case 'B_R': args.push('r' + B); break; + case 'B_RI': args.push('r' + B + '(indirect)'); break; + case 'B_C': args.push('c' + B); break; + case 'B_H': args.push('0x' + B.toString(16)); break; + case 'B_I': args.push(B.toString(10)); break; + case 'C_RC': args.push((Cconst ? 'c' : 'r') + C); break; + case 'C_R': args.push('r' + C); break; + case 'C_RI': args.push('r' + C + '(indirect)'); break; + case 'C_C': args.push('c' + C); break; + case 'C_H': args.push('0x' + C.toString(16)); break; + case 'C_I': args.push(C.toString(10)); break; + case 'BC_R': args.push('r' + BC); break; + case 'BC_C': args.push('c' + BC); break; + case 'BC_H': args.push('0x' + BC.toString(16)); break; + case 'BC_I': args.push(BC.toString(10)); break; + case 'ABC_H': args.push(ABC.toString(16)); break; + case 'ABC_I': args.push(ABC.toString(10)); break; + case 'BC_LDINT': args.push(BC - (1 << 15)); break; + case 'BC_LDINTX': args.push(BC - 0); break; // no bias in LDINTX + case 'ABC_JUMP': { + var pc_add = ABC - (1 << 23) + 1; // pc is preincremented before adding + var pc_dst = pc + pc_add; + args.push(pc_dst + ' (' + (pc_add >= 0 ? '+' : '') + pc_add + ')'); + break; + } + default: args.push('?'); break; + } + } + } + if (op.flags) { + for (j = 0, m = op.flags.length; j < m; j++) { + if (ins & op.flags[j].mask) { + comments.push(op.flags[j].name); + } + } + } + + if (args.length > 0) { + str = sprintf('%05d %08x %-10s %s', pc, ins, op.name, args.join(', ')); + } else { + str = sprintf('%05d %08x %-10s', pc, ins, op.name); + } + if (comments.length > 0) { + str = sprintf('%-44s ; %s', str, comments.join(', ')); + } + + res.push({ + str: str, + ins: ins + }); + } + + return res; +}; + +Debugger.prototype.uiMessage = function (type, val) { + var msg; + if (typeof type === 'object') { + msg = type; + } else if (typeof type === 'string') { + msg = { type: type, message: val }; + } else { + throw new TypeError('invalid ui message: ' + type); + } + this.messageLines.push(msg); + while (this.messageLines.length > this.messageScrollBack) { + this.messageLines.shift(); + } + this.emit('ui-message-update'); // just trigger a sync, gets rate limited +}; + +Debugger.prototype.sendRequest = function (msg) { + var _this = this; + return new Promise(function (resolve, reject) { + var dvals = []; + var dval; + var data; + var i; + + if (!_this.attached || !_this.handshook || !_this.reqQueue || !_this.targetStream) { + throw new Error('invalid state for sendRequest'); + } + + for (i = 0; i < msg.length; i++) { + try { + dval = formatDebugValue(msg[i]); + } catch (e) { + console.log('Failed to format dvalue, dropping connection: ' + e); + console.log(e.stack || e); + _this.targetStream.destroy(); + throw new Error('failed to format dvalue'); + } + dvals.push(dval); + } + + data = Buffer.concat(dvals); + + _this.targetStream.write(data); + _this.outputPassThroughStream.write(data); // stats and dumping + + if (optLogMessages) { + console.log('Request ' + prettyDebugCommand(msg[1]) + ': ' + prettyDebugMessage(msg)); + } + + if (!_this.reqQueue) { + throw new Error('no reqQueue'); + } + + _this.reqQueue.push({ + reqMsg: msg, + reqCmd: msg[1], + resolveCb: resolve, + rejectCb: reject + }); + }); +}; + +Debugger.prototype.sendBasicInfoRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_BASICINFO, DVAL_EOM ]).then(function (msg) { + _this.dukVersion = msg[1]; + _this.dukGitDescribe = msg[2]; + _this.targetInfo = msg[3]; + _this.endianness = { 1: 'little', 2: 'mixed', 3: 'big' }[msg[4]] || 'unknown'; + _this.emit('basic-info-update'); + return msg; + }); +}; + +Debugger.prototype.sendGetVarRequest = function (varname, level) { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_GETVAR, (typeof level === 'number' ? level : -1), varname, DVAL_EOM ]).then(function (msg) { + return { found: msg[1] === 1, value: msg[2] }; + }); +}; + +Debugger.prototype.sendPutVarRequest = function (varname, varvalue, level) { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_PUTVAR, (typeof level === 'number' ? level : -1), varname, varvalue, DVAL_EOM ]); +}; + +Debugger.prototype.sendInvalidCommandTestRequest = function () { + // Intentional invalid command + var _this = this; + return this.sendRequest([ DVAL_REQ, 0xdeadbeef, DVAL_EOM ]); +}; + +Debugger.prototype.sendStatusRequest = function () { + // Send a status request to trigger a status notify, result is ignored: + // target sends a status notify instead of a meaningful reply + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_TRIGGERSTATUS, DVAL_EOM ]); +}; + +Debugger.prototype.sendBreakpointListRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_LISTBREAK, DVAL_EOM ]).then(function (msg) { + var i, n; + var breakpts = []; + + for (i = 1, n = msg.length - 1; i < n; i += 2) { + breakpts.push({ fileName: msg[i], lineNumber: msg[i + 1] }); + } + + _this.breakpoints = breakpts; + _this.emit('breakpoints-update'); + return msg; + }); +}; + +Debugger.prototype.sendGetLocalsRequest = function (level) { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_GETLOCALS, (typeof level === 'number' ? level : -1), DVAL_EOM ]).then(function (msg) { + var i; + var locals = []; + + for (i = 1; i <= msg.length - 2; i += 2) { + // XXX: do pretty printing in debug client for now + locals.push({ key: msg[i], value: prettyUiDebugValue(msg[i + 1], LOCALS_CLIPLEN) }); + } + + _this.locals = locals; + _this.emit('locals-update'); + return msg; + }); +}; + +Debugger.prototype.sendGetCallStackRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_GETCALLSTACK, DVAL_EOM ]).then(function (msg) { + var i; + var stack = []; + + for (i = 1; i + 3 <= msg.length - 1; i += 4) { + stack.push({ + fileName: msg[i], + funcName: msg[i + 1], + lineNumber: msg[i + 2], + pc: msg[i + 3] + }); + } + + _this.callstack = stack; + _this.emit('callstack-update'); + return msg; + }); +}; + +Debugger.prototype.sendStepIntoRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_STEPINTO, DVAL_EOM ]); +}; + +Debugger.prototype.sendStepOverRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_STEPOVER, DVAL_EOM ]); +}; + +Debugger.prototype.sendStepOutRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_STEPOUT, DVAL_EOM ]); +}; + +Debugger.prototype.sendPauseRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_PAUSE, DVAL_EOM ]); +}; + +Debugger.prototype.sendResumeRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_RESUME, DVAL_EOM ]); +}; + +Debugger.prototype.sendEvalRequest = function (evalInput, level) { + var _this = this; + // Use explicit level if given. If no level is given, use null if the call + // stack is empty, -1 otherwise. This works well when we're paused and the + // callstack information is not liable to change before we do an Eval. + if (typeof level !== 'number') { + level = this.callstack && this.callstack.length > 0 ? -1 : null; + } + return this.sendRequest([ DVAL_REQ, CMD_EVAL, level, evalInput, DVAL_EOM ]).then(function (msg) { + return { error: msg[1] === 1 /*error*/, value: msg[2] }; + }); +}; + +Debugger.prototype.sendDetachRequest = function () { + var _this = this; + return this.sendRequest([ DVAL_REQ, CMD_DETACH, DVAL_EOM ]); +}; + +Debugger.prototype.sendDumpHeapRequest = function () { + var _this = this; + + return this.sendRequest([ DVAL_REQ, CMD_DUMPHEAP, DVAL_EOM ]).then(function (msg) { + var res = {}; + var objs = []; + var i, j, n, m, o, prop; + + res.type = 'heapDump'; + res.heapObjects = objs; + + for (i = 1, n = msg.length - 1; i < n; /*nop*/) { + o = {}; + o.ptr = msg[i++]; + o.type = msg[i++]; + o.flags = msg[i++] >>> 0; /* unsigned */ + o.refc = msg[i++]; + + if (o.type === DUK_HTYPE_STRING) { + o.blen = msg[i++]; + o.clen = msg[i++]; + o.hash = msg[i++] >>> 0; /* unsigned */ + o.data = msg[i++]; + } else if (o.type === DUK_HTYPE_BUFFER) { + o.len = msg[i++]; + o.data = msg[i++]; + } else if (o.type === DUK_HTYPE_OBJECT) { + o['class'] = msg[i++]; + o.proto = msg[i++]; + o.esize = msg[i++]; + o.enext = msg[i++]; + o.asize = msg[i++]; + o.hsize = msg[i++]; + o.props = []; + for (j = 0, m = o.enext; j < m; j++) { + prop = {}; + prop.flags = msg[i++]; + prop.key = msg[i++]; + prop.accessor = (msg[i++] == 1); + if (prop.accessor) { + prop.getter = msg[i++]; + prop.setter = msg[i++]; + } else { + prop.value = msg[i++]; + } + o.props.push(prop); + } + o.array = []; + for (j = 0, m = o.asize; j < m; j++) { + prop = {}; + prop.value = msg[i++]; + o.array.push(prop); + } + } else { + console.log('invalid htype: ' + o.type + ', disconnect'); + _this.disconnectDebugger(); + throw new Error('invalid htype'); + return; + } + + objs.push(o); + } + + return res; + }); +}; + +Debugger.prototype.sendGetBytecodeRequest = function () { + var _this = this; + + return this.sendRequest([ DVAL_REQ, CMD_GETBYTECODE, -1 /* level; could be other than -1 too */, DVAL_EOM ]).then(function (msg) { + var idx = 1; + var nconst; + var nfunc; + var val; + var buf; + var i, n; + var consts = []; + var funcs = []; + var bcode; + var preformatted; + var ret; + var idxPreformattedInstructions; + + //console.log(JSON.stringify(msg)); + + nconst = msg[idx++]; + for (i = 0; i < nconst; i++) { + val = msg[idx++]; + consts.push(val); + } + + nfunc = msg[idx++]; + for (i = 0; i < nfunc; i++) { + val = msg[idx++]; + funcs.push(val); + } + val = msg[idx++]; + + // Right now bytecode is a string containing a direct dump of the + // bytecode in target endianness. Decode here so that the web UI + // doesn't need to. + + buf = new Buffer(val.length); + writeDebugStringToBuffer(val, buf, 0); + bcode = _this.decodeBytecodeFromBuffer(buf, consts, funcs); + + preformatted = []; + consts.forEach(function (v, i) { + preformatted.push('; c' + i + ' ' + JSON.stringify(v)); + }); + preformatted.push(''); + idxPreformattedInstructions = preformatted.length; + bcode.forEach(function (v) { + preformatted.push(v.str); + }); + preformatted = preformatted.join('\n') + '\n'; + + ret = { + constants: consts, + functions: funcs, + bytecode: bcode, + preformatted: preformatted, + idxPreformattedInstructions: idxPreformattedInstructions + }; + + return ret; + }); +}; + +Debugger.prototype.changeBreakpoint = function (fileName, lineNumber, mode) { + var _this = this; + + return this.sendRequest([ DVAL_REQ, CMD_LISTBREAK, DVAL_EOM ]).then(function (msg) { + var i, n; + var breakpts = []; + var deleted = false; + + // Up-to-date list of breakpoints on target + for (i = 1, n = msg.length - 1; i < n; i += 2) { + breakpts.push({ fileName: msg[i], lineNumber: msg[i + 1] }); + } + + // Delete matching breakpoints in reverse order so that indices + // remain valid. We do this for all operations so that duplicates + // are eliminated if present. + for (i = breakpts.length - 1; i >= 0; i--) { + var bp = breakpts[i]; + if (mode === 'deleteall' || (bp.fileName === fileName && bp.lineNumber === lineNumber)) { + deleted = true; + _this.sendRequest([ DVAL_REQ, CMD_DELBREAK, i, DVAL_EOM ], function (msg) { + // nop + }, function (err) { + // nop + }); + } + } + + // Technically we should wait for each delbreak reply but because + // target processes the requests in order, it doesn't matter. + if ((mode === 'add') || (mode === 'toggle' && !deleted)) { + _this.sendRequest([ DVAL_REQ, CMD_ADDBREAK, fileName, lineNumber, DVAL_EOM ], function (msg) { + // nop + }, function (err) { + _this.uiMessage('debugger-info', 'Failed to add breakpoint: ' + err); + }); + } + + // Read final, effective breakpoints from the target + _this.sendBreakpointListRequest(); + }); +}; + +Debugger.prototype.disconnectDebugger = function () { + if (this.targetStream) { + // We require a destroy() method from the actual target stream + this.targetStream.destroy(); + this.targetStream = null; + } + if (this.inputParser) { + this.inputParser.close(); + this.inputParser = null; + } + if (this.outputPassThroughStream) { + // There is no close() or destroy() for a passthrough stream, so just + // close the outputParser which will cancel timers etc. + } + if (this.outputParser) { + this.outputParser.close(); + this.outputParser = null; + } + + this.attached = false; + this.handshook = false; + this.reqQueue = null; + this.execStatus = { + attached: false, + state: 'detached', + fileName: '', + funcName: '', + line: 0, + pc: 0 + }; +}; + +Debugger.prototype.connectDebugger = function () { + var _this = this; + + this.disconnectDebugger(); // close previous target connection + + // CUSTOMTRANSPORT: to use a custom transport, change this.targetStream to + // use your custom transport. + + console.log('Connecting to ' + optTargetHost + ':' + optTargetPort + '...'); + this.targetStream = new net.Socket(); + this.targetStream.connect(optTargetPort, optTargetHost, function () { + console.log('Debug transport connected'); + _this.attached = true; + _this.reqQueue = []; + _this.uiMessage('debugger-info', 'Debug transport connected'); + }); + + this.inputParser = new DebugProtocolParser( + this.targetStream, + null, + optDumpDebugRead, + optDumpDebugPretty, + optDumpDebugPretty ? 'Recv: ' : null, + null, + null // console logging is done at a higher level to match request/response + ); + + // Use a PassThrough stream to debug dump and get stats for output messages. + // Simply write outgoing data to both the targetStream and this passthrough + // separately. + this.outputPassThroughStream = stream.PassThrough(); + this.outputParser = new DebugProtocolParser( + this.outputPassThroughStream, + 1, + optDumpDebugWrite, + optDumpDebugPretty, + optDumpDebugPretty ? 'Send: ' : null, + null, + null // console logging is done at a higher level to match request/response + ); + + this.inputParser.on('transport-close', function () { + _this.uiMessage('debugger-info', 'Debug transport closed'); + _this.disconnectDebugger(); + _this.emit('exec-status-update'); + _this.emit('detached'); + }); + + this.inputParser.on('transport-error', function (err) { + _this.uiMessage('debugger-info', 'Debug transport error: ' + err); + _this.disconnectDebugger(); + }); + + this.inputParser.on('protocol-version', function (msg) { + var ver = msg.protocolVersion; + console.log('Debug version identification:', msg.versionIdentification); + _this.protocolVersion = ver; + _this.uiMessage('debugger-info', 'Debug version identification: ' + msg.versionIdentification); + if (ver !== SUPPORTED_DEBUG_PROTOCOL_VERSION) { + console.log('Unsupported debug protocol version (got ' + ver + ', support ' + SUPPORTED_DEBUG_PROTOCOL_VERSION + ')'); + _this.uiMessage('debugger-info', 'Protocol version ' + ver + ' unsupported, dropping connection'); + _this.targetStream.destroy(); + } else { + _this.uiMessage('debugger-info', 'Debug protocol version: ' + ver); + _this.handshook = true; + _this.execStatus = { + attached: true, + state: 'attached', + fileName: '', + funcName: '', + line: 0, + pc: 0 + }; + _this.emit('exec-status-update'); + _this.emit('attached'); // inform web UI + + // Fetch basic info right away + _this.sendBasicInfoRequest(); + } + }); + + this.inputParser.on('debug-message', function (msg) { + _this.processDebugMessage(msg); + }); + + this.inputParser.on('stats-update', function () { + _this.stats.rxBytes = this.bytes; + _this.stats.rxDvalues = this.dvalues; + _this.stats.rxMessages = this.messages; + _this.stats.rxBytesPerSec = this.bytesPerSec; + _this.emit('debug-stats-update'); + }); + + this.outputParser.on('stats-update', function () { + _this.stats.txBytes = this.bytes; + _this.stats.txDvalues = this.dvalues; + _this.stats.txMessages = this.messages; + _this.stats.txBytesPerSec = this.bytesPerSec; + _this.emit('debug-stats-update'); + }); +}; + +Debugger.prototype.processDebugMessage = function (msg) { + var req; + var prevState, newState; + var err; + + if (msg[0] === DVAL_REQ) { + // No actual requests sent by the target right now (just notifys). + console.log('Unsolicited reply message, dropping connection: ' + prettyDebugMessage(msg)); + } else if (msg[0] === DVAL_REP) { + if (this.reqQueue.length <= 0) { + console.log('Unsolicited reply message, dropping connection: ' + prettyDebugMessage(msg)); + this.targetStream.destroy(); + } + req = this.reqQueue.shift(); + + if (optLogMessages) { + console.log('Reply for ' + prettyDebugCommand(req.reqCmd) + ': ' + prettyDebugMessage(msg)); + } + + if (req.resolveCb) { + req.resolveCb(msg); + } else { + // nop: no callback + } + } else if (msg[0] === DVAL_ERR) { + if (this.reqQueue.length <= 0) { + console.log('Unsolicited error message, dropping connection: ' + prettyDebugMessage(msg)); + this.targetStream.destroy(); + } + err = new Error(String(msg[2]) + ' (code ' + String(msg[1]) + ')'); + err.errorCode = msg[1] || 0; + req = this.reqQueue.shift(); + + if (optLogMessages) { + console.log('Error for ' + prettyDebugCommand(req.reqCmd) + ': ' + prettyDebugMessage(msg)); + } + + if (req.rejectCb) { + req.rejectCb(err); + } else { + // nop: no callback + } + } else if (msg[0] === DVAL_NFY) { + if (optLogMessages) { + console.log('Notify ' + prettyDebugCommand(msg[1]) + ': ' + prettyDebugMessage(msg)); + } + + if (msg[1] === CMD_STATUS) { + prevState = this.execStatus.state; + newState = msg[2] === 0 ? 'running' : 'paused'; + this.execStatus = { + attached: true, + state: newState, + fileName: msg[3], + funcName: msg[4], + line: msg[5], + pc: msg[6] + }; + + if (prevState !== newState && newState === 'paused') { + // update run state now that we're paused + this.sendBreakpointListRequest(); + this.sendGetLocalsRequest(); + this.sendGetCallStackRequest(); + } + + this.emit('exec-status-update'); + } else if (msg[1] === CMD_THROW) { + this.uiMessage({ type: 'throw', fatal: msg[2], message: (msg[2] ? 'UNCAUGHT: ' : 'THROW: ') + prettyUiStringUnquoted(msg[3], UI_MESSAGE_CLIPLEN), fileName: msg[4], lineNumber: msg[5] }); + } else if (msg[1] === CMD_DETACHING) { + this.uiMessage({ type: 'detaching', reason: msg[2], message: 'DETACH: ' + (msg.length >= 5 ? prettyUiStringUnquoted(msg[3]) : 'detaching') }); + } else { + // Ignore unknown notify messages + console.log('Unknown notify, ignoring: ' + prettyDebugMessage(msg)); + + //this.targetStream.destroy(); + } + } else { + console.log('Invalid initial dvalue, dropping connection: ' + prettyDebugMessage(msg)); + this.targetStream.destroy(); + } +}; + +Debugger.prototype.run = function () { + var _this = this; + + // Initial debugger connection + + this.connectDebugger(); + + // Poll various state items when running + + var sendRound = 0; + var statusPending = false; + var bplistPending = false; + var localsPending = false; + var callStackPending = false; + + setInterval(function () { + if (_this.execStatus.state !== 'running') { + return; + } + + // Could also check for an empty request queue, but that's probably + // too strict? + + // Pending flags are used to avoid requesting the same thing twice + // while a previous request is pending. The flag-based approach is + // quite awkward. Rework to use promises. + + switch (sendRound) { + case 0: + if (!statusPending) { + statusPending = true; + _this.sendStatusRequest().finally(function () { statusPending = false; }); + } + break; + case 1: + if (!bplistPending) { + bplistPending = true; + _this.sendBreakpointListRequest().finally(function () { bplistPending = false; }); + } + break; + case 2: + if (!localsPending) { + localsPending = true; + _this.sendGetLocalsRequest().finally(function () { localsPending = false; }); + } + break; + case 3: + if (!callStackPending) { + callStackPending = true; + _this.sendGetCallStackRequest().finally(function () { callStackPending = false; }); + } + break; + } + sendRound = (sendRound + 1) % 4; + }, 500); +}; + +/* + * Express setup and socket.io + */ + +function DebugWebServer() { + this.dbg = null; // debugger singleton + this.socket = null; // current socket (or null) + this.keepaliveTimer = null; + this.uiMessageLimiter = null; + this.cachedJson = {}; // cache to avoid resending identical data + this.sourceFileManager = new SourceFileManager(optSourceSearchDirs); + this.sourceFileManager.scan(); +} + +DebugWebServer.prototype.handleSourcePost = function (req, res) { + var fileName = req.body && req.body.fileName; + var fileData; + + console.log('Source request: ' + fileName); + + if (typeof fileName !== 'string') { + res.status(500).send('invalid request'); + return; + } + fileData = this.sourceFileManager.search(fileName, optSourceSearchDirs); + if (typeof fileData !== 'string') { + res.status(404).send('not found'); + return; + } + res.status(200).send(fileData); // UTF-8 +}; + +DebugWebServer.prototype.handleSourceListPost = function (req, res) { + console.log('Source list request'); + + var files = this.sourceFileManager.getFiles(); + res.header('Content-Type', 'application/json'); + res.status(200).json(files); +}; + +DebugWebServer.prototype.handleHeapDumpGet = function (req, res) { + console.log('Heap dump get'); + + this.dbg.sendDumpHeapRequest().then(function (val) { + res.header('Content-Type', 'application/json'); + //res.status(200).json(val); + res.status(200).send(JSON.stringify(val, null, 4)); + }).catch(function (err) { + res.status(500).send('Failed to get heap dump: ' + (err.stack || err)); + }); +}; + +DebugWebServer.prototype.run = function () { + var _this = this; + + var express = require('express'); + var bodyParser = require('body-parser'); + var app = express(); + var http = require('http').Server(app); + var io = require('socket.io')(http); + + app.use(bodyParser.json()); + app.post('/source', this.handleSourcePost.bind(this)); + app.post('/sourceList', this.handleSourceListPost.bind(this)); + app.get('/heapDump.json', this.handleHeapDumpGet.bind(this)); + app.use('/', express.static(__dirname + '/static')); + + http.listen(optHttpPort, function () { + console.log('Listening on *:' + optHttpPort); + }); + + io.on('connection', this.handleNewSocketIoConnection.bind(this)); + + this.dbg.on('attached', function () { + console.log('Debugger attached'); + }); + + this.dbg.on('detached', function () { + console.log('Debugger detached'); + }); + + this.dbg.on('debug-stats-update', function () { + _this.debugStatsLimiter.trigger(); + }); + + this.dbg.on('ui-message-update', function () { + // Explicit rate limiter because this is a source of a lot of traffic. + _this.uiMessageLimiter.trigger(); + }); + + this.dbg.on('basic-info-update', function () { + _this.emitBasicInfo(); + }); + + this.dbg.on('breakpoints-update', function () { + _this.emitBreakpoints(); + }); + + this.dbg.on('exec-status-update', function () { + // Explicit rate limiter because this is a source of a lot of traffic. + _this.execStatusLimiter.trigger(); + }); + + this.dbg.on('locals-update', function () { + _this.emitLocals(); + }); + + this.dbg.on('callstack-update', function () { + _this.emitCallStack(); + }); + + this.uiMessageLimiter = new RateLimited(10, 1000, this.uiMessageLimiterCallback.bind(this)); + this.execStatusLimiter = new RateLimited(50, 500, this.execStatusLimiterCallback.bind(this)); + this.debugStatsLimiter = new RateLimited(1, 2000, this.debugStatsLimiterCallback.bind(this)); + + this.keepaliveTimer = setInterval(this.emitKeepalive.bind(this), 30000); +}; + +DebugWebServer.prototype.handleNewSocketIoConnection = function (socket) { + var _this = this; + + console.log('Socket.io connected'); + if (this.socket) { + console.log('Closing previous socket.io socket'); + this.socket.emit('replaced'); + } + this.socket = socket; + + this.emitKeepalive(); + + socket.on('disconnect', function () { + console.log('Socket.io disconnected'); + if (_this.socket === socket) { + _this.socket = null; + } + }); + + socket.on('keepalive', function (msg) { + // nop + }); + + socket.on('attach', function (msg) { + if (_this.dbg.targetStream) { + console.log('Attach request when debugger already has a connection, ignoring'); + } else { + _this.dbg.connectDebugger(); + } + }); + + socket.on('detach', function (msg) { + // Try to detach cleanly, timeout if no response + Promise.any([ + _this.dbg.sendDetachRequest(), + Promise.delay(3000) + ]).finally(function () { + _this.dbg.disconnectDebugger(); + }); + }); + + socket.on('stepinto', function (msg) { + _this.dbg.sendStepIntoRequest(); + }); + + socket.on('stepover', function (msg) { + _this.dbg.sendStepOverRequest(); + }); + + socket.on('stepout', function (msg) { + _this.dbg.sendStepOutRequest(); + }); + + socket.on('pause', function (msg) { + _this.dbg.sendPauseRequest(); + }); + + socket.on('resume', function (msg) { + _this.dbg.sendResumeRequest(); + }); + + socket.on('eval', function (msg) { + // msg.input is a proper Unicode strings here, and needs to be + // converted into a protocol string (U+0000...U+00FF). + var input = stringToDebugString(msg.input); + _this.dbg.sendEvalRequest(input, msg.level).then(function (v) { + socket.emit('eval-result', { error: v.error, result: prettyUiDebugValue(v.value, EVAL_CLIPLEN) }); + }); + + // An eval call quite possibly changes the local variables so always + // re-read locals afterwards. We don't need to wait for Eval to + // complete here; the requests will pipeline automatically and be + // executed in order. + + // XXX: move this to the web UI so that the UI can control what + // locals are listed (or perhaps show locals for all levels with + // an expandable tree view). + _this.dbg.sendGetLocalsRequest(); + }); + + socket.on('getvar', function (msg) { + // msg.varname is a proper Unicode strings here, and needs to be + // converted into a protocol string (U+0000...U+00FF). + var varname = stringToDebugString(msg.varname); + _this.dbg.sendGetVarRequest(varname, msg.level) + .then(function (v) { + socket.emit('getvar-result', { found: v.found, result: prettyUiDebugValue(v.value, GETVAR_CLIPLEN) }); + }); + }); + + socket.on('putvar', function (msg) { + // msg.varname and msg.varvalue are proper Unicode strings here, they + // need to be converted into protocol strings (U+0000...U+00FF). + var varname = stringToDebugString(msg.varname); + var varvalue = msg.varvalue; + + // varvalue is JSON parsed by the web UI for now, need special string + // encoding here. + if (typeof varvalue === 'string') { + varvalue = stringToDebugString(msg.varvalue); + } + + _this.dbg.sendPutVarRequest(varname, varvalue, msg.level) + .then(function (v) { + console.log('putvar done'); // XXX: signal success to UI? + }); + + // A PutVar call quite possibly changes the local variables so always + // re-read locals afterwards. We don't need to wait for PutVar to + // complete here; the requests will pipeline automatically and be + // executed in order. + + // XXX: make the client do this? + _this.dbg.sendGetLocalsRequest(); + }); + + socket.on('add-breakpoint', function (msg) { + _this.dbg.changeBreakpoint(msg.fileName, msg.lineNumber, 'add'); + }); + + socket.on('delete-breakpoint', function (msg) { + _this.dbg.changeBreakpoint(msg.fileName, msg.lineNumber, 'delete'); + }); + + socket.on('toggle-breakpoint', function (msg) { + _this.dbg.changeBreakpoint(msg.fileName, msg.lineNumber, 'toggle'); + }); + + socket.on('delete-all-breakpoints', function (msg) { + _this.dbg.changeBreakpoint(null, null, 'deleteall'); + }); + + socket.on('get-bytecode', function (msg) { + _this.dbg.sendGetBytecodeRequest().then(function (res) { + socket.emit('bytecode', res); + }); + }); + + // Resend all debugger state for new client + this.cachedJson = {}; // clear client state cache + this.emitBasicInfo(); + this.emitStats(); + this.emitExecStatus(); + this.emitUiMessages(); + this.emitBreakpoints(); + this.emitCallStack(); + this.emitLocals(); +}; + +// Check if 'msg' would encode to the same JSON which was previously sent +// to the web client. The caller then avoid resending unnecessary stuff. +DebugWebServer.prototype.cachedJsonCheck = function (cacheKey, msg) { + var newJson = JSON.stringify(msg); + if (this.cachedJson[cacheKey] === newJson) { + return true; // cached + } + this.cachedJson[cacheKey] = newJson; + return false; // not cached, send (cache already updated) +}; + +DebugWebServer.prototype.uiMessageLimiterCallback = function () { + this.emitUiMessages(); +}; + +DebugWebServer.prototype.execStatusLimiterCallback = function () { + this.emitExecStatus(); +}; + +DebugWebServer.prototype.debugStatsLimiterCallback = function () { + this.emitStats(); +}; + +DebugWebServer.prototype.emitKeepalive = function () { + if (!this.socket) { return; } + + this.socket.emit('keepalive', { nodeVersion: process.version }); +}; + +DebugWebServer.prototype.emitBasicInfo = function () { + if (!this.socket) { return; } + + var newMsg = { + duk_version: this.dbg.dukVersion, + duk_git_describe: this.dbg.dukGitDescribe, + target_info: this.dbg.targetInfo, + endianness: this.dbg.endianness + }; + if (this.cachedJsonCheck('basic-info', newMsg)) { + return; + } + this.socket.emit('basic-info', newMsg); +}; + +DebugWebServer.prototype.emitStats = function () { + if (!this.socket) { return; } + + this.socket.emit('debug-stats', this.dbg.stats); +}; + +DebugWebServer.prototype.emitExecStatus = function () { + if (!this.socket) { return; } + + var newMsg = this.dbg.execStatus; + if (this.cachedJsonCheck('exec-status', newMsg)) { + return; + } + this.socket.emit('exec-status', newMsg); +}; + +DebugWebServer.prototype.emitUiMessages = function () { + if (!this.socket) { return; } + + var newMsg = this.dbg.messageLines; + if (this.cachedJsonCheck('output-lines', newMsg)) { + return; + } + this.socket.emit('output-lines', newMsg); +}; + +DebugWebServer.prototype.emitBreakpoints = function () { + if (!this.socket) { return; } + + var newMsg = { breakpoints: this.dbg.breakpoints }; + if (this.cachedJsonCheck('breakpoints', newMsg)) { + return; + } + this.socket.emit('breakpoints', newMsg); +}; + +DebugWebServer.prototype.emitCallStack = function () { + if (!this.socket) { return; } + + var newMsg = { callstack: this.dbg.callstack }; + if (this.cachedJsonCheck('callstack', newMsg)) { + return; + } + this.socket.emit('callstack', newMsg); +}; + +DebugWebServer.prototype.emitLocals = function () { + if (!this.socket) { return; } + + var newMsg = { locals: this.dbg.locals }; + if (this.cachedJsonCheck('locals', newMsg)) { + return; + } + this.socket.emit('locals', newMsg); +}; + +/* + * JSON debug proxy + */ + +function DebugProxy(serverPort) { + this.serverPort = serverPort; + this.server = null; + this.socket = null; + this.targetStream = null; + this.inputParser = null; + + // preformatted dvalues + this.dval_eom = formatDebugValue(DVAL_EOM); + this.dval_req = formatDebugValue(DVAL_REQ); + this.dval_rep = formatDebugValue(DVAL_REP); + this.dval_nfy = formatDebugValue(DVAL_NFY); + this.dval_err = formatDebugValue(DVAL_ERR); +} + +DebugProxy.prototype.determineCommandNumber = function (cmdName, cmdNumber) { + var ret; + if (typeof cmdName === 'string') { + ret = debugCommandNumbers[cmdName]; + } else if (typeof cmdName === 'number') { + ret = cmdName; + } + ret = ret || cmdNumber; + if (typeof ret !== 'number') { + throw Error('cannot figure out command number for "' + cmdName + '" (' + cmdNumber + ')'); + } + return ret; +}; + +DebugProxy.prototype.commandNumberToString = function (id) { + return debugCommandNames[id] || String(id); +}; + +DebugProxy.prototype.formatDvalues = function (args) { + if (!args) { + return []; + } + return args.map(function (v) { + return formatDebugValue(v); + }); +}; + +DebugProxy.prototype.writeJson = function (val) { + this.socket.write(JSON.stringify(val) + '\n'); +}; + +DebugProxy.prototype.writeJsonSafe = function (val) { + try { + this.writeJson(val); + } catch (e) { + console.log('Failed to write JSON in writeJsonSafe, ignoring: ' + e); + } +}; + +DebugProxy.prototype.disconnectJsonClient = function () { + if (this.socket) { + this.socket.destroy(); + this.socket = null; + } +}; + +DebugProxy.prototype.disconnectTarget = function () { + if (this.inputParser) { + this.inputParser.close(); + this.inputParser = null; + } + if (this.targetStream) { + this.targetStream.destroy(); + this.targetStream = null; + } +}; + +DebugProxy.prototype.run = function () { + var _this = this; + + console.log('Waiting for client connections on port ' + this.serverPort); + this.server = net.createServer(function (socket) { + console.log('JSON proxy client connected'); + + _this.disconnectJsonClient(); + _this.disconnectTarget(); + + // A byline-parser is simple and good enough for now (assume + // compact JSON with no newlines). + var socketByline = byline(socket); + _this.socket = socket; + + socketByline.on('data', function (line) { + try { + // console.log('Received json proxy input line: ' + line.toString('utf8')); + var msg = JSON.parse(line.toString('utf8')); + var first_dval; + var args_dvalues = _this.formatDvalues(msg.args); + var last_dval = _this.dval_eom; + var cmd; + + if (msg.request) { + // "request" can be a string or "true" + first_dval = _this.dval_req; + cmd = _this.determineCommandNumber(msg.request, msg.command); + } else if (msg.reply) { + first_dval = _this.dval_rep; + } else if (msg.notify) { + // "notify" can be a string or "true" + first_dval = _this.dval_nfy; + cmd = _this.determineCommandNumber(msg.notify, msg.command); + } else if (msg.error) { + first_dval = _this.dval_err; + } else { + throw new Error('Invalid input JSON message: ' + JSON.stringify(msg)); + } + + _this.targetStream.write(first_dval); + if (cmd) { + _this.targetStream.write(formatDebugValue(cmd)); + } + args_dvalues.forEach(function (v) { + _this.targetStream.write(v); + }); + _this.targetStream.write(last_dval); + } catch (e) { + console.log(e); + + _this.writeJsonSafe({ + notify: '_Error', + args: [ 'Failed to handle input json message: ' + e ] + }); + + _this.disconnectJsonClient(); + _this.disconnectTarget(); + } + }); + + _this.connectToTarget(); + }).listen(this.serverPort); +}; + +DebugProxy.prototype.connectToTarget = function () { + var _this = this; + + console.log('Connecting to ' + optTargetHost + ':' + optTargetPort + '...'); + this.targetStream = new net.Socket(); + this.targetStream.connect(optTargetPort, optTargetHost, function () { + console.log('Debug transport connected'); + }); + + this.inputParser = new DebugProtocolParser( + this.targetStream, + null, + optDumpDebugRead, + optDumpDebugPretty, + optDumpDebugPretty ? 'Recv: ' : null, + null, + null // console logging is done at a higher level to match request/response + ); + + // Don't add a 'value' key to numbers. + this.inputParser.readableNumberValue = false; + + this.inputParser.on('transport-close', function () { + console.log('Debug transport closed'); + + _this.writeJsonSafe({ + notify: '_Disconnecting' + }); + + _this.disconnectJsonClient(); + _this.disconnectTarget(); + }); + + this.inputParser.on('transport-error', function (err) { + console.log('Debug transport error', err); + + _this.writeJsonSafe({ + notify: '_Error', + args: [ String(err) ] + }); + }); + + this.inputParser.on('protocol-version', function (msg) { + var ver = msg.protocolVersion; + console.log('Debug version identification:', msg.versionIdentification); + + _this.writeJson({ + notify: '_TargetConnected', + args: [ msg.versionIdentification ] // raw identification string + }); + + if (ver !== 1) { + console.log('Protocol version ' + ver + ' unsupported, dropping connection'); + } + }); + + this.inputParser.on('debug-message', function (msg) { + var t; + + //console.log(msg); + + if (typeof msg[0] !== 'object' || msg[0] === null) { + throw new Error('unexpected initial dvalue: ' + msg[0]); + } else if (msg[0].type === 'eom') { + throw new Error('unexpected initial dvalue: ' + msg[0]); + } else if (msg[0].type === 'req') { + if (typeof msg[1] !== 'number') { + throw new Error('unexpected request command number: ' + msg[1]); + } + t = { + request: _this.commandNumberToString(msg[1]), + command: msg[1], + args: msg.slice(2, msg.length - 1) + }; + _this.writeJson(t); + } else if (msg[0].type === 'rep') { + t = { + reply: true, + args: msg.slice(1, msg.length - 1) + }; + _this.writeJson(t); + } else if (msg[0].type === 'err') { + t = { + error: true, + args: msg.slice(1, msg.length - 1) + }; + _this.writeJson(t); + } else if (msg[0].type === 'nfy') { + if (typeof msg[1] !== 'number') { + throw new Error('unexpected notify command number: ' + msg[1]); + } + t = { + notify: _this.commandNumberToString(msg[1]), + command: msg[1], + args: msg.slice(2, msg.length - 1) + }; + _this.writeJson(t); + } else { + throw new Error('unexpected initial dvalue: ' + msg[0]); + } + }); + + this.inputParser.on('stats-update', function () { + }); +}; + +/* + * Command line parsing and initialization + */ + +function main() { + console.log('((o) Duktape debugger'); + + // Parse arguments. + + var argv = require('minimist')(process.argv.slice(2)); + //console.dir(argv); + if (argv['target-host']) { + optTargetHost = argv['target-host']; + } + if (argv['target-port']) { + optTargetPort = argv['target-port']; + } + if (argv['http-port']) { + optHttpPort = argv['http-port']; + } + if (argv['json-proxy-port']) { + optJsonProxyPort = argv['json-proxy-port']; + } + if (argv['json-proxy']) { + optJsonProxy = argv['json-proxy']; + } + if (argv['source-dirs']) { + optSourceSearchDirs = argv['source-dirs'].split(path.delimiter); + } + if (argv['dump-debug-read']) { + optDumpDebugRead = argv['dump-debug-read']; + } + if (argv['dump-debug-write']) { + optDumpDebugWrite = argv['dump-debug-write']; + } + if (argv['dump-debug-pretty']) { + optDumpDebugPretty = argv['dump-debug-pretty']; + } + if (argv['log-messages']) { + optLogMessages = true; + } + + // Dump effective options. Also provides a list of option names. + + console.log(''); + console.log('Effective options:'); + console.log(' --target-host: ' + optTargetHost); + console.log(' --target-port: ' + optTargetPort); + console.log(' --http-port: ' + optHttpPort); + console.log(' --json-proxy-port: ' + optJsonProxyPort); + console.log(' --json-proxy: ' + optJsonProxy); + console.log(' --source-dirs: ' + optSourceSearchDirs.join(' ')); + console.log(' --dump-debug-read: ' + optDumpDebugRead); + console.log(' --dump-debug-write: ' + optDumpDebugWrite); + console.log(' --dump-debug-pretty: ' + optDumpDebugPretty); + console.log(' --log-messages: ' + optLogMessages); + console.log(''); + + // Create debugger and web UI singletons, tie them together and + // start them. + + if (optJsonProxy) { + console.log('Starting in JSON proxy mode, JSON port: ' + optJsonProxyPort); + + var prx = new DebugProxy(optJsonProxyPort); + prx.run(); + } else { + var dbg = new Debugger(); + var web = new DebugWebServer(); + dbg.web = web; + web.dbg = dbg; + dbg.run(); + web.run(); + } +} + +main(); diff --git a/lib/duktape-2.2.1/debugger/duk_debug_meta.json b/lib/duktape-2.2.1/debugger/duk_debug_meta.json new file mode 100644 index 0000000..146041b --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_debug_meta.json @@ -0,0 +1,1901 @@ +{ + "error_codes": [ + "Unknown", + "UnsupportedCommand", + "TooMany", + "NotFound", + "ApplicationError" + ], + "opcodes": [ + { + "args": [ + "A_R", + "BC_R" + ], + "name": "LDREG" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "STREG" + }, + { + "args": [ + "ABC_JUMP" + ], + "name": "JUMP" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "LDCONST" + }, + { + "args": [ + "A_R", + "BC_LDINT" + ], + "name": "LDINT" + }, + { + "args": [ + "A_R", + "BC_LDINTX" + ], + "name": "LDINTX" + }, + { + "args": [ + "BC_R" + ], + "name": "LDTHIS" + }, + { + "args": [ + "BC_R" + ], + "name": "LDUNDEF" + }, + { + "args": [ + "BC_R" + ], + "name": "LDNULL" + }, + { + "args": [ + "BC_R" + ], + "name": "LDTRUE" + }, + { + "args": [ + "BC_R" + ], + "name": "LDFALSE" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "GETVAR" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "BNOT" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "LNOT" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "UNM" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "UNP" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "EQ_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "EQ_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "EQ_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "EQ_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "NEQ_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "NEQ_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "NEQ_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "NEQ_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "SEQ_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "SEQ_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "SEQ_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "SEQ_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "SNEQ_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "SNEQ_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "SNEQ_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "SNEQ_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "GT_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "GT_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "GT_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "GT_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "GE_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "GE_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "GE_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "GE_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "LT_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "LT_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "LT_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "LT_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "LE_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "LE_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "LE_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "LE_CC" + }, + { + "args": [ + "BC_R" + ], + "name": "IFTRUE_R" + }, + { + "args": [ + "BC_C" + ], + "name": "IFTRUE_C" + }, + { + "args": [ + "BC_R" + ], + "name": "IFFALSE_R" + }, + { + "args": [ + "BC_C" + ], + "name": "IFFALSE_C" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "ADD_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "ADD_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "ADD_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "ADD_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "SUB_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "SUB_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "SUB_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "SUB_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "MUL_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "MUL_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "MUL_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "MUL_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "DIV_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "DIV_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "DIV_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "DIV_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "MOD_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "MOD_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "MOD_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "MOD_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "EXP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "EXP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "EXP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "EXP_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "BAND_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "BAND_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "BAND_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "BAND_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "BOR_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "BOR_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "BOR_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "BOR_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "BXOR_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "BXOR_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "BXOR_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "BXOR_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "BASL_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "BASL_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "BASL_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "BASL_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "BLSR_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "BLSR_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "BLSR_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "BLSR_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "BASR_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "BASR_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "BASR_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "BASR_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "INSTOF_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "INSTOF_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "INSTOF_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "INSTOF_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "IN_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "IN_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "IN_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "IN_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "GETPROP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "GETPROP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "GETPROP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "GETPROP_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "PUTPROP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "PUTPROP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "PUTPROP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "PUTPROP_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "DELPROP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "DELPROP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "DELPROP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "DELPROP_CC" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "PREINCR" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "PREDECR" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "POSTINCR" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "POSTDECR" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "PREINCV" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "PREDECV" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "POSTINCV" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "POSTDECV" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "PREINCP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "PREINCP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "PREINCP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "PREINCP_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "PREDECP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "PREDECP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "PREDECP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "PREDECP_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "POSTINCP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "POSTINCP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "POSTINCP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "POSTINCP_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "POSTDECP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "POSTDECP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "POSTDECP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "POSTDECP_CC" + }, + { + "args": [ + "A_H", + "B_R", + "C_R" + ], + "flags": [ + { + "mask": 256, + "name": "writable" + }, + { + "mask": 512, + "name": "enumerable" + }, + { + "mask": 1024, + "name": "configurable" + }, + { + "mask": 2048, + "name": "accessor" + }, + { + "mask": 4096, + "name": "func_decl" + } + ], + "name": "DECLVAR_RR" + }, + { + "args": [ + "A_H", + "B_C", + "C_R" + ], + "flags": [ + { + "mask": 256, + "name": "writable" + }, + { + "mask": 512, + "name": "enumerable" + }, + { + "mask": 1024, + "name": "configurable" + }, + { + "mask": 2048, + "name": "accessor" + }, + { + "mask": 4096, + "name": "func_decl" + } + ], + "name": "DECLVAR_CR" + }, + { + "args": [ + "A_H", + "B_R", + "C_C" + ], + "flags": [ + { + "mask": 256, + "name": "writable" + }, + { + "mask": 512, + "name": "enumerable" + }, + { + "mask": 1024, + "name": "configurable" + }, + { + "mask": 2048, + "name": "accessor" + }, + { + "mask": 4096, + "name": "func_decl" + } + ], + "name": "DECLVAR_RC" + }, + { + "args": [ + "A_H", + "B_C", + "C_C" + ], + "flags": [ + { + "mask": 256, + "name": "writable" + }, + { + "mask": 512, + "name": "enumerable" + }, + { + "mask": 1024, + "name": "configurable" + }, + { + "mask": 2048, + "name": "accessor" + }, + { + "mask": 4096, + "name": "func_decl" + } + ], + "name": "DECLVAR_CC" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "REGEXP_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "REGEXP_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "REGEXP_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "REGEXP_CC" + }, + { + "args": [ + "A_R", + "BC_I" + ], + "name": "CLOSURE" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "TYPEOF" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "TYPEOFID" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "PUTVAR" + }, + { + "args": [ + "A_R", + "BC_C" + ], + "name": "DELVAR" + }, + { + "args": [ + "BC_R" + ], + "name": "RETREG" + }, + { + "name": "RETUNDEF" + }, + { + "args": [ + "BC_C" + ], + "name": "RETCONST" + }, + { + "args": [ + "BC_C" + ], + "name": "RETCONSTN" + }, + { + "args": [ + "BC_I" + ], + "name": "LABEL" + }, + { + "args": [ + "BC_I" + ], + "name": "ENDLABEL" + }, + { + "args": [ + "BC_I" + ], + "name": "BREAK" + }, + { + "args": [ + "BC_I" + ], + "name": "CONTINUE" + }, + { + "args": [ + "A_H", + "BC_R" + ], + "flags": [ + { + "mask": 64, + "name": "have_catch" + }, + { + "mask": 128, + "name": "have_finally" + }, + { + "mask": 256, + "name": "catch_binding" + }, + { + "mask": 512, + "name": "with_binding" + } + ], + "name": "TRYCATCH" + }, + { + "name": "ENDTRY" + }, + { + "name": "ENDCATCH" + }, + { + "args": [ + "ABC_R" + ], + "name": "ENDFIN" + }, + { + "args": [ + "BC_R" + ], + "name": "THROW" + }, + { + "name": "INVLHS" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "CSREG" + }, + { + "args": [ + "A_R", + "B_R" + ], + "name": "CSVAR_RR" + }, + { + "args": [ + "A_R", + "B_C" + ], + "name": "CSVAR_CR" + }, + { + "args": [ + "A_R", + "B_R" + ], + "name": "CSVAR_RC" + }, + { + "args": [ + "A_R", + "B_C" + ], + "name": "CSVAR_CC" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL0" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL1" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL2" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL3" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL4" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL5" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL6" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL7" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL8" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL9" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL10" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL11" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL12" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL13" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL14" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "CALL15" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "NEWOBJ" + }, + { + "args": [ + "A_I", + "BC_R" + ], + "name": "NEWARR" + }, + { + "args": [ + "A_R", + "B_R", + "C_I" + ], + "name": "MPUTOBJ" + }, + { + "args": [ + "A_R", + "B_RI", + "C_I" + ], + "name": "MPUTOBJI" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "INITSET" + }, + { + "args": [ + "A_R", + "BC_R" + ], + "name": "INITGET" + }, + { + "args": [ + "A_R", + "B_R", + "C_I" + ], + "name": "MPUTARR" + }, + { + "args": [ + "A_R", + "B_RI", + "C_I" + ], + "name": "MPUTARRI" + }, + { + "args": [ + "B_R", + "C_R" + ], + "name": "SETALEN" + }, + { + "args": [ + "B_R", + "C_R" + ], + "name": "INITENUM" + }, + { + "args": [ + "B_R", + "C_R" + ], + "name": "NEXTENUM" + }, + { + "args": [ + "BC_R" + ], + "name": "NEWTARGET" + }, + { + "name": "DEBUGGER" + }, + { + "args": [ + "ABC_I" + ], + "name": "NOP" + }, + { + "args": [ + "ABC_I" + ], + "name": "INVALID" + }, + { + "name": "UNUSED207" + }, + { + "args": [ + "A_R", + "B_R", + "C_R" + ], + "name": "GETPROPC_RR" + }, + { + "args": [ + "A_R", + "B_C", + "C_R" + ], + "name": "GETPROPC_CR" + }, + { + "args": [ + "A_R", + "B_R", + "C_C" + ], + "name": "GETPROPC_RC" + }, + { + "args": [ + "A_R", + "B_C", + "C_C" + ], + "name": "GETPROPC_CC" + }, + { + "name": "UNUSED212" + }, + { + "name": "UNUSED213" + }, + { + "name": "UNUSED214" + }, + { + "name": "UNUSED215" + }, + { + "name": "UNUSED216" + }, + { + "name": "UNUSED217" + }, + { + "name": "UNUSED218" + }, + { + "name": "UNUSED219" + }, + { + "name": "UNUSED220" + }, + { + "name": "UNUSED221" + }, + { + "name": "UNUSED222" + }, + { + "name": "UNUSED223" + }, + { + "name": "UNUSED224" + }, + { + "name": "UNUSED225" + }, + { + "name": "UNUSED226" + }, + { + "name": "UNUSED227" + }, + { + "name": "UNUSED228" + }, + { + "name": "UNUSED229" + }, + { + "name": "UNUSED230" + }, + { + "name": "UNUSED231" + }, + { + "name": "UNUSED232" + }, + { + "name": "UNUSED233" + }, + { + "name": "UNUSED234" + }, + { + "name": "UNUSED235" + }, + { + "name": "UNUSED236" + }, + { + "name": "UNUSED237" + }, + { + "name": "UNUSED238" + }, + { + "name": "UNUSED239" + }, + { + "name": "UNUSED240" + }, + { + "name": "UNUSED241" + }, + { + "name": "UNUSED242" + }, + { + "name": "UNUSED243" + }, + { + "name": "UNUSED244" + }, + { + "name": "UNUSED245" + }, + { + "name": "UNUSED246" + }, + { + "name": "UNUSED247" + }, + { + "name": "UNUSED248" + }, + { + "name": "UNUSED249" + }, + { + "name": "UNUSED250" + }, + { + "name": "UNUSED251" + }, + { + "name": "UNUSED252" + }, + { + "name": "UNUSED253" + }, + { + "name": "UNUSED254" + }, + { + "name": "UNUSED255" + } + ], + "client_commands": [ + "Reserved_0", + "Status", + "Reserved_2", + "Reserved_3", + "Reserved_4", + "Throw", + "Detaching", + "AppNotify" + ], + "class_names": [ + "none", + "Object", + "Array", + "Function", + "Arguments", + "Boolean", + "Date", + "Error", + "JSON", + "Math", + "Number", + "RegExp", + "String", + "global", + "Symbol", + "ObjEnv", + "DecEnv", + "Pointer", + "Thread", + "ArrayBuffer", + "DataView", + "Int8Array", + "Uint8Array", + "Uint8ClampedArray", + "Int16Array", + "Uint16Array", + "Int32Array", + "Uint32Array", + "Float32Array", + "Float64Array" + ], + "target_commands": [ + "Reserved_0", + "Reserved_1", + "Reserved_2", + "Reserved_3", + "Reserved_4", + "Reserved_5", + "Reserved_6", + "Reserved_7", + "Reserved_8", + "Reserved_9", + "Reserved_10", + "Reserved_11", + "Reserved_12", + "Reserved_13", + "Reserved_14", + "Reserved_15", + "BasicInfo", + "TriggerStatus", + "Pause", + "Resume", + "StepInto", + "StepOver", + "StepOut", + "ListBreak", + "AddBreak", + "DelBreak", + "GetVar", + "PutVar", + "GetCallStack", + "GetLocals", + "Eval", + "Detach", + "DumpHeap", + "GetBytecode", + "AppRequest", + "GetHeapObjInfo", + "GetObjPropDesc", + "GetObjPropDescRange" + ] +} diff --git a/lib/duktape-2.2.1/debugger/duk_debug_proxy.js b/lib/duktape-2.2.1/debugger/duk_debug_proxy.js new file mode 100644 index 0000000..fd8ba91 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_debug_proxy.js @@ -0,0 +1,1044 @@ +/* + * JSON debug proxy written in DukLuv + * + * This single file JSON debug proxy implementation is an alternative to the + * Node.js-based proxy in duk_debug.js. DukLuv is a much smaller dependency + * than Node.js so embedding DukLuv in a debug client is easier. + */ + +'use strict'; + +// XXX: Code assumes uv.write() will write fully. This is not necessarily +// true; should add support for partial writes (or at least failing when +// a partial write occurs). + +var log = new Duktape.Logger('Proxy'); // default logger +//log.l = 0; // enable debug and trace logging + +/* + * Config + */ + +var serverHost = '0.0.0.0'; +var serverPort = 9093; +var targetHost = '127.0.0.1'; +var targetPort = 9091; +var singleConnection = false; +var readableNumberValue = false; +var lenientJsonParse = false; +var jxParse = false; +var metadataFile = null; +var metadata = {}; +var TORTURE = false; // for manual testing of binary/json parsing robustness + +/* + * Duktape 1.x and 2.x buffer harmonization + */ + +var allocPlain = (typeof Uint8Array.allocPlain === 'function' ? + Uint8Array.allocPlain : Duktape.Buffer); +var plainOf = (typeof Uint8Array.plainOf === 'function' ? + Uint8Array.plainOf : Duktape.Buffer); +var bufferToString = (typeof String.fromBuffer === 'function' ? + String.fromBuffer : String); + +/* + * Detect missing 'var' declarations + */ + +// Prevent new bindings on global object. This detects missing 'var' +// declarations, e.g. "x = 123;" in a function without declaring it. +var global = new Function('return this;')(); +log.debug('Preventing extensions on global object'); +log.debug('Global is extensible:', Object.isExtensible(global)); +Object.preventExtensions(global); +log.debug('Global is extensible:', Object.isExtensible(global)); + +/* + * Misc helpers + */ + +function jxEncode(v) { + return Duktape.enc('jx', v); +} + +function plainBufferCopy(typedarray) { + // This is still pretty awkward in Duktape 1.4.x. + // Argument may be a "slice" and we want a copy of the slice + // (not the full underlying buffer). + + var u8 = new Uint8Array(typedarray.length); + u8.set(typedarray); // make a copy, ensuring there's no slice offset + return plainOf(u8); // get underlying plain buffer +} + +function isObject(x) { + // Note that typeof null === 'object'. + return (typeof x === 'object' && x !== null); +} + +function readFully(filename, cb) { + uv.fs_open(metadataFile, 'r', 0, function (handle, err) { + var fileOff = 0; + var data = new Uint8Array(256); + var dataOff = 0; + + if (err) { + return cb(null, err); + } + function readCb(buf, err) { + var res; + var newData; + + log.debug('Read callback:', buf.length, err); + if (err) { + uv.fs_close(handle); + return cb(null, err); + } + if (buf.length == 0) { + uv.fs_close(handle); + res = new Uint8Array(dataOff); + res.set(data.subarray(0, dataOff)); + res = plainOf(res); // plain buffer + log.debug('Read', res.length, 'bytes from', filename); + return cb(res, null); + } + while (data.length - dataOff < buf.length) { + log.debug('Resize file read buffer:', data.length, '->', data.length * 2); + newData = new Uint8Array(data.length * 2); + newData.set(data); + data = newData; + } + data.set(new Uint8Array(buf), dataOff); + dataOff += buf.length; + fileOff += buf.length; + uv.fs_read(handle, 4096, fileOff, readCb); + } + uv.fs_read(handle, 4096, fileOff, readCb); + }); +} + +/* + * JSON proxy server + * + * Accepts an incoming JSON proxy client and connects to a debug target, + * tying the two connections together. Supports both a single connection + * and a persistent mode. + */ + +function JsonProxyServer(host, port) { + this.name = 'JsonProxyServer'; + this.handle = uv.new_tcp(); + uv.tcp_bind(this.handle, host, port); + uv.listen(this.handle, 128, this.onConnection.bind(this)); +} + +JsonProxyServer.prototype.onConnection = function onConnection(err) { + if (err) { + log.error('JSON proxy onConnection error:', err); + return; + } + log.info('JSON proxy client connected'); // XXX: it'd be nice to log remote peer host:port + + var jsonSock = new JsonConnHandler(this); + var targSock = new TargetConnHandler(this); + jsonSock.targetHandler = targSock; + targSock.jsonHandler = jsonSock; + uv.accept(this.handle, jsonSock.handle); + + log.info('Connecting to debug target at', targetHost + ':' + targetPort); + jsonSock.writeJson({ notify: '_TargetConnecting', args: [ targetHost, targetPort ] }); + uv.tcp_connect(targSock.handle, targetHost, targetPort, targSock.onConnect.bind(targSock)); + + if (singleConnection) { + log.info('Single connection mode, stop listening for more connections'); + uv.shutdown(this.handle); + uv.read_stop(this.handle); // unnecessary but just in case + uv.close(this.handle); + this.handle = null; + } +}; + +JsonProxyServer.prototype.onProxyClientDisconnected = function onProxyClientDisconnected() { + // When this is invoked the proxy connection and the target connection + // have both been closed. + if (singleConnection) { + log.info('Proxy connection finished (single connection mode: we should be exiting now)'); + } else { + log.info('Proxy connection finished (persistent mode: wait for more connections)'); + } +}; + +/* + * JSON connection handler + */ + +function JsonConnHandler(server) { + var i, n; + + this.name = 'JsonConnHandler'; + this.server = server; + this.handle = uv.new_tcp(); + this.incoming = new Uint8Array(4096); + this.incomingOffset = 0; + this.targetHandler = null; + + this.commandNumberLookup = {}; + if (metadata && metadata.target_commands) { + for (i = 0, n = metadata.target_commands.length; i < n; i++) { + this.commandNumberLookup[metadata.target_commands[i]] = i; + } + } +} + +JsonConnHandler.prototype.finish = function finish(msg) { + var args; + + if (!this.handle) { + log.info('JsonConnHandler already disconnected, ignore finish()'); + return; + } + log.info('JsonConnHandler finished:', msg); + try { + args = msg ? [ msg ] : void 0; + this.writeJson({ notify: '_Disconnecting', args: args }); + } catch (e) { + log.info('Failed to write _Disconnecting notify, ignoring:', e); + } + uv.shutdown(this.handle); + uv.read_stop(this.handle); + uv.close(this.handle); + this.handle = null; + + this.targetHandler.finish(msg); // disconnect target too (if not already disconnected) + + this.server.onProxyClientDisconnected(); +}; + +JsonConnHandler.prototype.onRead = function onRead(err, data) { + var newIncoming; + var msg; + var errmsg; + var tmpBuf; + + log.trace('Received data from JSON socket, err:', err, 'data length:', data ? data.length : 'null'); + + if (err) { + errmsg = 'Error reading data from JSON debug client: ' + err; + this.finish(errmsg); + return; + } + if (data) { + // Feed the data one byte at a time when torture testing. + if (TORTURE && data.length > 1) { + for (var i = 0; i < data.length; i++) { + tmpBuf = allocPlain(1); + tmpBuf[0] = data[i]; + this.onRead(null, tmpBuf); + } + return; + } + + // Receive data into 'incoming', resizing as necessary. + while (data.length > this.incoming.length - this.incomingOffset) { + newIncoming = new Uint8Array(this.incoming.length * 1.3 + 16); + newIncoming.set(this.incoming); + this.incoming = newIncoming; + log.debug('Resize incoming JSON buffer to ' + this.incoming.length); + } + this.incoming.set(new Uint8Array(data), this.incomingOffset); + this.incomingOffset += data.length; + + // Trial parse JSON message(s). + while (true) { + msg = this.trialParseJsonMessage(); + if (!msg) { + break; + } + try { + this.dispatchJsonMessage(msg); + } catch (e) { + errmsg = 'JSON message dispatch failed: ' + e; + this.writeJson({ notify: '_Error', args: [ errmsg ] }); + if (lenientJsonParse) { + log.warn('JSON message dispatch failed (lenient mode, ignoring):', e); + } else { + log.warn('JSON message dispatch failed (dropping connection):', e); + this.finish(errmsg); + } + } + } + } else { + this.finish('JSON proxy client disconnected'); + } +}; + +JsonConnHandler.prototype.writeJson = function writeJson(msg) { + log.info('PROXY --> CLIENT:', JSON.stringify(msg)); + if (this.handle) { + uv.write(this.handle, JSON.stringify(msg) + '\n'); + } +}; + +JsonConnHandler.prototype.handleDebugMessage = function handleDebugMessage(dvalues) { + var msg = {}; + var idx = 0; + var cmd; + + if (dvalues.length <= 0) { + throw new Error('invalid dvalues list: length <= 0'); + } + var x = dvalues[idx++]; + if (!isObject(x)) { + throw new Error('invalid initial dvalue: ' + Duktape.enc('jx', dvalues)); + } + if (x.type === 'req') { + cmd = dvalues[idx++]; + if (typeof cmd !== 'number') { + throw new Error('invalid command: ' + Duktape.enc('jx', cmd)); + } + msg.request = this.determineCommandName(cmd) || true; + msg.command = cmd; + } else if (x.type === 'rep') { + msg.reply = true; + } else if (x.type === 'err') { + msg.error = true; + } else if (x.type === 'nfy') { + cmd = dvalues[idx++]; + if (typeof cmd !== 'number') { + throw new Error('invalid command: ' + Duktape.enc('jx', cmd)); + } + msg.notify = this.determineCommandName(cmd) || true; + msg.command = cmd; + } else { + throw new Error('invalid initial dvalue: ' + Duktape.enc('jx', dvalues)); + } + + for (; idx < dvalues.length - 1; idx++) { + if (!msg.args) { + msg.args = []; + } + msg.args.push(dvalues[idx]); + } + + if (!isObject(dvalues[idx]) || dvalues[idx].type !== 'eom') { + throw new Error('invalid final dvalue: ' + Duktape.enc('jx', dvalues)); + } + + this.writeJson(msg); +}; + +JsonConnHandler.prototype.determineCommandName = function determineCommandName(cmd) { + if (!(metadata && metadata.client_commands)) { + return; + } + return metadata.client_commands[cmd]; +}; + +JsonConnHandler.prototype.trialParseJsonMessage = function trialParseJsonMessage() { + var buf = this.incoming; + var avail = this.incomingOffset; + var i; + var msg, str, errmsg; + + for (i = 0; i < avail; i++) { + if (buf[i] == 0x0a) { + str = bufferToString(plainBufferCopy(buf.subarray(0, i))); + try { + if (jxParse) { + msg = Duktape.dec('jx', str); + } else { + msg = JSON.parse(str); + } + } catch (e) { + // In lenient mode if JSON parse fails just send back an _Error + // and ignore the line (useful for initial development). + // + // In non-lenient mode drop the connection here; if the failed line + // was a request the client is expecting a reply/error message back + // (otherwise it may go out of sync) but we can't send a synthetic + // one (as we can't parse the request). + errmsg = 'JSON parse failed for: ' + jxEncode(str) + ': ' + e; + this.writeJson({ notify: '_Error', args: [ errmsg ] }); + if (lenientJsonParse) { + log.warn('JSON parse failed (lenient mode, ignoring):', e); + } else { + log.warn('JSON parse failed (dropping connection):', e); + this.finish(errmsg); + } + } + + this.incoming.set(this.incoming.subarray(i + 1)); + this.incomingOffset -= i + 1; + return msg; + } + } +}; + +JsonConnHandler.prototype.dispatchJsonMessage = function dispatchJsonMessage(msg) { + var cmd; + var dvalues = []; + var i, n; + + log.info('PROXY <-- CLIENT:', JSON.stringify(msg)); + + // Parse message type, determine initial marker for binary message. + if (msg.request) { + cmd = this.determineCommandNumber(msg.request, msg.command); + dvalues.push(new Uint8Array([ 0x01 ])); + dvalues.push(this.encodeJsonDvalue(cmd)); + } else if (msg.reply) { + dvalues.push(new Uint8Array([ 0x02 ])); + } else if (msg.notify) { + cmd = this.determineCommandNumber(msg.notify, msg.command); + dvalues.push(new Uint8Array([ 0x04 ])); + dvalues.push(this.encodeJsonDvalue(cmd)); + } else if (msg.error) { + dvalues.push(new Uint8Array([ 0x03 ])); + } else { + throw new Error('invalid input JSON message: ' + jxEncode(msg)); + } + + // Encode arguments into dvalues. + for (i = 0, n = (msg.args ? msg.args.length : 0); i < n; i++) { + dvalues.push(this.encodeJsonDvalue(msg.args[i])); + } + + // Add an EOM, and write out the dvalues to the debug target. + dvalues.push(new Uint8Array([ 0x00 ])); + for (i = 0, n = dvalues.length; i < n; i++) { + this.targetHandler.writeBinary(dvalues[i]); + } +}; + +JsonConnHandler.prototype.determineCommandNumber = function determineCommandNumber(name, val) { + var res; + + if (typeof name === 'string') { + res = this.commandNumberLookup[name]; + if (!res) { + log.info('Unknown command name: ' + name + ', command number: ' + val); + } + } else if (typeof name === 'number') { + res = name; + } else if (name !== true) { + throw new Error('invalid command name (must be string, number, or "true"): ' + name); + } + if (typeof res === 'undefined' && typeof val === 'undefined') { + throw new Error('cannot determine command number from name: ' + name); + } + if (typeof val !== 'number' && typeof val !== 'undefined') { + throw new Error('invalid command number: ' + val); + } + res = res || val; + return res; +}; + +JsonConnHandler.prototype.writeDebugStringToBuffer = function writeDebugStringToBuffer(v, buf, off) { + var i, n; + + for (i = 0, n = v.length; i < n; i++) { + buf[off + i] = v.charCodeAt(i) & 0xff; // truncate higher bits + } +}; + +JsonConnHandler.prototype.encodeJsonDvalue = function encodeJsonDvalue(v) { + var buf, dec, len, dv; + + if (isObject(v)) { + if (v.type === 'eom') { + return new Uint8Array([ 0x00 ]); + } else if (v.type === 'req') { + return new Uint8Array([ 0x01 ]); + } else if (v.type === 'rep') { + return new Uint8Array([ 0x02 ]); + } else if (v.type === 'err') { + return new Uint8Array([ 0x03 ]); + } else if (v.type === 'nfy') { + return new Uint8Array([ 0x04 ]); + } else if (v.type === 'unused') { + return new Uint8Array([ 0x15 ]); + } else if (v.type === 'undefined') { + return new Uint8Array([ 0x16 ]); + } else if (v.type === 'number') { + dec = Duktape.dec('hex', v.data); + len = dec.length; + if (len !== 8) { + throw new TypeError('value cannot be converted to dvalue: ' + jxEncode(v)); + } + buf = new Uint8Array(1 + len); + buf[0] = 0x1a; + buf.set(new Uint8Array(dec), 1); + return buf; + } else if (v.type === 'buffer') { + dec = Duktape.dec('hex', v.data); + len = dec.length; + if (len <= 0xffff) { + buf = new Uint8Array(3 + len); + buf[0] = 0x14; + buf[1] = (len >> 8) & 0xff; + buf[2] = (len >> 0) & 0xff; + buf.set(new Uint8Arrau(dec), 3); + return buf; + } else { + buf = new Uint8Array(5 + len); + buf[0] = 0x13; + buf[1] = (len >> 24) & 0xff; + buf[2] = (len >> 16) & 0xff; + buf[3] = (len >> 8) & 0xff; + buf[4] = (len >> 0) & 0xff; + buf.set(new Uint8Array(dec), 5); + return buf; + } + } else if (v.type === 'object') { + dec = Duktape.dec('hex', v.pointer); + len = dec.length; + buf = new Uint8Array(3 + len); + buf[0] = 0x1b; + buf[1] = v.class; + buf[2] = len; + buf.set(new Uint8Array(dec), 3); + return buf; + } else if (v.type === 'pointer') { + dec = Duktape.dec('hex', v.pointer); + len = dec.length; + buf = new Uint8Array(2 + len); + buf[0] = 0x1c; + buf[1] = len; + buf.set(new Uint8Array(dec), 2); + return buf; + } else if (v.type === 'lightfunc') { + dec = Duktape.dec('hex', v.pointer); + len = dec.length; + buf = new Uint8Array(4 + len); + buf[0] = 0x1d; + buf[1] = (v.flags >> 8) & 0xff; + buf[2] = v.flags & 0xff; + buf[3] = len; + buf.set(new Uint8Array(dec), 4); + return buf; + } else if (v.type === 'heapptr') { + dec = Duktape.dec('hex', v.pointer); + len = dec.length; + buf = new Uint8Array(2 + len); + buf[0] = 0x1e; + buf[1] = len; + buf.set(new Uint8Array(dec), 2); + return buf; + } + } else if (v === null) { + return new Uint8Array([ 0x17 ]); + } else if (typeof v === 'boolean') { + return new Uint8Array([ v ? 0x18 : 0x19 ]); + } else if (typeof v === 'number') { + if (Math.floor(v) === v && /* whole */ + (v !== 0 || 1 / v > 0) && /* not negative zero */ + v >= -0x80000000 && v <= 0x7fffffff) { + // Represented signed 32-bit integers as plain integers. + // Debugger code expects this for all fields that are not + // duk_tval representations (e.g. command numbers and such). + if (v >= 0x00 && v <= 0x3f) { + return new Uint8Array([ 0x80 + v ]); + } else if (v >= 0x0000 && v <= 0x3fff) { + return new Uint8Array([ 0xc0 + (v >> 8), v & 0xff ]); + } else if (v >= -0x80000000 && v <= 0x7fffffff) { + return new Uint8Array([ 0x10, + (v >> 24) & 0xff, + (v >> 16) & 0xff, + (v >> 8) & 0xff, + (v >> 0) & 0xff ]); + } else { + throw new Error('internal error when encoding integer to dvalue: ' + v); + } + } else { + // Represent non-integers as IEEE double dvalues. + buf = new Uint8Array(1 + 8); + buf[0] = 0x1a; + new DataView(buf).setFloat64(1, v, false); + return buf; + } + } else if (typeof v === 'string') { + if (v.length < 0 || v.length > 0xffffffff) { + // Not possible in practice. + throw new TypeError('cannot convert to dvalue, invalid string length: ' + v.length); + } + if (v.length <= 0x1f) { + buf = new Uint8Array(1 + v.length); + buf[0] = 0x60 + v.length; + this.writeDebugStringToBuffer(v, buf, 1); + return buf; + } else if (v.length <= 0xffff) { + buf = new Uint8Array(3 + v.length); + buf[0] = 0x12; + buf[1] = (v.length >> 8) & 0xff; + buf[2] = (v.length >> 0) & 0xff; + this.writeDebugStringToBuffer(v, buf, 3); + return buf; + } else { + buf = new Uint8Array(5 + v.length); + buf[0] = 0x11; + buf[1] = (v.length >> 24) & 0xff; + buf[2] = (v.length >> 16) & 0xff; + buf[3] = (v.length >> 8) & 0xff; + buf[4] = (v.length >> 0) & 0xff; + this.writeDebugStringToBuffer(v, buf, 5); + return buf; + } + } + + throw new TypeError('value cannot be converted to dvalue: ' + jxEncode(v)); +}; + +/* + * Target binary connection handler + */ + +function TargetConnHandler(server) { + this.name = 'TargetConnHandler'; + this.server = server; + this.handle = uv.new_tcp(); + this.jsonHandler = null; + this.incoming = new Uint8Array(4096); + this.incomingOffset = 0; + this.dvalues = []; +} + +TargetConnHandler.prototype.finish = function finish(msg) { + if (!this.handle) { + log.info('TargetConnHandler already disconnected, ignore finish()'); + return; + } + log.info('TargetConnHandler finished:', msg); + + this.jsonHandler.writeJson({ notify: '_TargetDisconnected' }); + + // XXX: write a notify to target? + + uv.shutdown(this.handle); + uv.read_stop(this.handle); + uv.close(this.handle); + this.handle = null; + + this.jsonHandler.finish(msg); // disconnect JSON client too (if not already disconnected) +}; + +TargetConnHandler.prototype.onConnect = function onConnect(err) { + var errmsg; + + if (err) { + errmsg = 'Failed to connect to target: ' + err; + log.warn(errmsg); + this.jsonHandler.writeJson({ notify: '_Error', args: [ String(err) ] }); + this.finish(errmsg); + return; + } + + // Once we're connected to the target, start read both binary and JSON + // input. We don't want to read JSON input before this so that we can + // always translate incoming messages to dvalues and write them out + // without queueing. Any pending JSON messages will be queued by the + // OS instead. + + log.info('Connected to debug target at', targetHost + ':' + targetPort); + uv.read_start(this.jsonHandler.handle, this.jsonHandler.onRead.bind(this.jsonHandler)); + uv.read_start(this.handle, this.onRead.bind(this)); +}; + +TargetConnHandler.prototype.writeBinary = function writeBinary(buf) { + var plain = plainBufferCopy(buf); + log.info('PROXY --> TARGET:', Duktape.enc('jx', plain)); + if (this.handle) { + uv.write(this.handle, plain); + } +}; + +TargetConnHandler.prototype.onRead = function onRead(err, data) { + var res; + var errmsg; + var tmpBuf; + var newIncoming; + + log.trace('Received data from target socket, err:', err, 'data length:', data ? data.length : 'null'); + + if (err) { + errmsg = 'Error reading data from debug target: ' + err; + this.finish(errmsg); + return; + } + + if (data) { + // Feed the data one byte at a time when torture testing. + if (TORTURE && data.length > 1) { + for (var i = 0; i < data.length; i++) { + tmpBuf = allocPlain(1); + tmpBuf[0] = data[i]; + this.onRead(null, tmpBuf); + } + return; + } + + // Receive data into 'incoming', resizing as necessary. + while (data.length > this.incoming.length - this.incomingOffset) { + newIncoming = new Uint8Array(this.incoming.length * 1.3 + 16); + newIncoming.set(this.incoming); + this.incoming = newIncoming; + log.debug('Resize incoming binary buffer to ' + this.incoming.length); + } + this.incoming.set(new Uint8Array(data), this.incomingOffset); + this.incomingOffset += data.length; + + // Trial parse handshake unless done. + if (!this.handshake) { + this.trialParseHandshake(); + } + + // Trial parse dvalue(s) and debug messages. + if (this.handshake) { + for (;;) { + res = this.trialParseDvalue(); + if (!res) { + break; + } + log.trace('Got dvalue:', Duktape.enc('jx', res.dvalue)); + this.dvalues.push(res.dvalue); + if (isObject(res.dvalue) && res.dvalue.type === 'eom') { + try { + this.jsonHandler.handleDebugMessage(this.dvalues); + this.dvalues = []; + } catch (e) { + errmsg = 'JSON message handling failed: ' + e; + this.jsonHandler.writeJson({ notify: '_Error', args: [ errmsg ] }); + if (lenientJsonParse) { + log.warn('JSON message handling failed (lenient mode, ignoring):', e); + } else { + log.warn('JSON message handling failed (dropping connection):', e); + this.finish(errmsg); + } + } + } + } + } + } else { + log.info('Target disconnected'); + this.finish('Target disconnected'); + } +}; + +TargetConnHandler.prototype.trialParseHandshake = function trialParseHandshake() { + var buf = this.incoming; + var avail = this.incomingOffset; + var i; + var msg; + var m; + var protocolVersion; + + for (i = 0; i < avail; i++) { + if (buf[i] == 0x0a) { + msg = bufferToString(plainBufferCopy(buf.subarray(0, i))); + this.incoming.set(this.incoming.subarray(i + 1)); + this.incomingOffset -= i + 1; + + // Generic handshake format: only relies on initial version field. + m = /^(\d+) (.*)$/.exec(msg) || {}; + protocolVersion = +m[1]; + this.handshake = { + line: msg, + protocolVersion: protocolVersion, + text: m[2] + }; + + // More detailed v1 handshake line. + if (protocolVersion === 1) { + m = /^(\d+) (\d+) (.*?) (.*?) (.*)$/.exec(msg) || {}; + this.handshake.dukVersion = m[1]; + this.handshake.dukGitDescribe = m[2]; + this.handshake.targetString = m[3]; + } + + this.jsonHandler.writeJson({ notify: '_TargetConnected', args: [ msg ] }); + + log.info('Target handshake: ' + JSON.stringify(this.handshake)); + return; + } + } +}; + +TargetConnHandler.prototype.bufferToDebugString = function bufferToDebugString(buf) { + return String.fromCharCode.apply(null, buf); +}; + +TargetConnHandler.prototype.trialParseDvalue = function trialParseDvalue() { + var _this = this; + var buf = this.incoming; + var avail = this.incomingOffset; + var v; + var gotValue = false; // explicit flag for e.g. v === undefined + var dv = new DataView(buf); + var tmp; + var x; + var len; + + function consume(n) { + log.info('PROXY <-- TARGET:', Duktape.enc('jx', _this.incoming.subarray(0, n))); + _this.incoming.set(_this.incoming.subarray(n)); + _this.incomingOffset -= n; + } + + x = buf[0]; + if (avail <= 0) { + ; + } else if (x >= 0xc0) { + // 0xc0...0xff: integers 0-16383 + if (avail >= 2) { + v = ((x - 0xc0) << 8) + buf[1]; + consume(2); + } + } else if (x >= 0x80) { + // 0x80...0xbf: integers 0-63 + v = x - 0x80; + consume(1); + } else if (x >= 0x60) { + // 0x60...0x7f: strings with length 0-31 + len = x - 0x60; + if (avail >= 1 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(1, 1 + len)); + v = this.bufferToDebugString(v); + consume(1 + len); + } + } else { + switch (x) { + case 0x00: consume(1); v = { type: 'eom' }; break; + case 0x01: consume(1); v = { type: 'req' }; break; + case 0x02: consume(1); v = { type: 'rep' }; break; + case 0x03: consume(1); v = { type: 'err' }; break; + case 0x04: consume(1); v = { type: 'nfy' }; break; + case 0x10: // 4-byte signed integer + if (avail >= 5) { + v = dv.getInt32(1, false); + consume(5); + } + break; + case 0x11: // 4-byte string + if (avail >= 5) { + len = dv.getUint32(1, false); + if (avail >= 5 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(5, 5 + len)); + v = this.bufferToDebugString(v); + consume(5 + len); + } + } + break; + case 0x12: // 2-byte string + if (avail >= 3) { + len = dv.getUint16(1, false); + if (avail >= 3 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(3, 3 + len)); + v = this.bufferToDebugString(v); + consume(3 + len); + } + } + break; + case 0x13: // 4-byte buffer + if (avail >= 5) { + len = dv.getUint32(1, false); + if (avail >= 5 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(5, 5 + len)); + v = { type: 'buffer', data: Duktape.enc('hex', plainOf(v)) }; + consume(5 + len); + } + } + break; + case 0x14: // 2-byte buffer + if (avail >= 3) { + len = dv.getUint16(1, false); + if (avail >= 3 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(3, 3 + len)); + v = { type: 'buffer', data: Duktape.enc('hex', plainOf(v)) }; + consume(3 + len); + } + } + break; + case 0x15: // unused/none + v = { type: 'unused' }; + consume(1); + break; + case 0x16: // undefined + v = { type: 'undefined' }; + gotValue = true; // indicate 'v' is actually set + consume(1); + break; + case 0x17: // null + v = null; + gotValue = true; // indicate 'v' is actually set + consume(1); + break; + case 0x18: // true + v = true; + consume(1); + break; + case 0x19: // false + v = false; + consume(1); + break; + case 0x1a: // number (IEEE double), big endian + if (avail >= 9) { + tmp = new Uint8Array(8); + tmp.set(buf.subarray(1, 9)); + v = { type: 'number', data: Duktape.enc('hex', plainOf(tmp)) }; + if (readableNumberValue) { + // The value key should not be used programmatically, + // it is just there to make the dumps more readable. + v.value = new DataView(tmp.buffer).getFloat64(0, false); + } + consume(9); + } + break; + case 0x1b: // object + if (avail >= 3) { + len = buf[2]; + if (avail >= 3 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(3, 3 + len)); + v = { type: 'object', 'class': buf[1], pointer: Duktape.enc('hex', plainOf(v)) }; + consume(3 + len); + } + } + break; + case 0x1c: // pointer + if (avail >= 2) { + len = buf[1]; + if (avail >= 2 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(2, 2 + len)); + v = { type: 'pointer', pointer: Duktape.enc('hex', plainOf(v)) }; + consume(2 + len); + } + } + break; + case 0x1d: // lightfunc + if (avail >= 4) { + len = buf[3]; + if (avail >= 4 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(4, 4 + len)); + v = { type: 'lightfunc', flags: dv.getUint16(1, false), pointer: Duktape.enc('hex', plainOf(v)) }; + consume(4 + len); + } + } + break; + case 0x1e: // heapptr + if (avail >= 2) { + len = buf[1]; + if (avail >= 2 + len) { + v = new Uint8Array(len); + v.set(buf.subarray(2, 2 + len)); + v = { type: 'heapptr', pointer: Duktape.enc('hex', plainOf(v)) }; + consume(2 + len); + } + } + break; + default: + throw new Error('failed parse initial byte: ' + buf[0]); + } + } + + if (typeof v !== 'undefined' || gotValue) { + return { dvalue: v }; + } +}; + +/* + * Main + */ + +function main() { + var argv = typeof uv.argv === 'function' ? uv.argv() : []; + var i; + for (i = 2; i < argv.length; i++) { // skip dukluv and script name + if (argv[i] == '--help') { + print('Usage: dukluv ' + argv[1] + ' [option]+'); + print(''); + print(' --server-host HOST JSON proxy server listen address'); + print(' --server-port PORT JSON proxy server listen port'); + print(' --target-host HOST Debug target address'); + print(' --target-port PORT Debug target port'); + print(' --metadata FILE Proxy metadata file (usually named duk_debug_meta.json)'); + print(' --log-level LEVEL Set log level, default is 2; 0=trace, 1=debug, 2=info, 3=warn, etc'); + print(' --single Run a single proxy connection and exit (default: persist for multiple connections)'); + print(' --readable-numbers Add a non-programmatic "value" key for IEEE doubles help readability'); + print(' --lenient Ignore (with warning) invalid JSON without dropping connection'); + print(' --jx-parse Parse JSON proxy input with JX, useful when testing manually'); + print(''); + return; // don't register any sockets/timers etc to exit + } else if (argv[i] == '--single') { + singleConnection = true; + continue; + } else if (argv[i] == '--readable-numbers') { + readableNumberValue = true; + continue; + } else if (argv[i] == '--lenient') { + lenientJsonParse = true; + continue; + } else if (argv[i] == '--jx-parse') { + jxParse = true; + continue; + } + if (i >= argv.length - 1) { + throw new Error('missing option value for ' + argv[i]); + } + if (argv[i] == '--server-host') { + serverHost = argv[i + 1]; + i++; + } else if (argv[i] == '--server-port') { + serverPort = Math.floor(+argv[i + 1]); + i++; + } else if (argv[i] == '--target-host') { + targetHost = argv[i + 1]; + i++; + } else if (argv[i] == '--target-port') { + targetPort = Math.floor(+argv[i + 1]); + i++; + } else if (argv[i] == '--metadata') { + metadataFile = argv[i + 1]; + i++; + } else if (argv[i] == '--log-level') { + log.l = Math.floor(+argv[i + 1]); + i++; + } else { + throw new Error('invalid option ' + argv[i]); + } + } + + function runServer() { + var serverSocket = new JsonProxyServer(serverHost, serverPort); + var connMode = singleConnection ? 'single connection mode' : 'persistent connection mode'; + log.info('Listening for incoming JSON debug connection on ' + serverHost + ':' + serverPort + + ', target is ' + targetHost + ':' + targetPort + ', ' + connMode); + } + + if (metadataFile) { + log.info('Read proxy metadata from', metadataFile); + readFully(metadataFile, function (data, err) { + if (err) { + log.error('Failed to load metadata:', err); + throw err; + } + try { + metadata = JSON.parse(bufferToString(data)); + } catch (e) { + log.error('Failed to parse JSON metadata from ' + metadataFile + ': ' + e); + throw e; + } + runServer(); + }); + } else { + runServer(); + } +} + +main(); diff --git a/lib/duktape-2.2.1/debugger/duk_debugcommands.yaml b/lib/duktape-2.2.1/debugger/duk_debugcommands.yaml new file mode 100644 index 0000000..f253ba6 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_debugcommands.yaml @@ -0,0 +1,52 @@ +# Debug request/notify command names provided by the debug client. +# These are concretely notify names now. +client_commands: + - Reserved_0 + - Status + - Reserved_2 # Duktape 1.x: print notify + - Reserved_3 # Duktape 1.x: alert notify + - Reserved_4 # Duktape 1.x: log notify + - Throw + - Detaching + - AppNotify + +# Debug request/notify command names provided by the debug target (Duktape). +target_commands: + - Reserved_0 + - Reserved_1 + - Reserved_2 + - Reserved_3 + - Reserved_4 + - Reserved_5 + - Reserved_6 + - Reserved_7 + - Reserved_8 + - Reserved_9 + - Reserved_10 + - Reserved_11 + - Reserved_12 + - Reserved_13 + - Reserved_14 + - Reserved_15 + - BasicInfo + - TriggerStatus + - Pause + - Resume + - StepInto + - StepOver + - StepOut + - ListBreak + - AddBreak + - DelBreak + - GetVar + - PutVar + - GetCallStack + - GetLocals + - Eval + - Detach + - DumpHeap + - GetBytecode + - AppRequest + - GetHeapObjInfo + - GetObjPropDesc + - GetObjPropDescRange diff --git a/lib/duktape-2.2.1/debugger/duk_debugerrors.yaml b/lib/duktape-2.2.1/debugger/duk_debugerrors.yaml new file mode 100644 index 0000000..500265f --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_debugerrors.yaml @@ -0,0 +1,6 @@ +error_codes: + - Unknown + - UnsupportedCommand + - TooMany + - NotFound + - ApplicationError diff --git a/lib/duktape-2.2.1/debugger/duk_opcodes.yaml b/lib/duktape-2.2.1/debugger/duk_opcodes.yaml new file mode 100644 index 0000000..21d9327 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/duk_opcodes.yaml @@ -0,0 +1,1049 @@ +# Duktape opcode metadata for debugger. +# - See duk_debug.js for the argument formats (A_R etc). +# - Flag bits are for the whole instruction as a 32-bit integer, +# they are not field shifted +# +# NOTE: Use YAML comments only on comment-only lines (not trailing content): +# Node.js 'yamljs' seems to refuse parsing trailing comments in some cases. + +opcodes: + - name: LDREG + args: + - A_R + - BC_R + - name: STREG + args: + - A_R + - BC_R + - name: JUMP + args: + - ABC_JUMP + - name: LDCONST + args: + - A_R + - BC_C + - name: LDINT + args: + - A_R + - BC_LDINT + - name: LDINTX + args: + - A_R + - BC_LDINTX + - name: LDTHIS + args: + - BC_R + - name: LDUNDEF + args: + - BC_R + - name: LDNULL + args: + - BC_R + - name: LDTRUE + args: + - BC_R + - name: LDFALSE + args: + - BC_R + - name: GETVAR + args: + - A_R + - BC_C + - name: BNOT + args: + - A_R + - BC_R + - name: LNOT + args: + - A_R + - BC_R + - name: UNM + args: + - A_R + - BC_R + - name: UNP + args: + - A_R + - BC_R + - name: EQ_RR + args: + - A_R + - B_R + - C_R + - name: EQ_CR + args: + - A_R + - B_C + - C_R + - name: EQ_RC + args: + - A_R + - B_R + - C_C + - name: EQ_CC + args: + - A_R + - B_C + - C_C + - name: NEQ_RR + args: + - A_R + - B_R + - C_R + - name: NEQ_CR + args: + - A_R + - B_C + - C_R + - name: NEQ_RC + args: + - A_R + - B_R + - C_C + - name: NEQ_CC + args: + - A_R + - B_C + - C_C + - name: SEQ_RR + args: + - A_R + - B_R + - C_R + - name: SEQ_CR + args: + - A_R + - B_C + - C_R + - name: SEQ_RC + args: + - A_R + - B_R + - C_C + - name: SEQ_CC + args: + - A_R + - B_C + - C_C + - name: SNEQ_RR + args: + - A_R + - B_R + - C_R + - name: SNEQ_CR + args: + - A_R + - B_C + - C_R + - name: SNEQ_RC + args: + - A_R + - B_R + - C_C + - name: SNEQ_CC + args: + - A_R + - B_C + - C_C + - name: GT_RR + args: + - A_R + - B_R + - C_R + - name: GT_CR + args: + - A_R + - B_C + - C_R + - name: GT_RC + args: + - A_R + - B_R + - C_C + - name: GT_CC + args: + - A_R + - B_C + - C_C + - name: GE_RR + args: + - A_R + - B_R + - C_R + - name: GE_CR + args: + - A_R + - B_C + - C_R + - name: GE_RC + args: + - A_R + - B_R + - C_C + - name: GE_CC + args: + - A_R + - B_C + - C_C + - name: LT_RR + args: + - A_R + - B_R + - C_R + - name: LT_CR + args: + - A_R + - B_C + - C_R + - name: LT_RC + args: + - A_R + - B_R + - C_C + - name: LT_CC + args: + - A_R + - B_C + - C_C + - name: LE_RR + args: + - A_R + - B_R + - C_R + - name: LE_CR + args: + - A_R + - B_C + - C_R + - name: LE_RC + args: + - A_R + - B_R + - C_C + - name: LE_CC + args: + - A_R + - B_C + - C_C + - name: IFTRUE_R + args: + - BC_R + - name: IFTRUE_C + args: + - BC_C + - name: IFFALSE_R + args: + - BC_R + - name: IFFALSE_C + args: + - BC_C + - name: ADD_RR + args: + - A_R + - B_R + - C_R + - name: ADD_CR + args: + - A_R + - B_C + - C_R + - name: ADD_RC + args: + - A_R + - B_R + - C_C + - name: ADD_CC + args: + - A_R + - B_C + - C_C + - name: SUB_RR + args: + - A_R + - B_R + - C_R + - name: SUB_CR + args: + - A_R + - B_C + - C_R + - name: SUB_RC + args: + - A_R + - B_R + - C_C + - name: SUB_CC + args: + - A_R + - B_C + - C_C + - name: MUL_RR + args: + - A_R + - B_R + - C_R + - name: MUL_CR + args: + - A_R + - B_C + - C_R + - name: MUL_RC + args: + - A_R + - B_R + - C_C + - name: MUL_CC + args: + - A_R + - B_C + - C_C + - name: DIV_RR + args: + - A_R + - B_R + - C_R + - name: DIV_CR + args: + - A_R + - B_C + - C_R + - name: DIV_RC + args: + - A_R + - B_R + - C_C + - name: DIV_CC + args: + - A_R + - B_C + - C_C + - name: MOD_RR + args: + - A_R + - B_R + - C_R + - name: MOD_CR + args: + - A_R + - B_C + - C_R + - name: MOD_RC + args: + - A_R + - B_R + - C_C + - name: MOD_CC + args: + - A_R + - B_C + - C_C + - name: EXP_RR + args: + - A_R + - B_R + - C_R + - name: EXP_CR + args: + - A_R + - B_C + - C_R + - name: EXP_RC + args: + - A_R + - B_R + - C_C + - name: EXP_CC + args: + - A_R + - B_C + - C_C + - name: BAND_RR + args: + - A_R + - B_R + - C_R + - name: BAND_CR + args: + - A_R + - B_C + - C_R + - name: BAND_RC + args: + - A_R + - B_R + - C_C + - name: BAND_CC + args: + - A_R + - B_C + - C_C + - name: BOR_RR + args: + - A_R + - B_R + - C_R + - name: BOR_CR + args: + - A_R + - B_C + - C_R + - name: BOR_RC + args: + - A_R + - B_R + - C_C + - name: BOR_CC + args: + - A_R + - B_C + - C_C + - name: BXOR_RR + args: + - A_R + - B_R + - C_R + - name: BXOR_CR + args: + - A_R + - B_C + - C_R + - name: BXOR_RC + args: + - A_R + - B_R + - C_C + - name: BXOR_CC + args: + - A_R + - B_C + - C_C + - name: BASL_RR + args: + - A_R + - B_R + - C_R + - name: BASL_CR + args: + - A_R + - B_C + - C_R + - name: BASL_RC + args: + - A_R + - B_R + - C_C + - name: BASL_CC + args: + - A_R + - B_C + - C_C + - name: BLSR_RR + args: + - A_R + - B_R + - C_R + - name: BLSR_CR + args: + - A_R + - B_C + - C_R + - name: BLSR_RC + args: + - A_R + - B_R + - C_C + - name: BLSR_CC + args: + - A_R + - B_C + - C_C + - name: BASR_RR + args: + - A_R + - B_R + - C_R + - name: BASR_CR + args: + - A_R + - B_C + - C_R + - name: BASR_RC + args: + - A_R + - B_R + - C_C + - name: BASR_CC + args: + - A_R + - B_C + - C_C + - name: INSTOF_RR + args: + - A_R + - B_R + - C_R + - name: INSTOF_CR + args: + - A_R + - B_C + - C_R + - name: INSTOF_RC + args: + - A_R + - B_R + - C_C + - name: INSTOF_CC + args: + - A_R + - B_C + - C_C + - name: IN_RR + args: + - A_R + - B_R + - C_R + - name: IN_CR + args: + - A_R + - B_C + - C_R + - name: IN_RC + args: + - A_R + - B_R + - C_C + - name: IN_CC + args: + - A_R + - B_C + - C_C + - name: GETPROP_RR + args: + - A_R + - B_R + - C_R + - name: GETPROP_CR + args: + - A_R + - B_C + - C_R + - name: GETPROP_RC + args: + - A_R + - B_R + - C_C + - name: GETPROP_CC + args: + - A_R + - B_C + - C_C + - name: PUTPROP_RR + args: + - A_R + - B_R + - C_R + - name: PUTPROP_CR + args: + - A_R + - B_C + - C_R + - name: PUTPROP_RC + args: + - A_R + - B_R + - C_C + - name: PUTPROP_CC + args: + - A_R + - B_C + - C_C + - name: DELPROP_RR + args: + - A_R + - B_R + - C_R + - name: DELPROP_CR + args: + - A_R + - B_C + - C_R + - name: DELPROP_RC + args: + - A_R + - B_R + - C_C + - name: DELPROP_CC + args: + - A_R + - B_C + - C_C + - name: PREINCR + args: + - A_R + - BC_R + - name: PREDECR + args: + - A_R + - BC_R + - name: POSTINCR + args: + - A_R + - BC_R + - name: POSTDECR + args: + - A_R + - BC_R + - name: PREINCV + args: + - A_R + - BC_C + - name: PREDECV + args: + - A_R + - BC_C + - name: POSTINCV + args: + - A_R + - BC_C + - name: POSTDECV + args: + - A_R + - BC_C + - name: PREINCP_RR + args: + - A_R + - B_R + - C_R + - name: PREINCP_CR + args: + - A_R + - B_C + - C_R + - name: PREINCP_RC + args: + - A_R + - B_R + - C_C + - name: PREINCP_CC + args: + - A_R + - B_C + - C_C + - name: PREDECP_RR + args: + - A_R + - B_R + - C_R + - name: PREDECP_CR + args: + - A_R + - B_C + - C_R + - name: PREDECP_RC + args: + - A_R + - B_R + - C_C + - name: PREDECP_CC + args: + - A_R + - B_C + - C_C + - name: POSTINCP_RR + args: + - A_R + - B_R + - C_R + - name: POSTINCP_CR + args: + - A_R + - B_C + - C_R + - name: POSTINCP_RC + args: + - A_R + - B_R + - C_C + - name: POSTINCP_CC + args: + - A_R + - B_C + - C_C + - name: POSTDECP_RR + args: + - A_R + - B_R + - C_R + - name: POSTDECP_CR + args: + - A_R + - B_C + - C_R + - name: POSTDECP_RC + args: + - A_R + - B_R + - C_C + - name: POSTDECP_CC + args: + - A_R + - B_C + - C_C + - name: DECLVAR_RR + args: + - A_H + - B_R + - C_R + flags: + - mask: 0x100 + name: writable + - mask: 0x200 + name: enumerable + - mask: 0x400 + name: configurable + - mask: 0x800 + name: accessor + - mask: 0x1000 + name: func_decl + - name: DECLVAR_CR + args: + - A_H + - B_C + - C_R + flags: + - mask: 0x100 + name: writable + - mask: 0x200 + name: enumerable + - mask: 0x400 + name: configurable + - mask: 0x800 + name: accessor + - mask: 0x1000 + name: func_decl + - name: DECLVAR_RC + args: + - A_H + - B_R + - C_C + flags: + - mask: 0x100 + name: writable + - mask: 0x200 + name: enumerable + - mask: 0x400 + name: configurable + - mask: 0x800 + name: accessor + - mask: 0x1000 + name: func_decl + - name: DECLVAR_CC + args: + - A_H + - B_C + - C_C + flags: + - mask: 0x100 + name: writable + - mask: 0x200 + name: enumerable + - mask: 0x400 + name: configurable + - mask: 0x800 + name: accessor + - mask: 0x1000 + name: func_decl + - name: REGEXP_RR + args: + - A_R + - B_R + - C_R + - name: REGEXP_CR + args: + - A_R + - B_C + - C_R + - name: REGEXP_RC + args: + - A_R + - B_R + - C_C + - name: REGEXP_CC + args: + - A_R + - B_C + - C_C + - name: CLOSURE + args: + - A_R + - BC_I + - name: TYPEOF + args: + - A_R + - BC_R + - name: TYPEOFID + args: + - A_R + - BC_C + - name: PUTVAR + args: + - A_R + - BC_C + - name: DELVAR + args: + - A_R + - BC_C + - name: RETREG + args: + - BC_R + - name: RETUNDEF + - name: RETCONST + args: + - BC_C + - name: RETCONSTN + args: + - BC_C + - name: LABEL + args: + - BC_I + - name: ENDLABEL + args: + - BC_I + - name: BREAK + args: + - BC_I + - name: CONTINUE + args: + - BC_I + - name: TRYCATCH + args: + - A_H + # base register for two consecutive regs (base_reg + 0, base_reg + 1) used for two things: + # - input: either 'with' target register or catch varname constant (base_reg + 0), depending on flags + # - output: when caught, catch value (base_reg + 0) and type (base_reg + 1) + - BC_R + flags: + - mask: 0x40 + name: have_catch + - mask: 0x80 + name: have_finally + - mask: 0x100 + name: catch_binding + - mask: 0x200 + name: with_binding + - name: ENDTRY + - name: ENDCATCH + - name: ENDFIN + args: + - ABC_R + - name: THROW + args: + - BC_R + - name: INVLHS + - name: CSREG + args: + - A_R + - BC_R + - name: CSVAR_RR + args: + - A_R + - B_R + - name: CSVAR_CR + args: + - A_R + - B_C + - name: CSVAR_RC + args: + - A_R + - B_R + - name: CSVAR_CC + args: + - A_R + - B_C + - name: CALL0 + args: + - A_I + - BC_R + - name: CALL1 + args: + - A_I + - BC_R + - name: CALL2 + args: + - A_I + - BC_R + - name: CALL3 + args: + - A_I + - BC_R + - name: CALL4 + args: + - A_I + - BC_R + - name: CALL5 + args: + - A_I + - BC_R + - name: CALL6 + args: + - A_I + - BC_R + - name: CALL7 + args: + - A_I + - BC_R + - name: CALL8 + args: + - A_I + - BC_R + - name: CALL9 + args: + - A_I + - BC_R + - name: CALL10 + args: + - A_I + - BC_R + - name: CALL11 + args: + - A_I + - BC_R + - name: CALL12 + args: + - A_I + - BC_R + - name: CALL13 + args: + - A_I + - BC_R + - name: CALL14 + args: + - A_I + - BC_R + - name: CALL15 + args: + - A_I + - BC_R + - name: NEWOBJ + args: + - A_I # property count init size + - BC_R + - name: NEWARR + args: + - A_I # array item count init size + - BC_R + - name: MPUTOBJ + args: + - A_R + - B_R + - C_I + - name: MPUTOBJI + args: + - A_R + - B_RI + - C_I + - name: INITSET + args: + - A_R + - BC_R + - name: INITGET + args: + - A_R + - BC_R + - name: MPUTARR + args: + - A_R + - B_R + - C_I + - name: MPUTARRI + args: + - A_R + - B_RI + - C_I + - name: SETALEN + args: + - B_R + - C_R + - name: INITENUM + args: + - B_R + - C_R + - name: NEXTENUM + args: + - B_R + - C_R + - name: NEWTARGET + args: + - BC_R + - name: DEBUGGER + - name: NOP + args: + - ABC_I + - name: INVALID + args: + - ABC_I + - name: UNUSED207 + - name: GETPROPC_RR + args: + - A_R + - B_R + - C_R + - name: GETPROPC_CR + args: + - A_R + - B_C + - C_R + - name: GETPROPC_RC + args: + - A_R + - B_R + - C_C + - name: GETPROPC_CC + args: + - A_R + - B_C + - C_C + - name: UNUSED212 + - name: UNUSED213 + - name: UNUSED214 + - name: UNUSED215 + - name: UNUSED216 + - name: UNUSED217 + - name: UNUSED218 + - name: UNUSED219 + - name: UNUSED220 + - name: UNUSED221 + - name: UNUSED222 + - name: UNUSED223 + - name: UNUSED224 + - name: UNUSED225 + - name: UNUSED226 + - name: UNUSED227 + - name: UNUSED228 + - name: UNUSED229 + - name: UNUSED230 + - name: UNUSED231 + - name: UNUSED232 + - name: UNUSED233 + - name: UNUSED234 + - name: UNUSED235 + - name: UNUSED236 + - name: UNUSED237 + - name: UNUSED238 + - name: UNUSED239 + - name: UNUSED240 + - name: UNUSED241 + - name: UNUSED242 + - name: UNUSED243 + - name: UNUSED244 + - name: UNUSED245 + - name: UNUSED246 + - name: UNUSED247 + - name: UNUSED248 + - name: UNUSED249 + - name: UNUSED250 + - name: UNUSED251 + - name: UNUSED252 + - name: UNUSED253 + - name: UNUSED254 + - name: UNUSED255 diff --git a/lib/duktape-2.2.1/debugger/package.json b/lib/duktape-2.2.1/debugger/package.json new file mode 100644 index 0000000..870cf65 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/package.json @@ -0,0 +1,27 @@ +{ + "name": "duk-debug", + "version": "0.1.0", + "description": "Duktape debugger", + "author": { + "name": "Sami Vaarala", + "email": "sami.vaarala@iki.fi" + }, + "dependencies": { + "bluebird": "~2.6.4", + "body-parser": "~1.9.3", + "byline": "~4.2.1", + "events": "~1.0.2", + "express": "~4.10.1", + "http": "0.0.0", + "minimist": "~1.1.0", + "readline": "0.0.5", + "recursive-readdir-sync": "^1.0.6", + "socket.io": "~1.2.1", + "sprintf": "~0.1.5", + "stream": "0.0.2", + "utf8": "~2.0.0", + "util": "~0.10.3", + "yamljs": "~0.2.1" + }, + "main": "duk_debug.js" +} diff --git a/lib/duktape-2.2.1/debugger/static/index.html b/lib/duktape-2.2.1/debugger/static/index.html new file mode 100644 index 0000000..ff26ecb --- /dev/null +++ b/lib/duktape-2.2.1/debugger/static/index.html @@ -0,0 +1,96 @@ + + + + + + + +Duktape debugger + + + +

    +((o) Duktape debugger +
    + +
    + + + +
    +
    
    +// No source loaded
    +
    +
    +
    + +
    +
    +
    ?
    +
    ?
    ?
    +
    +
    +
    (output from script, print() and alert() calls)
    +
    +
    + +
    +
    +
    (callstack)
    +
    +
    +
    (locals)
    +
    +
    +
    (breakpoints)
    +
    +
    + watch (eval on pause) +
    + +
    +
    +
    + +
    + + + +
    +

    Duktape debugger is a web UI for debugging Ecmascript on a target device.

    +

    This web UI talks to a NodeJS debug server using socket.io. +The debug server talks to the target device using the Duktape debug protocol +(see debugger.rst).

    +
    + +
    +
    
    +
    + + + + + + + diff --git a/lib/duktape-2.2.1/debugger/static/style.css b/lib/duktape-2.2.1/debugger/static/style.css new file mode 100644 index 0000000..1b6dd86 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/static/style.css @@ -0,0 +1,517 @@ +// http://stackoverflow.com/questions/71074/how-to-remove-firefoxs-dotted-outline-on-buttons-as-well-as-links/3844452#3844452 +:focus { + outline: none; +} +::-moz-focus-inner { + border: 0; +} + +@keyframes pulsate { + from { opacity: 1; } + to { opacity: 0.25; } +} + +#part-header { + background: #444444; + color: #ffffff; + font: 24pt monospace; + border-bottom: 2px solid #cccccc; + padding: 20px 0px 20px 10px; +} + +/* http://css-tricks.com/snippets/css/a-guide-to-flexbox/ */ +#part-middle { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: space-between; + align-items: stretch; + align-content: stretch; + + min-height: 800px; + + border-top: 1px solid #ffffff; + padding: 8px; + margin-top: 2px; +} +#left-area { + flex: 0 0 11em; + margin-right: 20px; + margin-bottom: 10px; +} +#center-area { + flex: 1 1 0; + margin-bottom: 10px; +} +#right-area { + flex: 0 0 40em; + margin-left: 20px; + margin-bottom: 10px; +} + +#part-footer { + clear: both; + border-top: 2px solid #bbbbbb; + background: #eeeeee; + color: #555555; + text-align: center; + padding-top: 12px; + padding-bottom: 12px; + line-height: 1.5; +} + +#exec-status { + margin-top: 25px; + margin-bottom: 25px; +} +#exec-state { + display: inline-block; + vertical-align: middle; +} +#exec-other { + display: inline-block; + vertical-align: middle; + font-size: 125%; +} +#current-state { + background: #228822; + color: #ffffff; + font: 16pt; + padding: 6pt; + border: 5px solid #228822; + border-radius: 10px; + font-size: 200%; + font-weight: bold; + margin-right: 10px; +} +#current-state.notrunning { + background: #882222; + border: 5px solid #882222; + border-radius: 10px; + animation: pulsate 0.7s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate; +} +#exec-other:hover { + text-decoration: underline; + color: #9999ff; +} + +#left-area .button { + display: inline-block; + text-align: center; + width: 95%; + min-width: 6em; + background: #226622; + color: #ffffff; + font: 16pt sans-serif; + font-weight: bold; + text-decoration: none; + margin: 10px 0 0 0; + padding: 0.4em; + border: 2px solid #000000; + border-radius: 4px; +} +#left-area .button a { + color: #ffffff; + text-decoration: none; +} +#left-area .button:hover { + background: #55aa55; +} +#left-area .button:disabled { + background: #555555; + color: #888888; +} +#left-area .button:disabled a { + background: #555555; + color: #888888; +} + +#pause-button.pending { + background: #5555ff; + animation: pulsate 0.2s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate; +} + +#attach-button { +} +#attach-button.enabled { + animation: pulsate 0.7s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate; +} + +.duktape-exec-line { + outline: 2px solid red; + background: #550000; +} +.duktape-break-line { + outline: 2px solid white; +} + +#output { + font: 9pt monospace; + color: #000000; + border: 2px solid #cccccc; + border-radius: 5px; + padding: 3px; + height: 30ex; + overflow: scroll; + overflow-x: auto; + overflow-y: scroll; + white-space: pre; +} +#output .alert { + color: #ff0000; +} +/* Default color (should be overridden by level) */ +#output .log { + color: #00ff00; +} +/* Trace */ +#output .loglevel0 { + color: #cccccc; +} +/* Debug */ +#output .loglevel1 { + color: #cccccc; +} +/* Info */ +#output .loglevel2 { + color: #888888; + font-weight: bold; +} +/* Warn */ +#output .loglevel3 { + color: #ff4444; + font-weight: bold; +} +/* Error */ +#output .loglevel4 { + color: #ff0000; + font-weight: bold; +} +/* Fatal */ +#output .loglevel5 { + background: #000000; + color: #ff0000; + font-weight: bold; +} +#output .debugger-info { + color: #880000; + font-weight: bold; + font-style: italic; +} +#output .debugger-debug { + color: #888888; + font-weight: bold; + font-style: italic; +} + +#callstack { + font: 9pt monospace; + color: #000000; + margin-top: 10px; + border: 2px solid #cccccc; + border-radius: 5px; + padding: 3px; + height: 14ex; + overflow: scroll; + overflow-x: auto; + overflow-y: scroll; + white-space: pre; +} +#callstack div:nth-child(2n) { + background: #eeeeee; +} +#callstack .func { +} +#callstack .rest { + float: right; + color: #6666ff; +} +#callstack .rest:hover { + text-decoration: underline; + color: #9999ff; +} + +#locals { + font: 9pt monospace; + color: #000000; + margin-top: 10px; + border: 2px solid #cccccc; + border-radius: 5px; + padding: 10px; + height: 30ex; + overflow: scroll; + overflow-x: auto; + overflow-y: scroll; + white-space: pre; +} +#locals div:nth-child(2n) { + background: #eeeeee; +} +#locals .key { +} +#locals .value { + float: right; + color: #888888; +} + +#breakpoints { + color: #000000; + margin-top: 10px; + border: 2px solid #cccccc; + border-radius: 5px; + padding: 3px; + height: 15ex; + overflow: scroll; + overflow-x: auto; + overflow-y: scroll; + white-space: pre; +} +#breakpoints div { + margin: 2px 0 2px 0; +} +#breakpoints div:nth-child(2n) { + background: #eeeeee; +} +#breakpoints a { + font: 9pt monospace; + color: #6666ff; +} +#breakpoints a:hover { + text-decoration: underline; + color: #9999ff; +} +.breakpoint-line { + clear: both; + padding-top: 2px; + padding-bottom: 2px; +} +#add-breakpoint-file { + font: 10pt monospace; + width: 10em; + padding: 5px; +} +#add-breakpoint-line { + font: 10pt monospace; + width: 3em; + margin-left: 3px; + padding: 5px; +} +#delete-all-breakpoints-button { + float: right; + font: 10pt sans-serif; + padding: 5px; + border: 1px solid #888888; + background: #ddffdd; + color: #000000; +} +#delete-all-breakpoints-button:hover { + background: #f8fff8; +} +#delete-all-breakpoints-button:disabled { + background: #dddddd; + color: #444444; +} +#add-breakpoint-button { + font: 10pt sans-serif; + margin-left: 10px; + padding: 5px; + border: 1px solid #888888; + background: #ddffdd; + color: #000000; +} +#add-breakpoint-button:hover { + background: #f8fff8; +} +#add-breakpoint-button:disabled { + background: #dddddd; + color: #444444; +} +#breakpoint-hint { + color: #aaaaaa; + font-style: italic; + margin-left: 10px; +} +.delete-breakpoint-button { + float: right; + display: inline; + font: 9pt sans-serif; + padding: 3px; + border: none; + background: none; + color: #6666ff; +} +.delete-breakpoint-button { + font: 9pt sans-serif; +} +.delete-breakpoint-button:hover { + text-decoration: underline; + color: #9999ff; +} +.delete-breakpoint-button:disabled { + color: #888888; +} + +#about-dialog p { + margin: 10px 0 10px 0; +} + +#bytecode-dialog p { + margin: 10px 0 10px 0; +} +#bytecode-dialog pre { + font: 10pt monospace; + color: #000000; +} +#bytecode-dialog div.highlight { + background: #888888; + color: #ffffff; +} + +#eval { + color: #000000; + margin-top: 10px; + border: 2px solid #cccccc; + border-radius: 5px; + padding: 3px; + height: 30ex; + overflow: scroll; + overflow-x: auto; + overflow-y: scroll; + white-space: pre; +} +#eval-input { + display: inline; + font: 10pt monospace; + width: 20em; + padding: 5px; +} +#eval-button { + display: inline; + margin-left: 10px; + padding: 5px; + border: 1px solid #888888; + font: 10pt sans-serif; + background: #ddffdd; + color: #000000; +} +#eval-button { +} +#eval-button:hover { + background: #f8fff8; +} +#eval-button:disabled { + background: #dddddd; + color: #444444; +} +#eval-button.pending { + background: #5555ff; + animation: pulsate 0.2s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate; +} +#eval-watch { + margin-left: 20px; + vertical-align: middle; +} +#eval-output { + font: 10pt monospace; + white-space: pre; + padding: 5px; + border: 1px solid #888888; + min-height: 4ex; + margin-top: 5px; +} + +#varname-input { + font: 10pt monospace; + width: 10em; + padding: 5px; +} +#varvalue-input { + margin-left: 10px; + font: 10pt monospace; + width: 20em; + padding: 5px; +} +#getvar-button, +#putvar-button { + display: inline; + float: right; + margin-left: 10px; + padding: 5px; + border: 1px solid #888888; + font: 10pt sans-serif; + background: #ddffdd; + color: #000000; +} +#getvar-button:hover, +#putvar-button:hover { + background: #f8fff8; +} +#getvar-button:disabled, +#putvar-button:disabled { + background: #dddddd; + color: #444444; +} +#var-output { + font: 10pt monospace; + white-space: pre; + padding: 5px; + border: 1px solid #888888; + min-height: 4ex; + margin-top: 5px; +} + +#source-pre { + margin-top: 10px; + border: 2px solid #cccccc; + border-radius: 5px; + height: 400px; + overflow: scroll; + overflow-x: auto; + overflow-y: scroll; +} +#source-pre.running { + background: #eeeeee; + color: #888888; +} +#source-pre.running #source-code { + background: #eeeeee; + color: #888888; +} +#source-filename { + font-size: 125%; + color: #888888; +} +code.sourcecode { + counter-reset: source-line; +} +code.sourcecode div { + font: 10pt monospace; + padding: 2px 5px 2px 5px; + white-space: pre; + border-bottom: 1px solid #eeeeee; +} +code.sourcecode div:before { + display: inline-block; + content: counter(source-line); + counter-increment: source-line; + width: 4em; + color: #888888; + text-align: right; + margin-right: 20px; +} +code.sourcecode div.breakpoint:before { + margin-right: 0px; + border-right: 20px solid #ff0000; +} +code.sourcecode div.highlight { + background: #aaaaaa; + color: #000000; +} +code.sourcecode div.execution { + background: #000000; + color: #ffffff; +} + +#source-select { + margin-top: 5px; +} diff --git a/lib/duktape-2.2.1/debugger/static/webui.js b/lib/duktape-2.2.1/debugger/static/webui.js new file mode 100644 index 0000000..cb683f1 --- /dev/null +++ b/lib/duktape-2.2.1/debugger/static/webui.js @@ -0,0 +1,808 @@ +/* + * Duktape debugger web client + * + * Talks to the NodeJS server using socket.io. + * + * http://unixpapa.com/js/key.html + */ + +// Update interval for custom source highlighting. +var SOURCE_UPDATE_INTERVAL = 350; + +// Source view +var activeFileName = null; // file that we want to be loaded in source view +var activeLine = null; // scroll to line once file has been loaded +var activeHighlight = null; // line that we want to highlight (if any) +var loadedFileName = null; // currently loaded (shown) file +var loadedLineCount = 0; // currently loaded file line count +var loadedFileExecuting = false; // true if currFileName (loosely) matches loadedFileName +var loadedLinePending = null; // if set, scroll loaded file to requested line +var highlightLine = null; // highlight line +var sourceEditedLines = []; // line numbers which have been modified + // (added classes etc, tracked for removing) +var sourceUpdateInterval = null; // timer for updating source view +var sourceFetchXhr = null; // current AJAX request for fetching a source file (if any) +var forceButtonUpdate = false; // hack to reset button states +var bytecodeDialogOpen = false; // bytecode dialog active +var bytecodeIdxHighlight = null; // index of currently highlighted line (or null) +var bytecodeIdxInstr = 0; // index to first line of bytecode instructions + +// Execution state +var prevState = null; // previous execution state ('paused', 'running', etc) +var prevAttached = null; // previous debugger attached state (true, false, null) +var currFileName = null; // current filename being executed +var currFuncName = null; // current function name being executed +var currLine = 0; // current line being executed +var currPc = 0; // current bytecode PC being executed +var currState = 0; // current execution state ('paused', 'running', 'detached', etc) +var currAttached = false; // current debugger attached state (true or false) +var currLocals = []; // current local variables +var currCallstack = []; // current callstack (from top to bottom) +var currBreakpoints = []; // current breakpoints +var startedRunning = 0; // timestamp when last started running (if running) + // (used to grey out the source file if running for long enough) + +/* + * Helpers + */ + +function formatBytes(x) { + if (x < 1024) { + return String(x) + ' bytes'; + } else if (x < 1024 * 1024) { + return (x / 1024).toPrecision(3) + ' kB'; + } else { + return (x / (1024 * 1024)).toPrecision(3) + ' MB'; + } +} + +/* + * Source view periodic update handling + */ + +function doSourceUpdate() { + var elem; + + // Remove previously added custom classes + sourceEditedLines.forEach(function (linenum) { + elem = $('#source-code div')[linenum - 1]; + if (elem) { + elem.classList.remove('breakpoint'); + elem.classList.remove('execution'); + elem.classList.remove('highlight'); + } + }); + sourceEditedLines.length = 0; + + // If we're executing the file shown, highlight current line + if (loadedFileExecuting) { + elem = $('#source-code div')[currLine - 1]; + if (elem) { + sourceEditedLines.push(currLine); + elem.classList.add('execution'); + } + } + + // Add breakpoints + currBreakpoints.forEach(function (bp) { + if (bp.fileName === loadedFileName) { + elem = $('#source-code div')[bp.lineNumber - 1]; + if (elem) { + sourceEditedLines.push(bp.lineNumber); + elem.classList.add('breakpoint'); + } + } + }); + + if (highlightLine !== null) { + elem = $('#source-code div')[highlightLine - 1]; + if (elem) { + sourceEditedLines.push(highlightLine); + elem.classList.add('highlight'); + } + } + + // Bytecode dialog highlight + if (loadedFileExecuting && bytecodeDialogOpen && bytecodeIdxHighlight !== bytecodeIdxInstr + currPc) { + if (typeof bytecodeIdxHighlight === 'number') { + $('#bytecode-preformatted div')[bytecodeIdxHighlight].classList.remove('highlight'); + } + bytecodeIdxHighlight = bytecodeIdxInstr + currPc; + $('#bytecode-preformatted div')[bytecodeIdxHighlight].classList.add('highlight'); + } + + // If no-one requested us to scroll to a specific line, finish. + if (loadedLinePending == null) { + return; + } + + var reqLine = loadedLinePending; + loadedLinePending = null; + + // Scroll to requested line. This is not very clean, so a better solution + // should be found: + // https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollIntoView + // http://erraticdev.blogspot.fi/2011/02/jquery-scroll-into-view-plugin-with.html + // http://flesler.blogspot.fi/2007/10/jqueryscrollto.html + var tmpLine = Math.max(reqLine - 5, 0); + elem = $('#source-code div')[tmpLine]; + if (elem) { + elem.scrollIntoView(); + } +} + +// Source is updated periodically. Other code can also call doSourceUpdate() +// directly if an immediate update is needed. +sourceUpdateInterval = setInterval(doSourceUpdate, SOURCE_UPDATE_INTERVAL); + +/* + * UI update handling when exec-status update arrives + */ + +function doUiUpdate() { + var now = Date.now(); + + // Note: loadedFileName can be either from target or from server, but they + // must match exactly. We could do a loose match here, but exact matches + // are needed for proper breakpoint handling anyway. + loadedFileExecuting = (loadedFileName === currFileName); + + // If we just started running, store a timestamp so we can grey out the + // source view only if we execute long enough (i.e. we're not just + // stepping). + if (currState !== prevState && currState === 'running') { + startedRunning = now; + } + + // If we just became paused, check for eval watch + if (currState !== prevState && currState === 'paused') { + if ($('#eval-watch').is(':checked')) { + submitEval(); // don't clear eval input + } + } + + // Update current execution state + if (currFileName === '' && currLine === 0) { + $('#current-fileline').text(''); + } else { + $('#current-fileline').text(String(currFileName) + ':' + String(currLine)); + } + if (currFuncName === '' && currPc === 0) { + $('#current-funcpc').text(''); + } else { + $('#current-funcpc').text(String(currFuncName) + '() pc ' + String(currPc)); + } + $('#current-state').text(String(currState)); + + // Update buttons + if (currState !== prevState || currAttached !== prevAttached || forceButtonUpdate) { + $('#stepinto-button').prop('disabled', !currAttached || currState !== 'paused'); + $('#stepover-button').prop('disabled', !currAttached || currState !== 'paused'); + $('#stepout-button').prop('disabled', !currAttached || currState !== 'paused'); + $('#resume-button').prop('disabled', !currAttached || currState !== 'paused'); + $('#pause-button').prop('disabled', !currAttached || currState !== 'running'); + $('#attach-button').prop('disabled', currAttached); + if (currAttached) { + $('#attach-button').removeClass('enabled'); + } else { + $('#attach-button').addClass('enabled'); + } + $('#detach-button').prop('disabled', !currAttached); + $('#eval-button').prop('disabled', !currAttached); + $('#add-breakpoint-button').prop('disabled', !currAttached); + $('#delete-all-breakpoints-button').prop('disabled', !currAttached); + $('.delete-breakpoint-button').prop('disabled', !currAttached); + $('#putvar-button').prop('disabled', !currAttached); + $('#getvar-button').prop('disabled', !currAttached); + $('#heap-dump-download-button').prop('disabled', !currAttached); + } + if (currState !== 'running' || forceButtonUpdate) { + // Remove pending highlight once we're no longer running. + $('#pause-button').removeClass('pending'); + $('#eval-button').removeClass('pending'); + } + forceButtonUpdate = false; + + // Make source window grey when running for a longer time, use a small + // delay to avoid flashing grey when stepping. + if (currState === 'running' && now - startedRunning >= 500) { + $('#source-pre').removeClass('notrunning'); + $('#current-state').removeClass('notrunning'); + } else { + $('#source-pre').addClass('notrunning'); + $('#current-state').addClass('notrunning'); + } + + // Force source view to match currFileName only when running or when + // just became paused (from running or detached). + var fetchSource = false; + if (typeof currFileName === 'string') { + if (currState === 'running' || + (prevState !== 'paused' && currState === 'paused') || + (currAttached !== prevAttached)) { + if (activeFileName !== currFileName) { + fetchSource = true; + activeFileName = currFileName; + activeLine = currLine; + activeHighlight = null; + requestSourceRefetch(); + } + } + } + + // Force line update (scrollTop) only when running or just became paused. + // Otherwise let user browse and scroll source files freely. + if (!fetchSource) { + if ((prevState !== 'paused' && currState === 'paused') || + currState === 'running') { + loadedLinePending = currLine || 0; + } + } +} + +/* + * Init socket.io and add handlers + */ + +var socket = io(); // returns a Manager + +setInterval(function () { + socket.emit('keepalive', { + userAgent: (navigator || {}).userAgent + }); +}, 30000); + +socket.on('connect', function () { + $('#socketio-info').text('connected'); + currState = 'connected'; + + fetchSourceList(); +}); +socket.on('disconnect', function () { + $('#socketio-info').text('not connected'); + currState = 'disconnected'; +}); +socket.on('reconnecting', function () { + $('#socketio-info').text('reconnecting'); + currState = 'reconnecting'; +}); +socket.on('error', function (err) { + $('#socketio-info').text(err); +}); + +socket.on('replaced', function () { + // XXX: how to minimize the chance we'll further communciate with the + // server or reconnect to it? socket.reconnection()? + + // We'd like to window.close() here but can't (not allowed from scripts). + // Alert is the next best thing. + alert('Debugger connection replaced by a new one, do you have multiple tabs open? If so, please close this tab.'); +}); + +socket.on('keepalive', function (msg) { + // Not really interesting in the UI + // $('#server-info').text(new Date() + ': ' + JSON.stringify(msg)); +}); + +socket.on('basic-info', function (msg) { + $('#duk-version').text(String(msg.duk_version)); + $('#duk-git-describe').text(String(msg.duk_git_describe)); + $('#target-info').text(String(msg.target_info)); + $('#endianness').text(String(msg.endianness)); +}); + +socket.on('exec-status', function (msg) { + // Not 100% reliable if callstack has several functions of the same name + if (bytecodeDialogOpen && (currFileName != msg.fileName || currFuncName != msg.funcName)) { + socket.emit('get-bytecode', {}); + } + + currFileName = msg.fileName; + currFuncName = msg.funcName; + currLine = msg.line; + currPc = msg.pc; + currState = msg.state; + currAttached = msg.attached; + + // Duktape now restricts execution status updates quite effectively so + // there's no need to rate limit UI updates now. + + doUiUpdate(); + + prevState = currState; + prevAttached = currAttached; +}); + +// Update the "console" output based on lines sent by the server. The server +// rate limits these updates to keep the browser load under control. Even +// better would be for the client to pull this (and other stuff) on its own. +socket.on('output-lines', function (msg) { + var elem = $('#output'); + var i, n, ent; + + elem.empty(); + for (i = 0, n = msg.length; i < n; i++) { + ent = msg[i]; + if (ent.type === 'print') { + elem.append($('
    ').text(ent.message)); + } else if (ent.type === 'alert') { + elem.append($('
    ').text(ent.message)); + } else if (ent.type === 'log') { + elem.append($('
    ').text(ent.message)); + } else if (ent.type === 'debugger-info') { + elem.append($('
    ').text(ent.message)); + } else if (ent.type === 'debugger-debug') { + elem.append($('
    ').text(ent.message)); + } else { + elem.append($('
    ').text(ent.message)); + } + } + + // http://stackoverflow.com/questions/14918787/jquery-scroll-to-bottom-of-div-even-after-it-updates + // Stop queued animations so that we always scroll quickly to bottom + $('#output').stop(true); + $('#output').animate({ scrollTop: $('#output')[0].scrollHeight}, 1000); +}); + +socket.on('callstack', function (msg) { + var elem = $('#callstack'); + var s1, s2, div; + + currCallstack = msg.callstack; + + elem.empty(); + msg.callstack.forEach(function (e) { + s1 = $('').text(e.fileName + ':' + e.lineNumber + ' (pc ' + e.pc + ')'); // float + s1.on('click', function () { + activeFileName = e.fileName; + activeLine = e.lineNumber || 1; + activeHighlight = activeLine; + requestSourceRefetch(); + }); + s2 = $('').text(e.funcName + '()'); + div = $('
    '); + div.append(s1); + div.append(s2); + elem.append(div); + }); +}); + +socket.on('locals', function (msg) { + var elem = $('#locals'); + var s1, s2, div; + var i, n, e; + + currLocals = msg.locals; + + elem.empty(); + for (i = 0, n = msg.locals.length; i < n; i++) { + e = msg.locals[i]; + s1 = $('').text(e.value); // float + s2 = $('').text(e.key); + div = $('
    '); + div.append(s1); + div.append(s2); + elem.append(div); + } +}); + +socket.on('debug-stats', function (msg) { + $('#debug-rx-bytes').text(formatBytes(msg.rxBytes)); + $('#debug-rx-dvalues').text(msg.rxDvalues); + $('#debug-rx-messages').text(msg.rxMessages); + $('#debug-rx-kbrate').text((msg.rxBytesPerSec / 1024).toFixed(2)); + $('#debug-tx-bytes').text(formatBytes(msg.txBytes)); + $('#debug-tx-dvalues').text(msg.txDvalues); + $('#debug-tx-messages').text(msg.txMessages); + $('#debug-tx-kbrate').text((msg.txBytesPerSec / 1024).toFixed(2)); +}); + +socket.on('breakpoints', function (msg) { + var elem = $('#breakpoints'); + var div; + var sub; + + currBreakpoints = msg.breakpoints; + + elem.empty(); + + // First line is special + div = $('
    '); + sub = $('').text('Delete all breakpoints'); + sub.on('click', function () { + socket.emit('delete-all-breakpoints'); + }); + div.append(sub); + sub = $('').val('file.js'); + div.append(sub); + sub = $('').text(':'); + div.append(sub); + sub = $('').val('123'); + div.append(sub); + sub = $('').text('Add breakpoint'); + sub.on('click', function () { + socket.emit('add-breakpoint', { + fileName: $('#add-breakpoint-file').val(), + lineNumber: Number($('#add-breakpoint-line').val()) + }); + }); + div.append(sub); + sub = $('').text('or dblclick source'); + div.append(sub); + elem.append(div); + + // Active breakpoints follow + msg.breakpoints.forEach(function (bp) { + var div; + var sub; + + div = $('
    '); + sub = $('').text('Delete'); + sub.on('click', function () { + socket.emit('delete-breakpoint', { + fileName: bp.fileName, + lineNumber: bp.lineNumber + }); + }); + div.append(sub); + sub = $('').text((bp.fileName || '?') + ':' + (bp.lineNumber || 0)); + sub.on('click', function () { + activeFileName = bp.fileName || ''; + activeLine = bp.lineNumber || 1; + activeHighlight = activeLine; + requestSourceRefetch(); + }); + div.append(sub); + elem.append(div); + }); + + forceButtonUpdate = true; + doUiUpdate(); +}); + +socket.on('eval-result', function (msg) { + $('#eval-output').text((msg.error ? 'ERROR: ' : '') + msg.result); + + // Remove eval button "pulsating" glow when we get a result + $('#eval-button').removeClass('pending'); +}); + +socket.on('getvar-result', function (msg) { + $('#var-output').text(msg.found ? msg.result : 'NOTFOUND'); +}); + +socket.on('bytecode', function (msg) { + var elem, div; + var div; + + elem = $('#bytecode-preformatted'); + elem.empty(); + + msg.preformatted.split('\n').forEach(function (line, idx) { + div = $('
    '); + div.text(line); + elem.append(div); + }); + + bytecodeIdxHighlight = null; + bytecodeIdxInstr = msg.idxPreformattedInstructions; +}); + +$('#stepinto-button').click(function () { + socket.emit('stepinto', {}); +}); + +$('#stepover-button').click(function () { + socket.emit('stepover', {}); +}); + +$('#stepout-button').click(function () { + socket.emit('stepout', {}); +}); + +$('#pause-button').click(function () { + socket.emit('pause', {}); + + // Pause may take seconds to complete so indicate it is pending. + $('#pause-button').addClass('pending'); +}); + +$('#resume-button').click(function () { + socket.emit('resume', {}); +}); + +$('#attach-button').click(function () { + socket.emit('attach', {}); +}); + +$('#detach-button').click(function () { + socket.emit('detach', {}); +}); + +$('#about-button').click(function () { + $('#about-dialog').dialog('open'); +}); + +$('#show-bytecode-button').click(function () { + bytecodeDialogOpen = true; + $('#bytecode-dialog').dialog('open'); + + elem = $('#bytecode-preformatted'); + elem.empty().text('Loading bytecode...'); + + socket.emit('get-bytecode', {}); +}); + +function submitEval() { + socket.emit('eval', { input: $('#eval-input').val() }); + + // Eval may take seconds to complete so indicate it is pending. + $('#eval-button').addClass('pending'); +} + +$('#eval-button').click(function () { + submitEval(); + $('#eval-input').val(''); +}); + +$('#getvar-button').click(function () { + socket.emit('getvar', { varname: $('#varname-input').val() }); +}); + +$('#putvar-button').click(function () { + // The variable value is parsed as JSON right now, but it'd be better to + // also be able to parse buffer values etc. + var val = JSON.parse($('#varvalue-input').val()); + socket.emit('putvar', { varname: $('#varname-input').val(), varvalue: val }); +}); + +$('#source-code').dblclick(function (event) { + var target = event.target; + var elems = $('#source-code div'); + var i, n; + var line = 0; + + // XXX: any faster way; elems doesn't have e.g. indexOf() + for (i = 0, n = elems.length; i < n; i++) { + if (target === elems[i]) { + line = i + 1; + } + } + + socket.emit('toggle-breakpoint', { + fileName: loadedFileName, + lineNumber: line + }); +}); + +function setSourceText(data) { + var elem, div; + + elem = $('#source-code'); + elem.empty(); + data.split('\n').forEach(function (line) { + div = $('
    '); + div.text(line); + elem.append(div); + }); + + sourceEditedLines = []; +} + +function setSourceSelect(fileName) { + var elem; + var i, n, t; + + if (fileName == null) { + $('#source-select').val('__none__'); + return; + } + + elem = $('#source-select option'); + for (i = 0, n = elem.length; i < n; i++) { + // Exact match is required. + t = $(elem[i]).val(); + if (t === fileName) { + $('#source-select').val(t); + return; + } + } +} + +/* + * AJAX request handling to fetch source files + */ + +function requestSourceRefetch() { + // If previous update is pending, abort and start a new one. + if (sourceFetchXhr) { + sourceFetchXhr.abort(); + sourceFetchXhr = null; + } + + // Make copies of the requested file/line so that we have the proper + // values in case they've changed. + var fileName = activeFileName; + var lineNumber = activeLine; + + // AJAX request for the source. + sourceFetchXhr = $.ajax({ + type: 'POST', + url: '/source', + data: JSON.stringify({ fileName: fileName }), + contentType: 'application/json', + success: function (data, status, jqxhr) { + var elem; + + sourceFetchXhr = null; + + loadedFileName = fileName; + loadedLineCount = data.split('\n').length; // XXX: ignore issue with last empty line for now + loadedFileExecuting = (loadedFileName === currFileName); + setSourceText(data); + setSourceSelect(fileName); + loadedLinePending = activeLine || 1; + highlightLine = activeHighlight; // may be null + activeLine = null; + activeHighlight = null; + doSourceUpdate(); + + // XXX: hacky transition, make source change visible + $('#source-pre').fadeTo('fast', 0.25, function () { + $('#source-pre').fadeTo('fast', 1.0); + }); + }, + error: function (jqxhr, status, err) { + // Not worth alerting about because source fetch errors happen + // all the time, e.g. for dynamically evaluated code. + + sourceFetchXhr = null; + + // XXX: prevent retry of no-such-file by negative caching? + loadedFileName = fileName; + loadedLineCount = 1; + loadedFileExecuting = false; + setSourceText('// Cannot load source file: ' + fileName); + setSourceSelect(null); + loadedLinePending = 1; + activeLine = null; + activeHighlight = null; + doSourceUpdate(); + + // XXX: error transition here + $('#source-pre').fadeTo('fast', 0.25, function () { + $('#source-pre').fadeTo('fast', 1.0); + }); + }, + dataType: 'text' + }); +} + +/* + * AJAX request for fetching the source list + */ + +function fetchSourceList() { + $.ajax({ + type: 'POST', + url: '/sourceList', + data: JSON.stringify({}), + contentType: 'application/json', + success: function (data, status, jqxhr) { + var elem = $('#source-select'); + + data = JSON.parse(data); + + elem.empty(); + var opt = $('').attr({ 'value': '__none__' }).text('No source file selected'); + elem.append(opt); + data.forEach(function (ent) { + var opt = $('').attr({ 'value': ent }).text(ent); + elem.append(opt); + }); + elem.change(function () { + activeFileName = elem.val(); + activeLine = 1; + requestSourceRefetch(); + }); + }, + error: function (jqxhr, status, err) { + // This is worth alerting about as the UI is somewhat unusable + // if we don't get a source list. + + alert('Failed to load source list: ' + err); + }, + dataType: 'text' + }); +} + +/* + * Initialization + */ + +$(document).ready(function () { + var showAbout = true; + + // About dialog, shown automatically on first startup. + $('#about-dialog').dialog({ + autoOpen: false, + hide: 'fade', // puff + show: 'fade', // slide, puff + width: 500, + height: 300 + }); + + // Bytecode dialog + $('#bytecode-dialog').dialog({ + autoOpen: false, + hide: 'fade', // puff + show: 'fade', // slide, puff + width: 700, + height: 600, + close: function () { + bytecodeDialogOpen = false; + bytecodeIdxHighlight = null; + bytecodeIdxInstr = 0; + } + }); + + // http://diveintohtml5.info/storage.html + if (typeof localStorage !== 'undefined') { + if (localStorage.getItem('about-shown')) { + showAbout = false; + } else { + localStorage.setItem('about-shown', 'yes'); + } + } + if (showAbout) { + $('#about-dialog').dialog('open'); + } + + // onclick handler for exec status text + function loadCurrFunc() { + activeFileName = currFileName; + activeLine = currLine; + requestSourceRefetch(); + } + $('#exec-other').on('click', loadCurrFunc); + + // Enter handling for eval input + // https://forum.jquery.com/topic/bind-html-input-to-enter-key-keypress + $('#eval-input').keypress(function (event) { + if (event.keyCode == 13) { + submitEval(); + $('#eval-input').val(''); + } + }); + + // Eval watch handling + $('#eval-watch').change(function () { + // nop + }); + + // Function keys + $('body').keydown(function(e){ + //alert("keydown: "+e.which); + switch (e.which) { + case 116: // F5: step into + socket.emit('stepinto', {}); + e.preventDefault(); + return; + case 117: // F6: step over + socket.emit('stepover', {}); + e.preventDefault(); + return; + case 118: // F7: step out (= step return) + socket.emit('stepout', {}); + e.preventDefault(); + return; + case 119: // F8: resume + socket.emit('resume', {}); + e.preventDefault(); + return; + } + }); + + forceButtonUpdate = true; + doUiUpdate(); +}); diff --git a/lib/duktape-2.2.1/duk_dist_meta.json b/lib/duktape-2.2.1/duk_dist_meta.json new file mode 100644 index 0000000..e2d8758 --- /dev/null +++ b/lib/duktape-2.2.1/duk_dist_meta.json @@ -0,0 +1,9 @@ +{ + "comment": "Metadata for Duktape distributable", + "duk_version_string": "2.2.1", + "type": "duk_dist_meta", + "duk_version": 20201, + "git_branch": "v2.2-maintenance", + "git_commit": "25420e773c5fbc50d5b46bf487fc45717e35b94f", + "git_describe": "v2.2.1" +} \ No newline at end of file diff --git a/lib/duktape-2.2.1/examples/README.rst b/lib/duktape-2.2.1/examples/README.rst new file mode 100644 index 0000000..f254432 --- /dev/null +++ b/lib/duktape-2.2.1/examples/README.rst @@ -0,0 +1,10 @@ +================ +Duktape examples +================ + +Examples for using Duktape. These support user documentation and are +intended as informative illustrations only. + +Examples are unmaintained and are not production quality code. Bugs are +not not necessarily fixed, unless the bug makes the example misleading +as documentation. diff --git a/lib/duktape-2.2.1/examples/alloc-hybrid/README.rst b/lib/duktape-2.2.1/examples/alloc-hybrid/README.rst new file mode 100644 index 0000000..ed63a13 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-hybrid/README.rst @@ -0,0 +1,10 @@ +===================== +Hybrid pool allocator +===================== + +Example allocator that tries to satisfy memory allocations for small sizes +from a set of fixed pools, but always falls back to malloc/realloc/free if +a larger size is requested or the pools have been exhausted. + +This may be useful to reduce memory churn when the platform allocator does +not handle allocations for a lot of small memory areas efficiently. diff --git a/lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.c b/lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.c new file mode 100644 index 0000000..3f63249 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.c @@ -0,0 +1,294 @@ +/* + * Example memory allocator with pool allocation for small sizes and + * fallback into malloc/realloc/free for larger sizes or when the pools + * are exhausted. + * + * Useful to reduce memory churn or work around a platform allocator + * that doesn't handle a lot of small allocations efficiently. + */ + +#include "duktape.h" +#include +#include +#include +#include +#include "duk_alloc_hybrid.h" + +/* Define to enable some debug printfs. */ +/* #define DUK_ALLOC_HYBRID_DEBUG */ + +typedef struct { + size_t size; + int count; +} pool_size_spec; + +static pool_size_spec pool_sizes[] = { + { 32, 1024 }, + { 48, 2048 }, + { 64, 2048 }, + { 128, 2048 }, + { 256, 512 }, + { 1024, 64 }, + { 2048, 32 } +}; + +#define NUM_POOLS (sizeof(pool_sizes) / sizeof(pool_size_spec)) + +/* This must fit into the smallest pool entry. */ +struct pool_free_entry; +typedef struct pool_free_entry pool_free_entry; +struct pool_free_entry { + pool_free_entry *next; +}; + +typedef struct { + pool_free_entry *free; + char *alloc_start; + char *alloc_end; + size_t size; + int count; +} pool_header; + +typedef struct { + pool_header headers[NUM_POOLS]; + size_t pool_max_size; + char *alloc_start; + char *alloc_end; +} pool_state; + +#define ADDR_IN_STATE_ALLOC(st,p) \ + ((char *) (p) >= (st)->alloc_start && (char *) (p) < (st)->alloc_end) +#define ADDR_IN_HEADER_ALLOC(hdr,p) \ + ((char *) (p) >= (hdr)->alloc_start && (char *) (p) < (hdr)->alloc_end) + +#if defined(DUK_ALLOC_HYBRID_DEBUG) +static void dump_pool_state(pool_state *st) { + pool_free_entry *free; + int free_len; + int i; + + printf("=== Pool state: st=%p\n", (void *) st); + for (i = 0; i < (int) NUM_POOLS; i++) { + pool_header *hdr = st->headers + i; + + for (free = hdr->free, free_len = 0; free != NULL; free = free->next) { + free_len++; + } + + printf("[%d]: size %ld, count %ld, used %ld, free list len %ld\n", + i, (long) hdr->size, (long) hdr->count, + (long) (hdr->count - free_len), + (long) free_len); + } +} +#else +static void dump_pool_state(pool_state *st) { + (void) st; +} +#endif + +void *duk_alloc_hybrid_init(void) { + pool_state *st; + size_t total_size, max_size; + int i, j; + char *p; + + st = (pool_state *) malloc(sizeof(pool_state)); + if (!st) { + return NULL; + } + memset((void *) st, 0, sizeof(pool_state)); + st->alloc_start = NULL; + st->alloc_end = NULL; + + for (i = 0, total_size = 0, max_size = 0; i < (int) NUM_POOLS; i++) { +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("Pool %d: size %ld, count %ld\n", i, (long) pool_sizes[i].size, (long) pool_sizes[i].count); +#endif + total_size += pool_sizes[i].size * (size_t) pool_sizes[i].count; + if (pool_sizes[i].size > max_size) { + max_size = pool_sizes[i].size; + } + } +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("Total size %ld, max pool size %ld\n", (long) total_size, (long) max_size); +#endif + + st->alloc_start = (char *) malloc(total_size); + if (!st->alloc_start) { + free(st); + return NULL; + } + st->alloc_end = st->alloc_start + total_size; + st->pool_max_size = max_size; + memset((void *) st->alloc_start, 0, total_size); + + for (i = 0, p = st->alloc_start; i < (int) NUM_POOLS; i++) { + pool_header *hdr = st->headers + i; + + hdr->alloc_start = p; + hdr->alloc_end = p + pool_sizes[i].size * (size_t) pool_sizes[i].count; + hdr->free = (pool_free_entry *) (void *) p; + hdr->size = pool_sizes[i].size; + hdr->count = pool_sizes[i].count; + + for (j = 0; j < pool_sizes[i].count; j++) { + pool_free_entry *ent = (pool_free_entry *) (void *) p; + if (j == pool_sizes[i].count - 1) { + ent->next = (pool_free_entry *) NULL; + } else { + ent->next = (pool_free_entry *) (void *) (p + pool_sizes[i].size); + } + p += pool_sizes[i].size; + } + } + + dump_pool_state(st); + + /* Use 'st' as udata. */ + return (void *) st; +} + +void *duk_alloc_hybrid(void *udata, duk_size_t size) { + pool_state *st = (pool_state *) udata; + int i; + void *new_ptr; + +#if 0 + dump_pool_state(st); +#endif + + if (size == 0) { + return NULL; + } + if (size > st->pool_max_size) { +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("alloc fallback: %ld\n", (long) size); +#endif + return malloc(size); + } + + for (i = 0; i < (int) NUM_POOLS; i++) { + pool_header *hdr = st->headers + i; + if (hdr->size < size) { + continue; + } + + if (hdr->free) { +#if 0 + printf("alloc from pool: %ld -> pool size %ld\n", (long) size, (long) hdr->size); +#endif + new_ptr = (void *) hdr->free; + hdr->free = hdr->free->next; + return new_ptr; + } else { +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("alloc out of pool entries: %ld -> pool size %ld\n", (long) size, (long) hdr->size); +#endif + break; + } + } + +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("alloc fallback (out of pool): %ld\n", (long) size); +#endif + return malloc(size); +} + +void *duk_realloc_hybrid(void *udata, void *ptr, duk_size_t size) { + pool_state *st = (pool_state *) udata; + void *new_ptr; + int i; + +#if 0 + dump_pool_state(st); +#endif + + if (ADDR_IN_STATE_ALLOC(st, ptr)) { + /* 'ptr' cannot be NULL. */ + for (i = 0; i < (int) NUM_POOLS; i++) { + pool_header *hdr = st->headers + i; + if (ADDR_IN_HEADER_ALLOC(hdr, ptr)) { + if (size <= hdr->size) { + /* Still fits, no shrink support. */ +#if 0 + printf("realloc original from pool: still fits, size %ld, pool size %ld\n", + (long) size, (long) hdr->size); +#endif + return ptr; + } + + new_ptr = duk_alloc_hybrid(udata, size); + if (!new_ptr) { +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("realloc original from pool: needed larger size, failed to alloc\n"); +#endif + return NULL; + } + memcpy(new_ptr, ptr, hdr->size); + + ((pool_free_entry *) ptr)->next = hdr->free; + hdr->free = (pool_free_entry *) ptr; +#if 0 + printf("realloc original from pool: size %ld, pool size %ld\n", (long) size, (long) hdr->size); +#endif + return new_ptr; + } + } +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("NEVER HERE\n"); +#endif + return NULL; + } else if (ptr != NULL) { + if (size == 0) { + free(ptr); + return NULL; + } else { +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("realloc fallback: size %ld\n", (long) size); +#endif + return realloc(ptr, size); + } + } else { +#if 0 + printf("realloc NULL ptr, call alloc: %ld\n", (long) size); +#endif + return duk_alloc_hybrid(udata, size); + } +} + +void duk_free_hybrid(void *udata, void *ptr) { + pool_state *st = (pool_state *) udata; + int i; + +#if 0 + dump_pool_state(st); +#endif + + if (!ADDR_IN_STATE_ALLOC(st, ptr)) { + if (ptr == NULL) { + return; + } +#if 0 + printf("free out of pool: %p\n", (void *) ptr); +#endif + free(ptr); + return; + } + + for (i = 0; i < (int) NUM_POOLS; i++) { + pool_header *hdr = st->headers + i; + if (ADDR_IN_HEADER_ALLOC(hdr, ptr)) { + ((pool_free_entry *) ptr)->next = hdr->free; + hdr->free = (pool_free_entry *) ptr; +#if 0 + printf("free from pool: %p\n", ptr); +#endif + return; + } + } + +#if defined(DUK_ALLOC_HYBRID_DEBUG) + printf("NEVER HERE\n"); +#endif +} diff --git a/lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.h b/lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.h new file mode 100644 index 0000000..d8c09e9 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-hybrid/duk_alloc_hybrid.h @@ -0,0 +1,11 @@ +#if !defined(DUK_ALLOC_HYBRID_H_INCLUDED) +#define DUK_ALLOC_HYBRID_H_INCLUDED + +#include "duktape.h" + +void *duk_alloc_hybrid_init(void); +void *duk_alloc_hybrid(void *udata, duk_size_t size); +void *duk_realloc_hybrid(void *udata, void *ptr, duk_size_t size); +void duk_free_hybrid(void *udata, void *ptr); + +#endif /* DUK_ALLOC_HYBRID_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/alloc-logging/README.rst b/lib/duktape-2.2.1/examples/alloc-logging/README.rst new file mode 100644 index 0000000..97c1a32 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-logging/README.rst @@ -0,0 +1,7 @@ +====================== +Allocator with logging +====================== + +Example allocator that writes all memory alloc/realloc/free calls into a +log file so that memory usage can replayed later. This is useful to e.g. +optimize pool sizes. diff --git a/lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.c b/lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.c new file mode 100644 index 0000000..b78fde4 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.c @@ -0,0 +1,139 @@ +/* + * Example memory allocator with machine parseable logging. + * + * Also sizes for reallocs and frees are logged so that the memory + * behavior can be essentially replayed to accurately determine e.g. + * optimal pool sizes for a pooled allocator. + * + * Allocation structure: + * + * [ alloc_hdr | user area ] + * + * ^ ^ + * | `--- pointer returned to Duktape + * `--- underlying malloc ptr + */ + +#include "duktape.h" +#include +#include +#include +#include +#include "duk_alloc_logging.h" + +#define ALLOC_LOG_FILE "/tmp/duk-alloc-log.txt" + +typedef struct { + /* The double value in the union is there to ensure alignment is + * good for IEEE doubles too. In many 32-bit environments 4 bytes + * would be sufficiently aligned and the double value is unnecessary. + */ + union { + size_t sz; + double d; + } u; +} alloc_hdr; + +static FILE *log_file = NULL; + +static void write_log(const char *fmt, ...) { + va_list ap; + + if (!log_file) { + log_file = fopen(ALLOC_LOG_FILE, "wb"); + if (!log_file) { + return; + } + } + + va_start(ap, fmt); + vfprintf(log_file, fmt, ap); + va_end(ap); +} + +void *duk_alloc_logging(void *udata, duk_size_t size) { + alloc_hdr *hdr; + void *ret; + + (void) udata; /* Suppress warning. */ + + if (size == 0) { + write_log("A NULL %ld\n", (long) size); + return NULL; + } + + hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr)); + if (!hdr) { + write_log("A FAIL %ld\n", (long) size); + return NULL; + } + hdr->u.sz = size; + ret = (void *) (hdr + 1); + write_log("A %p %ld\n", ret, (long) size); + return ret; +} + +void *duk_realloc_logging(void *udata, void *ptr, duk_size_t size) { + alloc_hdr *hdr; + size_t old_size; + void *t; + void *ret; + + (void) udata; /* Suppress warning. */ + + /* Handle the ptr-NULL vs. size-zero cases explicitly to minimize + * platform assumptions. You can get away with much less in specific + * well-behaving environments. + */ + + if (ptr) { + hdr = (alloc_hdr *) (void *) ((unsigned char *) ptr - sizeof(alloc_hdr)); + old_size = hdr->u.sz; + + if (size == 0) { + write_log("R %p %ld NULL 0\n", ptr, (long) old_size); + free((void *) hdr); + return NULL; + } else { + t = realloc((void *) hdr, size + sizeof(alloc_hdr)); + if (!t) { + write_log("R %p %ld FAIL %ld\n", ptr, (long) old_size, (long) size); + return NULL; + } + hdr = (alloc_hdr *) t; + hdr->u.sz = size; + ret = (void *) (hdr + 1); + write_log("R %p %ld %p %ld\n", ptr, (long) old_size, ret, (long) size); + return ret; + } + } else { + if (size == 0) { + write_log("R NULL 0 NULL 0\n"); + return NULL; + } else { + hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr)); + if (!hdr) { + write_log("R NULL 0 FAIL %ld\n", (long) size); + return NULL; + } + hdr->u.sz = size; + ret = (void *) (hdr + 1); + write_log("R NULL 0 %p %ld\n", ret, (long) size); + return ret; + } + } +} + +void duk_free_logging(void *udata, void *ptr) { + alloc_hdr *hdr; + + (void) udata; /* Suppress warning. */ + + if (!ptr) { + write_log("F NULL 0\n"); + return; + } + hdr = (alloc_hdr *) (void *) ((unsigned char *) ptr - sizeof(alloc_hdr)); + write_log("F %p %ld\n", ptr, (long) hdr->u.sz); + free((void *) hdr); +} diff --git a/lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.h b/lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.h new file mode 100644 index 0000000..a496c29 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-logging/duk_alloc_logging.h @@ -0,0 +1,10 @@ +#if !defined(DUK_ALLOC_LOGGING_H_INCLUDED) +#define DUK_ALLOC_LOGGING_H_INCLUDED + +#include "duktape.h" + +void *duk_alloc_logging(void *udata, duk_size_t size); +void *duk_realloc_logging(void *udata, void *ptr, duk_size_t size); +void duk_free_logging(void *udata, void *ptr); + +#endif /* DUK_ALLOC_LOGGING_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/alloc-logging/log2gnuplot.py b/lib/duktape-2.2.1/examples/alloc-logging/log2gnuplot.py new file mode 100644 index 0000000..7a009f2 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-logging/log2gnuplot.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python2 +# +# Analyze allocator logs and write total-bytes-in-use after every +# operation to stdout. The output can be gnuplotted as: +# +# $ python log2gnuplot.py /tmp/output.txt +# $ gnuplot +# > plot "output.txt" with lines +# + +import os +import sys + +def main(): + allocated = 0 + + for line in sys.stdin: + line = line.strip() + parts = line.split(' ') + + # A ptr/NULL/FAIL size + # F ptr/NULL size + # R ptr/NULL oldsize ptr/NULL/FAIL newsize + + # Note: duk-low doesn't log oldsize (uses -1 instead) + + if parts[0] == 'A': + if parts[1] != 'NULL' and parts[1] != 'FAIL': + allocated += long(parts[2]) + elif parts[0] == 'F': + allocated -= long(parts[2]) + elif parts[0] == 'R': + allocated -= long(parts[2]) + if parts[3] != 'NULL' and parts[3] != 'FAIL': + allocated += long(parts[4]) + print(allocated) + + print(allocated) + +if __name__ == '__main__': + main() diff --git a/lib/duktape-2.2.1/examples/alloc-torture/README.rst b/lib/duktape-2.2.1/examples/alloc-torture/README.rst new file mode 100644 index 0000000..f3278bb --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-torture/README.rst @@ -0,0 +1,10 @@ +========================================== +Allocator with memory wiping and red zones +========================================== + +Example allocator that wipes memory on free and checks that no out-of-bounds +writes have been made to bytes just before and after the allocated area. + +Valgrind is a better tool for detecting these memory issues, but it's not +available for all targets so you can use something like this to detect +memory lifecycle or out-of-bounds issues. diff --git a/lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.c b/lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.c new file mode 100644 index 0000000..fd1dbe3 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.c @@ -0,0 +1,183 @@ +/* + * Example torture memory allocator with memory wiping and check for + * out-of-bounds writes. + * + * Allocation structure: + * + * [ alloc_hdr | red zone before | user area | red zone after ] + * + * ^ ^ + * | `--- pointer returned to Duktape + * `--- underlying malloc ptr + */ + +#include "duktape.h" +#include +#include +#include +#include +#include "duk_alloc_torture.h" + +#define RED_ZONE_SIZE 16 +#define RED_ZONE_BYTE 0x5a +#define INIT_BYTE 0xa5 +#define WIPE_BYTE 0x27 + +typedef struct { + /* The double value in the union is there to ensure alignment is + * good for IEEE doubles too. In many 32-bit environments 4 bytes + * would be sufficiently aligned and the double value is unnecessary. + */ + union { + size_t sz; + double d; + } u; +} alloc_hdr; + +static void check_red_zone(alloc_hdr *hdr) { + size_t size; + int i; + int err; + unsigned char *p; + unsigned char *userptr; + + size = hdr->u.sz; + userptr = (unsigned char *) hdr + sizeof(alloc_hdr) + RED_ZONE_SIZE; + + err = 0; + p = (unsigned char *) hdr + sizeof(alloc_hdr); + for (i = 0; i < RED_ZONE_SIZE; i++) { + if (p[i] != RED_ZONE_BYTE) { + err = 1; + } + } + if (err) { + fprintf(stderr, "RED ZONE CORRUPTED BEFORE ALLOC: hdr=%p ptr=%p size=%ld\n", + (void *) hdr, (void *) userptr, (long) size); + fflush(stderr); + } + + err = 0; + p = (unsigned char *) hdr + sizeof(alloc_hdr) + RED_ZONE_SIZE + size; + for (i = 0; i < RED_ZONE_SIZE; i++) { + if (p[i] != RED_ZONE_BYTE) { + err = 1; + } + } + if (err) { + fprintf(stderr, "RED ZONE CORRUPTED AFTER ALLOC: hdr=%p ptr=%p size=%ld\n", + (void *) hdr, (void *) userptr, (long) size); + fflush(stderr); + } +} + +void *duk_alloc_torture(void *udata, duk_size_t size) { + unsigned char *p; + + (void) udata; /* Suppress warning. */ + + if (size == 0) { + return NULL; + } + + p = (unsigned char *) malloc(size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE); + if (!p) { + return NULL; + } + + ((alloc_hdr *) (void *) p)->u.sz = size; + p += sizeof(alloc_hdr); + memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE); + p += RED_ZONE_SIZE; + memset((void *) p, INIT_BYTE, size); + p += size; + memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE); + p -= size; + return (void *) p; +} + +void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size) { + unsigned char *p, *old_p; + size_t old_size; + + (void) udata; /* Suppress warning. */ + + /* Handle the ptr-NULL vs. size-zero cases explicitly to minimize + * platform assumptions. You can get away with much less in specific + * well-behaving environments. + */ + + if (ptr) { + old_p = (unsigned char *) ptr - sizeof(alloc_hdr) - RED_ZONE_SIZE; + old_size = ((alloc_hdr *) (void *) old_p)->u.sz; + check_red_zone((alloc_hdr *) (void *) old_p); + + if (size == 0) { + memset((void *) old_p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE); + free((void *) old_p); + return NULL; + } else { + /* Force address change on every realloc. */ + p = (unsigned char *) malloc(size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE); + if (!p) { + return NULL; + } + + ((alloc_hdr *) (void *) p)->u.sz = size; + p += sizeof(alloc_hdr); + memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE); + p += RED_ZONE_SIZE; + if (size > old_size) { + memcpy((void *) p, (void *) (old_p + sizeof(alloc_hdr) + RED_ZONE_SIZE), old_size); + memset((void *) (p + old_size), INIT_BYTE, size - old_size); + } else { + memcpy((void *) p, (void *) (old_p + sizeof(alloc_hdr) + RED_ZONE_SIZE), size); + } + p += size; + memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE); + p -= size; + + memset((void *) old_p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE); + free((void *) old_p); + + return (void *) p; + } + } else { + if (size == 0) { + return NULL; + } else { + p = (unsigned char *) malloc(size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE); + if (!p) { + return NULL; + } + + ((alloc_hdr *) (void *) p)->u.sz = size; + p += sizeof(alloc_hdr); + memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE); + p += RED_ZONE_SIZE; + memset((void *) p, INIT_BYTE, size); + p += size; + memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE); + p -= size; + return (void *) p; + } + } +} + +void duk_free_torture(void *udata, void *ptr) { + unsigned char *p; + size_t old_size; + + (void) udata; /* Suppress warning. */ + + if (!ptr) { + return; + } + + p = (unsigned char *) ptr - sizeof(alloc_hdr) - RED_ZONE_SIZE; + old_size = ((alloc_hdr *) (void *) p)->u.sz; + + check_red_zone((alloc_hdr *) (void *) p); + memset((void *) p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE); + free((void *) p); +} diff --git a/lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.h b/lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.h new file mode 100644 index 0000000..0b36b69 --- /dev/null +++ b/lib/duktape-2.2.1/examples/alloc-torture/duk_alloc_torture.h @@ -0,0 +1,10 @@ +#if !defined(DUK_ALLOC_TORTURE_H_INCLUDED) +#define DUK_ALLOC_TORTURE_H_INCLUDED + +#include "duktape.h" + +void *duk_alloc_torture(void *udata, duk_size_t size); +void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size); +void duk_free_torture(void *udata, void *ptr); + +#endif /* DUK_ALLOC_TORTURE_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/cmdline/README.rst b/lib/duktape-2.2.1/examples/cmdline/README.rst new file mode 100644 index 0000000..e0c6bce --- /dev/null +++ b/lib/duktape-2.2.1/examples/cmdline/README.rst @@ -0,0 +1,6 @@ +==================== +Duktape command line +==================== + +Ecmascript command line execution tool, useful for running Ecmascript code +from a file, stdin, or interactively. Also used by automatic testing. diff --git a/lib/duktape-2.2.1/examples/cmdline/duk_cmdline.c b/lib/duktape-2.2.1/examples/cmdline/duk_cmdline.c new file mode 100644 index 0000000..b55ec66 --- /dev/null +++ b/lib/duktape-2.2.1/examples/cmdline/duk_cmdline.c @@ -0,0 +1,1560 @@ +/* + * Command line execution tool. Useful for test cases and manual testing. + * + * Optional features: + * + * - To enable print()/alert() bindings, define DUK_CMDLINE_PRINTALERT_SUPPORT + * and add extras/print-alert/duk_print_alert.c to compilation. + * + * - To enable console.log() etc, define DUK_CMDLINE_CONSOLE_SUPPORT + * and add extras/console/duk_console.c to compilation. + * + * - To enable Duktape.Logger, define DUK_CMDLINE_LOGGING_SUPPORT + * and add extras/logging/duk_logging.c to compilation. + * + * - To enable Duktape 1.x module loading support (require(), + * Duktape.modSearch() etc), define DUK_CMDLINE_MODULE_SUPPORT and add + * extras/module-duktape/duk_module_duktape.c to compilation. + * + * - To enable linenoise and other fancy stuff, compile with -DDUK_CMDLINE_FANCY. + * It is not the default to maximize portability. You can also compile in + * support for example allocators, grep for DUK_CMDLINE_*. + */ + +/* Helper define to enable a feature set; can also use separate defines. */ +#if defined(DUK_CMDLINE_FANCY) +#define DUK_CMDLINE_LINENOISE +#define DUK_CMDLINE_LINENOISE_COMPLETION /* Enables completion and hints. */ +#define DUK_CMDLINE_RLIMIT +#define DUK_CMDLINE_SIGNAL +#endif + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \ + defined(WIN64) || defined(_WIN64) || defined(__WIN64__) +/* Suppress warnings about plain fopen() etc. */ +#define _CRT_SECURE_NO_WARNINGS +#if defined(_MSC_VER) && (_MSC_VER < 1900) +/* Workaround for snprintf() missing in older MSVC versions. + * Note that _snprintf() may not NUL terminate the string, but + * this difference does not matter here as a NUL terminator is + * always explicitly added. + */ +#define snprintf _snprintf +#endif +#endif + +#include +#include +#include +#if defined(DUK_CMDLINE_SIGNAL) +#include +#endif +#if defined(DUK_CMDLINE_RLIMIT) +#include +#endif +#if defined(DUK_CMDLINE_LINENOISE) +#include "linenoise.h" +#include /* Assume C99/C++11 with linenoise. */ +#endif +#if defined(DUK_CMDLINE_PRINTALERT_SUPPORT) +#include "duk_print_alert.h" +#endif +#if defined(DUK_CMDLINE_CONSOLE_SUPPORT) +#include "duk_console.h" +#endif +#if defined(DUK_CMDLINE_LOGGING_SUPPORT) +#include "duk_logging.h" +#endif +#if defined(DUK_CMDLINE_MODULE_SUPPORT) +#include "duk_module_duktape.h" +#endif +#if defined(DUK_CMDLINE_FILEIO) +#include +#endif +#if defined(EMSCRIPTEN) +#include +#endif +#if defined(DUK_CMDLINE_ALLOC_LOGGING) +#include "duk_alloc_logging.h" +#endif +#if defined(DUK_CMDLINE_ALLOC_TORTURE) +#include "duk_alloc_torture.h" +#endif +#if defined(DUK_CMDLINE_ALLOC_HYBRID) +#include "duk_alloc_hybrid.h" +#endif +#include "duktape.h" + +#include "duk_cmdline.h" + +#if defined(DUK_CMDLINE_LOWMEM) +#include "duk_alloc_pool.h" +#endif + +#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT) +#include "duk_trans_socket.h" +#endif + +#define MEM_LIMIT_NORMAL (128*1024*1024) /* 128 MB */ +#define MEM_LIMIT_HIGH (2047*1024*1024) /* ~2 GB */ +#define LINEBUF_SIZE 65536 + +static int main_argc = 0; +static char **main_argv = NULL; +static int interactive_mode = 0; +#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT) +static int debugger_reattach = 0; +#endif + +/* + * Misc helpers + */ + +static void print_greet_line(void) { + printf("((o) Duktape%s %d.%d.%d (%s)\n", +#if defined(DUK_CMDLINE_LINENOISE) + " [linenoise]", +#else + "", +#endif + (int) (DUK_VERSION / 10000), + (int) ((DUK_VERSION / 100) % 100), + (int) (DUK_VERSION % 100), + DUK_GIT_DESCRIBE); +} + +#if defined(DUK_CMDLINE_RLIMIT) +static void set_resource_limits(rlim_t mem_limit_value) { + int rc; + struct rlimit lim; + + rc = getrlimit(RLIMIT_AS, &lim); + if (rc != 0) { + fprintf(stderr, "Warning: cannot read RLIMIT_AS\n"); + return; + } + + if (lim.rlim_max < mem_limit_value) { + fprintf(stderr, "Warning: rlim_max < mem_limit_value (%d < %d)\n", (int) lim.rlim_max, (int) mem_limit_value); + return; + } + + lim.rlim_cur = mem_limit_value; + lim.rlim_max = mem_limit_value; + + rc = setrlimit(RLIMIT_AS, &lim); + if (rc != 0) { + fprintf(stderr, "Warning: setrlimit failed\n"); + return; + } + +#if 0 + fprintf(stderr, "Set RLIMIT_AS to %d\n", (int) mem_limit_value); +#endif +} +#endif /* DUK_CMDLINE_RLIMIT */ + +#if defined(DUK_CMDLINE_SIGNAL) +static void my_sighandler(int x) { + fprintf(stderr, "Got signal %d\n", x); + fflush(stderr); +} +static void set_sigint_handler(void) { + (void) signal(SIGINT, my_sighandler); + (void) signal(SIGPIPE, SIG_IGN); /* avoid SIGPIPE killing process */ +} +#endif /* DUK_CMDLINE_SIGNAL */ + +static void cmdline_fatal_handler(void *udata, const char *msg) { + (void) udata; + fprintf(stderr, "*** FATAL ERROR: %s\n", msg ? msg : "no message"); + fprintf(stderr, "Causing intentional segfault...\n"); + fflush(stderr); + *((volatile unsigned int *) 0) = (unsigned int) 0xdeadbeefUL; + abort(); +} + +static duk_ret_t get_stack_raw(duk_context *ctx, void *udata) { + (void) udata; + + if (!duk_is_object(ctx, -1)) { + return 1; + } + if (!duk_has_prop_string(ctx, -1, "stack")) { + return 1; + } + if (!duk_is_error(ctx, -1)) { + /* Not an Error instance, don't read "stack". */ + return 1; + } + + duk_get_prop_string(ctx, -1, "stack"); /* caller coerces */ + duk_remove(ctx, -2); + return 1; +} + +/* Print error to stderr and pop error. */ +static void print_pop_error(duk_context *ctx, FILE *f) { + /* Print error objects with a stack trace specially. + * Note that getting the stack trace may throw an error + * so this also needs to be safe call wrapped. + */ + (void) duk_safe_call(ctx, get_stack_raw, NULL /*udata*/, 1 /*nargs*/, 1 /*nrets*/); + fprintf(f, "%s\n", duk_safe_to_string(ctx, -1)); + fflush(f); + duk_pop(ctx); +} + +static duk_ret_t wrapped_compile_execute(duk_context *ctx, void *udata) { + const char *src_data; + duk_size_t src_len; + duk_uint_t comp_flags; + + (void) udata; + + /* XXX: Here it'd be nice to get some stats for the compilation result + * when a suitable command line is given (e.g. code size, constant + * count, function count. These are available internally but not through + * the public API. + */ + + /* Use duk_compile_lstring_filename() variant which avoids interning + * the source code. This only really matters for low memory environments. + */ + + /* [ ... bytecode_filename src_data src_len filename ] */ + + src_data = (const char *) duk_require_pointer(ctx, -3); + src_len = (duk_size_t) duk_require_uint(ctx, -2); + + if (src_data != NULL && src_len >= 1 && src_data[0] == (char) 0xbf) { + /* Bytecode. */ + void *buf; + buf = duk_push_fixed_buffer(ctx, src_len); + memcpy(buf, (const void *) src_data, src_len); + duk_load_function(ctx); + } else { + /* Source code. */ + comp_flags = DUK_COMPILE_SHEBANG; + duk_compile_lstring_filename(ctx, comp_flags, src_data, src_len); + } + + /* [ ... bytecode_filename src_data src_len function ] */ + + /* Optional bytecode dump. */ + if (duk_is_string(ctx, -4)) { + FILE *f; + void *bc_ptr; + duk_size_t bc_len; + size_t wrote; + char fnbuf[256]; + const char *filename; + + duk_dup_top(ctx); + duk_dump_function(ctx); + bc_ptr = duk_require_buffer(ctx, -1, &bc_len); + filename = duk_require_string(ctx, -5); +#if defined(EMSCRIPTEN) + if (filename[0] == '/') { + snprintf(fnbuf, sizeof(fnbuf), "%s", filename); + } else { + snprintf(fnbuf, sizeof(fnbuf), "/working/%s", filename); + } +#else + snprintf(fnbuf, sizeof(fnbuf), "%s", filename); +#endif + fnbuf[sizeof(fnbuf) - 1] = (char) 0; + + f = fopen(fnbuf, "wb"); + if (!f) { + (void) duk_generic_error(ctx, "failed to open bytecode output file"); + } + wrote = fwrite(bc_ptr, 1, (size_t) bc_len, f); /* XXX: handle partial writes */ + (void) fclose(f); + if (wrote != bc_len) { + (void) duk_generic_error(ctx, "failed to write all bytecode"); + } + + return 0; /* duk_safe_call() cleans up */ + } + +#if 0 + /* Manual test for bytecode dump/load cycle: dump and load before + * execution. Enable manually, then run "make ecmatest" for a + * reasonably good coverage of different functions and programs. + */ + duk_dump_function(ctx); + duk_load_function(ctx); +#endif + +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_start_exec_timeout(); +#endif + + duk_push_global_object(ctx); /* 'this' binding */ + duk_call_method(ctx, 0); + +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_clear_exec_timeout(); +#endif + + if (interactive_mode) { + /* + * In interactive mode, write to stdout so output won't + * interleave as easily. + * + * NOTE: the ToString() coercion may fail in some cases; + * for instance, if you evaluate: + * + * ( {valueOf: function() {return {}}, + * toString: function() {return {}}}); + * + * The error is: + * + * TypeError: coercion to primitive failed + * duk_api.c:1420 + * + * These are handled now by the caller which also has stack + * trace printing support. User code can print out errors + * safely using duk_safe_to_string(). + */ + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "dukFormat"); + duk_dup(ctx, -3); + duk_call(ctx, 1); /* -> [ ... res stash formatted ] */ + + fprintf(stdout, "= %s\n", duk_to_string(ctx, -1)); + fflush(stdout); + } else { + /* In non-interactive mode, success results are not written at all. + * It is important that the result value is not string coerced, + * as the string coercion may cause an error in some cases. + */ + } + + return 0; /* duk_safe_call() cleans up */ +} + +/* + * Minimal Linenoise completion support + */ + +#if defined(DUK_CMDLINE_LINENOISE_COMPLETION) +static duk_context *completion_ctx; + + +static const char *linenoise_completion_script = + "(function linenoiseCompletion(input, addCompletion) {\n" + " // Find maximal trailing string which looks like a property\n" + " // access. Look up all the components (starting from the global\n" + " // object now) except the last; treat the last component as a\n" + " // partial name and use it as a filter for possible properties.\n" + " var match, propseq, obj, i, partial, names, name, sanity;\n" + "\n" + " if (!input) { return; }\n" + " match = /^.*?((?:\\w+\\.)*\\w*)$/.exec(input);\n" + " if (!match || !match[1]) { return; }\n" + " var propseq = match[1].split('.');\n" + "\n" + " obj = Function('return this')();\n" + " for (i = 0; i < propseq.length - 1; i++) {\n" + " if (obj === void 0 || obj === null) { return; }\n" + " obj = obj[propseq[i]];\n" + " }\n" + " if (obj === void 0 || obj === null) { return; }\n" + "\n" + " partial = propseq[propseq.length - 1];\n" + " sanity = 1000;\n" + " while (obj != null) {\n" + " if (--sanity < 0) { throw new Error('sanity'); }\n" + " names = Object.getOwnPropertyNames(Object(obj));\n" + " for (i = 0; i < names.length; i++) {\n" + " if (--sanity < 0) { throw new Error('sanity'); }\n" + " name = names[i];\n" + " if (Number(name) >= 0) { continue; } // ignore array keys\n" + " if (name.substring(0, partial.length) !== partial) { continue; }\n" + " if (name === partial) { addCompletion(input + '.'); continue; }\n" + " addCompletion(input + name.substring(partial.length));\n" + " }\n" + " obj = Object.getPrototypeOf(Object(obj));\n" + " }\n" + "})"; + +static const char *linenoise_hints_script = + "(function linenoiseHints(input) {\n" + " // Similar to completions but different handling for final results.\n" + " var match, propseq, obj, i, partial, names, name, res, found, first, sanity;\n" + "\n" + " if (!input) { return; }\n" + " match = /^.*?((?:\\w+\\.)*\\w*)$/.exec(input);\n" + " if (!match || !match[1]) { return; }\n" + " var propseq = match[1].split('.');\n" + "\n" + " obj = Function('return this')();\n" + " for (i = 0; i < propseq.length - 1; i++) {\n" + " if (obj === void 0 || obj === null) { return; }\n" + " obj = obj[propseq[i]];\n" + " }\n" + " if (obj === void 0 || obj === null) { return; }\n" + "\n" + " partial = propseq[propseq.length - 1];\n" + " res = [];\n" + " found = Object.create(null); // keys already handled\n" + " sanity = 1000;\n" + " while (obj != null) {\n" + " if (--sanity < 0) { throw new Error('sanity'); }\n" + " names = Object.getOwnPropertyNames(Object(obj));\n" + " first = true;\n" + " for (i = 0; i < names.length; i++) {\n" + " if (--sanity < 0) { throw new Error('sanity'); }\n" + " name = names[i];\n" + " if (Number(name) >= 0) { continue; } // ignore array keys\n" + " if (name.substring(0, partial.length) !== partial) { continue; }\n" + " if (name === partial) { continue; }\n" + " if (found[name]) { continue; }\n" + " found[name] = true;\n" + " res.push(res.length === 0 ? name.substring(partial.length) : (first ? ' || ' : ' | ') + name);\n" + " first = false;\n" + " }\n" + " obj = Object.getPrototypeOf(Object(obj));\n" + " }\n" + " return { hints: res.join(''), color: 35, bold: 1 };\n" + "})"; + +static duk_ret_t linenoise_add_completion(duk_context *ctx) { + linenoiseCompletions *lc; + + duk_push_current_function(ctx); + duk_get_prop_string(ctx, -1, "lc"); + lc = duk_require_pointer(ctx, -1); + + linenoiseAddCompletion(lc, duk_require_string(ctx, 0)); + return 0; +} + +static char *linenoise_hints(const char *buf, int *color, int *bold) { + duk_context *ctx; + duk_int_t rc; + + ctx = completion_ctx; + if (!ctx) { + return NULL; + } + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "linenoiseHints"); + if (!buf) { + duk_push_undefined(ctx); + } else { + duk_push_string(ctx, buf); + } + + rc = duk_pcall(ctx, 1 /*nargs*/); /* [ stash func ] -> [ stash result ] */ + if (rc != 0) { + const char *res; + res = strdup(duk_safe_to_string(ctx, -1)); + *color = 31; /* red */ + *bold = 1; + duk_pop_2(ctx); + return (char *) (uintptr_t) res; /* uintptr_t cast to avoid const discard warning. */ + } + + if (duk_is_object(ctx, -1)) { + const char *tmp; + const char *res = NULL; + + duk_get_prop_string(ctx, -1, "hints"); + tmp = duk_get_string(ctx, -1); + if (tmp) { + res = strdup(tmp); + } + duk_pop(ctx); + + duk_get_prop_string(ctx, -1, "color"); + *color = duk_to_int(ctx, -1); + duk_pop(ctx); + + duk_get_prop_string(ctx, -1, "bold"); + *bold = duk_to_int(ctx, -1); + duk_pop(ctx); + + duk_pop_2(ctx); + return (char *) (uintptr_t) res; /* uintptr_t cast to avoid const discard warning. */ + } + + duk_pop_2(ctx); + return NULL; +} + +static void linenoise_freehints(void *ptr) { +#if 0 + printf("free hint: %p\n", (void *) ptr); +#endif + free(ptr); +} + +static void linenoise_completion(const char *buf, linenoiseCompletions *lc) { + duk_context *ctx; + duk_int_t rc; + + ctx = completion_ctx; + if (!ctx) { + return; + } + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "linenoiseCompletion"); + + if (!buf) { + duk_push_undefined(ctx); + } else { + duk_push_string(ctx, buf); + } + duk_push_c_function(ctx, linenoise_add_completion, 2 /*nargs*/); + duk_push_pointer(ctx, (void *) lc); + duk_put_prop_string(ctx, -2, "lc"); + + rc = duk_pcall(ctx, 2 /*nargs*/); /* [ stash func callback ] -> [ stash result ] */ + if (rc != 0) { + linenoiseAddCompletion(lc, duk_safe_to_string(ctx, -1)); + } + duk_pop_2(ctx); +} +#endif /* DUK_CMDLINE_LINENOISE_COMPLETION */ + +/* + * Execute from file handle etc + */ + +static int handle_fh(duk_context *ctx, FILE *f, const char *filename, const char *bytecode_filename) { + char *buf = NULL; + size_t bufsz; + size_t bufoff; + size_t got; + int rc; + int retval = -1; + + buf = (char *) malloc(1024); + if (!buf) { + goto error; + } + bufsz = 1024; + bufoff = 0; + + /* Read until EOF, avoid fseek/stat because it won't work with stdin. */ + for (;;) { + size_t avail; + + avail = bufsz - bufoff; + if (avail < 1024) { + size_t newsz; + char *buf_new; +#if 0 + fprintf(stderr, "resizing read buffer: %ld -> %ld\n", (long) bufsz, (long) (bufsz * 2)); +#endif + newsz = bufsz + (bufsz >> 2) + 1024; /* +25% and some extra */ + buf_new = (char *) realloc(buf, newsz); + if (!buf_new) { + goto error; + } + buf = buf_new; + bufsz = newsz; + } + + avail = bufsz - bufoff; +#if 0 + fprintf(stderr, "reading input: buf=%p bufsz=%ld bufoff=%ld avail=%ld\n", + (void *) buf, (long) bufsz, (long) bufoff, (long) avail); +#endif + + got = fread((void *) (buf + bufoff), (size_t) 1, avail, f); +#if 0 + fprintf(stderr, "got=%ld\n", (long) got); +#endif + if (got == 0) { + break; + } + bufoff += got; + + /* Emscripten specific: stdin EOF doesn't work as expected. + * Instead, when 'emduk' is executed using Node.js, a file + * piped to stdin repeats (!). Detect that repeat and cut off + * the stdin read. Ensure the loop repeats enough times to + * avoid detecting spurious loops. + * + * This only seems to work for inputs up to 256 bytes long. + */ +#if defined(EMSCRIPTEN) + if (bufoff >= 16384) { + size_t i, j, nloops; + int looped = 0; + + for (i = 16; i < bufoff / 8; i++) { + int ok; + + nloops = bufoff / i; + ok = 1; + for (j = 1; j < nloops; j++) { + if (memcmp((void *) buf, (void *) (buf + i * j), i) != 0) { + ok = 0; + break; + } + } + if (ok) { + fprintf(stderr, "emscripten workaround: detect looping at index %ld, verified with %ld loops\n", (long) i, (long) (nloops - 1)); + bufoff = i; + looped = 1; + break; + } + } + + if (looped) { + break; + } + } +#endif + } + + duk_push_string(ctx, bytecode_filename); + duk_push_pointer(ctx, (void *) buf); + duk_push_uint(ctx, (duk_uint_t) bufoff); + duk_push_string(ctx, filename); + + interactive_mode = 0; /* global */ + + rc = duk_safe_call(ctx, wrapped_compile_execute, NULL /*udata*/, 4 /*nargs*/, 1 /*nret*/); + +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_clear_exec_timeout(); +#endif + + free(buf); + buf = NULL; + + if (rc != DUK_EXEC_SUCCESS) { + print_pop_error(ctx, stderr); + goto error; + } else { + duk_pop(ctx); + retval = 0; + } + /* fall thru */ + + cleanup: + if (buf) { + free(buf); + buf = NULL; + } + return retval; + + error: + fprintf(stderr, "error in executing file %s\n", filename); + fflush(stderr); + goto cleanup; +} + +static int handle_file(duk_context *ctx, const char *filename, const char *bytecode_filename) { + FILE *f = NULL; + int retval; + char fnbuf[256]; + + /* Example of sending an application specific debugger notification. */ + duk_push_string(ctx, "DebuggerHandleFile"); + duk_push_string(ctx, filename); + duk_debugger_notify(ctx, 2); + +#if defined(EMSCRIPTEN) + if (filename[0] == '/') { + snprintf(fnbuf, sizeof(fnbuf), "%s", filename); + } else { + snprintf(fnbuf, sizeof(fnbuf), "/working/%s", filename); + } +#else + snprintf(fnbuf, sizeof(fnbuf), "%s", filename); +#endif + fnbuf[sizeof(fnbuf) - 1] = (char) 0; + + f = fopen(fnbuf, "rb"); + if (!f) { + fprintf(stderr, "failed to open source file: %s\n", filename); + fflush(stderr); + goto error; + } + + retval = handle_fh(ctx, f, filename, bytecode_filename); + + fclose(f); + return retval; + + error: + return -1; +} + +static int handle_eval(duk_context *ctx, char *code) { + int rc; + int retval = -1; + + duk_push_pointer(ctx, (void *) code); + duk_push_uint(ctx, (duk_uint_t) strlen(code)); + duk_push_string(ctx, "eval"); + + interactive_mode = 0; /* global */ + + rc = duk_safe_call(ctx, wrapped_compile_execute, NULL /*udata*/, 3 /*nargs*/, 1 /*nret*/); + +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_clear_exec_timeout(); +#endif + + if (rc != DUK_EXEC_SUCCESS) { + print_pop_error(ctx, stderr); + } else { + duk_pop(ctx); + retval = 0; + } + + return retval; +} + +#if defined(DUK_CMDLINE_LINENOISE) +static int handle_interactive(duk_context *ctx) { + const char *prompt = "duk> "; + char *buffer = NULL; + int retval = 0; + int rc; + + linenoiseSetMultiLine(1); + linenoiseHistorySetMaxLen(64); +#if defined(DUK_CMDLINE_LINENOISE_COMPLETION) + linenoiseSetCompletionCallback(linenoise_completion); + linenoiseSetHintsCallback(linenoise_hints); + linenoiseSetFreeHintsCallback(linenoise_freehints); + duk_push_global_stash(ctx); + duk_eval_string(ctx, linenoise_completion_script); + duk_put_prop_string(ctx, -2, "linenoiseCompletion"); + duk_eval_string(ctx, linenoise_hints_script); + duk_put_prop_string(ctx, -2, "linenoiseHints"); + duk_pop(ctx); +#endif + + for (;;) { + if (buffer) { + linenoiseFree(buffer); + buffer = NULL; + } + +#if defined(DUK_CMDLINE_LINENOISE_COMPLETION) + completion_ctx = ctx; +#endif + buffer = linenoise(prompt); +#if defined(DUK_CMDLINE_LINENOISE_COMPLETION) + completion_ctx = NULL; +#endif + + if (!buffer) { + break; + } + + if (buffer && buffer[0] != (char) 0) { + linenoiseHistoryAdd(buffer); + } + + duk_push_pointer(ctx, (void *) buffer); + duk_push_uint(ctx, (duk_uint_t) strlen(buffer)); + duk_push_string(ctx, "input"); + + interactive_mode = 1; /* global */ + + rc = duk_safe_call(ctx, wrapped_compile_execute, NULL /*udata*/, 3 /*nargs*/, 1 /*nret*/); + +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_clear_exec_timeout(); +#endif + + if (buffer) { + linenoiseFree(buffer); + buffer = NULL; + } + + if (rc != DUK_EXEC_SUCCESS) { + /* in interactive mode, write to stdout */ + print_pop_error(ctx, stdout); + retval = -1; /* an error 'taints' the execution */ + } else { + duk_pop(ctx); + } + } + + if (buffer) { + linenoiseFree(buffer); + buffer = NULL; + } + + return retval; +} +#else /* DUK_CMDLINE_LINENOISE */ +static int handle_interactive(duk_context *ctx) { + const char *prompt = "duk> "; + char *buffer = NULL; + int retval = 0; + int rc; + int got_eof = 0; + + buffer = (char *) malloc(LINEBUF_SIZE); + if (!buffer) { + fprintf(stderr, "failed to allocated a line buffer\n"); + fflush(stderr); + retval = -1; + goto done; + } + + while (!got_eof) { + size_t idx = 0; + + fwrite(prompt, 1, strlen(prompt), stdout); + fflush(stdout); + + for (;;) { + int c = fgetc(stdin); + if (c == EOF) { + got_eof = 1; + break; + } else if (c == '\n') { + break; + } else if (idx >= LINEBUF_SIZE) { + fprintf(stderr, "line too long\n"); + fflush(stderr); + retval = -1; + goto done; + } else { + buffer[idx++] = (char) c; + } + } + + duk_push_pointer(ctx, (void *) buffer); + duk_push_uint(ctx, (duk_uint_t) idx); + duk_push_string(ctx, "input"); + + interactive_mode = 1; /* global */ + + rc = duk_safe_call(ctx, wrapped_compile_execute, NULL /*udata*/, 3 /*nargs*/, 1 /*nret*/); + +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_clear_exec_timeout(); +#endif + + if (rc != DUK_EXEC_SUCCESS) { + /* in interactive mode, write to stdout */ + print_pop_error(ctx, stdout); + retval = -1; /* an error 'taints' the execution */ + } else { + duk_pop(ctx); + } + } + + done: + if (buffer) { + free(buffer); + buffer = NULL; + } + + return retval; +} +#endif /* DUK_CMDLINE_LINENOISE */ + +/* + * Simple file read/write bindings + */ + +#if defined(DUK_CMDLINE_FILEIO) +static duk_ret_t fileio_read_file(duk_context *ctx) { + const char *fn; + char *buf; + size_t len; + size_t off; + int rc; + FILE *f; + + fn = duk_require_string(ctx, 0); + f = fopen(fn, "rb"); + if (!f) { + (void) duk_type_error(ctx, "cannot open file %s for reading, errno %ld: %s", + fn, (long) errno, strerror(errno)); + } + + rc = fseek(f, 0, SEEK_END); + if (rc < 0) { + (void) fclose(f); + (void) duk_type_error(ctx, "fseek() failed for %s, errno %ld: %s", + fn, (long) errno, strerror(errno)); + } + len = (size_t) ftell(f); + rc = fseek(f, 0, SEEK_SET); + if (rc < 0) { + (void) fclose(f); + (void) duk_type_error(ctx, "fseek() failed for %s, errno %ld: %s", + fn, (long) errno, strerror(errno)); + } + + buf = (char *) duk_push_fixed_buffer(ctx, (duk_size_t) len); + for (off = 0; off < len;) { + size_t got; + got = fread((void *) (buf + off), 1, len - off, f); + if (ferror(f)) { + (void) fclose(f); + (void) duk_type_error(ctx, "error while reading %s", fn); + } + if (got == 0) { + if (feof(f)) { + break; + } else { + (void) fclose(f); + (void) duk_type_error(ctx, "error while reading %s", fn); + } + } + off += got; + } + + if (f) { + (void) fclose(f); + } + + return 1; +} + +static duk_ret_t fileio_write_file(duk_context *ctx) { + const char *fn; + const char *buf; + size_t len; + size_t off; + FILE *f; + + fn = duk_require_string(ctx, 0); + f = fopen(fn, "wb"); + if (!f) { + (void) duk_type_error(ctx, "cannot open file %s for writing, errno %ld: %s", + fn, (long) errno, strerror(errno)); + } + + len = 0; + buf = (char *) duk_to_buffer(ctx, 1, &len); + for (off = 0; off < len;) { + size_t got; + got = fwrite((const void *) (buf + off), 1, len - off, f); + if (ferror(f)) { + (void) fclose(f); + (void) duk_type_error(ctx, "error while writing %s", fn); + } + if (got == 0) { + (void) fclose(f); + (void) duk_type_error(ctx, "error while writing %s", fn); + } + off += got; + } + + if (f) { + (void) fclose(f); + } + + return 0; +} +#endif /* DUK_CMDLINE_FILEIO */ + +/* + * String.fromBufferRaw() + */ + +static duk_ret_t string_frombufferraw(duk_context *ctx) { + duk_buffer_to_string(ctx, 0); + return 1; +} + +/* + * Duktape heap lifecycle + */ + +#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT) +static duk_idx_t debugger_request(duk_context *ctx, void *udata, duk_idx_t nvalues) { + const char *cmd; + int i; + + (void) udata; + + if (nvalues < 1) { + duk_push_string(ctx, "missing AppRequest argument(s)"); + return -1; + } + + cmd = duk_get_string(ctx, -nvalues + 0); + + if (cmd && strcmp(cmd, "CommandLine") == 0) { + if (!duk_check_stack(ctx, main_argc)) { + /* Callback should avoid errors for now, so use + * duk_check_stack() rather than duk_require_stack(). + */ + duk_push_string(ctx, "failed to extend stack"); + return -1; + } + for (i = 0; i < main_argc; i++) { + duk_push_string(ctx, main_argv[i]); + } + return main_argc; + } + duk_push_sprintf(ctx, "command not supported"); + return -1; +} + +static void debugger_detached(duk_context *ctx, void *udata) { + fprintf(stderr, "Debugger detached, udata: %p\n", (void *) udata); + fflush(stderr); + + /* Ensure socket is closed even when detach is initiated by Duktape + * rather than debug client. + */ + duk_trans_socket_finish(); + + if (debugger_reattach) { + /* For automatic reattach testing. */ + duk_trans_socket_init(); + duk_trans_socket_waitconn(); + fprintf(stderr, "Debugger reconnected, call duk_debugger_attach()\n"); + fflush(stderr); +#if 0 + /* This is not necessary but should be harmless. */ + duk_debugger_detach(ctx); +#endif + duk_debugger_attach(ctx, + duk_trans_socket_read_cb, + duk_trans_socket_write_cb, + duk_trans_socket_peek_cb, + duk_trans_socket_read_flush_cb, + duk_trans_socket_write_flush_cb, + debugger_request, + debugger_detached, + NULL); + } +} +#endif + +#define ALLOC_DEFAULT 0 +#define ALLOC_LOGGING 1 +#define ALLOC_TORTURE 2 +#define ALLOC_HYBRID 3 +#define ALLOC_LOWMEM 4 + +static duk_context *create_duktape_heap(int alloc_provider, int debugger, int lowmem_log) { + duk_context *ctx; + + (void) lowmem_log; /* suppress warning */ + + ctx = NULL; + if (!ctx && alloc_provider == ALLOC_LOGGING) { +#if defined(DUK_CMDLINE_ALLOC_LOGGING) + ctx = duk_create_heap(duk_alloc_logging, + duk_realloc_logging, + duk_free_logging, + (void *) 0xdeadbeef, + cmdline_fatal_handler); +#else + fprintf(stderr, "Warning: option --alloc-logging ignored, no logging allocator support\n"); + fflush(stderr); +#endif + } + if (!ctx && alloc_provider == ALLOC_TORTURE) { +#if defined(DUK_CMDLINE_ALLOC_TORTURE) + ctx = duk_create_heap(duk_alloc_torture, + duk_realloc_torture, + duk_free_torture, + (void *) 0xdeadbeef, + cmdline_fatal_handler); +#else + fprintf(stderr, "Warning: option --alloc-torture ignored, no torture allocator support\n"); + fflush(stderr); +#endif + } + if (!ctx && alloc_provider == ALLOC_HYBRID) { +#if defined(DUK_CMDLINE_ALLOC_HYBRID) + void *udata = duk_alloc_hybrid_init(); + if (!udata) { + fprintf(stderr, "Failed to init hybrid allocator\n"); + fflush(stderr); + } else { + ctx = duk_create_heap(duk_alloc_hybrid, + duk_realloc_hybrid, + duk_free_hybrid, + udata, + cmdline_fatal_handler); + } +#else + fprintf(stderr, "Warning: option --alloc-hybrid ignored, no hybrid allocator support\n"); + fflush(stderr); +#endif + } + if (!ctx && alloc_provider == ALLOC_LOWMEM) { +#if defined(DUK_CMDLINE_LOWMEM) + lowmem_init(); + + ctx = duk_create_heap( + lowmem_log ? lowmem_alloc_wrapped : duk_alloc_pool, + lowmem_log ? lowmem_realloc_wrapped : duk_realloc_pool, + lowmem_log ? lowmem_free_wrapped : duk_free_pool, + (void *) lowmem_pool_ptr, + cmdline_fatal_handler); +#else + fprintf(stderr, "Warning: option --alloc-ajsheap ignored, no ajsheap allocator support\n"); + fflush(stderr); +#endif + } + if (!ctx && alloc_provider == ALLOC_DEFAULT) { + ctx = duk_create_heap(NULL, NULL, NULL, NULL, cmdline_fatal_handler); + } + + if (!ctx) { + fprintf(stderr, "Failed to create Duktape heap\n"); + fflush(stderr); + exit(1); + } + +#if defined(DUK_CMDLINE_LOWMEM) + if (alloc_provider == ALLOC_LOWMEM) { + fprintf(stderr, "*** pool dump after heap creation ***\n"); + lowmem_dump(); + } +#endif + +#if defined(DUK_CMDLINE_LOWMEM) + if (alloc_provider == ALLOC_LOWMEM) { + lowmem_register(ctx); + } +#endif + + /* Register print() and alert() (removed in Duktape 2.x). */ +#if defined(DUK_CMDLINE_PRINTALERT_SUPPORT) + duk_print_alert_init(ctx, 0 /*flags*/); +#endif + + /* Register String.fromBufferRaw() which does a 1:1 buffer-to-string + * coercion needed by testcases. String.fromBufferRaw() is -not- a + * default built-in! For stripped builds the 'String' built-in + * doesn't exist and we create it here; for ROM builds it may be + * present but unwritable (which is ignored). + */ + duk_eval_string(ctx, + "(function(v){" + "if (typeof String === 'undefined') { String = {}; }" + "Object.defineProperty(String, 'fromBufferRaw', {value:v, configurable:true});" + "})"); + duk_push_c_function(ctx, string_frombufferraw, 1 /*nargs*/); + (void) duk_pcall(ctx, 1); + duk_pop(ctx); + + /* Register console object. */ +#if defined(DUK_CMDLINE_CONSOLE_SUPPORT) + duk_console_init(ctx, DUK_CONSOLE_PROXY_WRAPPER | DUK_CONSOLE_FLUSH /*flags*/); +#endif + + /* Register Duktape.Logger (removed in Duktape 2.x). */ +#if defined(DUK_CMDLINE_LOGGING_SUPPORT) + duk_logging_init(ctx, 0 /*flags*/); +#endif + + /* Register require() (removed in Duktape 2.x). */ +#if defined(DUK_CMDLINE_MODULE_SUPPORT) + duk_module_duktape_init(ctx); +#endif + + /* Trivial readFile/writeFile bindings for testing. */ +#if defined(DUK_CMDLINE_FILEIO) + duk_push_c_function(ctx, fileio_read_file, 1 /*nargs*/); + duk_put_global_string(ctx, "readFile"); + duk_push_c_function(ctx, fileio_write_file, 2 /*nargs*/); + duk_put_global_string(ctx, "writeFile"); +#endif + + /* Stash a formatting function for evaluation results. */ + duk_push_global_stash(ctx); + duk_eval_string(ctx, + "(function (E) {" + "return function format(v){" + "try{" + "return E('jx',v);" + "}catch(e){" + "return ''+v;" + "}" + "};" + "})(Duktape.enc)"); + duk_put_prop_string(ctx, -2, "dukFormat"); + duk_pop(ctx); + + if (debugger) { +#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT) + fprintf(stderr, "Debugger enabled, create socket and wait for connection\n"); + fflush(stderr); + duk_trans_socket_init(); + duk_trans_socket_waitconn(); + fprintf(stderr, "Debugger connected, call duk_debugger_attach() and then execute requested file(s)/eval\n"); + fflush(stderr); + duk_debugger_attach(ctx, + duk_trans_socket_read_cb, + duk_trans_socket_write_cb, + duk_trans_socket_peek_cb, + duk_trans_socket_read_flush_cb, + duk_trans_socket_write_flush_cb, + debugger_request, + debugger_detached, + NULL); +#else + fprintf(stderr, "Warning: option --debugger ignored, no debugger support\n"); + fflush(stderr); +#endif + } + +#if 0 + /* Manual test for duk_debugger_cooperate() */ + { + for (i = 0; i < 60; i++) { + printf("cooperate: %d\n", i); + usleep(1000000); + duk_debugger_cooperate(ctx); + } + } +#endif + + return ctx; +} + +static void destroy_duktape_heap(duk_context *ctx, int alloc_provider) { + (void) alloc_provider; + +#if defined(DUK_CMDLINE_LOWMEM) + if (alloc_provider == ALLOC_LOWMEM) { + fprintf(stderr, "*** pool dump before duk_destroy_heap(), before forced gc ***\n"); + lowmem_dump(); + + duk_gc(ctx, 0); + + fprintf(stderr, "*** pool dump before duk_destroy_heap(), after forced gc ***\n"); + lowmem_dump(); + } +#endif + + if (ctx) { + duk_destroy_heap(ctx); + } + +#if defined(DUK_CMDLINE_LOWMEM) + if (alloc_provider == ALLOC_LOWMEM) { + fprintf(stderr, "*** pool dump after duk_destroy_heap() (should have zero allocs) ***\n"); + lowmem_dump(); + } + lowmem_free(); +#endif +} + +/* + * Main + */ + +int main(int argc, char *argv[]) { + duk_context *ctx = NULL; + int retval = 0; + int have_files = 0; + int have_eval = 0; + int interactive = 0; + int memlimit_high = 1; + int alloc_provider = ALLOC_DEFAULT; + int lowmem_log = 0; + int debugger = 0; + int recreate_heap = 0; + int no_heap_destroy = 0; + int verbose = 0; + int run_stdin = 0; + const char *compile_filename = NULL; + int i; + + main_argc = argc; + main_argv = (char **) argv; + +#if defined(EMSCRIPTEN) + /* Try to use NODEFS to provide access to local files. Mount the + * CWD as /working, and then prepend "/working/" to relative native + * paths in file calls to get something that works reasonably for + * relative paths. Emscripten doesn't support replacing virtual + * "/" with host "/" (the default MEMFS at "/" can't be unmounted) + * but we can mount "/tmp" as host "/tmp" to allow testcase runs. + * + * https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html#filesystem-api-nodefs + * https://github.com/kripken/emscripten/blob/master/tests/fs/test_nodefs_rw.c + */ + EM_ASM( + /* At the moment it's not possible to replace the default MEMFS mounted at '/': + * https://github.com/kripken/emscripten/issues/2040 + * https://github.com/kripken/emscripten/blob/incoming/src/library_fs.js#L1341-L1358 + */ + /* + try { + FS.unmount("/"); + } catch (e) { + console.log("Failed to unmount default '/' MEMFS mount: " + e); + } + */ + try { + FS.mkdir("/working"); + FS.mount(NODEFS, { root: "." }, "/working"); + } catch (e) { + console.log("Failed to mount NODEFS /working: " + e); + } + /* A virtual '/tmp' exists by default: + * https://gist.github.com/evanw/e6be28094f34451bd5bd#file-temp-js-L3806-L3809 + */ + /* + try { + FS.mkdir("/tmp"); + } catch (e) { + console.log("Failed to create virtual /tmp: " + e); + } + */ + try { + FS.mount(NODEFS, { root: "/tmp" }, "/tmp"); + } catch (e) { + console.log("Failed to mount NODEFS /tmp: " + e); + } + ); +#endif /* EMSCRIPTEN */ + +#if defined(DUK_CMDLINE_LOWMEM) + alloc_provider = ALLOC_LOWMEM; +#endif + (void) lowmem_log; + + /* + * Signal handling setup + */ + +#if defined(DUK_CMDLINE_SIGNAL) + set_sigint_handler(); + + /* This is useful at the global level; libraries should avoid SIGPIPE though */ + /*signal(SIGPIPE, SIG_IGN);*/ +#endif + + /* + * Parse options + */ + + for (i = 1; i < argc; i++) { + char *arg = argv[i]; + if (!arg) { + goto usage; + } + if (strcmp(arg, "--restrict-memory") == 0) { + memlimit_high = 0; + } else if (strcmp(arg, "-i") == 0) { + interactive = 1; + } else if (strcmp(arg, "-c") == 0) { + if (i == argc - 1) { + goto usage; + } + i++; + compile_filename = argv[i]; + } else if (strcmp(arg, "-e") == 0) { + have_eval = 1; + if (i == argc - 1) { + goto usage; + } + i++; /* skip code */ + } else if (strcmp(arg, "--alloc-default") == 0) { + alloc_provider = ALLOC_DEFAULT; + } else if (strcmp(arg, "--alloc-logging") == 0) { + alloc_provider = ALLOC_LOGGING; + } else if (strcmp(arg, "--alloc-torture") == 0) { + alloc_provider = ALLOC_TORTURE; + } else if (strcmp(arg, "--alloc-hybrid") == 0) { + alloc_provider = ALLOC_HYBRID; + } else if (strcmp(arg, "--alloc-lowmem") == 0) { + alloc_provider = ALLOC_LOWMEM; + } else if (strcmp(arg, "--lowmem-log") == 0) { + lowmem_log = 1; + } else if (strcmp(arg, "--debugger") == 0) { + debugger = 1; +#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT) + } else if (strcmp(arg, "--reattach") == 0) { + debugger_reattach = 1; +#endif + } else if (strcmp(arg, "--recreate-heap") == 0) { + recreate_heap = 1; + } else if (strcmp(arg, "--no-heap-destroy") == 0) { + no_heap_destroy = 1; + } else if (strcmp(arg, "--verbose") == 0) { + verbose = 1; + } else if (strcmp(arg, "--run-stdin") == 0) { + run_stdin = 1; + } else if (strlen(arg) >= 1 && arg[0] == '-') { + goto usage; + } else { + have_files = 1; + } + } + if (!have_files && !have_eval && !run_stdin) { + interactive = 1; + } + + /* + * Memory limit + */ + +#if defined(DUK_CMDLINE_RLIMIT) + set_resource_limits(memlimit_high ? MEM_LIMIT_HIGH : MEM_LIMIT_NORMAL); +#else + if (memlimit_high == 0) { + fprintf(stderr, "Warning: option --restrict-memory ignored, no rlimit support\n"); + fflush(stderr); + } +#endif + + /* + * Create heap + */ + + ctx = create_duktape_heap(alloc_provider, debugger, lowmem_log); + + /* + * Execute any argument file(s) + */ + + for (i = 1; i < argc; i++) { + char *arg = argv[i]; + if (!arg) { + continue; + } else if (strlen(arg) == 2 && strcmp(arg, "-e") == 0) { + /* Here we know the eval arg exists but check anyway */ + if (i == argc - 1) { + retval = 1; + goto cleanup; + } + if (handle_eval(ctx, argv[i + 1]) != 0) { + retval = 1; + goto cleanup; + } + i++; /* skip code */ + continue; + } else if (strlen(arg) == 2 && strcmp(arg, "-c") == 0) { + i++; /* skip filename */ + continue; + } else if (strlen(arg) >= 1 && arg[0] == '-') { + continue; + } + + if (verbose) { + fprintf(stderr, "*** Executing file: %s\n", arg); + fflush(stderr); + } + + if (handle_file(ctx, arg, compile_filename) != 0) { + retval = 1; + goto cleanup; + } + + if (recreate_heap) { + if (verbose) { + fprintf(stderr, "*** Recreating heap...\n"); + fflush(stderr); + } + + destroy_duktape_heap(ctx, alloc_provider); + ctx = create_duktape_heap(alloc_provider, debugger, lowmem_log); + } + } + + if (run_stdin) { + /* Running stdin like a full file (reading all lines before + * compiling) is useful with emduk: + * cat test.js | ./emduk --run-stdin + */ + if (handle_fh(ctx, stdin, "stdin", compile_filename) != 0) { + retval = 1; + goto cleanup; + } + + if (recreate_heap) { + if (verbose) { + fprintf(stderr, "*** Recreating heap...\n"); + fflush(stderr); + } + + destroy_duktape_heap(ctx, alloc_provider); + ctx = create_duktape_heap(alloc_provider, debugger, lowmem_log); + } + } + + /* + * Enter interactive mode if options indicate it + */ + + if (interactive) { + print_greet_line(); + if (handle_interactive(ctx) != 0) { + retval = 1; + goto cleanup; + } + } + + /* + * Cleanup and exit + */ + + cleanup: + if (interactive) { + fprintf(stderr, "Cleaning up...\n"); + fflush(stderr); + } + + if (ctx && no_heap_destroy) { + duk_gc(ctx, 0); + } + if (ctx && !no_heap_destroy) { + destroy_duktape_heap(ctx, alloc_provider); + } + ctx = NULL; + + return retval; + + /* + * Usage + */ + + usage: + fprintf(stderr, "Usage: duk [options] []\n" + "\n" + " -i enter interactive mode after executing argument file(s) / eval code\n" + " -e CODE evaluate code\n" + " -c FILE compile into bytecode (use with only one file argument)\n" + " --run-stdin treat stdin like a file, i.e. compile full input (not line by line)\n" + " --verbose verbose messages to stderr\n" + " --restrict-memory use lower memory limit (used by test runner)\n" + " --alloc-default use Duktape default allocator\n" +#if defined(DUK_CMDLINE_ALLOC_LOGGING) + " --alloc-logging use logging allocator, write alloc log to /tmp/duk-alloc-log.txt\n" +#endif +#if defined(DUK_CMDLINE_ALLOC_TORTURE) + " --alloc-torture use torture allocator\n" +#endif +#if defined(DUK_CMDLINE_ALLOC_HYBRID) + " --alloc-hybrid use hybrid allocator\n" +#endif +#if defined(DUK_CMDLINE_LOWMEM) + " --alloc-lowmem use pooled allocator (enabled by default for duk-low)\n" + " --lowmem-log write alloc log to /tmp/lowmem-alloc-log.txt\n" +#endif +#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT) + " --debugger start example debugger\n" + " --reattach automatically reattach debugger on detach\n" +#endif + " --recreate-heap recreate heap after every file\n" + " --no-heap-destroy force GC, but don't destroy heap at end (leak testing)\n" + "\n" + "If is omitted, interactive mode is started automatically.\n"); + fflush(stderr); + exit(1); +} diff --git a/lib/duktape-2.2.1/examples/cmdline/duk_cmdline.h b/lib/duktape-2.2.1/examples/cmdline/duk_cmdline.h new file mode 100644 index 0000000..0c5c03d --- /dev/null +++ b/lib/duktape-2.2.1/examples/cmdline/duk_cmdline.h @@ -0,0 +1,16 @@ +#if !defined(DUK_CMDLINE_H_INCLUDED) +#define DUK_CMDLINE_H_INCLUDED + +/* Defined in duk_cmdline_lowmem.c. */ +extern void *lowmem_pool_ptr; +void lowmem_init(void); +void lowmem_free(void); +void lowmem_dump(void); +void lowmem_register(duk_context *ctx); +void lowmem_start_exec_timeout(void); +void lowmem_clear_exec_timeout(void); +void *lowmem_alloc_wrapped(void *udata, duk_size_t size); +void *lowmem_realloc_wrapped(void *udata, void *ptr, duk_size_t size); +void lowmem_free_wrapped(void *udata, void *ptr); + +#endif /* DUK_CMDLINE_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/cmdline/duk_cmdline_lowmem.c b/lib/duktape-2.2.1/examples/cmdline/duk_cmdline_lowmem.c new file mode 100644 index 0000000..4bafbb3 --- /dev/null +++ b/lib/duktape-2.2.1/examples/cmdline/duk_cmdline_lowmem.c @@ -0,0 +1,1016 @@ +/* + * Examples for low memory techniques + */ + +#if defined(DUK_CMDLINE_LOWMEM) + +#include +#include +#include +#include +#include "duktape.h" +#include "duk_cmdline.h" +#include "duk_alloc_pool.h" + +#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16) +/* Pointer compression with ROM strings/objects: + * + * For now, use DUK_USE_ROM_OBJECTS to signal the need for compressed ROM + * pointers. DUK_USE_ROM_PTRCOMP_FIRST is provided for the ROM pointer + * compression range minimum to avoid duplication in user code. + */ +#if 0 /* This extern declaration is provided by duktape.h, array provided by duktape.c. */ +extern const void * const duk_rom_compressed_pointers[]; +#endif +static const void *duk__romptr_low = NULL; +static const void *duk__romptr_high = NULL; +#define DUK__ROMPTR_COMPRESSION +#define DUK__ROMPTR_FIRST ((duk_uint_t) DUK_USE_ROM_PTRCOMP_FIRST) +#endif + +#define LOWMEM_NUM_POOLS 28 + +#define LOWMEM_HEAP_SIZE (255 * 1024) + +static const duk_pool_config lowmem_config[LOWMEM_NUM_POOLS] = { + { 8, 10 * 8, 0 }, + { 12, 600 * 12, 0 }, + { 16, 300 * 16, 0 }, + { 20, 300 * 20, 0 }, + { 24, 300 * 24, 0 }, + { 28, 250 * 28, 0 }, + { 32, 150 * 32, 0 }, + { 40, 150 * 40, 0 }, + { 48, 50 * 48, 0 }, + { 52, 50 * 52, 0 }, + { 56, 50 * 56, 0 }, + { 60, 50 * 60, 0 }, + { 64, 50 * 64, 0 }, + { 96, 50 * 96, 0 }, + { 196, 0, 196 }, /* duk_heap, with heap ptr compression, ROM strings+objects */ + { 232, 0, 232 }, /* duk_hthread, with heap ptr compression, ROM strings+objects */ + { 256, 16 * 256, 0 }, + { 288, 1 * 288, 0 }, + { 320, 1 * 320, 0 }, + { 400, 0, 400 }, /* duk_hthread, with heap ptr compression, RAM strings+objects */ + { 520, 0, 520 }, /* duk_heap, with heap ptr compression, RAM strings+objects */ + { 512, 16 * 512, 0 }, + { 768, 0, 768 }, /* initial value stack for packed duk_tval */ + { 1024, 6 * 1024, 0 }, + { 2048, 5 * 2048, 0 }, + { 4096, 3 * 4096, 0 }, + { 8192, 3 * 8192, 0 }, + { 16384, 1 * 16384, 0 }, +}; + +static duk_pool_state lowmem_state[LOWMEM_NUM_POOLS]; + +static duk_pool_global lowmem_global; + +void *lowmem_pool_ptr = NULL; + +uint8_t *lowmem_ram = NULL; + +static void *duk__lose_const(const void *ptr) { + /* Somewhat portable way of losing a const without warnings. + * Another approach is to cast through intptr_t, but that + * type is not always available. + */ + union { + const void *p; + void *q; + } u; + u.p = ptr; + return u.q; +} + +static void duk__safe_print_chars(const char *p, duk_size_t len, int until_nul) { + duk_size_t i; + + fprintf(stderr, "\""); + for (i = 0; i < len; i++) { + unsigned char x = (unsigned char) p[i]; + if (until_nul && x == 0U) { + break; + } + if (x < 0x20 || x >= 0x7e || x == '"' || x == '\'' || x == '\\') { + fprintf(stderr, "\\x%02x", (int) x); + } else { + fprintf(stderr, "%c", (char) x); + } + } + fprintf(stderr, "\""); +} + + +void lowmem_init(void) { + void *ptr; + + lowmem_ram = (uint8_t *) malloc(LOWMEM_HEAP_SIZE); + if (lowmem_ram == NULL) { + fprintf(stderr, "Failed to allocate lowmem heap\n"); + fflush(stderr); + exit(1); + } + + ptr = duk_alloc_pool_init((char *) lowmem_ram, + LOWMEM_HEAP_SIZE, + lowmem_config, + lowmem_state, + LOWMEM_NUM_POOLS, + &lowmem_global); + if (ptr == NULL) { + free(lowmem_ram); + lowmem_ram = NULL; + fprintf(stderr, "Failed to init lowmem pool\n"); + fflush(stderr); + exit(1); + } + + lowmem_pool_ptr = ptr; + +#if defined(DUK__ROMPTR_COMPRESSION) + /* Scan ROM pointer range for faster detection of "is 'p' a ROM pointer" + * later on. + */ + if (1) { + const void * const * ptrs = (const void * const *) duk_rom_compressed_pointers; + duk__romptr_low = duk__romptr_high = (const void *) *ptrs; + while (*ptrs) { + if (*ptrs > duk__romptr_high) { + duk__romptr_high = (const void *) *ptrs; + } + if (*ptrs < duk__romptr_low) { + duk__romptr_low = (const void *) *ptrs; + } + ptrs++; + } + fprintf(stderr, "romptrs: low=%p high=%p\n", + (const void *) duk__romptr_low, (const void *) duk__romptr_high); + fflush(stderr); + } +#endif +} + +void lowmem_free(void) { + if (lowmem_ram != NULL) { + free(lowmem_ram); + lowmem_ram = NULL; + } + lowmem_pool_ptr = NULL; +} + +static duk_ret_t lowmem__dump_binding(duk_context *ctx) { + lowmem_dump(); + return 0; +} + +void lowmem_dump(void) { + int i; + duk_pool_global_stats global_stats; + + for (i = 0; i < LOWMEM_NUM_POOLS; i++) { + duk_pool_state *s = &lowmem_state[i]; + duk_pool_stats stats; + + duk_alloc_pool_get_pool_stats(s, &stats); + + fprintf(stderr, " %2ld: %4ld %5ldB | free %4ld %5ldB | used %4ld %5ldB | waste %5ldB | hwm %4ld (%3ld%%)%s\n", + (long) i, (long) s->count, (long) s->size, + (long) stats.free_count, (long) stats.free_bytes, + (long) stats.used_count, (long) stats.used_bytes, + (long) stats.waste_bytes, (long) stats.hwm_used_count, + (long) ((double) stats.hwm_used_count / (double) s->count * 100.0), + (stats.hwm_used_count == s->count ? " !" : "")); + } + + /* This causes another walk over the individual pools which is a bit + * inelegant, but we want the highwater mark stats too. + */ + duk_alloc_pool_get_global_stats(&lowmem_global, &global_stats); + + fprintf(stderr, " TOTAL: %ld bytes used, %ld bytes waste, %ld bytes free, %ld bytes total; highwater %ld used, %ld waste\n", + (long) global_stats.used_bytes, (long) global_stats.waste_bytes, + (long) global_stats.free_bytes, (long) (global_stats.used_bytes + global_stats.free_bytes), + (long) global_stats.hwm_used_bytes, (long) global_stats.hwm_waste_bytes); + fflush(stderr); +} + +void lowmem_register(duk_context *ctx) { + duk_push_global_object(ctx); + duk_push_string(ctx, "dumpHeap"); + duk_push_c_function(ctx, lowmem__dump_binding, 0); + duk_def_prop(ctx, -3, DUK_DEFPROP_SET_WRITABLE | + DUK_DEFPROP_CLEAR_ENUMERABLE | + DUK_DEFPROP_SET_CONFIGURABLE | + DUK_DEFPROP_HAVE_VALUE); + duk_pop(ctx); +} + +/* + * Wrapped alloc functions + * + * Used to write an alloc log. + */ + +static FILE *lowmem_alloc_log = NULL; + +static void lowmem_write_alloc_log(const char *fmt, ...) { + va_list ap; + char buf[256]; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + buf[sizeof(buf) - 1] = (char) 0; + va_end(ap); + + if (lowmem_alloc_log == NULL) { + lowmem_alloc_log = fopen("/tmp/lowmem-alloc-log.txt", "wb"); + if (lowmem_alloc_log == NULL) { + fprintf(stderr, "WARNING: failed to write alloc log, ignoring\n"); + fflush(stderr); + return; + } + } + + (void) fwrite((const void *) buf, 1, strlen(buf), lowmem_alloc_log); + (void) fflush(lowmem_alloc_log); +} + +void *lowmem_alloc_wrapped(void *udata, duk_size_t size) { + void *ret = duk_alloc_pool(udata, size); + if (size > 0 && ret == NULL) { + lowmem_write_alloc_log("A FAIL %ld\n", (long) size); + } else if (ret == NULL) { + lowmem_write_alloc_log("A NULL %ld\n", (long) size); + } else { + lowmem_write_alloc_log("A %p %ld\n", ret, (long) size); + } + return ret; +} + +void *lowmem_realloc_wrapped(void *udata, void *ptr, duk_size_t size) { + void *ret = duk_realloc_pool(udata, ptr, size); + if (size > 0 && ret == NULL) { + if (ptr == NULL) { + lowmem_write_alloc_log("R NULL -1 FAIL %ld\n", (long) size); + } else { + lowmem_write_alloc_log("R %p -1 FAIL %ld\n", ptr, (long) size); + } + } else if (ret == NULL) { + if (ptr == NULL) { + lowmem_write_alloc_log("R NULL -1 NULL %ld\n", (long) size); + } else { + lowmem_write_alloc_log("R %p -1 NULL %ld\n", ptr, (long) size); + } + } else { + if (ptr == NULL) { + lowmem_write_alloc_log("R NULL -1 %p %ld\n", ret, (long) size); + } else { + lowmem_write_alloc_log("R %p -1 %p %ld\n", ptr, ret, (long) size); + } + } + return ret; +} + +void lowmem_free_wrapped(void *udata, void *ptr) { + duk_free_pool(udata, ptr); + if (ptr == NULL) { + /* Ignore. */ + } else { + lowmem_write_alloc_log("F %p -1\n", ptr); + } +} + +/* + * Example pointer compression functions. + * + * 'base' is chosen so that no non-NULL pointer results in a zero result + * which is reserved for NULL pointers. + */ + +duk_uint16_t lowmem_enc16(void *ud, void *p) { + duk_uint32_t ret; + char *base = (char *) lowmem_ram - 4; + +#if defined(DUK__ROMPTR_COMPRESSION) + if (p >= duk__romptr_low && p <= duk__romptr_high) { + /* The if-condition should be the fastest possible check + * for "is 'p' in ROM?". If pointer is in ROM, we'd like + * to compress it quickly. Here we just scan a ~1K array + * which is very bad for performance and for illustration + * only. + */ + const void * const * ptrs = duk_rom_compressed_pointers; + while (*ptrs) { + if (*ptrs == p) { + ret = (duk_uint32_t) DUK__ROMPTR_FIRST + (duk_uint32_t) (ptrs - duk_rom_compressed_pointers); +#if 0 + fprintf(stderr, "lowmem_enc16: rom pointer: %p -> 0x%04lx\n", (void *) p, (long) ret); + fflush(stderr); +#endif + return (duk_uint16_t) ret; + } + ptrs++; + } + + /* We should really never be here: Duktape should only be + * compressing pointers which are in the ROM compressed + * pointers list, which are known at 'make dist' time. + * We go on, causing a pointer compression error. + */ + fprintf(stderr, "lowmem_enc16: rom pointer: %p could not be compressed, should never happen\n", (void *) p); + fflush(stderr); + } +#endif + + /* Userdata is not needed in this case but would be useful if heap + * pointer compression were used for multiple heaps. The userdata + * allows the callback to distinguish between heaps and their base + * pointers. + * + * If not needed, the userdata can be left out during compilation + * by simply ignoring the userdata argument of the pointer encode + * and decode macros. It is kept here so that any bugs in actually + * providing the value inside Duktape are revealed during compilation. + */ + (void) ud; +#if 1 + /* Ensure that we always get the heap_udata given in heap creation. + * (Useful for Duktape development, not needed for user programs.) + */ + if (ud != (void *) lowmem_pool_ptr) { + fprintf(stderr, "invalid udata for lowmem_enc16: %p\n", ud); + fflush(stderr); + } +#endif + + if (p == NULL) { + ret = 0; + } else { + ret = (duk_uint32_t) (((char *) p - base) >> 2); + } +#if 0 + fprintf(stderr, "lowmem_enc16: %p -> %u\n", p, (unsigned int) ret); +#endif + if (ret > 0xffffUL) { + fprintf(stderr, "Failed to compress pointer: %p (ret was %ld)\n", (void *) p, (long) ret); + fflush(stderr); + abort(); + } +#if defined(DUK__ROMPTR_COMPRESSION) + if (ret >= (duk_uint32_t) DUK__ROMPTR_FIRST) { + fprintf(stderr, "Failed to compress pointer, in 16-bit range but matches romptr range: %p (ret was %ld)\n", (void *) p, (long) ret); + fflush(stderr); + abort(); + } +#endif + return (duk_uint16_t) ret; +} + +void *lowmem_dec16(void *ud, duk_uint16_t x) { + void *ret; + char *base = (char *) lowmem_ram - 4; + +#if defined(DUK__ROMPTR_COMPRESSION) + if (x >= (duk_uint16_t) DUK__ROMPTR_FIRST) { + /* This is a blind lookup, could check index validity. + * Duktape should never decompress a pointer which would + * be out-of-bounds here. + */ + ret = (void *) duk__lose_const(duk_rom_compressed_pointers[x - (duk_uint16_t) DUK__ROMPTR_FIRST]); +#if 0 + fprintf(stderr, "lowmem_dec16: rom pointer: 0x%04lx -> %p\n", (long) x, ret); + fflush(stderr); +#endif + return ret; + } +#endif + + /* See userdata discussion in lowmem_enc16(). */ + (void) ud; +#if 1 + /* Ensure that we always get the heap_udata given in heap creation. */ + if (ud != (void *) lowmem_pool_ptr) { + fprintf(stderr, "invalid udata for lowmem_dec16: %p\n", ud); + fflush(stderr); + } +#endif + + if (x == 0) { + ret = NULL; + } else { + ret = (void *) (base + (((duk_uint32_t) x) << 2)); + } +#if 0 + fprintf(stderr, "lowmem_dec16: %u -> %p\n", (unsigned int) x, ret); +#endif + return ret; +} + +/* + * Simplified example of an external strings strategy where incoming strings + * are written sequentially into a fixed, memory mapped flash area. + * + * The example first scans if the string is already in the flash (which may + * happen if the same string is interned multiple times), then adds it to + * flash if there is space. + * + * This example is too slow to be used in a real world application: there + * should be e.g. a hash table to quickly check for strings that are already + * present in the string data (similarly to how string interning works in + * Duktape itself). + */ + +static uint8_t lowmem_strdata[65536]; +static size_t lowmem_strdata_used = 0; + +const void *lowmem_extstr_check_1(const void *ptr, duk_size_t len) { + uint8_t *p, *p_end; + uint8_t initial; + uint8_t *ret; + size_t left; + + (void) duk__safe_print_chars; /* potentially unused */ + + if (len <= 3) { + /* It's not worth it to make very small strings external, as + * they would take the same space anyway. Also avoids zero + * length degenerate case. + */ + return NULL; + } + + /* + * Check if we already have the string. Be careful to compare for + * NUL terminator too, it is NOT present in 'ptr'. This algorithm + * is too simplistic and way too slow for actual use. + */ + + initial = ((const uint8_t *) ptr)[0]; + for (p = lowmem_strdata, p_end = p + lowmem_strdata_used; p != p_end; p++) { + if (*p != initial) { + continue; + } + left = (size_t) (p_end - p); + if (left >= len + 1 && + memcmp(p, ptr, len) == 0 && + p[len] == 0) { + ret = p; +#if 0 + fprintf(stderr, "lowmem_extstr_check_1: ptr=%p, len=%ld ", + (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> existing %p (used=%ld)\n", + (void *) ret, (long) lowmem_strdata_used); +#endif + return ret; + } + } + + /* + * Not present yet, check if we have space. Again, be careful to + * ensure there is space for a NUL following the input data. + */ + + if (lowmem_strdata_used + len + 1 > sizeof(lowmem_strdata)) { +#if 0 + fprintf(stderr, "lowmem_extstr_check_1: ptr=%p, len=%ld ", (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> no space (used=%ld)\n", (long) lowmem_strdata_used); +#endif + return NULL; + } + + /* + * There is space, add the string to our collection, being careful + * to append the NUL. + */ + + ret = lowmem_strdata + lowmem_strdata_used; + memcpy(ret, ptr, len); + ret[len] = (uint8_t) 0; + lowmem_strdata_used += len + 1; + +#if 0 + fprintf(stderr, "lowmem_extstr_check_1: ptr=%p, len=%ld -> ", (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> %p (used=%ld)\n", (void *) ret, (long) lowmem_strdata_used); +#endif + return (const void *) ret; +} + +void lowmem_extstr_free_1(const void *ptr) { + (void) ptr; +#if 0 + fprintf(stderr, "lowmem_extstr_free_1: freeing extstr %p -> ", ptr); + duk__safe_print_chars((const char *) ptr, DUK_SIZE_MAX, 1 /*until_nul*/); + fprintf(stderr, "\n"); +#endif +} + +/* + * Simplified example of an external strings strategy where a set of strings + * is gathered during application compile time and baked into the application + * binary. + * + * Duktape built-in strings are available from duk_source_meta.json in a + * prepared source directory, see tools/duk_meta_to_strarray.py. There + * may also be a lot of application specific strings, e.g. those used by + * application specific APIs. These must be gathered through some other + * means, see e.g. tools/scan_strings.py. + */ + +static const char *strdata_duk_builtin_strings[] = { + /* + * These strings are from tools/duk_meta_to_strarray.py + */ + + "Logger", + "Thread", + "Pointer", + "Buffer", + "DecEnv", + "ObjEnv", + "", + "global", + "Arguments", + "JSON", + "Math", + "Error", + "RegExp", + "Date", + "Number", + "Boolean", + "String", + "Array", + "Function", + "Object", + "Null", + "Undefined", + "{_func:true}", + "{\x22" "_func\x22" ":true}", + "{\x22" "_ninf\x22" ":true}", + "{\x22" "_inf\x22" ":true}", + "{\x22" "_nan\x22" ":true}", + "{\x22" "_undef\x22" ":true}", + "toLogString", + "clog", + "l", + "n", + "fatal", + "error", + "warn", + "debug", + "trace", + "raw", + "fmt", + "current", + "resume", + "compact", + "jc", + "jx", + "base64", + "hex", + "dec", + "enc", + "fin", + "gc", + "act", + "info", + "version", + "env", + "modLoaded", + "modSearch", + "errThrow", + "errCreate", + "compile", + "\x82" "Regbase", + "\x82" "Thread", + "\x82" "Handler", + "\x82" "Finalizer", + "\x82" "Callee", + "\x82" "Map", + "\x82" "Args", + "\x82" "This", + "\x82" "Pc2line", + "\x82" "Source", + "\x82" "Varenv", + "\x82" "Lexenv", + "\x82" "Varmap", + "\x82" "Formals", + "\x82" "Bytecode", + "\x82" "Next", + "\x82" "Target", + "\x82" "Value", + "pointer", + "buffer", + "\x82" "Tracedata", + "lineNumber", + "fileName", + "pc", + "stack", + "ThrowTypeError", + "Duktape", + "id", + "require", + "__proto__", + "setPrototypeOf", + "ownKeys", + "enumerate", + "deleteProperty", + "has", + "Proxy", + "callee", + "Invalid Date", + "[...]", + "\x0a" "\x09", + " ", + ",", + "-0", + "+0", + "0", + "-Infinity", + "+Infinity", + "Infinity", + "object", + "string", + "number", + "boolean", + "undefined", + "stringify", + "tan", + "sqrt", + "sin", + "round", + "random", + "pow", + "min", + "max", + "log", + "floor", + "exp", + "cos", + "ceil", + "atan2", + "atan", + "asin", + "acos", + "abs", + "SQRT2", + "SQRT1_2", + "PI", + "LOG10E", + "LOG2E", + "LN2", + "LN10", + "E", + "message", + "name", + "input", + "index", + "(?:)", + "lastIndex", + "multiline", + "ignoreCase", + "source", + "test", + "exec", + "toGMTString", + "setYear", + "getYear", + "toJSON", + "toISOString", + "toUTCString", + "setUTCFullYear", + "setFullYear", + "setUTCMonth", + "setMonth", + "setUTCDate", + "setDate", + "setUTCHours", + "setHours", + "setUTCMinutes", + "setMinutes", + "setUTCSeconds", + "setSeconds", + "setUTCMilliseconds", + "setMilliseconds", + "setTime", + "getTimezoneOffset", + "getUTCMilliseconds", + "getMilliseconds", + "getUTCSeconds", + "getSeconds", + "getUTCMinutes", + "getMinutes", + "getUTCHours", + "getHours", + "getUTCDay", + "getDay", + "getUTCDate", + "getDate", + "getUTCMonth", + "getMonth", + "getUTCFullYear", + "getFullYear", + "getTime", + "toLocaleTimeString", + "toLocaleDateString", + "toTimeString", + "toDateString", + "now", + "UTC", + "parse", + "toPrecision", + "toExponential", + "toFixed", + "POSITIVE_INFINITY", + "NEGATIVE_INFINITY", + "NaN", + "MIN_VALUE", + "MAX_VALUE", + "substr", + "trim", + "toLocaleUpperCase", + "toUpperCase", + "toLocaleLowerCase", + "toLowerCase", + "substring", + "split", + "search", + "replace", + "match", + "localeCompare", + "charCodeAt", + "charAt", + "fromCharCode", + "reduceRight", + "reduce", + "filter", + "map", + "forEach", + "some", + "every", + "lastIndexOf", + "indexOf", + "unshift", + "splice", + "sort", + "slice", + "shift", + "reverse", + "push", + "pop", + "join", + "concat", + "isArray", + "arguments", + "caller", + "bind", + "call", + "apply", + "propertyIsEnumerable", + "isPrototypeOf", + "hasOwnProperty", + "valueOf", + "toLocaleString", + "toString", + "constructor", + "set", + "get", + "enumerable", + "configurable", + "writable", + "value", + "keys", + "isExtensible", + "isFrozen", + "isSealed", + "preventExtensions", + "freeze", + "seal", + "defineProperties", + "defineProperty", + "create", + "getOwnPropertyNames", + "getOwnPropertyDescriptor", + "getPrototypeOf", + "prototype", + "length", + "alert", + "print", + "unescape", + "escape", + "encodeURIComponent", + "encodeURI", + "decodeURIComponent", + "decodeURI", + "isFinite", + "isNaN", + "parseFloat", + "parseInt", + "eval", + "URIError", + "TypeError", + "SyntaxError", + "ReferenceError", + "RangeError", + "EvalError", + "break", + "case", + "catch", + "continue", + "debugger", + "default", + "delete", + "do", + "else", + "finally", + "for", + "function", + "if", + "in", + "instanceof", + "new", + "return", + "switch", + "this", + "throw", + "try", + "typeof", + "var", + "void", + "while", + "with", + "class", + "const", + "enum", + "export", + "extends", + "import", + "super", + "null", + "true", + "false", + "implements", + "interface", + "let", + "package", + "private", + "protected", + "public", + "static", + "yield", + + /* + * These strings are manually added, and would be gathered in some + * application specific manner. + */ + + "foo", + "bar", + "quux", + "enableFrob", + "disableFrob" + /* ... */ +}; + +const void *lowmem_extstr_check_2(const void *ptr, duk_size_t len) { + int i, n; + + (void) duk__safe_print_chars; /* potentially unused */ + + /* Linear scan. An actual implementation would need some acceleration + * structure, e.g. select a sublist based on first character. + * + * NOTE: input string (behind 'ptr' with 'len' bytes) DOES NOT have a + * trailing NUL character. Any strings returned from this function + * MUST have a trailing NUL character. + */ + + n = (int) (sizeof(strdata_duk_builtin_strings) / sizeof(const char *)); + for (i = 0; i < n; i++) { + const char *str; + + str = strdata_duk_builtin_strings[i]; + if (strlen(str) == len && memcmp(ptr, (const void *) str, len) == 0) { +#if 0 + fprintf(stderr, "lowmem_extstr_check_2: ptr=%p, len=%ld ", + (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> constant string index %ld\n", (long) i); +#endif + return (void *) duk__lose_const(strdata_duk_builtin_strings[i]); + } + } + +#if 0 + fprintf(stderr, "lowmem_extstr_check_2: ptr=%p, len=%ld ", + (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> not found\n"); +#endif + return NULL; +} + +void lowmem_extstr_free_2(const void *ptr) { + (void) ptr; +#if 0 + fprintf(stderr, "lowmem_extstr_free_2: freeing extstr %p -> ", ptr); + duk__safe_print_chars((const char *) ptr, DUK_SIZE_MAX, 1 /*until_nul*/); + fprintf(stderr, "\n"); +#endif +} + +/* + * External strings strategy intended for valgrind testing: external strings + * are allocated using malloc()/free() so that valgrind can be used to ensure + * that strings are e.g. freed exactly once. + */ + +const void *lowmem_extstr_check_3(const void *ptr, duk_size_t len) { + duk_uint8_t *ret; + + (void) duk__safe_print_chars; /* potentially unused */ + + ret = malloc((size_t) len + 1); + if (ret == NULL) { +#if 0 + fprintf(stderr, "lowmem_extstr_check_3: ptr=%p, len=%ld ", + (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> malloc failed, return NULL\n"); +#endif + return (const void *) NULL; + } + + if (len > 0) { + memcpy((void *) ret, ptr, (size_t) len); + } + ret[len] = (duk_uint8_t) 0; + +#if 0 + fprintf(stderr, "lowmem_extstr_check_3: ptr=%p, len=%ld ", + (void *) ptr, (long) len); + duk__safe_print_chars((const char *) ptr, len, 0 /*until_nul*/); + fprintf(stderr, " -> %p\n", (void *) ret); +#endif + return (const void *) ret; +} + +void lowmem_extstr_free_3(const void *ptr) { + (void) ptr; +#if 0 + fprintf(stderr, "lowmem_extstr_free_3: freeing extstr %p -> ", ptr); + duk__safe_print_chars((const char *) ptr, DUK_SIZE_MAX, 1 /*until_nul*/); + fprintf(stderr, "\n"); +#endif + free((void *) duk__lose_const(ptr)); +} + +/* + * Execution timeout example + */ + +#define AJSHEAP_EXEC_TIMEOUT 5 /* seconds */ + +static time_t curr_pcall_start = 0; +static long exec_timeout_check_counter = 0; + +void lowmem_start_exec_timeout(void) { + curr_pcall_start = time(NULL); +} + +void lowmem_clear_exec_timeout(void) { + curr_pcall_start = 0; +} + +duk_bool_t lowmem_exec_timeout_check(void *udata) { + time_t now = time(NULL); + time_t diff = now - curr_pcall_start; + + (void) udata; /* not needed */ + + exec_timeout_check_counter++; +#if 0 + fprintf(stderr, "exec timeout check %ld: now=%ld, start=%ld, diff=%ld\n", + (long) exec_timeout_check_counter, (long) now, (long) curr_pcall_start, (long) diff); + fflush(stderr); +#endif + + if (curr_pcall_start == 0) { + /* protected call not yet running */ + return 0; + } + if (diff > AJSHEAP_EXEC_TIMEOUT) { + return 1; + } + return 0; +} + +#else /* DUK_CMDLINE_LOWMEM */ + +int duk_lowmem_dummy = 0; /* to avoid empty source file */ + +#endif /* DUK_CMDLINE_LOWMEM */ diff --git a/lib/duktape-2.2.1/examples/codepage-conv/README.rst b/lib/duktape-2.2.1/examples/codepage-conv/README.rst new file mode 100644 index 0000000..98b53d2 --- /dev/null +++ b/lib/duktape-2.2.1/examples/codepage-conv/README.rst @@ -0,0 +1,8 @@ +Codepage conversion example +=========================== + +Example of how to convert an 8-bit input string (e.g. ISO-8859-1 or Windows +codepage 1252) into CESU-8 without using an external library like iconv. + +This is useful e.g. when compiling non-UTF-8 source code which cannot be +converted to UTF-8 (CESU-8) at build time. diff --git a/lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.c b/lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.c new file mode 100644 index 0000000..315f042 --- /dev/null +++ b/lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.c @@ -0,0 +1,54 @@ +/* + * Convert an 8-bit input string (e.g. ISO-8859-1) into CESU-8. + * Calling code supplies the "code page" as a 256-entry array of + * codepoints for the conversion. + * + * This is useful when input data is in non-UTF-8 format and must + * be converted at runtime, e.g. when compiling non-UTF-8 source + * code. Another alternative is to use e.g. iconv. + */ + +#include "duktape.h" + +/* Decode an 8-bit string using 'codepage' into Unicode codepoints and + * re-encode into CESU-8. Codepage argument must point to a 256-entry + * table. Only supports BMP (codepoints U+0000 to U+FFFF). + */ +void duk_decode_string_codepage(duk_context *ctx, const char *str, size_t len, unsigned int *codepage) { + unsigned char *tmp; + size_t tmplen, i; + unsigned char *p; + unsigned int cp; + + tmplen = 3 * len; /* max expansion is 1 input byte -> 3 output bytes */ + if (tmplen / 3 != len) { + /* Temporary buffer length wraps. */ + (void) duk_error(ctx, DUK_ERR_RANGE_ERROR, "input string too long"); + return; + } + + tmp = (unsigned char *) duk_push_fixed_buffer(ctx, tmplen); + + for (i = 0, p = tmp; i < len; i++) { + cp = codepage[((unsigned char *) str)[i]] & 0xffffUL; + if (cp < 0x80UL) { + *p++ = (unsigned char) cp; + } else if (cp < 0x800UL) { + *p++ = (unsigned char) (0xc0 + ((cp >> 6) & 0x1f)); + *p++ = (unsigned char) (0x80 + (cp & 0x3f)); + } else { + /* In CESU-8 all codepoints in [0x0000,0xFFFF] are + * allowed, including surrogates. + */ + *p++ = (unsigned char) (0xe0 + ((cp >> 12) & 0x0f)); + *p++ = (unsigned char) (0x80 + ((cp >> 6) & 0x3f)); + *p++ = (unsigned char) (0x80 + (cp & 0x3f)); + } + } + + duk_push_lstring(ctx, (const char *) tmp, (duk_size_t) (p - tmp)); + + /* [ ... tmp res ] */ + + duk_remove(ctx, -2); +} diff --git a/lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.h b/lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.h new file mode 100644 index 0000000..052d27f --- /dev/null +++ b/lib/duktape-2.2.1/examples/codepage-conv/duk_codepage_conv.h @@ -0,0 +1,8 @@ +#if !defined(DUK_CODEPAGE_CONV_H_INCLUDED) +#define DUK_CODEPAGE_CONV_H_INCLUDED + +#include "duktape.h" + +void duk_decode_string_codepage(duk_context *ctx, const char *str, size_t len, unsigned int *codepage); + +#endif /* DUK_CODEPAGE_CONV_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/codepage-conv/test.c b/lib/duktape-2.2.1/examples/codepage-conv/test.c new file mode 100644 index 0000000..7a89dd4 --- /dev/null +++ b/lib/duktape-2.2.1/examples/codepage-conv/test.c @@ -0,0 +1,298 @@ +#include "duktape.h" +#include "duk_codepage_conv.h" + +/* http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT */ +unsigned int cp1252[256] = { + (unsigned int) 0x0000, + (unsigned int) 0x0001, + (unsigned int) 0x0002, + (unsigned int) 0x0003, + (unsigned int) 0x0004, + (unsigned int) 0x0005, + (unsigned int) 0x0006, + (unsigned int) 0x0007, + (unsigned int) 0x0008, + (unsigned int) 0x0009, + (unsigned int) 0x000A, + (unsigned int) 0x000B, + (unsigned int) 0x000C, + (unsigned int) 0x000D, + (unsigned int) 0x000E, + (unsigned int) 0x000F, + (unsigned int) 0x0010, + (unsigned int) 0x0011, + (unsigned int) 0x0012, + (unsigned int) 0x0013, + (unsigned int) 0x0014, + (unsigned int) 0x0015, + (unsigned int) 0x0016, + (unsigned int) 0x0017, + (unsigned int) 0x0018, + (unsigned int) 0x0019, + (unsigned int) 0x001A, + (unsigned int) 0x001B, + (unsigned int) 0x001C, + (unsigned int) 0x001D, + (unsigned int) 0x001E, + (unsigned int) 0x001F, + (unsigned int) 0x0020, + (unsigned int) 0x0021, + (unsigned int) 0x0022, + (unsigned int) 0x0023, + (unsigned int) 0x0024, + (unsigned int) 0x0025, + (unsigned int) 0x0026, + (unsigned int) 0x0027, + (unsigned int) 0x0028, + (unsigned int) 0x0029, + (unsigned int) 0x002A, + (unsigned int) 0x002B, + (unsigned int) 0x002C, + (unsigned int) 0x002D, + (unsigned int) 0x002E, + (unsigned int) 0x002F, + (unsigned int) 0x0030, + (unsigned int) 0x0031, + (unsigned int) 0x0032, + (unsigned int) 0x0033, + (unsigned int) 0x0034, + (unsigned int) 0x0035, + (unsigned int) 0x0036, + (unsigned int) 0x0037, + (unsigned int) 0x0038, + (unsigned int) 0x0039, + (unsigned int) 0x003A, + (unsigned int) 0x003B, + (unsigned int) 0x003C, + (unsigned int) 0x003D, + (unsigned int) 0x003E, + (unsigned int) 0x003F, + (unsigned int) 0x0040, + (unsigned int) 0x0041, + (unsigned int) 0x0042, + (unsigned int) 0x0043, + (unsigned int) 0x0044, + (unsigned int) 0x0045, + (unsigned int) 0x0046, + (unsigned int) 0x0047, + (unsigned int) 0x0048, + (unsigned int) 0x0049, + (unsigned int) 0x004A, + (unsigned int) 0x004B, + (unsigned int) 0x004C, + (unsigned int) 0x004D, + (unsigned int) 0x004E, + (unsigned int) 0x004F, + (unsigned int) 0x0050, + (unsigned int) 0x0051, + (unsigned int) 0x0052, + (unsigned int) 0x0053, + (unsigned int) 0x0054, + (unsigned int) 0x0055, + (unsigned int) 0x0056, + (unsigned int) 0x0057, + (unsigned int) 0x0058, + (unsigned int) 0x0059, + (unsigned int) 0x005A, + (unsigned int) 0x005B, + (unsigned int) 0x005C, + (unsigned int) 0x005D, + (unsigned int) 0x005E, + (unsigned int) 0x005F, + (unsigned int) 0x0060, + (unsigned int) 0x0061, + (unsigned int) 0x0062, + (unsigned int) 0x0063, + (unsigned int) 0x0064, + (unsigned int) 0x0065, + (unsigned int) 0x0066, + (unsigned int) 0x0067, + (unsigned int) 0x0068, + (unsigned int) 0x0069, + (unsigned int) 0x006A, + (unsigned int) 0x006B, + (unsigned int) 0x006C, + (unsigned int) 0x006D, + (unsigned int) 0x006E, + (unsigned int) 0x006F, + (unsigned int) 0x0070, + (unsigned int) 0x0071, + (unsigned int) 0x0072, + (unsigned int) 0x0073, + (unsigned int) 0x0074, + (unsigned int) 0x0075, + (unsigned int) 0x0076, + (unsigned int) 0x0077, + (unsigned int) 0x0078, + (unsigned int) 0x0079, + (unsigned int) 0x007A, + (unsigned int) 0x007B, + (unsigned int) 0x007C, + (unsigned int) 0x007D, + (unsigned int) 0x007E, + (unsigned int) 0x007F, + (unsigned int) 0x20AC, + (unsigned int) 0xFFFD, /* undefined */ + (unsigned int) 0x201A, + (unsigned int) 0x0192, + (unsigned int) 0x201E, + (unsigned int) 0x2026, + (unsigned int) 0x2020, + (unsigned int) 0x2021, + (unsigned int) 0x02C6, + (unsigned int) 0x2030, + (unsigned int) 0x0160, + (unsigned int) 0x2039, + (unsigned int) 0x0152, + (unsigned int) 0xFFFD, /* undefined */ + (unsigned int) 0x017D, + (unsigned int) 0xFFFD, /* undefined */ + (unsigned int) 0xFFFD, /* undefined */ + (unsigned int) 0x2018, + (unsigned int) 0x2019, + (unsigned int) 0x201C, + (unsigned int) 0x201D, + (unsigned int) 0x2022, + (unsigned int) 0x2013, + (unsigned int) 0x2014, + (unsigned int) 0x02DC, + (unsigned int) 0x2122, + (unsigned int) 0x0161, + (unsigned int) 0x203A, + (unsigned int) 0x0153, + (unsigned int) 0xFFFD, /* undefined */ + (unsigned int) 0x017E, + (unsigned int) 0x0178, + (unsigned int) 0x00A0, + (unsigned int) 0x00A1, + (unsigned int) 0x00A2, + (unsigned int) 0x00A3, + (unsigned int) 0x00A4, + (unsigned int) 0x00A5, + (unsigned int) 0x00A6, + (unsigned int) 0x00A7, + (unsigned int) 0x00A8, + (unsigned int) 0x00A9, + (unsigned int) 0x00AA, + (unsigned int) 0x00AB, + (unsigned int) 0x00AC, + (unsigned int) 0x00AD, + (unsigned int) 0x00AE, + (unsigned int) 0x00AF, + (unsigned int) 0x00B0, + (unsigned int) 0x00B1, + (unsigned int) 0x00B2, + (unsigned int) 0x00B3, + (unsigned int) 0x00B4, + (unsigned int) 0x00B5, + (unsigned int) 0x00B6, + (unsigned int) 0x00B7, + (unsigned int) 0x00B8, + (unsigned int) 0x00B9, + (unsigned int) 0x00BA, + (unsigned int) 0x00BB, + (unsigned int) 0x00BC, + (unsigned int) 0x00BD, + (unsigned int) 0x00BE, + (unsigned int) 0x00BF, + (unsigned int) 0x00C0, + (unsigned int) 0x00C1, + (unsigned int) 0x00C2, + (unsigned int) 0x00C3, + (unsigned int) 0x00C4, + (unsigned int) 0x00C5, + (unsigned int) 0x00C6, + (unsigned int) 0x00C7, + (unsigned int) 0x00C8, + (unsigned int) 0x00C9, + (unsigned int) 0x00CA, + (unsigned int) 0x00CB, + (unsigned int) 0x00CC, + (unsigned int) 0x00CD, + (unsigned int) 0x00CE, + (unsigned int) 0x00CF, + (unsigned int) 0x00D0, + (unsigned int) 0x00D1, + (unsigned int) 0x00D2, + (unsigned int) 0x00D3, + (unsigned int) 0x00D4, + (unsigned int) 0x00D5, + (unsigned int) 0x00D6, + (unsigned int) 0x00D7, + (unsigned int) 0x00D8, + (unsigned int) 0x00D9, + (unsigned int) 0x00DA, + (unsigned int) 0x00DB, + (unsigned int) 0x00DC, + (unsigned int) 0x00DD, + (unsigned int) 0x00DE, + (unsigned int) 0x00DF, + (unsigned int) 0x00E0, + (unsigned int) 0x00E1, + (unsigned int) 0x00E2, + (unsigned int) 0x00E3, + (unsigned int) 0x00E4, + (unsigned int) 0x00E5, + (unsigned int) 0x00E6, + (unsigned int) 0x00E7, + (unsigned int) 0x00E8, + (unsigned int) 0x00E9, + (unsigned int) 0x00EA, + (unsigned int) 0x00EB, + (unsigned int) 0x00EC, + (unsigned int) 0x00ED, + (unsigned int) 0x00EE, + (unsigned int) 0x00EF, + (unsigned int) 0x00F0, + (unsigned int) 0x00F1, + (unsigned int) 0x00F2, + (unsigned int) 0x00F3, + (unsigned int) 0x00F4, + (unsigned int) 0x00F5, + (unsigned int) 0x00F6, + (unsigned int) 0x00F7, + (unsigned int) 0x00F8, + (unsigned int) 0x00F9, + (unsigned int) 0x00FA, + (unsigned int) 0x00FB, + (unsigned int) 0x00FC, + (unsigned int) 0x00FD, + (unsigned int) 0x00FE, + (unsigned int) 0x00FF +}; + +/* Exercise all 3 byte lengths: any ASCII character is 1 byte, 0xFC maps to + * U+00FC which is 2 bytes, and 0x80 maps to U+20AC which is 3 bytes. + */ +static const char *example_source = "print('Hello w\xfcrld - \x80');"; + +static duk_ret_t duk__print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 0; +} + +/* Example: compile and run test source encoded in Windows codepage 1252. */ +int main(int argc, char *argv[]) { + duk_context *ctx; + + (void) argc; (void) argv; + + ctx = duk_create_heap_default(); + if (!ctx) { + printf("Failed to create Duktape heap.\n"); + return 1; + } + + /* Minimal print() provider. */ + duk_push_c_function(ctx, duk__print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + duk_decode_string_codepage(ctx, example_source, strlen(example_source), cp1252); + duk_eval_noresult(ctx); + + duk_destroy_heap(ctx); + return 0; +} diff --git a/lib/duktape-2.2.1/examples/coffee/README.rst b/lib/duktape-2.2.1/examples/coffee/README.rst new file mode 100644 index 0000000..f147522 --- /dev/null +++ b/lib/duktape-2.2.1/examples/coffee/README.rst @@ -0,0 +1,10 @@ +===================== +Coffeescript examples +===================== + +A few tests to see how CoffeeScript works with Duktape. Just convert the +Coffeescript files to Javascript with the ``Makefile.coffee`` in the +distributable, or manually:: + + $ coffee -c hello.coffee + $ cat hello.js diff --git a/lib/duktape-2.2.1/examples/coffee/globals.coffee b/lib/duktape-2.2.1/examples/coffee/globals.coffee new file mode 100644 index 0000000..25773cd --- /dev/null +++ b/lib/duktape-2.2.1/examples/coffee/globals.coffee @@ -0,0 +1,7 @@ + +print '*** All globals' +print(name) for name in Object.getOwnPropertyNames(this) + +print '*** Globals with a short name (<= 8 chars)' +print(name) for name in Object.getOwnPropertyNames(this) when name.length <= 8 + diff --git a/lib/duktape-2.2.1/examples/coffee/hello.coffee b/lib/duktape-2.2.1/examples/coffee/hello.coffee new file mode 100644 index 0000000..088ed8d --- /dev/null +++ b/lib/duktape-2.2.1/examples/coffee/hello.coffee @@ -0,0 +1,2 @@ +print 'Hello world!' +print 'version: ' + Duktape.version diff --git a/lib/duktape-2.2.1/examples/coffee/mandel.coffee b/lib/duktape-2.2.1/examples/coffee/mandel.coffee new file mode 100644 index 0000000..8e3e170 --- /dev/null +++ b/lib/duktape-2.2.1/examples/coffee/mandel.coffee @@ -0,0 +1,28 @@ +mandel = (x0, y0, x1, y1, w, h, maxiter) -> + [dx, dy] = [(x1 - x0) / w, (y1 - y0) / h] + res = [] + + y = y0 + for yc in [0..h-1] + x = x0 + for xc in [0..w-1] + [xx, yy] = [x, y] + c = '*' + for i in [0..maxiter-1] + # (xx+i*yy)^2 + (x+i*y) = xx^2 + i*2*xx*yy - yy^2 + x + i*y + # = (xx^2 - yy^2 + x) + i*(2*xx*yy + y) + [xx2, yy2] = [xx*xx, yy*yy] + if xx2 + yy2 >= 4.0 + c = '.' + break + [xx, yy] = [xx2 - yy2 + x, 2*xx*yy + y] + res.push(c) + x += dx + res.push('\n') + y += dy + + print(res.join('')) + return + +mandel(-2, 2, 2, -2, 200, 100, 1000) + diff --git a/lib/duktape-2.2.1/examples/cpp-exceptions/README.rst b/lib/duktape-2.2.1/examples/cpp-exceptions/README.rst new file mode 100644 index 0000000..fb969da --- /dev/null +++ b/lib/duktape-2.2.1/examples/cpp-exceptions/README.rst @@ -0,0 +1,29 @@ +========================================= +C++ exceptions for long control transfers +========================================= + +Normally Duktape uses ``setjmp()`` / ``longjmp()`` or their variants for +internal long control transfers. One downside of these functions is that +C++ automatic destructors (scope-based resource management, SBRM, a special +case of RAII) in Duktape/C functions won't be executed which is awkward for +C++ programmers. + +When ``DUK_USE_CPP_EXCEPTIONS`` is defined, and both Duktape and application +code is compiled using a C++ compiler, Duktape uses C++ ``try-catch`` and +``throw`` for internal long control transfers. This allows automatic +destructors to run as expected. The config option is not enabled by default +because C++ exceptions are sometimes disabled even when a C++ compiler is +used (e.g. for performance reasons). + +The ``cpp_exceptions.cpp`` example illustrates how C++ exceptions can be +used in Duktape/C functions at the moment: + +* Duktape uses C++ try/catch/throw internally; this is not visible to user + code directly. + +* Automatic destructors (scope-based resource management) work as expected. + +* C++ exceptions can be used in Duktape/C functions normally, but user + exceptions must be caught before they reach Duktape. If this is not + done, such exceptions are caught by Duktape and converted to API errors + (in other words, they won't propagate "through" Duktape at the moment). diff --git a/lib/duktape-2.2.1/examples/cpp-exceptions/cpp_exceptions.cpp b/lib/duktape-2.2.1/examples/cpp-exceptions/cpp_exceptions.cpp new file mode 100644 index 0000000..67faf90 --- /dev/null +++ b/lib/duktape-2.2.1/examples/cpp-exceptions/cpp_exceptions.cpp @@ -0,0 +1,311 @@ +/* + * Example of how to use DUK_USE_CPP_EXCEPTIONS to support automatic + * variables (e.g. destructor calls) in Duktape/C functions. + * + * Configure and compile with -DDUK_USE_CPP_EXCEPTIONS: + * + * $ python2 tools/configure.py \ + * --source-directory src-input \ + * --output-directory /tmp/output \ + * --config-metadata config \ + * -DDUK_USE_CPP_EXCEPTIONS + * + * $ g++ -otest -I/tmp/output \ + * /tmp/output/duktape.c cpp_exceptions.cpp -lm + * + * When executed you should see something like: + * + * $ ./test + * my_class instance created + * my_class instance destroyed <== destructor gets called + * --> rc=1 (SyntaxError: parse error (line 1)) + * [...] + * + * Duktape uses a custom exception class (duk_internal_exception) which + * doesn't inherit from any base class, so that catching any base classes + * in user code won't accidentally catch exceptions thrown by Duktape. + */ + +#if !defined(__cplusplus) +#error compile using a c++ compiler +#endif + +#include +#include +#include "duktape.h" + +#if defined(__cplusplus) && (__cplusplus >= 201103L) +#define NOEXCEPT noexcept +#else +#define NOEXCEPT throw() +#endif + +/* + * Example class with a destructor + */ + +class my_class { + public: + my_class(); + ~my_class(); +}; + +my_class::my_class() { + printf("my_class instance created\n"); +} + +my_class::~my_class() { + printf("my_class instance destroyed\n"); +} + +/* + * SyntaxError caused by eval exits Duktape/C function but destructors + * are executed. + */ + +duk_ret_t test1(duk_context *ctx) { + my_class myclass; + + duk_eval_string(ctx, "aiee="); + + return 0; +} +duk_ret_t test1_safecall(duk_context *ctx, void *udata) { + (void) udata; + return test1(ctx); +} + +/* + * You can use C++ exceptions inside Duktape/C functions for your own + * purposes but you should catch them before they propagate to Duktape. + */ + +duk_ret_t test2(duk_context *ctx) { + my_class myclass; + + try { + throw 123; + } catch (int myvalue) { + printf("Caught: %d\n", myvalue); + } + + return 0; +} +duk_ret_t test2_safecall(duk_context *ctx, void *udata) { + (void) udata; + return test2(ctx); +} + +/* + * If you let your own C++ exceptions propagate out of a Duktape/C function + * it will be caught by Duktape and considered a programming error. Duktape + * will catch the exception and convert it to a Duktape error. + * + * This may be allowed in a later version once all the implications have been + * worked out. + */ + +duk_ret_t test3(duk_context *ctx) { + my_class myclass; + + throw 123; /* ERROR: exception propagated to Duktape */ + + return 0; +} +duk_ret_t test3_safecall(duk_context *ctx, void *udata) { + (void) udata; + return test3(ctx); +} + +/* + * Same as above, but if the exception inherits from std::exception, it's + * "what()" will be included in the error message. + */ + +class my_exception : public std::exception { + virtual const char *what() const NOEXCEPT { + return "my_exception"; + } +}; + +duk_ret_t test4(duk_context *ctx) { + my_class myclass; + my_exception myexc; + + throw myexc; /* ERROR: exception propagated to Duktape */ + + return 0; +} +duk_ret_t test4_safecall(duk_context *ctx, void *udata) { + (void) udata; + return test4(ctx); +} + +/* + * Same as above, but if the exception inherits from std::exception with + * a NULL what(). Duktape will describe the error as 'unknown' if so. + */ + +class my_exception2 : public std::exception { + virtual const char *what() const NOEXCEPT { + return NULL; + } +}; + +duk_ret_t test5(duk_context *ctx) { + my_class myclass; + my_exception2 myexc; + + throw myexc; /* ERROR: exception propagated to Duktape */ + + return 0; +} +duk_ret_t test5_safecall(duk_context *ctx, void *udata) { + (void) udata; + return test5(ctx); +} + +static duk_ret_t duk__print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 0; +} + +int main(int argc, char *argv[]) { + duk_context *ctx = duk_create_heap_default(); + duk_int_t rc; + + (void) argc; (void) argv; /* suppress warning */ + + /* Minimal print() provider. */ + duk_push_c_function(ctx, duk__print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + printf("*** test1 - duk_pcall()\n"); + duk_push_c_function(ctx, test1, 0); + rc = duk_pcall(ctx, 0); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test1 - duk_safe_call()\n"); + rc = duk_safe_call(ctx, test1_safecall, NULL, 0, 1); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test1 - ecmascript try-catch\n"); + duk_push_c_function(ctx, test1, 0); + duk_put_global_string(ctx, "test1"); + duk_eval_string_noresult(ctx, + "try {\n" + " test1();\n" + "} catch (e) {\n" + " print(e.stack || e);\n" + "}\n"); + printf("\n"); + + printf("*** test2 - duk_pcall()\n"); + duk_push_c_function(ctx, test2, 0); + rc = duk_pcall(ctx, 0); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test2 - duk_safe_call()\n"); + rc = duk_safe_call(ctx, test2_safecall, NULL, 0, 1); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test2 - ecmascript try-catch\n"); + duk_push_c_function(ctx, test2, 0); + duk_put_global_string(ctx, "test2"); + duk_eval_string_noresult(ctx, + "try {\n" + " test2();\n" + "} catch (e) {\n" + " print(e.stack || e);\n" + "}\n"); + printf("\n"); + + printf("*** test3 - duk_pcall()\n"); + duk_push_c_function(ctx, test3, 0); + rc = duk_pcall(ctx, 0); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test3 - duk_safe_call()\n"); + rc = duk_safe_call(ctx, test3_safecall, NULL, 0, 1); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test3 - ecmascript try-catch\n"); + duk_push_c_function(ctx, test3, 0); + duk_put_global_string(ctx, "test3"); + duk_eval_string_noresult(ctx, + "try {\n" + " test3();\n" + "} catch (e) {\n" + " print(e.stack || e);\n" + "}\n"); + printf("\n"); + + printf("*** test4 - duk_pcall()\n"); + duk_push_c_function(ctx, test4, 0); + rc = duk_pcall(ctx, 0); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test4 - duk_safe_call()\n"); + rc = duk_safe_call(ctx, test4_safecall, NULL, 0, 1); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test4 - ecmascript try-catch\n"); + duk_push_c_function(ctx, test4, 0); + duk_put_global_string(ctx, "test4"); + duk_eval_string_noresult(ctx, + "try {\n" + " test4();\n" + "} catch (e) {\n" + " print(e.stack || e);\n" + "}\n"); + printf("\n"); + + printf("*** test5 - duk_pcall()\n"); + duk_push_c_function(ctx, test5, 0); + rc = duk_pcall(ctx, 0); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test5 - duk_safe_call()\n"); + rc = duk_safe_call(ctx, test5_safecall, NULL, 0, 1); + printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + printf("\n"); + + printf("*** test5 - ecmascript try-catch\n"); + duk_push_c_function(ctx, test5, 0); + duk_put_global_string(ctx, "test5"); + duk_eval_string_noresult(ctx, + "try {\n" + " test5();\n" + "} catch (e) {\n" + " print(e.stack || e);\n" + "}\n"); + printf("\n"); + + printf("*** done\n"); + + duk_destroy_heap(ctx); + + return 0; +} diff --git a/lib/duktape-2.2.1/examples/debug-trans-dvalue/Makefile b/lib/duktape-2.2.1/examples/debug-trans-dvalue/Makefile new file mode 100644 index 0000000..79b7317 --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-dvalue/Makefile @@ -0,0 +1,16 @@ +DUKTAPE_OPTS= +DUKTAPE_OPTS+=-DDUK_USE_ASSERTIONS +DUKTAPE_OPTS+=-DDUK_USE_DEBUGGER_SUPPORT -DDUK_USE_INTERRUPT_COUNTER +DUKTAPE_OPTS+=-DDUK_USE_DEBUGGER_DUMPHEAP +#DUKTAPE_OPTS+=-DDUK_USE_DEBUGGER_TRANSPORT_TORTURE +TRANS_OPTS= +#TRANS_OPTS+=-DDEBUG_PRINTS + +test: test.c duk_trans_dvalue.c duk_trans_dvalue.h + rm -rf ./prep + python2 ../../tools/configure.py \ + --output-directory ./prep \ + $(DUKTAPE_OPTS) + gcc -O0 -g -ggdb -Wall -Wextra -std=c99 -o test -I./prep -I. \ + $(TRANS_OPTS) \ + ./prep/duktape.c duk_trans_dvalue.c test.c -lm diff --git a/lib/duktape-2.2.1/examples/debug-trans-dvalue/README.rst b/lib/duktape-2.2.1/examples/debug-trans-dvalue/README.rst new file mode 100644 index 0000000..86b2bb5 --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-dvalue/README.rst @@ -0,0 +1,8 @@ +=========================================================== +Debug transport with local debug protocol encoding/decoding +=========================================================== + +This example implements a debug transport which decodes/encodes the Duktape +debug protocol locally into a more easy to use C interface, which is useful +for debug clients implemented locally on the target. The example also +demonstrates how to trial parse dvalues in C. diff --git a/lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.c b/lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.c new file mode 100644 index 0000000..84cf70b --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.c @@ -0,0 +1,1241 @@ +/* + * Example debug transport with a local debug message encoder/decoder. + * + * Provides a "received dvalue" callback for a fully parsed dvalue (user + * code frees dvalue) and a "cooperate" callback for e.g. UI integration. + * There are a few other callbacks. See test.c for usage examples. + * + * This transport implementation is not multithreaded which means that: + * + * - Callbacks to "received dvalue" callback come from the Duktape thread, + * either during normal execution or from duk_debugger_cooperate(). + * + * - Calls into duk_trans_dvalue_send() must be made from the callbacks + * provided (e.g. "received dvalue" or "cooperate") which use the active + * Duktape thread. + * + * - The only exception to this is when Duktape is idle: you can then call + * duk_trans_dvalue_send() from any thread (only one thread at a time). + * When you next call into Duktape or call duk_debugger_cooperate(), the + * queued data will be read and processed by Duktape. + * + * There are functions for creating and freeing values; internally they use + * malloc() and free() for memory management. Duktape heap alloc functions + * are not used to minimize disturbances to the Duktape heap under debugging. + * + * Doesn't depend on C99 types; assumes "int" is at least 32 bits, and makes + * a few assumptions about format specifiers. + */ + +#include +#include +#include + +#include "duktape.h" +#include "duk_trans_dvalue.h" + +/* Define to enable debug prints to stderr. */ +#if 0 +#define DEBUG_PRINTS +#endif + +/* Define to enable error prints to stderr. */ +#if 1 +#define ERROR_PRINTS +#endif + +/* + * Dvalue handling + */ + +duk_dvalue *duk_dvalue_alloc(void) { + duk_dvalue *dv = (duk_dvalue *) malloc(sizeof(duk_dvalue)); + if (dv) { + memset((void *) dv, 0, sizeof(duk_dvalue)); + dv->buf = NULL; + } + return dv; +} + +void duk_dvalue_free(duk_dvalue *dv) { + if (dv) { + free(dv->buf); /* tolerates NULL */ + dv->buf = NULL; + free(dv); + } +} + +static void duk__dvalue_bufesc(duk_dvalue *dv, char *buf, size_t maxbytes, int stresc) { + size_t i, limit; + + *buf = (char) 0; + limit = dv->len > maxbytes ? maxbytes : dv->len; + for (i = 0; i < limit; i++) { + unsigned char c = dv->buf[i]; + if (stresc) { + if (c >= 0x20 && c <= 0x7e && c != (char) '"' && c != (char) '\'') { + sprintf(buf, "%c", c); + buf++; + } else { + sprintf(buf, "\\x%02x", (unsigned int) c); + buf += 4; + } + } else { + sprintf(buf, "%02x", (unsigned int) c); + buf += 2; + } + } + if (dv->len > maxbytes) { + sprintf(buf, "..."); + buf += 3; + } +} + +/* Caller must provide a buffer at least DUK_DVALUE_TOSTRING_BUFLEN in size. */ +void duk_dvalue_to_string(duk_dvalue *dv, char *buf) { + char hexbuf[32 * 4 + 4]; /* 32 hex encoded or \xXX escaped bytes, possible "...", NUL */ + + if (!dv) { + sprintf(buf, "NULL"); + return; + } + + switch (dv->tag) { + case DUK_DVALUE_EOM: + sprintf(buf, "EOM"); + break; + case DUK_DVALUE_REQ: + sprintf(buf, "REQ"); + break; + case DUK_DVALUE_REP: + sprintf(buf, "REP"); + break; + case DUK_DVALUE_ERR: + sprintf(buf, "ERR"); + break; + case DUK_DVALUE_NFY: + sprintf(buf, "NFY"); + break; + case DUK_DVALUE_INTEGER: + sprintf(buf, "%d", dv->i); + break; + case DUK_DVALUE_STRING: + duk__dvalue_bufesc(dv, hexbuf, 32, 1); + sprintf(buf, "str:%ld:\"%s\"", (long) dv->len, hexbuf); + break; + case DUK_DVALUE_BUFFER: + duk__dvalue_bufesc(dv, hexbuf, 32, 0); + sprintf(buf, "buf:%ld:%s", (long) dv->len, hexbuf); + break; + case DUK_DVALUE_UNUSED: + sprintf(buf, "undefined"); + break; + case DUK_DVALUE_UNDEFINED: + sprintf(buf, "undefined"); + break; + case DUK_DVALUE_NULL: + sprintf(buf, "null"); + break; + case DUK_DVALUE_TRUE: + sprintf(buf, "true"); + break; + case DUK_DVALUE_FALSE: + sprintf(buf, "false"); + break; + case DUK_DVALUE_NUMBER: + if (fpclassify(dv->d) == FP_ZERO) { + if (signbit(dv->d)) { + sprintf(buf, "-0"); + } else { + sprintf(buf, "0"); + } + } else { + sprintf(buf, "%lg", dv->d); + } + break; + case DUK_DVALUE_OBJECT: + duk__dvalue_bufesc(dv, hexbuf, 32, 0); + sprintf(buf, "obj:%d:%s", (int) dv->i, hexbuf); + break; + case DUK_DVALUE_POINTER: + duk__dvalue_bufesc(dv, hexbuf, 32, 0); + sprintf(buf, "ptr:%s", hexbuf); + break; + case DUK_DVALUE_LIGHTFUNC: + duk__dvalue_bufesc(dv, hexbuf, 32, 0); + sprintf(buf, "lfunc:%04x:%s", (unsigned int) dv->i, hexbuf); + break; + case DUK_DVALUE_HEAPPTR: + duk__dvalue_bufesc(dv, hexbuf, 32, 0); + sprintf(buf, "heapptr:%s", hexbuf); + break; + default: + sprintf(buf, "unknown:%d", (int) dv->tag); + } +} + +duk_dvalue *duk_dvalue_make_tag(int tag) { + duk_dvalue *dv = duk_dvalue_alloc(); + if (!dv) { return NULL; } + dv->tag = tag; + return dv; +} + +duk_dvalue *duk_dvalue_make_tag_int(int tag, int intval) { + duk_dvalue *dv = duk_dvalue_alloc(); + if (!dv) { return NULL; } + dv->tag = tag; + dv->i = intval; + return dv; +} + +duk_dvalue *duk_dvalue_make_tag_double(int tag, double dblval) { + duk_dvalue *dv = duk_dvalue_alloc(); + if (!dv) { return NULL; } + dv->tag = tag; + dv->d = dblval; + return dv; +} + +duk_dvalue *duk_dvalue_make_tag_data(int tag, const char *buf, size_t len) { + unsigned char *p; + duk_dvalue *dv = duk_dvalue_alloc(); + if (!dv) { return NULL; } + /* Alloc size is len + 1 so that a NUL terminator is always + * guaranteed which is convenient, e.g. you can printf() the + * value safely. + */ + p = (unsigned char *) malloc(len + 1); + if (!p) { + free(dv); + return NULL; + } + memcpy((void *) p, (const void *) buf, len); + p[len] = (unsigned char) 0; + dv->tag = tag; + dv->buf = p; + dv->len = len; + return dv; +} + +duk_dvalue *duk_dvalue_make_tag_int_data(int tag, int intval, const char *buf, size_t len) { + duk_dvalue *dv = duk_dvalue_make_tag_data(tag, buf, len); + if (!dv) { return NULL; } + dv->i = intval; + return dv; +} + +/* + * Dvalue transport handling + */ + +static void duk__trans_dvalue_double_byteswap(duk_trans_dvalue_ctx *ctx, volatile unsigned char *p) { + unsigned char t; + + /* Portable IEEE double byteswap. Relies on runtime detection of + * host endianness. + */ + + if (ctx->double_byteorder == 0) { + /* little endian */ + t = p[0]; p[0] = p[7]; p[7] = t; + t = p[1]; p[1] = p[6]; p[6] = t; + t = p[2]; p[2] = p[5]; p[5] = t; + t = p[3]; p[3] = p[4]; p[4] = t; + } else if (ctx->double_byteorder == 1) { + /* big endian: ok as is */ + ; + } else { + /* mixed endian */ + t = p[0]; p[0] = p[3]; p[3] = t; + t = p[1]; p[1] = p[2]; p[2] = t; + t = p[4]; p[4] = p[7]; p[7] = t; + t = p[5]; p[5] = p[6]; p[6] = t; + } +} + +static unsigned int duk__trans_dvalue_parse_u32(duk_trans_dvalue_ctx *ctx, unsigned char *p) { + /* Integers are network endian, read back into host format in + * a portable manner. + */ + (void) ctx; + return (((unsigned int) p[0]) << 24) + + (((unsigned int) p[1]) << 16) + + (((unsigned int) p[2]) << 8) + + (((unsigned int) p[3]) << 0); +} + +static int duk__trans_dvalue_parse_i32(duk_trans_dvalue_ctx *ctx, unsigned char *p) { + /* Portable sign handling, doesn't assume 'int' is exactly 32 bits + * like a direct cast would. + */ + unsigned int tmp = duk__trans_dvalue_parse_u32(ctx, p); + if (tmp & 0x80000000UL) { + return -((int) ((tmp ^ 0xffffffffUL) + 1UL)); + } else { + return tmp; + } +} + +static unsigned int duk__trans_dvalue_parse_u16(duk_trans_dvalue_ctx *ctx, unsigned char *p) { + /* Integers are network endian, read back into host format. */ + (void) ctx; + return (((unsigned int) p[0]) << 8) + + (((unsigned int) p[1]) << 0); +} + +static double duk__trans_dvalue_parse_double(duk_trans_dvalue_ctx *ctx, unsigned char *p) { + /* IEEE doubles are network endian, read back into host format. */ + volatile union { + double d; + unsigned char b[8]; + } u; + memcpy((void *) u.b, (const void *) p, 8); + duk__trans_dvalue_double_byteswap(ctx, u.b); + return u.d; +} + +static unsigned char *duk__trans_dvalue_encode_u32(duk_trans_dvalue_ctx *ctx, unsigned char *p, unsigned int val) { + /* Integers are written in network endian format. */ + (void) ctx; + *p++ = (unsigned char) ((val >> 24) & 0xff); + *p++ = (unsigned char) ((val >> 16) & 0xff); + *p++ = (unsigned char) ((val >> 8) & 0xff); + *p++ = (unsigned char) (val & 0xff); + return p; +} + +static unsigned char *duk__trans_dvalue_encode_i32(duk_trans_dvalue_ctx *ctx, unsigned char *p, int val) { + return duk__trans_dvalue_encode_u32(ctx, p, (unsigned int) val & 0xffffffffUL); +} + +static unsigned char *duk__trans_dvalue_encode_u16(duk_trans_dvalue_ctx *ctx, unsigned char *p, unsigned int val) { + /* Integers are written in network endian format. */ + (void) ctx; + *p++ = (unsigned char) ((val >> 8) & 0xff); + *p++ = (unsigned char) (val & 0xff); + return p; +} + +static unsigned char *duk__trans_dvalue_encode_double(duk_trans_dvalue_ctx *ctx, unsigned char *p, double val) { + /* IEEE doubles are written in network endian format. */ + volatile union { + double d; + unsigned char b[8]; + } u; + u.d = val; + duk__trans_dvalue_double_byteswap(ctx, u.b); + memcpy((void *) p, (const void *) u.b, 8); + p += 8; + return p; +} + +static unsigned char *duk__trans_buffer_ensure(duk_trans_buffer *dbuf, size_t space) { + size_t avail; + size_t used; + size_t new_size; + void *new_alloc; + + used = dbuf->write_offset; + avail = dbuf->alloc_size - dbuf->write_offset; + + if (avail >= space) { + if (avail - space > 256) { + /* Too big, resize so that we reclaim memory if we have just + * received a large string/buffer value. + */ + goto do_realloc; + } + } else { + /* Too small, resize. */ + goto do_realloc; + } + + return dbuf->base + dbuf->write_offset; + + do_realloc: + new_size = used + space + 256; /* some extra to reduce resizes */ + new_alloc = realloc(dbuf->base, new_size); + if (new_alloc) { + dbuf->base = (unsigned char *) new_alloc; + dbuf->alloc_size = new_size; +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: resized buffer %p to %ld bytes, read_offset=%ld, write_offset=%ld\n", + __func__, (void *) dbuf, (long) new_size, (long) dbuf->read_offset, (long) dbuf->write_offset); + fflush(stderr); +#endif + return dbuf->base + dbuf->write_offset; + } else { + return NULL; + } +} + +/* When read_offset is large enough, "rebase" buffer by deleting already + * read data and updating offsets. + */ +static void duk__trans_buffer_rebase(duk_trans_buffer *dbuf) { + if (dbuf->read_offset > 64) { +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: rebasing buffer %p, read_offset=%ld, write_offset=%ld\n", + __func__, (void *) dbuf, (long) dbuf->read_offset, (long) dbuf->write_offset); + fflush(stderr); +#endif + if (dbuf->write_offset > dbuf->read_offset) { + memmove((void *) dbuf->base, (const void *) (dbuf->base + dbuf->read_offset), dbuf->write_offset - dbuf->read_offset); + } + dbuf->write_offset -= dbuf->read_offset; + dbuf->read_offset = 0; + } +} + +duk_trans_dvalue_ctx *duk_trans_dvalue_init(void) { + volatile union { + double d; + unsigned char b[8]; + } u; + duk_trans_dvalue_ctx *ctx = NULL; + + ctx = (duk_trans_dvalue_ctx *) malloc(sizeof(duk_trans_dvalue_ctx)); + if (!ctx) { goto fail; } + memset((void *) ctx, 0, sizeof(duk_trans_dvalue_ctx)); + ctx->received = NULL; + ctx->cooperate = NULL; + ctx->handshake = NULL; + ctx->detached = NULL; + ctx->send_buf.base = NULL; + ctx->recv_buf.base = NULL; + + ctx->send_buf.base = malloc(256); + if (!ctx->send_buf.base) { goto fail; } + ctx->send_buf.alloc_size = 256; + + ctx->recv_buf.base = malloc(256); + if (!ctx->recv_buf.base) { goto fail; } + ctx->recv_buf.alloc_size = 256; + + /* IEEE double byte order, detect at run time (could also use + * preprocessor defines but that's verbose to make portable). + * + * >>> struct.unpack('>d', '1122334455667788'.decode('hex')) + * (3.841412024471731e-226,) + * >>> struct.unpack('>d', '8877665544332211'.decode('hex')) + * (-7.086876636573014e-268,) + * >>> struct.unpack('>d', '4433221188776655'.decode('hex')) + * (3.5294303071877444e+20,) + */ + u.b[0] = 0x11; u.b[1] = 0x22; u.b[2] = 0x33; u.b[3] = 0x44; + u.b[4] = 0x55; u.b[5] = 0x66; u.b[6] = 0x77; u.b[7] = 0x88; + if (u.d < 0.0) { + ctx->double_byteorder = 0; /* little endian */ + } else if (u.d < 1.0) { + ctx->double_byteorder = 1; /* big endian */ + } else { + ctx->double_byteorder = 2; /* mixed endian (arm) */ + } +#if defined(DEBUG_PRINTS) + fprintf(stderr, "double endianness test value is %lg -> byteorder %d\n", + u.d, ctx->double_byteorder); + fflush(stderr); +#endif + + return ctx; + + fail: + if (ctx) { + free(ctx->recv_buf.base); /* tolerates NULL */ + free(ctx->send_buf.base); /* tolerates NULL */ + free(ctx); + } + return NULL; +} + +void duk_trans_dvalue_free(duk_trans_dvalue_ctx *ctx) { + if (ctx) { + free(ctx->send_buf.base); /* tolerates NULL */ + free(ctx->recv_buf.base); /* tolerates NULL */ + free(ctx); + } +} + +void duk_trans_dvalue_send(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) { + unsigned char *p; + + /* Convert argument dvalue into Duktape debug protocol format. + * Literal constants are used here for the debug protocol, + * e.g. initial byte 0x02 is REP, see doc/debugger.rst. + */ + +#if defined(DEBUG_PRINTS) + { + char buf[DUK_DVALUE_TOSTRING_BUFLEN]; + duk_dvalue_to_string(dv, buf); + fprintf(stderr, "%s: sending dvalue: %s\n", __func__, buf); + fflush(stderr); + } +#endif + + switch (dv->tag) { + case DUK_DVALUE_EOM: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x00; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_REQ: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x01; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_REP: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x02; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_ERR: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x03; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_NFY: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x04; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_INTEGER: { + int i = dv->i; + if (i >= 0 && i <= 63) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = (unsigned char) (0x80 + i); + ctx->send_buf.write_offset += 1; + } else if (i >= 0 && i <= 16383L) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 2); + if (!p) { goto alloc_error; } + *p++ = (unsigned char) (0xc0 + (i >> 8)); + *p++ = (unsigned char) (i & 0xff); + ctx->send_buf.write_offset += 2; + } else if (i >= -0x80000000L && i <= 0x7fffffffL) { /* Harmless warning on some platforms (re: range) */ + p = duk__trans_buffer_ensure(&ctx->send_buf, 5); + if (!p) { goto alloc_error; } + *p++ = 0x10; + p = duk__trans_dvalue_encode_i32(ctx, p, i); + ctx->send_buf.write_offset += 5; + } else { + goto dvalue_error; + } + break; + } + case DUK_DVALUE_STRING: { + size_t i = dv->len; + if (i <= 0x1fUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1 + i); + if (!p) { goto alloc_error; } + *p++ = (unsigned char) (0x60 + i); + memcpy((void *) p, (const void *) dv->buf, i); + p += i; + ctx->send_buf.write_offset += 1 + i; + } else if (i <= 0xffffUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 3 + i); + if (!p) { goto alloc_error; } + *p++ = 0x12; + p = duk__trans_dvalue_encode_u16(ctx, p, (unsigned int) i); + memcpy((void *) p, (const void *) dv->buf, i); + p += i; + ctx->send_buf.write_offset += 3 + i; + } else if (i <= 0xffffffffUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 5 + i); + if (!p) { goto alloc_error; } + *p++ = 0x11; + p = duk__trans_dvalue_encode_u32(ctx, p, (unsigned int) i); + memcpy((void *) p, (const void *) dv->buf, i); + p += i; + ctx->send_buf.write_offset += 5 + i; + } else { + goto dvalue_error; + } + break; + } + case DUK_DVALUE_BUFFER: { + size_t i = dv->len; + if (i <= 0xffffUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 3 + i); + if (!p) { goto alloc_error; } + *p++ = 0x14; + p = duk__trans_dvalue_encode_u16(ctx, p, (unsigned int) i); + memcpy((void *) p, (const void *) dv->buf, i); + p += i; + ctx->send_buf.write_offset += 3 + i; + } else if (i <= 0xffffffffUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 5 + i); + if (!p) { goto alloc_error; } + *p++ = 0x13; + p = duk__trans_dvalue_encode_u32(ctx, p, (unsigned int) i); + memcpy((void *) p, (const void *) dv->buf, i); + p += i; + ctx->send_buf.write_offset += 5 + i; + } else { + goto dvalue_error; + } + break; + } + case DUK_DVALUE_UNUSED: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x15; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_UNDEFINED: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x16; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_NULL: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x17; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_TRUE: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x18; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_FALSE: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 1); + if (!p) { goto alloc_error; } + *p++ = 0x19; + ctx->send_buf.write_offset += 1; + break; + } + case DUK_DVALUE_NUMBER: { + p = duk__trans_buffer_ensure(&ctx->send_buf, 9); + if (!p) { goto alloc_error; } + *p++ = 0x1a; + p = duk__trans_dvalue_encode_double(ctx, p, dv->d); + ctx->send_buf.write_offset += 9; + break; + } + case DUK_DVALUE_OBJECT: { + size_t i = dv->len; + if (i <= 0xffUL && dv->i >= 0 && dv->i <= 0xffL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 3 + i); + if (!p) { goto alloc_error; } + *p++ = 0x1b; + *p++ = (unsigned char) dv->i; + *p++ = (unsigned char) i; + memcpy((void *) p, (const void *) dv->buf, i); + ctx->send_buf.write_offset += 3 + i; + } else { + goto dvalue_error; + } + break; + } + case DUK_DVALUE_POINTER: { + size_t i = dv->len; + if (i <= 0xffUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 2 + i); + if (!p) { goto alloc_error; } + *p++ = 0x1c; + *p++ = (unsigned char) i; + memcpy((void *) p, (const void *) dv->buf, i); + ctx->send_buf.write_offset += 2 + i; + } else { + goto dvalue_error; + } + break; + } + case DUK_DVALUE_LIGHTFUNC: { + size_t i = dv->len; + if (i <= 0xffUL && dv->i >= 0 && dv->i <= 0xffffL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 4 + i); + if (!p) { goto alloc_error; } + *p++ = 0x1d; + p = duk__trans_dvalue_encode_u16(ctx, p, (unsigned int) dv->i); + *p++ = (unsigned char) i; + memcpy((void *) p, (const void *) dv->buf, i); + ctx->send_buf.write_offset += 4 + i; + } else { + goto dvalue_error; + } + break; + } + case DUK_DVALUE_HEAPPTR: { + size_t i = dv->len; + if (i <= 0xffUL) { + p = duk__trans_buffer_ensure(&ctx->send_buf, 2 + i); + if (!p) { goto alloc_error; } + *p++ = 0x1e; + *p++ = (unsigned char) i; + memcpy((void *) p, (const void *) dv->buf, i); + ctx->send_buf.write_offset += 2 + i; + } else { + goto dvalue_error; + } + break; + } + default: { + goto dvalue_error; + } + } /* end switch */ + + return; + + dvalue_error: +#if defined(ERROR_PRINTS) + fprintf(stderr, "%s: internal error, argument dvalue is invalid\n", __func__); + fflush(stdout); +#endif + return; + + alloc_error: +#if defined(ERROR_PRINTS) + fprintf(stderr, "%s: internal error, failed to allocate space for write\n", __func__); + fflush(stdout); +#endif + return; +} + +static void duk__trans_dvalue_send_and_free(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) { + if (!dv) { return; } + duk_trans_dvalue_send(ctx, dv); + duk_dvalue_free(dv); +} + +void duk_trans_dvalue_send_eom(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_EOM)); +} + +void duk_trans_dvalue_send_req(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_REQ)); +} + +void duk_trans_dvalue_send_rep(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_REP)); +} + +void duk_trans_dvalue_send_err(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_ERR)); +} + +void duk_trans_dvalue_send_nfy(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_NFY)); +} + +void duk_trans_dvalue_send_integer(duk_trans_dvalue_ctx *ctx, int val) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, val)); +} + +void duk_trans_dvalue_send_string(duk_trans_dvalue_ctx *ctx, const char *str) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_STRING, str, strlen(str))); +} + +void duk_trans_dvalue_send_lstring(duk_trans_dvalue_ctx *ctx, const char *str, size_t len) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_STRING, str, len)); +} + +void duk_trans_dvalue_send_buffer(duk_trans_dvalue_ctx *ctx, const char *buf, size_t len) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_BUFFER, buf, len)); +} + +void duk_trans_dvalue_send_unused(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_UNUSED)); +} + +void duk_trans_dvalue_send_undefined(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_UNDEFINED)); +} + +void duk_trans_dvalue_send_null(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_NULL)); +} + +void duk_trans_dvalue_send_true(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_TRUE)); +} + +void duk_trans_dvalue_send_false(duk_trans_dvalue_ctx *ctx) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_FALSE)); +} + +void duk_trans_dvalue_send_number(duk_trans_dvalue_ctx *ctx, double val) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_double(DUK_DVALUE_NUMBER, val)); +} + +void duk_trans_dvalue_send_object(duk_trans_dvalue_ctx *ctx, int classnum, const char *ptr_data, size_t ptr_len) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_int_data(DUK_DVALUE_OBJECT, classnum, ptr_data, ptr_len)); +} + +void duk_trans_dvalue_send_pointer(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_POINTER, ptr_data, ptr_len)); +} + +void duk_trans_dvalue_send_lightfunc(duk_trans_dvalue_ctx *ctx, int lf_flags, const char *ptr_data, size_t ptr_len) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_int_data(DUK_DVALUE_LIGHTFUNC, lf_flags, ptr_data, ptr_len)); +} + +void duk_trans_dvalue_send_heapptr(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len) { + duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_HEAPPTR, ptr_data, ptr_len)); +} + +void duk_trans_dvalue_send_req_cmd(duk_trans_dvalue_ctx *ctx, int cmd) { + duk_trans_dvalue_send_req(ctx); + duk_trans_dvalue_send_integer(ctx, cmd); +} + +static duk_dvalue *duk__trans_trial_parse_dvalue(duk_trans_dvalue_ctx *ctx) { + unsigned char *p; + size_t len; + unsigned char ib; + duk_dvalue *dv; + size_t datalen; + + p = ctx->recv_buf.base + ctx->recv_buf.read_offset; + len = ctx->recv_buf.write_offset - ctx->recv_buf.read_offset; + + if (len == 0) { + return NULL; + } + ib = p[0]; + +#if defined(DEBUG_PRINTS) + { + size_t i; + fprintf(stderr, "%s: parsing dvalue, window:", __func__); + for (i = 0; i < 16; i++) { + if (i < len) { + fprintf(stderr, " %02x", (unsigned int) p[i]); + } else { + fprintf(stderr, " ??"); + } + } + fprintf(stderr, " (length %ld, read_offset %ld, write_offset %ld, alloc_size %ld)\n", + (long) len, (long) ctx->recv_buf.read_offset, (long) ctx->recv_buf.write_offset, + (long) ctx->recv_buf.alloc_size); + fflush(stderr); + } +#endif + + if (ib <= 0x1fU) { + /* 0x00 ... 0x1f */ + switch (ib) { + case 0x00: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_EOM); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x01: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_REQ); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x02: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_REP); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x03: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_ERR); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x04: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_NFY); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x10: { + int intval; + if (len < 5) { goto partial; } + intval = duk__trans_dvalue_parse_i32(ctx, p + 1); + ctx->recv_buf.read_offset += 5; + dv = duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, intval); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x11: { + if (len < 5) { goto partial; } + datalen = (size_t) duk__trans_dvalue_parse_u32(ctx, p + 1); + if (len < 5 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 5 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) (p + 5), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x12: { + if (len < 3) { goto partial; } + datalen = (size_t) duk__trans_dvalue_parse_u16(ctx, p + 1); + if (len < 3 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 3 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) (p + 3), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x13: { + if (len < 5) { goto partial; } + datalen = (size_t) duk__trans_dvalue_parse_u32(ctx, p + 1); + if (len < 5 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 5 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_BUFFER, (const char *) (p + 5), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x14: { + if (len < 3) { goto partial; } + datalen = (size_t) duk__trans_dvalue_parse_u16(ctx, p + 1); + if (len < 3 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 3 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_BUFFER, (const char *) (p + 3), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x15: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_UNUSED); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x16: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_UNDEFINED); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x17: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_NULL); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x18: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_TRUE); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x19: { + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag(DUK_DVALUE_FALSE); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x1a: { + double dblval; + if (len < 9) { goto partial; } + dblval = duk__trans_dvalue_parse_double(ctx, p + 1); + ctx->recv_buf.read_offset += 9; + dv = duk_dvalue_make_tag_double(DUK_DVALUE_NUMBER, dblval); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x1b: { + int classnum; + if (len < 3) { goto partial; } + datalen = (size_t) p[2]; + if (len < 3 + datalen) { goto partial; } + classnum = (int) p[1]; + ctx->recv_buf.read_offset += 3 + datalen; + dv = duk_dvalue_make_tag_int_data(DUK_DVALUE_OBJECT, classnum, (const char *) (p + 3), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x1c: { + if (len < 2) { goto partial; } + datalen = (size_t) p[1]; + if (len < 2 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 2 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_POINTER, (const char *) (p + 2), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x1d: { + int lf_flags; + if (len < 4) { goto partial; } + datalen = (size_t) p[3]; + if (len < 4 + datalen) { goto partial; } + lf_flags = (int) duk__trans_dvalue_parse_u16(ctx, p + 1); + ctx->recv_buf.read_offset += 4 + datalen; + dv = duk_dvalue_make_tag_int_data(DUK_DVALUE_LIGHTFUNC, lf_flags, (const char *) (p + 4), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + case 0x1e: { + if (len < 2) { goto partial; } + datalen = (size_t) p[1]; + if (len < 2 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 2 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_HEAPPTR, (const char *) (p + 2), datalen); + if (!dv) { goto alloc_error; } + return dv; + } + default: { + goto format_error; + } + } /* end switch */ + } else if (ib <= 0x5fU) { + /* 0x20 ... 0x5f */ + goto format_error; + } else if (ib <= 0x7fU) { + /* 0x60 ... 0x7f */ + datalen = (size_t) (ib - 0x60U); + if (len < 1 + datalen) { goto partial; } + ctx->recv_buf.read_offset += 1 + datalen; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) (p + 1), datalen); + if (!dv) { goto alloc_error; } + return dv; + } else if (ib <= 0xbfU) { + /* 0x80 ... 0xbf */ + int intval; + intval = (int) (ib - 0x80U); + ctx->recv_buf.read_offset += 1; + dv = duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, intval); + if (!dv) { goto alloc_error; } + return dv; + } else { + /* 0xc0 ... 0xff */ + int intval; + if (len < 2) { goto partial; } + intval = (((int) (ib - 0xc0U)) << 8) + (int) p[1]; + ctx->recv_buf.read_offset += 2; + dv = duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, intval); + if (!dv) { goto alloc_error; } + return dv; + } + + /* never here */ + + partial: + return NULL; + + alloc_error: +#if defined(ERROR_PRINTS) + fprintf(stderr, "%s: internal error, cannot allocate space for dvalue\n", __func__); + fflush(stdout); +#endif + return NULL; + + format_error: +#if defined(ERROR_PRINTS) + fprintf(stderr, "%s: internal error, dvalue format error\n", __func__); + fflush(stdout); +#endif + return NULL; +} + +static duk_dvalue *duk__trans_trial_parse_handshake(duk_trans_dvalue_ctx *ctx) { + unsigned char *p; + size_t len; + duk_dvalue *dv; + size_t i; + + p = ctx->recv_buf.base + ctx->recv_buf.read_offset; + len = ctx->recv_buf.write_offset - ctx->recv_buf.read_offset; + + for (i = 0; i < len; i++) { + if (p[i] == 0x0a) { + /* Handshake line is returned as a dvalue for convenience; it's + * not actually a part of the dvalue phase of the protocol. + */ + ctx->recv_buf.read_offset += i + 1; + dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) p, i); + if (!dv) { goto alloc_error; } + return dv; + } + } + + return NULL; + + alloc_error: +#if defined(ERROR_PRINTS) + fprintf(stderr, "%s: internal error, cannot allocate space for handshake line\n", __func__); + fflush(stdout); +#endif + return NULL; +} + +static void duk__trans_call_cooperate(duk_trans_dvalue_ctx *ctx, int block) { + if (ctx->cooperate) { + ctx->cooperate(ctx, block); + } +} + +static void duk__trans_call_received(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) { + if (ctx->received) { + ctx->received(ctx, dv); + } +} + +static void duk__trans_call_handshake(duk_trans_dvalue_ctx *ctx, const char *line) { + if (ctx->handshake) { + ctx->handshake(ctx, line); + } +} + +static void duk__trans_call_detached(duk_trans_dvalue_ctx *ctx) { + if (ctx->detached) { + ctx->detached(ctx); + } +} + +/* + * Duktape callbacks + */ + +duk_size_t duk_trans_dvalue_read_cb(void *udata, char *buffer, duk_size_t length) { + duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata; + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: %p %p %ld\n", __func__, udata, (void *) buffer, (long) length); + fflush(stderr); +#endif + + duk__trans_call_cooperate(ctx, 0); + + for (;;) { + size_t avail, now; + + avail = (size_t) (ctx->send_buf.write_offset - ctx->send_buf.read_offset); + if (avail == 0) { + /* Must cooperate until user callback provides data. From + * Duktape's perspective we MUST block until data is received. + */ + duk__trans_call_cooperate(ctx, 1); + } else { + now = avail; + if (now > length) { + now = length; + } + memcpy((void *) buffer, (const void *) (ctx->send_buf.base + ctx->send_buf.read_offset), now); + duk__trans_buffer_rebase(&ctx->send_buf); + ctx->send_buf.read_offset += now; + return now; + } + } +} + +duk_size_t duk_trans_dvalue_write_cb(void *udata, const char *buffer, duk_size_t length) { + duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata; + unsigned char *p; + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: %p %p %ld\n", __func__, udata, (void *) buffer, (long) length); + fflush(stderr); +#endif + + duk__trans_call_cooperate(ctx, 0); + + /* Append data. */ + duk__trans_buffer_rebase(&ctx->recv_buf); + p = duk__trans_buffer_ensure(&ctx->recv_buf, length); + memcpy((void *) p, (const void *) buffer, (size_t) length); + ctx->recv_buf.write_offset += length; + + /* Trial parse handshake line or dvalue(s). */ + if (!ctx->handshake_done) { + duk_dvalue *dv = duk__trans_trial_parse_handshake(ctx); + if (dv) { + /* Handshake line is available for caller for the + * duration of the callback, and must not be freed + * by the caller. + */ + duk__trans_call_handshake(ctx, (const char *) dv->buf); +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: handshake ok\n", __func__); + fflush(stderr); +#endif + duk_dvalue_free(dv); + ctx->handshake_done = 1; + } + } + if (ctx->handshake_done) { + for (;;) { + duk_dvalue *dv = duk__trans_trial_parse_dvalue(ctx); + if (dv) { +#if defined(DEBUG_PRINTS) + { + char buf[DUK_DVALUE_TOSTRING_BUFLEN]; + duk_dvalue_to_string(dv, buf); + fprintf(stderr, "%s: received dvalue: %s\n", __func__, buf); + fflush(stderr); + } +#endif + + duk__trans_call_received(ctx, dv); + } else { + break; + } + } + } + + duk__trans_call_cooperate(ctx, 0); /* just in case, if dvalues changed something */ + + return length; +} + +duk_size_t duk_trans_dvalue_peek_cb(void *udata) { + duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata; + size_t avail; + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: %p\n", __func__, udata); + fflush(stderr); +#endif + + duk__trans_call_cooperate(ctx, 0); + avail = (size_t) (ctx->send_buf.write_offset - ctx->send_buf.read_offset); + return (duk_size_t) avail; +} + +void duk_trans_dvalue_read_flush_cb(void *udata) { + duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata; + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: %p\n", __func__, udata); + fflush(stderr); +#endif + + duk__trans_call_cooperate(ctx, 0); +} + +void duk_trans_dvalue_write_flush_cb(void *udata) { + duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata; + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: %p\n", __func__, udata); + fflush(stderr); +#endif + + duk__trans_call_cooperate(ctx, 0); +} + +void duk_trans_dvalue_detached_cb(duk_context *duk_ctx, void *udata) { + duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata; + + (void) duk_ctx; + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: %p\n", __func__, udata); + fflush(stderr); +#endif + + duk__trans_call_detached(ctx); +} diff --git a/lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.h b/lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.h new file mode 100644 index 0000000..a9f44ed --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-dvalue/duk_trans_dvalue.h @@ -0,0 +1,113 @@ +#if !defined(DUK_TRANS_DVALUE_H_INCLUDED) +#define DUK_TRANS_DVALUE_H_INCLUDED + +#include "duktape.h" + +typedef struct duk_dvalue duk_dvalue; +typedef struct duk_trans_buffer duk_trans_buffer; +typedef struct duk_trans_dvalue_ctx duk_trans_dvalue_ctx; + +typedef void (*duk_trans_dvalue_received_function)(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv); +typedef void (*duk_trans_dvalue_cooperate_function)(duk_trans_dvalue_ctx *ctx, int block); +typedef void (*duk_trans_dvalue_handshake_function)(duk_trans_dvalue_ctx *ctx, const char *handshake_line); +typedef void (*duk_trans_dvalue_detached_function)(duk_trans_dvalue_ctx *ctx); + +/* struct duk_dvalue 'tag' values, note that these have nothing to do with + * Duktape debug protocol inital byte. Struct fields used with the type + * are noted next to the define. + */ +#define DUK_DVALUE_EOM 1 /* no fields */ +#define DUK_DVALUE_REQ 2 /* no fields */ +#define DUK_DVALUE_REP 3 /* no fields */ +#define DUK_DVALUE_ERR 4 /* no fields */ +#define DUK_DVALUE_NFY 5 /* no fields */ +#define DUK_DVALUE_INTEGER 6 /* i: 32-bit signed integer */ +#define DUK_DVALUE_STRING 7 /* buf: string data, len: string length */ +#define DUK_DVALUE_BUFFER 8 /* buf: buffer data, len: buffer length */ +#define DUK_DVALUE_UNUSED 9 /* no fields */ +#define DUK_DVALUE_UNDEFINED 10 /* no fields */ +#define DUK_DVALUE_NULL 11 /* no fields */ +#define DUK_DVALUE_TRUE 12 /* no fields */ +#define DUK_DVALUE_FALSE 13 /* no fields */ +#define DUK_DVALUE_NUMBER 14 /* d: ieee double */ +#define DUK_DVALUE_OBJECT 15 /* i: class number, buf: pointer data, len: pointer length */ +#define DUK_DVALUE_POINTER 16 /* buf: pointer data, len: pointer length */ +#define DUK_DVALUE_LIGHTFUNC 17 /* i: lightfunc flags, buf: pointer data, len: pointer length */ +#define DUK_DVALUE_HEAPPTR 18 /* buf: pointer data, len: pointer length */ + +struct duk_dvalue { + /* Could use a union for the value but the gain would be relatively small. */ + int tag; + int i; + double d; + size_t len; + unsigned char *buf; +}; + +struct duk_trans_buffer { + unsigned char *base; + size_t write_offset; + size_t read_offset; + size_t alloc_size; +}; + +struct duk_trans_dvalue_ctx { + duk_trans_dvalue_received_function received; + duk_trans_dvalue_cooperate_function cooperate; + duk_trans_dvalue_handshake_function handshake; + duk_trans_dvalue_detached_function detached; + duk_trans_buffer send_buf; /* sending towards Duktape (duktape read callback) */ + duk_trans_buffer recv_buf; /* receiving from Duktape (duktape write callback) */ + int handshake_done; + int double_byteorder; /* 0=little endian, 1=big endian, 2=mixed endian */ +}; + +/* Buffer size needed by duk_dvalue_to_string(). */ +#define DUK_DVALUE_TOSTRING_BUFLEN 256 + +/* Dvalue handling. */ +duk_dvalue *duk_dvalue_alloc(void); +void duk_dvalue_free(duk_dvalue *dv); +void duk_dvalue_to_string(duk_dvalue *dv, char *buf); +duk_dvalue *duk_dvalue_make_tag(int tag); +duk_dvalue *duk_dvalue_make_tag_int(int tag, int intval); +duk_dvalue *duk_dvalue_make_tag_double(int tag, double dblval); +duk_dvalue *duk_dvalue_make_tag_data(int tag, const char *buf, size_t len); +duk_dvalue *duk_dvalue_make_tag_int_data(int tag, int intval, const char *buf, size_t len); + +/* Initializing and freeing the transport context. */ +duk_trans_dvalue_ctx *duk_trans_dvalue_init(void); +void duk_trans_dvalue_free(duk_trans_dvalue_ctx *ctx); + +/* Sending dvalues towards Duktape. */ +void duk_trans_dvalue_send(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv); +void duk_trans_dvalue_send_eom(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_req(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_rep(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_err(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_nfy(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_integer(duk_trans_dvalue_ctx *ctx, int val); +void duk_trans_dvalue_send_string(duk_trans_dvalue_ctx *ctx, const char *str); +void duk_trans_dvalue_send_lstring(duk_trans_dvalue_ctx *ctx, const char *str, size_t len); +void duk_trans_dvalue_send_buffer(duk_trans_dvalue_ctx *ctx, const char *buf, size_t len); +void duk_trans_dvalue_send_unused(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_undefined(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_null(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_true(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_false(duk_trans_dvalue_ctx *ctx); +void duk_trans_dvalue_send_number(duk_trans_dvalue_ctx *ctx, double val); +void duk_trans_dvalue_send_object(duk_trans_dvalue_ctx *ctx, int classnum, const char *ptr_data, size_t ptr_len); +void duk_trans_dvalue_send_pointer(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len); +void duk_trans_dvalue_send_lightfunc(duk_trans_dvalue_ctx *ctx, int lf_flags, const char *ptr_data, size_t ptr_len); +void duk_trans_dvalue_send_heapptr(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len); +void duk_trans_dvalue_send_req_cmd(duk_trans_dvalue_ctx *ctx, int cmd); + +/* Duktape debug callbacks provided by the transport. */ +duk_size_t duk_trans_dvalue_read_cb(void *udata, char *buffer, duk_size_t length); +duk_size_t duk_trans_dvalue_write_cb(void *udata, const char *buffer, duk_size_t length); +duk_size_t duk_trans_dvalue_peek_cb(void *udata); +void duk_trans_dvalue_read_flush_cb(void *udata); +void duk_trans_dvalue_write_flush_cb(void *udata); +void duk_trans_dvalue_detached_cb(duk_context *ctx, void *udata); + +#endif /* DUK_TRANS_DVALUE_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/debug-trans-dvalue/test.c b/lib/duktape-2.2.1/examples/debug-trans-dvalue/test.c new file mode 100644 index 0000000..80b35d7 --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-dvalue/test.c @@ -0,0 +1,248 @@ +/* + * Example program using the dvalue debug transport. + */ + +#include +#include + +#include "duktape.h" +#include "duk_trans_dvalue.h" + +void my_cooperate(duk_trans_dvalue_ctx *ctx, int block) { + static int first_blocked = 1; + + if (!block) { + /* Duktape is not blocked; you can cooperate with e.g. a user + * interface here and send dvalues to Duktape, but don't block. + */ + return; + } + + /* Duktape is blocked on a read and won't continue until debug + * command(s) are sent. + * + * Normally you'd enter your own event loop here, and process + * events until something needs to be sent to Duktape. For + * example, the user might press a "Step over" button in the + * UI which would cause dvalues to be sent. You can then + * return from this callback. + * + * The code below sends some example messages for testing the + * dvalue handling of the transport. + * + * If you create dvalues manually and send them using + * duk_trans_dvalue_send(), you must free the dvalues after + * the send call returns using duk_dvalue_free(). + */ + + if (first_blocked) { + char *tmp; + int i; + + /* First time Duktape becomes blocked, send DumpHeap which + * exercises a lot of parsing code. + * + * NOTE: Valgrind may complain about reading uninitialized + * bytes. This is caused by the DumpHeap command writing out + * verbatim duk_tval values which are intentionally not + * always fully initialized for performance reasons. + */ + first_blocked = 0; + + fprintf(stderr, "Duktape is blocked, send DumpHeap\n"); + fflush(stderr); + + duk_trans_dvalue_send_req(ctx); + duk_trans_dvalue_send_integer(ctx, 0x20); /* DumpHeap */ + duk_trans_dvalue_send_eom(ctx); + + /* Also send a dummy TriggerStatus request with trailing dvalues + * ignored by Duktape; Duktape will parse the dvalues to be able to + * skip them, so that the dvalue encoding is exercised. + */ + + tmp = malloc(100000); /* long buffer, >= 65536 chars */ + for (i = 0; i < 100000; i++) { + tmp[i] = (char) i; + } + duk_trans_dvalue_send_req(ctx); + duk_trans_dvalue_send_integer(ctx, 0x11); /* TriggerStatus */ + duk_trans_dvalue_send_string(ctx, "dummy"); /* short, <= 31 chars */ + duk_trans_dvalue_send_string(ctx, "123456789012345678901234567890foobar"); /* medium, >= 32 chars */ + duk_trans_dvalue_send_lstring(ctx, (const char *) tmp, 65535UL); + duk_trans_dvalue_send_lstring(ctx, (const char *) tmp, 65536UL); + duk_trans_dvalue_send_lstring(ctx, (const char *) tmp, 100000UL); + duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 255U); + duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 65535UL); + duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 65536UL); + duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 100000UL); + duk_trans_dvalue_send_unused(ctx); + duk_trans_dvalue_send_undefined(ctx); + duk_trans_dvalue_send_null(ctx); + duk_trans_dvalue_send_true(ctx); + duk_trans_dvalue_send_false(ctx); + duk_trans_dvalue_send_number(ctx, 123.456); + duk_trans_dvalue_send_object(ctx, 12 /*classnum*/, (const char *) tmp, 8); /* fake ptr len */ + duk_trans_dvalue_send_pointer(ctx, (const char *) tmp, 8); /* fake ptr len */ + duk_trans_dvalue_send_lightfunc(ctx, 0xdabc /*lf_flags*/, (const char *) tmp, 8); /* fake ptr len */ + duk_trans_dvalue_send_heapptr(ctx, (const char *) tmp, 8); /* fake ptr len */ + + duk_trans_dvalue_send_eom(ctx); + } + + fprintf(stderr, "Duktape is blocked, send Eval and StepInto to resume execution\n"); + fflush(stderr); + + /* duk_trans_dvalue_send_req_cmd() sends a REQ dvalue followed by + * an integer dvalue (command) for convenience. + */ + + duk_trans_dvalue_send_req_cmd(ctx, 0x1e); /* 0x1e = Eval */ + duk_trans_dvalue_send_string(ctx, "evalMe"); + duk_trans_dvalue_send_eom(ctx); + + duk_trans_dvalue_send_req_cmd(ctx, 0x14); /* 0x14 = StepOver */ + duk_trans_dvalue_send_eom(ctx); +} + +void my_received(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) { + char buf[DUK_DVALUE_TOSTRING_BUFLEN]; + (void) ctx; + + duk_dvalue_to_string(dv, buf); + fprintf(stderr, "Received dvalue: %s\n", buf); + fflush(stderr); + + /* Here a normal debug client would wait for dvalues until an EOM + * dvalue was received (which completes a debug message). The + * debug message would then be handled, possibly causing UI changes + * and/or causing debug commands to be sent to Duktape. + * + * The callback is responsible for eventually freeing the dvalue. + * Here we free it immediately, but an actual client would probably + * gather dvalues into an array or linked list to handle when the + * debug message was complete. + */ + + duk_dvalue_free(dv); +} + +void my_handshake(duk_trans_dvalue_ctx *ctx, const char *line) { + (void) ctx; + + /* The Duktape handshake line is given in 'line' (without LF). + * The 'line' argument can be accessed for the duration of the + * callback (read only). Don't free 'line' here, the transport + * handles that. + */ + + fprintf(stderr, "Received handshake line: '%s'\n", line); + fflush(stderr); +} + +void my_detached(duk_trans_dvalue_ctx *ctx) { + (void) ctx; + + /* Detached call forwarded as is. */ + + fprintf(stderr, "Debug transport detached\n"); + fflush(stderr); +} + +static duk_ret_t native_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_to_string(ctx, -1)); + return 0; +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + duk_trans_dvalue_ctx *trans_ctx; + int exitval = 0; + + (void) argc; (void) argv; /* suppress warning */ + + ctx = duk_create_heap_default(); + if (!ctx) { + fprintf(stderr, "Failed to create Duktape heap\n"); + fflush(stderr); + exitval = 1; + goto cleanup; + } + + duk_push_c_function(ctx, native_print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + trans_ctx = duk_trans_dvalue_init(); + if (!trans_ctx) { + fprintf(stderr, "Failed to create debug transport context\n"); + fflush(stderr); + exitval = 1; + goto cleanup; + } + trans_ctx->cooperate = my_cooperate; + trans_ctx->received = my_received; + trans_ctx->handshake = my_handshake; + trans_ctx->detached = my_detached; + + /* Attach debugger; this will fail with a fatal error here unless + * debugger support is compiled in. To fail more gracefully, call + * this under a duk_safe_call() to catch the error. + */ + duk_debugger_attach(ctx, + duk_trans_dvalue_read_cb, + duk_trans_dvalue_write_cb, + duk_trans_dvalue_peek_cb, + duk_trans_dvalue_read_flush_cb, + duk_trans_dvalue_write_flush_cb, + NULL, /* app request cb */ + duk_trans_dvalue_detached_cb, + (void *) trans_ctx); + + fprintf(stderr, "Debugger attached, running eval\n"); + fflush(stderr); + + /* Evaluate simple test code, callbacks will "step over" until end. + * + * The test code here is just for exercising the debug transport. + * The 'evalMe' variable is evaluated (using debugger command Eval) + * before every step to force different dvalues to be carried over + * the transport. + */ + + duk_eval_string(ctx, + "var evalMe;\n" + "\n" + "print('Hello world!');\n" + "[ undefined, null, true, false, 123, -123, 123.1, 0, -0, 1/0, 0/0, -1/0, \n" + " 'foo', Uint8Array.allocPlain('bar'), Duktape.Pointer('dummy'), Math.cos, \n" + "].forEach(function (val) {\n" + " print(val);\n" + " evalMe = val;\n" + "});\n" + "\n" + "var str = 'xxx'\n" + "for (i = 0; i < 10; i++) {\n" + " print(i, str);\n" + " evalMe = str;\n" + " evalMe = Uint8Array.allocPlain(str);\n" + " str = str + str;\n" + "}\n" + ); + duk_pop(ctx); + + duk_debugger_detach(ctx); + + cleanup: + if (trans_ctx) { + duk_trans_dvalue_free(trans_ctx); + trans_ctx = NULL; + } + if (ctx) { + duk_destroy_heap(ctx); + } + + return exitval; +} diff --git a/lib/duktape-2.2.1/examples/debug-trans-socket/README.rst b/lib/duktape-2.2.1/examples/debug-trans-socket/README.rst new file mode 100644 index 0000000..78522cd --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-socket/README.rst @@ -0,0 +1,17 @@ +================================================ +Debug transport using a simple socket connection +================================================ + +This example implements an example debug transport which uses a Linux or +Windows TCP server socket on the debug target. + +Files: + +* ``duk_trans_socket.h``: header file for the transport, used for both Linux + and Windows socket variants. + +* ``duk_trans_socket_unix.c``: implementation for Linux/Unix. + +* ``duk_trans_socket_windows.c``: implementation for Windows. + +Compile either Unix or Windows source file only. diff --git a/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket.h b/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket.h new file mode 100644 index 0000000..281ddc8 --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket.h @@ -0,0 +1,15 @@ +#if !defined(DUK_TRANS_SOCKET_H_INCLUDED) +#define DUK_TRANS_SOCKET_H_INCLUDED + +#include "duktape.h" + +void duk_trans_socket_init(void); +void duk_trans_socket_finish(void); +void duk_trans_socket_waitconn(void); +duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length); +duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length); +duk_size_t duk_trans_socket_peek_cb(void *udata); +void duk_trans_socket_read_flush_cb(void *udata); +void duk_trans_socket_write_flush_cb(void *udata); + +#endif /* DUK_TRANS_SOCKET_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_unix.c b/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_unix.c new file mode 100644 index 0000000..0633eff --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_unix.c @@ -0,0 +1,364 @@ +/* + * Example debug transport using a Linux/Unix TCP socket + * + * Provides a TCP server socket which a debug client can connect to. + * After that data is just passed through. + * + * On some UNIX systems poll() may not be available but select() is. + * The default is to use poll(), but you can switch to select() by + * defining USE_SELECT. See https://daniel.haxx.se/docs/poll-vs-select.html. + */ + +#include +#include +#include +#include +#include +#if !defined(USE_SELECT) +#include +#endif /* !USE_SELECT */ +#include +#include "duktape.h" +#include "duk_trans_socket.h" + +#if !defined(DUK_DEBUG_PORT) +#define DUK_DEBUG_PORT 9091 +#endif + +#if 0 +#define DEBUG_PRINTS +#endif + +static int server_sock = -1; +static int client_sock = -1; + +/* + * Transport init and finish + */ + +void duk_trans_socket_init(void) { + struct sockaddr_in addr; + int on; + + server_sock = socket(AF_INET, SOCK_STREAM, 0); + if (server_sock < 0) { + fprintf(stderr, "%s: failed to create server socket: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; + } + + on = 1; + if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &on, sizeof(on)) < 0) { + fprintf(stderr, "%s: failed to set SO_REUSEADDR for server socket: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; + } + + memset((void *) &addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = htons(DUK_DEBUG_PORT); + + if (bind(server_sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + fprintf(stderr, "%s: failed to bind server socket: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; + } + + listen(server_sock, 1 /*backlog*/); + return; + + fail: + if (server_sock >= 0) { + (void) close(server_sock); + server_sock = -1; + } +} + +void duk_trans_socket_finish(void) { + if (client_sock >= 0) { + (void) close(client_sock); + client_sock = -1; + } + if (server_sock >= 0) { + (void) close(server_sock); + server_sock = -1; + } +} + +void duk_trans_socket_waitconn(void) { + struct sockaddr_in addr; + socklen_t sz; + + if (server_sock < 0) { + fprintf(stderr, "%s: no server socket, skip waiting for connection\n", + __FILE__); + fflush(stderr); + return; + } + if (client_sock >= 0) { + (void) close(client_sock); + client_sock = -1; + } + + fprintf(stderr, "Waiting for debug connection on port %d\n", (int) DUK_DEBUG_PORT); + fflush(stderr); + + sz = (socklen_t) sizeof(addr); + client_sock = accept(server_sock, (struct sockaddr *) &addr, &sz); + if (client_sock < 0) { + fprintf(stderr, "%s: accept() failed, skip waiting for connection: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; + } + + fprintf(stderr, "Debug connection established\n"); + fflush(stderr); + + /* XXX: For now, close the listen socket because we won't accept new + * connections anyway. A better implementation would allow multiple + * debug attaches. + */ + + if (server_sock >= 0) { + (void) close(server_sock); + server_sock = -1; + } + return; + + fail: + if (client_sock >= 0) { + (void) close(client_sock); + client_sock = -1; + } +} + +/* + * Duktape callbacks + */ + +/* Duktape debug transport callback: (possibly partial) read. */ +duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length) { + ssize_t ret; + + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n", + __func__, (void *) udata, (void *) buffer, (long) length); + fflush(stderr); +#endif + + if (client_sock < 0) { + return 0; + } + + if (length == 0) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: read request length == 0, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + if (buffer == NULL) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: read request buffer == NULL, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + /* In a production quality implementation there would be a sanity + * timeout here to recover from "black hole" disconnects. + */ + + ret = read(client_sock, (void *) buffer, (size_t) length); + if (ret < 0) { + fprintf(stderr, "%s: debug read failed, closing connection: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; + } else if (ret == 0) { + fprintf(stderr, "%s: debug read failed, ret == 0 (EOF), closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } else if (ret > (ssize_t) length) { + fprintf(stderr, "%s: debug read failed, ret too large (%ld > %ld), closing connection\n", + __FILE__, (long) ret, (long) length); + fflush(stderr); + goto fail; + } + + return (duk_size_t) ret; + + fail: + if (client_sock >= 0) { + (void) close(client_sock); + client_sock = -1; + } + return 0; +} + +/* Duktape debug transport callback: (possibly partial) write. */ +duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length) { + ssize_t ret; + + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n", + __func__, (void *) udata, (const void *) buffer, (long) length); + fflush(stderr); +#endif + + if (client_sock < 0) { + return 0; + } + + if (length == 0) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: write request length == 0, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + if (buffer == NULL) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: write request buffer == NULL, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + /* In a production quality implementation there would be a sanity + * timeout here to recover from "black hole" disconnects. + */ + + ret = write(client_sock, (const void *) buffer, (size_t) length); + if (ret <= 0 || ret > (ssize_t) length) { + fprintf(stderr, "%s: debug write failed, closing connection: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; + } + + return (duk_size_t) ret; + + fail: + if (client_sock >= 0) { + (void) close(client_sock); + client_sock = -1; + } + return 0; +} + +duk_size_t duk_trans_socket_peek_cb(void *udata) { +#if defined(USE_SELECT) + struct timeval tm; + fd_set rfds; + int select_rc; +#else + struct pollfd fds[1]; + int poll_rc; +#endif + + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata); + fflush(stderr); +#endif + + if (client_sock < 0) { + return 0; + } +#if defined(USE_SELECT) + FD_ZERO(&rfds); + FD_SET(client_sock, &rfds); + tm.tv_sec = tm.tv_usec = 0; + select_rc = select(client_sock + 1, &rfds, NULL, NULL, &tm); + if (select_rc == 0) { + return 0; + } else if (select_rc == 1) { + return 1; + } + goto fail; +#else /* USE_SELECT */ + fds[0].fd = client_sock; + fds[0].events = POLLIN; + fds[0].revents = 0; + + poll_rc = poll(fds, 1, 0); + if (poll_rc < 0) { + fprintf(stderr, "%s: poll returned < 0, closing connection: %s\n", + __FILE__, strerror(errno)); + fflush(stderr); + goto fail; /* also returns 0, which is correct */ + } else if (poll_rc > 1) { + fprintf(stderr, "%s: poll returned > 1, treating like 1\n", + __FILE__); + fflush(stderr); + return 1; /* should never happen */ + } else if (poll_rc == 0) { + return 0; /* nothing to read */ + } else { + return 1; /* something to read */ + } +#endif /* USE_SELECT */ + fail: + if (client_sock >= 0) { + (void) close(client_sock); + client_sock = -1; + } + return 0; +} + +void duk_trans_socket_read_flush_cb(void *udata) { + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata); + fflush(stderr); +#endif + + /* Read flush: Duktape may not be making any more read calls at this + * time. If the transport maintains a receive window, it can use a + * read flush as a signal to update the window status to the remote + * peer. A read flush is guaranteed to occur before Duktape stops + * reading for a while; it may occur in other situations as well so + * it's not a 100% reliable indication. + */ + + /* This TCP transport requires no read flush handling so ignore. + * You can also pass a NULL to duk_debugger_attach() and not + * implement this callback at all. + */ +} + +void duk_trans_socket_write_flush_cb(void *udata) { + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata); + fflush(stderr); +#endif + + /* Write flush. If the transport combines multiple writes + * before actually sending, a write flush is an indication + * to write out any pending bytes: Duktape may not be doing + * any more writes on this occasion. + */ + + /* This TCP transport requires no write flush handling so ignore. + * You can also pass a NULL to duk_debugger_attach() and not + * implement this callback at all. + */ + return; +} diff --git a/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_windows.c b/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_windows.c new file mode 100644 index 0000000..e07866e --- /dev/null +++ b/lib/duktape-2.2.1/examples/debug-trans-socket/duk_trans_socket_windows.c @@ -0,0 +1,419 @@ +/* + * Example debug transport using a Windows TCP socket + * + * Provides a TCP server socket which a debug client can connect to. + * After that data is just passed through. + * + * https://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx + * + * Compiling 'duk' with debugger support using MSVC (Visual Studio): + * + * > python2 tools\configure.py \ + * --output-directory prep + * -DDUK_USE_DEBUGGER_SUPPORT -DDUK_USE_INTERRUPT_COUNTER + * > cl /W3 /O2 /Feduk.exe \ + * /DDUK_CMDLINE_DEBUGGER_SUPPORT + * /Iexamples\debug-trans-socket /Iprep + * examples\cmdline\duk_cmdline.c + * examples\debug-trans-socket\duk_trans_socket_windows.c + * prep\duktape.c + * + * With MinGW: + * + * $ python2 tools\configure.py \ + * --output-directory prep + * -DDUK_USE_DEBUGGER_SUPPORT -DDUK_USE_INTERRUPT_COUNTER + * $ gcc -oduk.exe -Wall -O2 \ + * -DDUK_CMDLINE_DEBUGGER_SUPPORT \ + * -Iexamples/debug-trans-socket -Iprep \ + * examples/cmdline/duk_cmdline.c \ + * examples/debug-trans-socket/duk_trans_socket_windows.c \ + * prep/duktape.c -lm -lws2_32 + */ + +#undef UNICODE +#if !defined(WIN32_LEAN_AND_MEAN) +#define WIN32_LEAN_AND_MEAN +#endif + +/* MinGW workaround for missing getaddrinfo() etc: + * http://programmingrants.blogspot.fi/2009/09/tips-on-undefined-reference-to.html + */ +#if defined(__MINGW32__) || defined(__MINGW64__) +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x0501 +#endif +#endif + +#include +#include +#include +#include +#include +#include "duktape.h" +#include "duk_trans_socket.h" + +#if defined(_MSC_VER) +#pragma comment (lib, "Ws2_32.lib") +#endif + +#if !defined(DUK_DEBUG_PORT) +#define DUK_DEBUG_PORT 9091 +#endif +#if !defined(DUK_DEBUG_ADDRESS) +#define DUK_DEBUG_ADDRESS "0.0.0.0" +#endif +#define DUK__STRINGIFY_HELPER(x) #x +#define DUK__STRINGIFY(x) DUK__STRINGIFY_HELPER(x) + +#if 0 +#define DEBUG_PRINTS +#endif + +static SOCKET server_sock = INVALID_SOCKET; +static SOCKET client_sock = INVALID_SOCKET; +static int wsa_inited = 0; + +/* + * Transport init and finish + */ + +void duk_trans_socket_init(void) { + WSADATA wsa_data; + struct addrinfo hints; + struct addrinfo *result = NULL; + int rc; + + memset((void *) &wsa_data, 0, sizeof(wsa_data)); + memset((void *) &hints, 0, sizeof(hints)); + + rc = WSAStartup(MAKEWORD(2, 2), &wsa_data); + if (rc != 0) { + fprintf(stderr, "%s: WSAStartup() failed: %d\n", __FILE__, rc); + fflush(stderr); + goto fail; + } + wsa_inited = 1; + + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + + rc = getaddrinfo(DUK_DEBUG_ADDRESS, DUK__STRINGIFY(DUK_DEBUG_PORT), &hints, &result); + if (rc != 0) { + fprintf(stderr, "%s: getaddrinfo() failed: %d\n", __FILE__, rc); + fflush(stderr); + goto fail; + } + + server_sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol); + if (server_sock == INVALID_SOCKET) { + fprintf(stderr, "%s: socket() failed with error: %ld\n", + __FILE__, (long) WSAGetLastError()); + fflush(stderr); + goto fail; + } + + rc = bind(server_sock, result->ai_addr, (int) result->ai_addrlen); + if (rc == SOCKET_ERROR) { + fprintf(stderr, "%s: bind() failed with error: %ld\n", + __FILE__, (long) WSAGetLastError()); + fflush(stderr); + goto fail; + } + + rc = listen(server_sock, SOMAXCONN); + if (rc == SOCKET_ERROR) { + fprintf(stderr, "%s: listen() failed with error: %ld\n", + __FILE__, (long) WSAGetLastError()); + fflush(stderr); + goto fail; + } + + if (result != NULL) { + freeaddrinfo(result); + result = NULL; + } + return; + + fail: + if (result != NULL) { + freeaddrinfo(result); + result = NULL; + } + if (server_sock != INVALID_SOCKET) { + (void) closesocket(server_sock); + server_sock = INVALID_SOCKET; + } + if (wsa_inited) { + WSACleanup(); + wsa_inited = 0; + } +} + +void duk_trans_socket_finish(void) { + if (client_sock != INVALID_SOCKET) { + (void) closesocket(client_sock); + client_sock = INVALID_SOCKET; + } + if (server_sock != INVALID_SOCKET) { + (void) closesocket(server_sock); + server_sock = INVALID_SOCKET; + } + if (wsa_inited) { + WSACleanup(); + wsa_inited = 0; + } +} + +void duk_trans_socket_waitconn(void) { + if (server_sock == INVALID_SOCKET) { + fprintf(stderr, "%s: no server socket, skip waiting for connection\n", + __FILE__); + fflush(stderr); + return; + } + if (client_sock != INVALID_SOCKET) { + (void) closesocket(client_sock); + client_sock = INVALID_SOCKET; + } + + fprintf(stderr, "Waiting for debug connection on port %d\n", (int) DUK_DEBUG_PORT); + fflush(stderr); + + client_sock = accept(server_sock, NULL, NULL); + if (client_sock == INVALID_SOCKET) { + fprintf(stderr, "%s: accept() failed with error %ld, skip waiting for connection\n", + __FILE__, (long) WSAGetLastError()); + fflush(stderr); + goto fail; + } + + fprintf(stderr, "Debug connection established\n"); + fflush(stderr); + + /* XXX: For now, close the listen socket because we won't accept new + * connections anyway. A better implementation would allow multiple + * debug attaches. + */ + + if (server_sock != INVALID_SOCKET) { + (void) closesocket(server_sock); + server_sock = INVALID_SOCKET; + } + return; + + fail: + if (client_sock != INVALID_SOCKET) { + (void) closesocket(client_sock); + client_sock = INVALID_SOCKET; + } +} + +/* + * Duktape callbacks + */ + +/* Duktape debug transport callback: (possibly partial) read. */ +duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length) { + int ret; + + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n", + __FUNCTION__, (void *) udata, (void *) buffer, (long) length); + fflush(stderr); +#endif + + if (client_sock == INVALID_SOCKET) { + return 0; + } + + if (length == 0) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: read request length == 0, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + if (buffer == NULL) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: read request buffer == NULL, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + /* In a production quality implementation there would be a sanity + * timeout here to recover from "black hole" disconnects. + */ + + ret = recv(client_sock, (void *) buffer, (int) length, 0); + if (ret < 0) { + fprintf(stderr, "%s: debug read failed, error %d, closing connection\n", + __FILE__, ret); + fflush(stderr); + goto fail; + } else if (ret == 0) { + fprintf(stderr, "%s: debug read failed, ret == 0 (EOF), closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } else if (ret > (int) length) { + fprintf(stderr, "%s: debug read failed, ret too large (%ld > %ld), closing connection\n", + __FILE__, (long) ret, (long) length); + fflush(stderr); + goto fail; + } + + return (duk_size_t) ret; + + fail: + if (client_sock != INVALID_SOCKET) { + (void) closesocket(client_sock); + client_sock = INVALID_SOCKET; + } + return 0; +} + +/* Duktape debug transport callback: (possibly partial) write. */ +duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length) { + int ret; + + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n", + __FUNCTION__, (void *) udata, (const void *) buffer, (long) length); + fflush(stderr); +#endif + + if (client_sock == INVALID_SOCKET) { + return 0; + } + + if (length == 0) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: write request length == 0, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + if (buffer == NULL) { + /* This shouldn't happen. */ + fprintf(stderr, "%s: write request buffer == NULL, closing connection\n", + __FILE__); + fflush(stderr); + goto fail; + } + + /* In a production quality implementation there would be a sanity + * timeout here to recover from "black hole" disconnects. + */ + + ret = send(client_sock, (const void *) buffer, (int) length, 0); + if (ret <= 0 || ret > (int) length) { + fprintf(stderr, "%s: debug write failed, ret %d, closing connection\n", + __FILE__, ret); + fflush(stderr); + goto fail; + } + + return (duk_size_t) ret; + + fail: + if (client_sock != INVALID_SOCKET) { + (void) closesocket(INVALID_SOCKET); + client_sock = INVALID_SOCKET; + } + return 0; +} + +duk_size_t duk_trans_socket_peek_cb(void *udata) { + u_long avail; + int rc; + + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata); + fflush(stderr); +#endif + + if (client_sock == INVALID_SOCKET) { + return 0; + } + + avail = 0; + rc = ioctlsocket(client_sock, FIONREAD, &avail); + if (rc != 0) { + fprintf(stderr, "%s: ioctlsocket() returned %d, closing connection\n", + __FILE__, rc); + fflush(stderr); + goto fail; /* also returns 0, which is correct */ + } else { + if (avail == 0) { + return 0; /* nothing to read */ + } else { + return 1; /* something to read */ + } + } + /* never here */ + + fail: + if (client_sock != INVALID_SOCKET) { + (void) closesocket(client_sock); + client_sock = INVALID_SOCKET; + } + return 0; +} + +void duk_trans_socket_read_flush_cb(void *udata) { + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata); + fflush(stderr); +#endif + + /* Read flush: Duktape may not be making any more read calls at this + * time. If the transport maintains a receive window, it can use a + * read flush as a signal to update the window status to the remote + * peer. A read flush is guaranteed to occur before Duktape stops + * reading for a while; it may occur in other situations as well so + * it's not a 100% reliable indication. + */ + + /* This TCP transport requires no read flush handling so ignore. + * You can also pass a NULL to duk_debugger_attach() and not + * implement this callback at all. + */ +} + +void duk_trans_socket_write_flush_cb(void *udata) { + (void) udata; /* not needed by the example */ + +#if defined(DEBUG_PRINTS) + fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata); + fflush(stderr); +#endif + + /* Write flush. If the transport combines multiple writes + * before actually sending, a write flush is an indication + * to write out any pending bytes: Duktape may not be doing + * any more writes on this occasion. + */ + + /* This TCP transport requires no write flush handling so ignore. + * You can also pass a NULL to duk_debugger_attach() and not + * implement this callback at all. + */ + return; +} + +#undef DUK__STRINGIFY_HELPER +#undef DUK__STRINGIFY diff --git a/lib/duktape-2.2.1/examples/dummy-date-provider/README.rst b/lib/duktape-2.2.1/examples/dummy-date-provider/README.rst new file mode 100644 index 0000000..bc62779 --- /dev/null +++ b/lib/duktape-2.2.1/examples/dummy-date-provider/README.rst @@ -0,0 +1,5 @@ +==================================== +Dummy external Date provider example +==================================== + +This example implements a dummy, minimal external Date provider. diff --git a/lib/duktape-2.2.1/examples/dummy-date-provider/dummy_date_provider.c b/lib/duktape-2.2.1/examples/dummy-date-provider/dummy_date_provider.c new file mode 100644 index 0000000..9c9e716 --- /dev/null +++ b/lib/duktape-2.2.1/examples/dummy-date-provider/dummy_date_provider.c @@ -0,0 +1,27 @@ +/* + * Dummy Date provider + * + * There are two minimally required macros which you must provide in + * duk_config.h: + * + * extern duk_double_t dummy_get_now(void); + * + * #define DUK_USE_DATE_GET_NOW(ctx) dummy_get_now() + * #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) 0 + * + * Note that since the providers are macros, you don't need to use + * all arguments. Similarly, you can "return" fixed values as + * constants. Above, local timezone offset is always zero i.e. + * we're always in UTC. + * + * You can also provide optional macros to parse and format timestamps + * in a platform specific format. If not provided, Duktape will use + * ISO 8601 only (which is often good enough). + */ + +#include "duktape.h" + +duk_double_t dummy_get_now(void) { + /* Return a fixed time here as a dummy example. */ + return -11504520000.0; +} diff --git a/lib/duktape-2.2.1/examples/eval/README.rst b/lib/duktape-2.2.1/examples/eval/README.rst new file mode 100644 index 0000000..eed1806 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eval/README.rst @@ -0,0 +1,5 @@ +============ +Eval example +============ + +Evaluate expressions from command line. diff --git a/lib/duktape-2.2.1/examples/eval/eval.c b/lib/duktape-2.2.1/examples/eval/eval.c new file mode 100644 index 0000000..1ec6c40 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eval/eval.c @@ -0,0 +1,62 @@ +/* + * Very simple example program for evaluating expressions from + * command line + */ + +#include "duktape.h" +#include + +static duk_ret_t native_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_to_string(ctx, -1)); + return 0; +} + +static duk_ret_t eval_raw(duk_context *ctx, void *udata) { + (void) udata; + duk_eval(ctx); + return 1; +} + +static duk_ret_t tostring_raw(duk_context *ctx, void *udata) { + (void) udata; + duk_to_string(ctx, -1); + return 1; +} + +static void usage_exit(void) { + fprintf(stderr, "Usage: eval [] ...\n"); + fflush(stderr); + exit(1); +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + int i; + const char *res; + + if (argc < 2) { + usage_exit(); + } + + ctx = duk_create_heap_default(); + + duk_push_c_function(ctx, native_print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + for (i = 1; i < argc; i++) { + printf("=== eval: '%s' ===\n", argv[i]); + duk_push_string(ctx, argv[i]); + duk_safe_call(ctx, eval_raw, NULL, 1 /*nargs*/, 1 /*nrets*/); + duk_safe_call(ctx, tostring_raw, NULL, 1 /*nargs*/, 1 /*nrets*/); + res = duk_get_string(ctx, -1); + printf("%s\n", res ? res : "null"); + duk_pop(ctx); + } + + duk_destroy_heap(ctx); + + return 0; +} diff --git a/lib/duktape-2.2.1/examples/eventloop/README.rst b/lib/duktape-2.2.1/examples/eventloop/README.rst new file mode 100644 index 0000000..5b1b147 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/README.rst @@ -0,0 +1,76 @@ +================== +Eventloop examples +================== + +Overview and usage +================== + +A few examples on how an event loop can be implemented with Duktape, mainly +illlustrating how the Duktape interface works (not how event loops should be +built otherwise). + +To test (Linux only, perhaps other Unix):: + + $ make + $ ./evloop curses-timers.js # run with Ecmascript eventloop + $ ./evloop -c curses-timers.js # run with C eventloop + +Implementation approaches +========================= + +There are several approaches to implementation timers. Here we demonstrate +two main approaches: + +1. Using a C eventloop which calls into Javascript. All the event loop state + like timers, sockets, etc, is held in C structures. + (See ``c_eventloop.c`` and ``c_eventloop.js``.) + +2. Using an Ecmascript eventloop which never returns. All the event loop state + can be managed with Ecmascript code instead of C structures. The Ecmascript + eventloop calls a Duktape/C helper to do the lowest level poll() call. + (See ``ecma_eventloop.js``.) + +Services provided +================= + +The event loop API provided by both examples is the same, and includes: + +* Timers: setTimeout, clearTimeout, setInterval, clearInterval + +* Sockets: simple network sockets + +In addition there are a few synchronous API bindings which are not event loop +related: + +* File I/O + +* Curses, for doing beautiful character graphics + +Limitations +=========== + +This is **not** a production quality event loop. This is on purpose, to +keep the example somewhat simple. Some shortcomings include: + +* A production quality event loop would track its internal state (active + timers and sockets) much more efficiently. In general memory usage and + code footprint can be reduced. + +* Buffer churn caused by allocating a new buffer for every socket read + should be eliminated by reusing buffers where appropriate. Although + churn doesn't increase memory footprint with reference counting, it + is slower than reusing buffers and might increase memory fragmentation. + +* There is no way to suspend reading or writing in the example. Adding + them is straightforward: the poll set needs to be managed dynamically. + +* The example uses poll() while one should use epoll() on Linux, kqueue() + on BSD systems, etc. + +* Timers are not very accurate, e.g. setInterval() does not try to guarantee + a steady schedule. Instead, the next interval is scheduled after the + current callback has finished. This is not the best behavior for some + environments, but avoids bunching callbacks. + +* Error handling is mostly missing. Debug prints don't interact well + with curses. diff --git a/lib/duktape-2.2.1/examples/eventloop/basic-test.js b/lib/duktape-2.2.1/examples/eventloop/basic-test.js new file mode 100644 index 0000000..04b3392 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/basic-test.js @@ -0,0 +1,17 @@ +/* + * A few basic tests + */ + +var count = 0; +var intervalId; + +setTimeout(function (x) { print('timer 1', x); }, 1234, 'foo'); +setTimeout('print("timer 2");', 4321); +setTimeout(function () { print('timer 3'); }, 2345); +intervalId = setInterval(function (x, y) { + print('interval', ++count, x, y); + if (count >= 10) { + clearInterval(intervalId); + } +}, 400, 'foo', 'bar'); + diff --git a/lib/duktape-2.2.1/examples/eventloop/c_eventloop.c b/lib/duktape-2.2.1/examples/eventloop/c_eventloop.c new file mode 100644 index 0000000..1161439 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/c_eventloop.c @@ -0,0 +1,620 @@ +/* + * C eventloop example. + * + * Timer management is similar to eventloop.js but implemented in C. + * In particular, timer insertion is an O(n) operation; in a real world + * eventloop based on a heap insertion would be O(log N). + */ + +#include +#include +#include +#include +#include +#include + +#include "duktape.h" + +#define MAX_TIMERS 4096 /* this is quite excessive for embedded use, but good for testing */ +#define MIN_DELAY 1.0 +#define MIN_WAIT 1.0 +#define MAX_WAIT 60000.0 +#define MAX_EXPIRYS 10 + +#define MAX_FDS 256 + +typedef struct { + int64_t id; /* numeric ID (returned from e.g. setTimeout); zero if unused */ + double target; /* next target time */ + double delay; /* delay/interval */ + int oneshot; /* oneshot=1 (setTimeout), repeated=0 (setInterval) */ + int removed; /* timer has been requested for removal */ + + /* The callback associated with the timer is held in the "global stash", + * in .eventTimers[String(id)]. The references must be deleted + * when a timer struct is deleted. + */ +} ev_timer; + +/* Active timers. Dense list, terminates to end of list or first unused timer. + * The list is sorted by 'target', with lowest 'target' (earliest expiry) last + * in the list. When a timer's callback is being called, the timer is moved + * to 'timer_expiring' as it needs special handling should the user callback + * delete that particular timer. + */ +static ev_timer timer_list[MAX_TIMERS]; +static ev_timer timer_expiring; +static int timer_count; /* last timer at timer_count - 1 */ +static int64_t timer_next_id = 1; + +/* Socket poll state. */ +static struct pollfd poll_list[MAX_FDS]; +static int poll_count = 0; + +/* Misc */ +static int exit_requested = 0; + +/* Get Javascript compatible 'now' timestamp (millisecs since 1970). */ +static double get_now(void) { + struct timeval tv; + int rc; + + rc = gettimeofday(&tv, NULL); + if (rc != 0) { + /* Should never happen, so return whatever. */ + return 0.0; + } + return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0; +} + +static ev_timer *find_nearest_timer(void) { + /* Last timer expires first (list is always kept sorted). */ + if (timer_count <= 0) { + return NULL; + } + return timer_list + timer_count - 1; +} + +/* Bubble last timer on timer list backwards until it has been moved to + * its proper sorted position (based on 'target' time). + */ +static void bubble_last_timer(void) { + int i; + int n = timer_count; + ev_timer *t; + ev_timer tmp; + + for (i = n - 1; i > 0; i--) { + /* Timer to bubble is at index i, timer to compare to is + * at i-1 (both guaranteed to exist). + */ + t = timer_list + i; + if (t->target <= (t-1)->target) { + /* 't' expires earlier than (or same time as) 't-1', so we're done. */ + break; + } else { + /* 't' expires later than 't-1', so swap them and repeat. */ + memcpy((void *) &tmp, (void *) (t - 1), sizeof(ev_timer)); + memcpy((void *) (t - 1), (void *) t, sizeof(ev_timer)); + memcpy((void *) t, (void *) &tmp, sizeof(ev_timer)); + } + } +} + +static void expire_timers(duk_context *ctx) { + ev_timer *t; + int sanity = MAX_EXPIRYS; + double now; + int rc; + + /* Because a user callback can mutate the timer list (by adding or deleting + * a timer), we expire one timer and then rescan from the end again. There + * is a sanity limit on how many times we do this per expiry round. + */ + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "eventTimers"); + + /* [ ... stash eventTimers ] */ + + now = get_now(); + while (sanity-- > 0) { + /* + * If exit has been requested, exit without running further + * callbacks. + */ + + if (exit_requested) { +#if 0 + fprintf(stderr, "exit requested, exiting timer expiry loop\n"); + fflush(stderr); +#endif + break; + } + + /* + * Expired timer(s) still exist? + */ + + if (timer_count <= 0) { + break; + } + t = timer_list + timer_count - 1; + if (t->target > now) { + break; + } + + /* + * Move the timer to 'expiring' for the duration of the callback. + * Mark a one-shot timer deleted, compute a new target for an interval. + */ + + memcpy((void *) &timer_expiring, (void *) t, sizeof(ev_timer)); + memset((void *) t, 0, sizeof(ev_timer)); + timer_count--; + t = &timer_expiring; + + if (t->oneshot) { + t->removed = 1; + } else { + t->target = now + t->delay; /* XXX: or t->target + t->delay? */ + } + + /* + * Call timer callback. The callback can operate on the timer list: + * add new timers, remove timers. The callback can even remove the + * expired timer whose callback we're calling. However, because the + * timer being expired has been moved to 'timer_expiring', we don't + * need to worry about the timer's offset changing on the timer list. + */ + +#if 0 + fprintf(stderr, "calling user callback for timer id %d\n", (int) t->id); + fflush(stderr); +#endif + + duk_push_number(ctx, (double) t->id); + duk_get_prop(ctx, -2); /* -> [ ... stash eventTimers func ] */ + rc = duk_pcall(ctx, 0 /*nargs*/); /* -> [ ... stash eventTimers retval ] */ + if (rc != 0) { +#if 0 + fprintf(stderr, "timer callback failed for timer %d: %s\n", (int) t->id, duk_to_string(ctx, -1)); + fflush(stderr); +#endif + } + duk_pop(ctx); /* ignore errors for now -> [ ... stash eventTimers ] */ + + if (t->removed) { + /* One-shot timer (always removed) or removed by user callback. */ +#if 0 + fprintf(stderr, "deleting callback state for timer %d\n", (int) t->id); + fflush(stderr); +#endif + duk_push_number(ctx, (double) t->id); + duk_del_prop(ctx, -2); + } else { + /* Interval timer, not removed by user callback. Queue back to + * timer list and bubble to its final sorted position. + */ +#if 0 + fprintf(stderr, "queueing timer %d back into active list\n", (int) t->id); + fflush(stderr); +#endif + if (timer_count >= MAX_TIMERS) { + (void) duk_error(ctx, DUK_ERR_RANGE_ERROR, "out of timer slots"); + } + memcpy((void *) (timer_list + timer_count), (void *) t, sizeof(ev_timer)); + timer_count++; + bubble_last_timer(); + } + } + + memset((void *) &timer_expiring, 0, sizeof(ev_timer)); + + duk_pop_2(ctx); /* -> [ ... ] */ +} + +static void compact_poll_list(void) { + int i, j, n; + + /* i = input index + * j = output index (initially same as i) + */ + + n = poll_count; + for (i = 0, j = 0; i < n; i++) { + struct pollfd *pfd = poll_list + i; + if (pfd->fd == 0) { + /* keep output index the same */ +#if 0 + fprintf(stderr, "remove pollfd (index %d): fd=%d, events=%d, revents=%d\n", + i, pfd->fd, pfd->events, pfd->revents), + fflush(stderr); +#endif + + continue; + } +#if 0 + fprintf(stderr, "keep pollfd (index %d -> %d): fd=%d, events=%d, revents=%d\n", + i, j, pfd->fd, pfd->events, pfd->revents), + fflush(stderr); +#endif + if (i != j) { + /* copy only if indices have diverged */ + memcpy((void *) (poll_list + j), (void *) (poll_list + i), sizeof(struct pollfd)); + } + j++; + } + + if (j < poll_count) { + /* zeroize unused entries for sanity */ + memset((void *) (poll_list + j), 0, (poll_count - j) * sizeof(struct pollfd)); + } + + poll_count = j; +} + +duk_ret_t eventloop_run(duk_context *ctx, void *udata) { + ev_timer *t; + double now; + double diff; + int timeout; + int rc; + int i, n; + int idx_eventloop; + int idx_fd_handler; + + (void) udata; + + /* The Ecmascript poll handler is passed through EventLoop.fdPollHandler + * which c_eventloop.js sets before we come here. + */ + duk_push_global_object(ctx); + duk_get_prop_string(ctx, -1, "EventLoop"); + duk_get_prop_string(ctx, -1, "fdPollHandler"); /* -> [ global EventLoop fdPollHandler ] */ + idx_fd_handler = duk_get_top_index(ctx); + idx_eventloop = idx_fd_handler - 1; + + for (;;) { + /* + * Expire timers. + */ + + expire_timers(ctx); + + /* + * If exit requested, bail out as fast as possible. + */ + + if (exit_requested) { +#if 0 + fprintf(stderr, "exit requested, exiting event loop\n"); + fflush(stderr); +#endif + break; + } + + /* + * Compact poll list by removing pollfds with fd == 0. + */ + + compact_poll_list(); + + /* + * Determine poll() timeout (as close to poll() as possible as + * the wait is relative). + */ + + now = get_now(); + t = find_nearest_timer(); + if (t) { + diff = t->target - now; + if (diff < MIN_WAIT) { + diff = MIN_WAIT; + } else if (diff > MAX_WAIT) { + diff = MAX_WAIT; + } + timeout = (int) diff; /* clamping ensures that fits */ + } else { + if (poll_count == 0) { +#if 0 + fprintf(stderr, "no timers and no sockets to poll, exiting\n"); + fflush(stderr); +#endif + break; + } + timeout = (int) MAX_WAIT; + } + + /* + * Poll for activity or timeout. + */ + +#if 0 + fprintf(stderr, "going to poll, timeout %d ms, pollfd count %d\n", timeout, poll_count); + fflush(stderr); +#endif + + rc = poll(poll_list, poll_count, timeout); +#if 0 + fprintf(stderr, "poll rc: %d\n", rc); + fflush(stderr); +#endif + if (rc < 0) { + /* error */ + } else if (rc == 0) { + /* timeout */ + } else { + /* 'rc' fds active */ + } + + /* + * Check socket activity, handle all sockets. Handling is offloaded to + * Ecmascript code (fd + revents). + * + * If FDs are removed from the poll list while we're processing callbacks, + * the entries are simply marked unused (fd set to 0) without actually + * removing them from the poll list. This ensures indices are not + * disturbed. The poll list is compacted before next poll(). + */ + + n = (rc == 0 ? 0 : poll_count); /* if timeout, no need to check pollfd */ + for (i = 0; i < n; i++) { + struct pollfd *pfd = poll_list + i; + + if (pfd->fd == 0) { + /* deleted, perhaps by previous callback */ + continue; + } + + if (pfd->revents) { +#if 0 + fprintf(stderr, "fd %d has revents: %d\n", (int) pfd->fd, (int) pfd->revents); + fflush(stderr); +#endif + duk_dup(ctx, idx_fd_handler); + duk_dup(ctx, idx_eventloop); + duk_push_int(ctx, pfd->fd); + duk_push_int(ctx, pfd->revents); + rc = duk_pcall_method(ctx, 2 /*nargs*/); + if (rc) { +#if 0 + fprintf(stderr, "fd callback failed for fd %d: %s\n", (int) pfd->fd, duk_to_string(ctx, -1)); + fflush(stderr); +#endif + } + duk_pop(ctx); + + pfd->revents = 0; + } + + } + } + + duk_pop_n(ctx, 3); + + return 0; +} + +static int create_timer(duk_context *ctx) { + double delay; + int oneshot; + int idx; + int64_t timer_id; + double now; + ev_timer *t; + + now = get_now(); + + /* indexes: + * 0 = function (callback) + * 1 = delay + * 2 = boolean: oneshot + */ + + delay = duk_require_number(ctx, 1); + if (delay < MIN_DELAY) { + delay = MIN_DELAY; + } + oneshot = duk_require_boolean(ctx, 2); + + if (timer_count >= MAX_TIMERS) { + (void) duk_error(ctx, DUK_ERR_RANGE_ERROR, "out of timer slots"); + } + idx = timer_count++; + timer_id = timer_next_id++; + t = timer_list + idx; + + memset((void *) t, 0, sizeof(ev_timer)); + t->id = timer_id; + t->target = now + delay; + t->delay = delay; + t->oneshot = oneshot; + t->removed = 0; + + /* Timer is now at the last position; use swaps to "bubble" it to its + * correct sorted position. + */ + + bubble_last_timer(); + + /* Finally, register the callback to the global stash 'eventTimers' object. */ + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "eventTimers"); /* -> [ func delay oneshot stash eventTimers ] */ + duk_push_number(ctx, (double) timer_id); + duk_dup(ctx, 0); + duk_put_prop(ctx, -3); /* eventTimers[timer_id] = callback */ + + /* Return timer id. */ + + duk_push_number(ctx, (double) timer_id); +#if 0 + fprintf(stderr, "created timer id: %d\n", (int) timer_id); + fflush(stderr); +#endif + return 1; +} + +static int delete_timer(duk_context *ctx) { + int i, n; + int64_t timer_id; + ev_timer *t; + int found = 0; + + /* indexes: + * 0 = timer id + */ + + timer_id = (int64_t) duk_require_number(ctx, 0); + + /* + * Unlike insertion, deletion needs a full scan of the timer list + * and an expensive remove. If no match is found, nothing is deleted. + * Caller gets a boolean return code indicating match. + * + * When a timer is being expired and its user callback is running, + * the timer has been moved to 'timer_expiring' and its deletion + * needs special handling: just mark it to-be-deleted and let the + * expiry code remove it. + */ + + t = &timer_expiring; + if (t->id == timer_id) { + t->removed = 1; + duk_push_true(ctx); +#if 0 + fprintf(stderr, "deleted expiring timer id: %d\n", (int) timer_id); + fflush(stderr); +#endif + return 1; + } + + n = timer_count; + for (i = 0; i < n; i++) { + t = timer_list + i; + if (t->id == timer_id) { + found = 1; + + /* Shift elements downwards to keep the timer list dense + * (no need if last element). + */ + if (i < timer_count - 1) { + memmove((void *) t, (void *) (t + 1), (timer_count - i - 1) * sizeof(ev_timer)); + } + + /* Zero last element for clarity. */ + memset((void *) (timer_list + n - 1), 0, sizeof(ev_timer)); + + /* Update timer_count. */ + timer_count--; + + /* The C state is now up-to-date, but we still need to delete + * the timer callback state from the global 'stash'. + */ + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "eventTimers"); /* -> [ timer_id stash eventTimers ] */ + duk_push_number(ctx, (double) timer_id); + duk_del_prop(ctx, -2); /* delete eventTimers[timer_id] */ + +#if 0 + fprintf(stderr, "deleted timer id: %d\n", (int) timer_id); + fflush(stderr); +#endif + break; + } + } + +#if 0 + if (!found) { + fprintf(stderr, "trying to delete timer id %d, but not found; ignoring\n", (int) timer_id); + fflush(stderr); + } +#endif + + duk_push_boolean(ctx, found); + return 1; +} + +static int listen_fd(duk_context *ctx) { + int fd = duk_require_int(ctx, 0); + int events = duk_require_int(ctx, 1); + int i, n; + struct pollfd *pfd; + +#if 0 + fprintf(stderr, "listen_fd: fd=%d, events=%d\n", fd, events); + fflush(stderr); +#endif + /* events == 0 means stop listening to the FD */ + + n = poll_count; + for (i = 0; i < n; i++) { + pfd = poll_list + i; + if (pfd->fd == fd) { +#if 0 + fprintf(stderr, "listen_fd: fd found at index %d\n", i); + fflush(stderr); +#endif + if (events == 0) { + /* mark to-be-deleted, cleaned up by next poll */ + pfd->fd = 0; + } else { + pfd->events = events; + } + return 0; + } + } + + /* not found, append to list */ +#if 0 + fprintf(stderr, "listen_fd: fd not found on list, add new entry\n"); + fflush(stderr); +#endif + + if (poll_count >= MAX_FDS) { + (void) duk_error(ctx, DUK_ERR_ERROR, "out of fd slots"); + } + + pfd = poll_list + poll_count; + pfd->fd = fd; + pfd->events = events; + pfd->revents = 0; + poll_count++; + + return 0; +} + +static int request_exit(duk_context *ctx) { + (void) ctx; + exit_requested = 1; + return 0; +} + +static duk_function_list_entry eventloop_funcs[] = { + { "createTimer", create_timer, 3 }, + { "deleteTimer", delete_timer, 1 }, + { "listenFd", listen_fd, 2 }, + { "requestExit", request_exit, 0 }, + { NULL, NULL, 0 } +}; + +void eventloop_register(duk_context *ctx) { + memset((void *) timer_list, 0, MAX_TIMERS * sizeof(ev_timer)); + memset((void *) &timer_expiring, 0, sizeof(ev_timer)); + memset((void *) poll_list, 0, MAX_FDS * sizeof(struct pollfd)); + + /* Set global 'EventLoop'. */ + duk_push_global_object(ctx); + duk_push_object(ctx); + duk_put_function_list(ctx, -1, eventloop_funcs); + duk_put_prop_string(ctx, -2, "EventLoop"); + duk_pop(ctx); + + /* Initialize global stash 'eventTimers'. */ + duk_push_global_stash(ctx); + duk_push_object(ctx); + duk_put_prop_string(ctx, -2, "eventTimers"); + duk_pop(ctx); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/c_eventloop.js b/lib/duktape-2.2.1/examples/eventloop/c_eventloop.js new file mode 100644 index 0000000..b9e2d63 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/c_eventloop.js @@ -0,0 +1,179 @@ +/* + * C eventloop example (c_eventloop.c). + * + * Ecmascript code to initialize the exposed API (setTimeout() etc) when + * using the C eventloop. + * + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers + */ + +/* + * Timer API + */ + +function setTimeout(func, delay) { + var cb_func; + var bind_args; + var timer_id; + + if (typeof delay !== 'number') { + throw new TypeError('delay is not a number'); + } + + if (typeof func === 'string') { + // Legacy case: callback is a string. + cb_func = eval.bind(this, func); + } else if (typeof func !== 'function') { + throw new TypeError('callback is not a function/string'); + } else if (arguments.length > 2) { + // Special case: callback arguments are provided. + bind_args = Array.prototype.slice.call(arguments, 2); // [ arg1, arg2, ... ] + bind_args.unshift(this); // [ global(this), arg1, arg2, ... ] + cb_func = func.bind.apply(func, bind_args); + } else { + // Normal case: callback given as a function without arguments. + cb_func = func; + } + + timer_id = EventLoop.createTimer(cb_func, delay, true /*oneshot*/); + + return timer_id; +} + +function clearTimeout(timer_id) { + if (typeof timer_id !== 'number') { + throw new TypeError('timer ID is not a number'); + } + var success = EventLoop.deleteTimer(timer_id); /* retval ignored */ +} + +function setInterval(func, delay) { + var cb_func; + var bind_args; + var timer_id; + + if (typeof delay !== 'number') { + throw new TypeError('delay is not a number'); + } + + if (typeof func === 'string') { + // Legacy case: callback is a string. + cb_func = eval.bind(this, func); + } else if (typeof func !== 'function') { + throw new TypeError('callback is not a function/string'); + } else if (arguments.length > 2) { + // Special case: callback arguments are provided. + bind_args = Array.prototype.slice.call(arguments, 2); // [ arg1, arg2, ... ] + bind_args.unshift(this); // [ global(this), arg1, arg2, ... ] + cb_func = func.bind.apply(func, bind_args); + } else { + // Normal case: callback given as a function without arguments. + cb_func = func; + } + + timer_id = EventLoop.createTimer(cb_func, delay, false /*oneshot*/); + + return timer_id; +} + +function clearInterval(timer_id) { + if (typeof timer_id !== 'number') { + throw new TypeError('timer ID is not a number'); + } + EventLoop.deleteTimer(timer_id); +} + +function requestEventLoopExit() { + EventLoop.requestExit(); +} + +/* + * Socket handling + * + * Ideally this would be implemented more in C than here for more speed + * and smaller footprint: C code would directly maintain the callback state + * and such. + * + * Also for more optimal I/O, the buffer churn caused by allocating and + * freeing a lot of buffer values could be eliminated by reusing buffers. + * Socket reads would then go into a pre-allocated buffer, for instance. + */ + +EventLoop.socketListening = {}; +EventLoop.socketReading = {}; +EventLoop.socketConnecting = {}; + +EventLoop.fdPollHandler = function(fd, revents) { + var data; + var cb; + var rc; + var acc_res; + + //print('activity on fd', fd, 'revents', revents); + + if (revents & Poll.POLLIN) { + cb = this.socketReading[fd]; + if (cb) { + data = Socket.read(fd); // no size control now + //print('READ', Duktape.enc('jx', data)); + if (data.length === 0) { + this.close(fd); + return; + } + cb(fd, data); + } else { + cb = this.socketListening[fd]; + if (cb) { + acc_res = Socket.accept(fd); + //print('ACCEPT:', Duktape.enc('jx', acc_res)); + cb(acc_res.fd, acc_res.addr, acc_res.port); + } else { + //print('UNKNOWN'); + } + } + } + + if (revents & Poll.POLLOUT) { + // Connected + cb = this.socketConnecting[fd]; + if (cb) { + delete this.socketConnecting[fd]; + cb(fd); + } + } + + if ((revents & ~(Poll.POLLIN | Poll.POLLOUT)) !== 0) { + //print('unexpected revents, close fd'); + this.close(fd); + } +} + +EventLoop.server = function(address, port, cb_accepted) { + var fd = Socket.createServerSocket(address, port); + this.socketListening[fd] = cb_accepted; + this.listenFd(fd, Poll.POLLIN); +} + +EventLoop.connect = function(address, port, cb_connected) { + var fd = Socket.connect(address, port); + this.socketConnecting[fd] = cb_connected; + this.listenFd(fd, Poll.POLLOUT); +} + +EventLoop.close = function(fd) { + EventLoop.listenFd(fd, 0); + delete this.socketListening[fd]; + delete this.socketReading[fd]; + delete this.socketConnecting[fd]; + Socket.close(fd); +} + +EventLoop.setReader = function(fd, cb_read) { + this.socketReading[fd] = cb_read; + this.listenFd(fd, Poll.POLLIN); +} + +EventLoop.write = function(fd, data) { + // This simple example doesn't have support for write blocking / draining + var rc = Socket.write(fd, Duktape.Buffer(data)); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/client-socket-test.js b/lib/duktape-2.2.1/examples/eventloop/client-socket-test.js new file mode 100644 index 0000000..ff87784 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/client-socket-test.js @@ -0,0 +1,24 @@ + +var HOST = 'localhost'; +var PORT = 80; +var EXIT_TIMEOUT = 300e3; + +print('automatic exit after ' + (EXIT_TIMEOUT / 1e3) + ' seconds'); +setTimeout(function () { + print('exit timer'); + EventLoop.requestExit(); +}, EXIT_TIMEOUT); + +EventLoop.connect(HOST, PORT, function (fd) { + print('connected to ' + HOST + ':' + PORT + ', fd', fd); + EventLoop.setReader(fd, function (fd, data) { + print('read from fd', fd); + print(data); + EventLoop.close(fd); + }); + EventLoop.write(fd, "GET / HTTP/1.1\r\n" + + "Host: " + HOST + "\r\n" + + "User-Agent: client-socket-test.js\r\n" + + "\r\n"); +}); + diff --git a/lib/duktape-2.2.1/examples/eventloop/curses-timers.js b/lib/duktape-2.2.1/examples/eventloop/curses-timers.js new file mode 100644 index 0000000..4508665 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/curses-timers.js @@ -0,0 +1,79 @@ +/* + * Test using timers and intervals with curses. + */ + +if (typeof Ncurses !== 'object') { + throw new Error('Ncurses required'); +} + +function fillScreen(ch) { + var size, w, h; + var i, j; + + size = Ncurses.getmaxyx(); + h = size[0]; + w = size[1]; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + Ncurses.mvprintw(i, j, ch); + } + } + Ncurses.refresh(); +} + +function main() { + var i, j; + var counters = []; + var size, w, h; + + Ncurses.initscr(); + size = Ncurses.getmaxyx(); + h = size[0]; + w = size[1]; + + fillScreen('.'); + + setInterval(function () { + Ncurses.mvprintw(1, 4, new Date().toISOString()); + Ncurses.refresh(); + }, 1000); + + function addCounter(row, index, interval) { + counters[index] = 0; + setInterval(function () { + counters[index]++; + Ncurses.mvprintw(row, 4, '' + Date.now() + ' ' + counters[index]); + Ncurses.refresh(); + }, interval); + } + + function addRandomChar(row, col, interval) { + setTimeout(function () { + Ncurses.mvprintw(row, col, String.fromCharCode(Math.random() * 64 + 0x20)); + Ncurses.refresh(); + }, interval); + } + + for (i = 0; i < h - 5; i++) { + addCounter(3 + i, i, 363 * i + 400); + } + + /* Here the inserts take a lot of time because the underlying timer manager + * data structure has O(n) insertion performance. + */ + for (i = 0; i < h - 5; i++) { + for (j = 0; j < w - 50; j++) { + // Math.exp(0)...Math.exp(8) is an uneven distribution between 1...~2980. + addRandomChar(3 + i, 28 + j, 58000 - Math.exp(Math.random() * 8) * 20); + } + } + + setTimeout(function () { + Ncurses.endwin(); + Ncurses.delscreen(); + requestEventLoopExit(); + }, 120e3); +} + +main(); diff --git a/lib/duktape-2.2.1/examples/eventloop/ecma_eventloop.js b/lib/duktape-2.2.1/examples/eventloop/ecma_eventloop.js new file mode 100644 index 0000000..bad4e4d --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/ecma_eventloop.js @@ -0,0 +1,466 @@ +/* + * Pure Ecmascript eventloop example. + * + * Timer state handling is inefficient in this trivial example. Timers are + * kept in an array sorted by their expiry time which works well for expiring + * timers, but has O(n) insertion performance. A better implementation would + * use a heap or some other efficient structure for managing timers so that + * all operations (insert, remove, get nearest timer) have good performance. + * + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers + */ + +/* + * Event loop + * + * Timers are sorted by 'target' property which indicates expiry time of + * the timer. The timer expiring next is last in the array, so that + * removals happen at the end, and inserts for timers expiring in the + * near future displace as few elements in the array as possible. + */ + +EventLoop = { + // timers + timers: [], // active timers, sorted (nearest expiry last) + expiring: null, // set to timer being expired (needs special handling in clearTimeout/clearInterval) + nextTimerId: 1, + minimumDelay: 1, + minimumWait: 1, + maximumWait: 60000, + maxExpirys: 10, + + // sockets + socketListening: {}, // fd -> callback + socketReading: {}, // fd -> callback + socketConnecting: {}, // fd -> callback + + // misc + exitRequested: false +}; + +EventLoop.dumpState = function() { + print('TIMER STATE:'); + this.timers.forEach(function(t) { + print(' ' + Duktape.enc('jx', t)); + }); + if (this.expiring) { + print(' EXPIRING: ' + Duktape.enc('jx', this.expiring)); + } +} + +// Get timer with lowest expiry time. Since the active timers list is +// sorted, it's always the last timer. +EventLoop.getEarliestTimer = function() { + var timers = this.timers; + n = timers.length; + return (n > 0 ? timers[n - 1] : null); +} + +EventLoop.getEarliestWait = function() { + var t = this.getEarliestTimer(); + return (t ? t.target - Date.now() : null); +} + +EventLoop.insertTimer = function(timer) { + var timers = this.timers; + var i, n, t; + + /* + * Find 'i' such that we want to insert *after* timers[i] at index i+1. + * If no such timer, for-loop terminates with i-1, and we insert at -1+1=0. + */ + + n = timers.length; + for (i = n - 1; i >= 0; i--) { + t = timers[i]; + if (timer.target <= t.target) { + // insert after 't', to index i+1 + break; + } + } + + timers.splice(i + 1 /*start*/, 0 /*deleteCount*/, timer); +} + +// Remove timer/interval with a timer ID. The timer/interval can reside +// either on the active list or it may be an expired timer (this.expiring) +// whose user callback we're running when this function gets called. +EventLoop.removeTimerById = function(timer_id) { + var timers = this.timers; + var i, n, t; + + t = this.expiring; + if (t) { + if (t.id === timer_id) { + // Timer has expired and we're processing its callback. User + // callback has requested timer deletion. Mark removed, so + // that the timer is not reinserted back into the active list. + // This is actually a common case because an interval may very + // well cancel itself. + t.removed = true; + return; + } + } + + n = timers.length; + for (i = 0; i < n; i++) { + t = timers[i]; + if (t.id === timer_id) { + // Timer on active list: mark removed (not really necessary, but + // nice for dumping), and remove from active list. + t.removed = true; + this.timers.splice(i /*start*/, 1 /*deleteCount*/); + return; + } + } + + // no such ID, ignore +} + +EventLoop.processTimers = function() { + var now = Date.now(); + var timers = this.timers; + var sanity = this.maxExpirys; + var n, t; + + /* + * Here we must be careful with mutations: user callback may add and + * delete an arbitrary number of timers. + * + * Current solution is simple: check whether the timer at the end of + * the list has expired. If not, we're done. If it has expired, + * remove it from the active list, record it in this.expiring, and call + * the user callback. If user code deletes the this.expiring timer, + * there is special handling which just marks the timer deleted so + * it won't get inserted back into the active list. + * + * This process is repeated at most maxExpirys times to ensure we don't + * get stuck forever; user code could in principle add more and more + * already expired timers. + */ + + while (sanity-- > 0) { + // If exit requested, don't call any more callbacks. This allows + // a callback to do cleanups and request exit, and can be sure that + // no more callbacks are processed. + + if (this.exitRequested) { + //print('exit requested, exit'); + break; + } + + // Timers to expire? + + n = timers.length; + if (n <= 0) { + break; + } + t = timers[n - 1]; + if (now <= t.target) { + // Timer has not expired, and no other timer could have expired + // either because the list is sorted. + break; + } + timers.pop(); + + // Remove the timer from the active list and process it. The user + // callback may add new timers which is not a problem. The callback + // may also delete timers which is not a problem unless the timer + // being deleted is the timer whose callback we're running; this is + // why the timer is recorded in this.expiring so that clearTimeout() + // and clearInterval() can detect this situation. + + if (t.oneshot) { + t.removed = true; // flag for removal + } else { + t.target = now + t.delay; + } + this.expiring = t; + try { + t.cb(); + } catch (e) { + print('timer callback failed, ignored: ' + e); + } + this.expiring = null; + + // If the timer was one-shot, it's marked 'removed'. If the user callback + // requested deletion for the timer, it's also marked 'removed'. If the + // timer is an interval (and is not marked removed), insert it back into + // the timer list. + + if (!t.removed) { + // Reinsert interval timer to correct sorted position. The timer + // must be an interval timer because one-shot timers are marked + // 'removed' above. + this.insertTimer(t); + } + } +} + +EventLoop.run = function() { + var wait; + var POLLIN = Poll.POLLIN; + var POLLOUT = Poll.POLLOUT; + var poll_set; + var poll_count; + var fd; + var t, rev; + var rc; + var acc_res; + + for (;;) { + /* + * Process expired timers. + */ + + this.processTimers(); + //this.dumpState(); + + /* + * Exit check (may be requested by a user callback) + */ + + if (this.exitRequested) { + //print('exit requested, exit'); + break; + } + + /* + * Create poll socket list. This is a very naive approach. + * On Linux, one could use e.g. epoll() and manage socket lists + * incrementally. + */ + + poll_set = {}; + poll_count = 0; + for (fd in this.socketListening) { + poll_set[fd] = { events: POLLIN, revents: 0 }; + poll_count++; + } + for (fd in this.socketReading) { + poll_set[fd] = { events: POLLIN, revents: 0 }; + poll_count++; + } + for (fd in this.socketConnecting) { + poll_set[fd] = { events: POLLOUT, revents: 0 }; + poll_count++; + } + //print(new Date(), 'poll_set IN:', Duktape.enc('jx', poll_set)); + + /* + * Wait timeout for timer closest to expiry. Since the poll + * timeout is relative, get this as close to poll() as possible. + */ + + wait = this.getEarliestWait(); + if (wait === null) { + if (poll_count === 0) { + print('no active timers and no sockets to poll, exit'); + break; + } else { + wait = this.maximumWait; + } + } else { + wait = Math.min(this.maximumWait, Math.max(this.minimumWait, wait)); + } + + /* + * Do the actual poll. + */ + + try { + Poll.poll(poll_set, wait); + } catch (e) { + // Eat errors silently. When resizing curses window an EINTR + // happens now. + } + + /* + * Process all sockets so that nothing is left unhandled for the + * next round. + */ + + //print(new Date(), 'poll_set OUT:', Duktape.enc('jx', poll_set)); + for (fd in poll_set) { + t = poll_set[fd]; + rev = t.revents; + + if (rev & POLLIN) { + cb = this.socketReading[fd]; + if (cb) { + data = Socket.read(fd); // no size control now + //print('READ', Duktape.enc('jx', data)); + if (data.length === 0) { + //print('zero read for fd ' + fd + ', closing forcibly'); + rc = Socket.close(fd); // ignore result + delete this.socketListening[fd]; + delete this.socketReading[fd]; + } else { + cb(fd, data); + } + } else { + cb = this.socketListening[fd]; + if (cb) { + acc_res = Socket.accept(fd); + //print('ACCEPT:', Duktape.enc('jx', acc_res)); + cb(acc_res.fd, acc_res.addr, acc_res.port); + } else { + //print('UNKNOWN'); + } + } + } + + if (rev & POLLOUT) { + cb = this.socketConnecting[fd]; + if (cb) { + delete this.socketConnecting[fd]; + cb(fd); + } else { + //print('UNKNOWN POLLOUT'); + } + } + + if ((rev & ~(POLLIN | POLLOUT)) !== 0) { + //print('revents ' + t.revents + ' for fd ' + fd + ', closing forcibly'); + rc = Socket.close(fd); // ignore result + delete this.socketListening[fd]; + delete this.socketReading[fd]; + } + } + } +} + +EventLoop.requestExit = function() { + this.exitRequested = true; +} + +EventLoop.server = function(address, port, cb_accepted) { + var fd = Socket.createServerSocket(address, port); + this.socketListening[fd] = cb_accepted; +} + +EventLoop.connect = function(address, port, cb_connected) { + var fd = Socket.connect(address, port); + this.socketConnecting[fd] = cb_connected; +} + +EventLoop.close = function(fd) { + delete this.socketReading[fd]; + delete this.socketListening[fd]; +} + +EventLoop.setReader = function(fd, cb_read) { + this.socketReading[fd] = cb_read; +} + +EventLoop.write = function(fd, data) { + // This simple example doesn't have support for write blocking / draining + var rc = Socket.write(fd, Duktape.Buffer(data)); +} + +/* + * Timer API + * + * These interface with the singleton EventLoop. + */ + +function setTimeout(func, delay) { + var cb_func; + var bind_args; + var timer_id; + var evloop = EventLoop; + + if (typeof delay !== 'number') { + throw new TypeError('delay is not a number'); + } + delay = Math.max(evloop.minimumDelay, delay); + + if (typeof func === 'string') { + // Legacy case: callback is a string. + cb_func = eval.bind(this, func); + } else if (typeof func !== 'function') { + throw new TypeError('callback is not a function/string'); + } else if (arguments.length > 2) { + // Special case: callback arguments are provided. + bind_args = Array.prototype.slice.call(arguments, 2); // [ arg1, arg2, ... ] + bind_args.unshift(this); // [ global(this), arg1, arg2, ... ] + cb_func = func.bind.apply(func, bind_args); + } else { + // Normal case: callback given as a function without arguments. + cb_func = func; + } + + timer_id = evloop.nextTimerId++; + + evloop.insertTimer({ + id: timer_id, + oneshot: true, + cb: cb_func, + delay: delay, + target: Date.now() + delay + }); + + return timer_id; +} + +function clearTimeout(timer_id) { + var evloop = EventLoop; + + if (typeof timer_id !== 'number') { + throw new TypeError('timer ID is not a number'); + } + evloop.removeTimerById(timer_id); +} + +function setInterval(func, delay) { + var cb_func; + var bind_args; + var timer_id; + var evloop = EventLoop; + + if (typeof delay !== 'number') { + throw new TypeError('delay is not a number'); + } + delay = Math.max(evloop.minimumDelay, delay); + + if (typeof func === 'string') { + // Legacy case: callback is a string. + cb_func = eval.bind(this, func); + } else if (typeof func !== 'function') { + throw new TypeError('callback is not a function/string'); + } else if (arguments.length > 2) { + // Special case: callback arguments are provided. + bind_args = Array.prototype.slice.call(arguments, 2); // [ arg1, arg2, ... ] + bind_args.unshift(this); // [ global(this), arg1, arg2, ... ] + cb_func = func.bind.apply(func, bind_args); + } else { + // Normal case: callback given as a function without arguments. + cb_func = func; + } + + timer_id = evloop.nextTimerId++; + + evloop.insertTimer({ + id: timer_id, + oneshot: false, + cb: cb_func, + delay: delay, + target: Date.now() + delay + }); + + return timer_id; +} + +function clearInterval(timer_id) { + var evloop = EventLoop; + + if (typeof timer_id !== 'number') { + throw new TypeError('timer ID is not a number'); + } + evloop.removeTimerById(timer_id); +} + +/* custom call */ +function requestEventLoopExit() { + EventLoop.requestExit(); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/fileio.c b/lib/duktape-2.2.1/examples/eventloop/fileio.c new file mode 100644 index 0000000..bcf2b26 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/fileio.c @@ -0,0 +1,84 @@ +/* + * File I/O binding example. + */ + +#include +#include +#include + +#include "duktape.h" + +/* Push file as a buffer. */ +void fileio_push_file_buffer(duk_context *ctx, const char *filename) { + FILE *f = NULL; + long len; + void *buf; + size_t got; + + if (!filename) { + goto error; + } + + f = fopen(filename, "rb"); + if (!f) { + goto error; + } + + if (fseek(f, 0, SEEK_END) != 0) { + goto error; + } + + len = ftell(f); + + if (fseek(f, 0, SEEK_SET) != 0) { + goto error; + } + + buf = duk_push_fixed_buffer(ctx, (size_t) len); + + got = fread(buf, 1, len, f); + if (got != (size_t) len) { + duk_pop(ctx); + goto error; + } + + fclose(f); + return; + + error: + if (f) { + fclose(f); + } + duk_push_undefined(ctx); +} + +/* Push file as a string. */ +void fileio_push_file_string(duk_context *ctx, const char *filename) { + fileio_push_file_buffer(ctx, filename); + if (duk_is_buffer(ctx, -1)) { + duk_buffer_to_string(ctx, -1); + } +} + +static int fileio_readfile(duk_context *ctx) { + const char *filename = duk_to_string(ctx, 0); + fileio_push_file_buffer(ctx, filename); + if (!duk_is_buffer(ctx, -1)) { + return DUK_RET_ERROR; + } + return 1; +} + +static duk_function_list_entry fileio_funcs[] = { + { "readfile", fileio_readfile, 1 }, + { NULL, NULL, 0 } +}; + +void fileio_register(duk_context *ctx) { + /* Set global 'FileIo'. */ + duk_push_global_object(ctx); + duk_push_object(ctx); + duk_put_function_list(ctx, -1, fileio_funcs); + duk_put_prop_string(ctx, -2, "FileIo"); + duk_pop(ctx); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/main.c b/lib/duktape-2.2.1/examples/eventloop/main.c new file mode 100644 index 0000000..f9270a1 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/main.c @@ -0,0 +1,276 @@ +/* + * Main for evloop command line tool. + * + * Runs a given script from file or stdin inside an eventloop. The + * script can then access setTimeout() etc. + */ + +#include +#include +#include +#if !defined(NO_SIGNAL) +#include +#endif + +#include "duktape.h" + +extern void poll_register(duk_context *ctx); +extern void ncurses_register(duk_context *ctx); +extern void socket_register(duk_context *ctx); +extern void fileio_register(duk_context *ctx); +extern void fileio_push_file_buffer(duk_context *ctx, const char *filename); +extern void fileio_push_file_string(duk_context *ctx, const char *filename); +extern void eventloop_register(duk_context *ctx); +extern duk_ret_t eventloop_run(duk_context *ctx, void *udata); + +static int c_evloop = 0; + +#if !defined(NO_SIGNAL) +static void my_sighandler(int x) { + fprintf(stderr, "Got signal %d\n", x); + fflush(stderr); +} +static void set_sigint_handler(void) { + (void) signal(SIGINT, my_sighandler); +} +#endif /* NO_SIGNAL */ + +/* Print error to stderr and pop error. */ +static void print_error(duk_context *ctx, FILE *f) { + if (duk_is_object(ctx, -1) && duk_has_prop_string(ctx, -1, "stack")) { + /* XXX: print error objects specially */ + /* XXX: pcall the string coercion */ + duk_get_prop_string(ctx, -1, "stack"); + if (duk_is_string(ctx, -1)) { + fprintf(f, "%s\n", duk_get_string(ctx, -1)); + fflush(f); + duk_pop_2(ctx); + return; + } else { + duk_pop(ctx); + } + } + duk_to_string(ctx, -1); + fprintf(f, "%s\n", duk_get_string(ctx, -1)); + fflush(f); + duk_pop(ctx); +} + +static duk_ret_t native_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 0; +} + +static void print_register(duk_context *ctx) { + duk_push_c_function(ctx, native_print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); +} + +duk_ret_t wrapped_compile_execute(duk_context *ctx, void *udata) { + int comp_flags = 0; + int rc; + + (void) udata; + + /* Compile input and place it into global _USERCODE */ + duk_compile(ctx, comp_flags); + duk_push_global_object(ctx); + duk_insert(ctx, -2); /* [ ... global func ] */ + duk_put_prop_string(ctx, -2, "_USERCODE"); + duk_pop(ctx); +#if 0 + printf("compiled usercode\n"); +#endif + + /* Start a zero timer which will call _USERCODE from within + * the event loop. + */ + fprintf(stderr, "set _USERCODE timer\n"); + fflush(stderr); + duk_eval_string(ctx, "setTimeout(function() { _USERCODE(); }, 0);"); + duk_pop(ctx); + + /* Finally, launch eventloop. This call only returns after the + * eventloop terminates. + */ + if (c_evloop) { + fprintf(stderr, "calling eventloop_run()\n"); + fflush(stderr); + rc = duk_safe_call(ctx, eventloop_run, NULL, 0 /*nargs*/, 1 /*nrets*/); + if (rc != 0) { + fprintf(stderr, "eventloop_run() failed: %s\n", duk_to_string(ctx, -1)); + fflush(stderr); + } + duk_pop(ctx); + } else { + fprintf(stderr, "calling EventLoop.run()\n"); + fflush(stderr); + duk_eval_string(ctx, "EventLoop.run();"); + duk_pop(ctx); + } + + return 0; +} + +int handle_fh(duk_context *ctx, FILE *f, const char *filename) { + char *buf = NULL; + int len; + int got; + int rc; + int retval = -1; + + if (fseek(f, 0, SEEK_END) < 0) { + goto error; + } + len = (int) ftell(f); + if (fseek(f, 0, SEEK_SET) < 0) { + goto error; + } + buf = (char *) malloc(len); + if (!buf) { + goto error; + } + + got = fread((void *) buf, (size_t) 1, (size_t) len, f); + + duk_push_lstring(ctx, buf, got); + duk_push_string(ctx, filename); + + free(buf); + buf = NULL; + + rc = duk_safe_call(ctx, wrapped_compile_execute, NULL, 2 /*nargs*/, 1 /*nret*/); + if (rc != DUK_EXEC_SUCCESS) { + print_error(ctx, stderr); + goto error; + } else { + duk_pop(ctx); + retval = 0; + } + /* fall thru */ + + error: + if (buf) { + free(buf); + } + return retval; +} + +int handle_file(duk_context *ctx, const char *filename) { + FILE *f = NULL; + int retval; + + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "failed to open source file: %s\n", filename); + fflush(stderr); + goto error; + } + + retval = handle_fh(ctx, f, filename); + + fclose(f); + return retval; + + error: + return -1; +} + +int handle_stdin(duk_context *ctx) { + int retval; + + retval = handle_fh(ctx, stdin, "stdin"); + + return retval; +} + +int main(int argc, char *argv[]) { + duk_context *ctx = NULL; + int retval = 0; + const char *filename = NULL; + int i; + +#if !defined(NO_SIGNAL) + set_sigint_handler(); + + /* This is useful at the global level; libraries should avoid SIGPIPE though */ + /*signal(SIGPIPE, SIG_IGN);*/ +#endif + + for (i = 1; i < argc; i++) { + char *arg = argv[i]; + if (!arg) { + goto usage; + } + if (strcmp(arg, "-c") == 0) { + c_evloop = 1; + } else if (strlen(arg) > 1 && arg[0] == '-') { + goto usage; + } else { + if (filename) { + goto usage; + } + filename = arg; + } + } + if (!filename) { + goto usage; + } + + ctx = duk_create_heap_default(); + + print_register(ctx); + poll_register(ctx); + ncurses_register(ctx); + socket_register(ctx); + fileio_register(ctx); + + if (c_evloop) { + fprintf(stderr, "Using C based eventloop (omit -c to use Ecmascript based eventloop)\n"); + fflush(stderr); + + eventloop_register(ctx); + fileio_push_file_string(ctx, "c_eventloop.js"); + duk_eval(ctx); + } else { + fprintf(stderr, "Using Ecmascript based eventloop (give -c to use C based eventloop)\n"); + fflush(stderr); + + fileio_push_file_string(ctx, "ecma_eventloop.js"); + duk_eval(ctx); + } + + fprintf(stderr, "Executing code from: '%s'\n", filename); + fflush(stderr); + + if (strcmp(filename, "-") == 0) { + if (handle_stdin(ctx) != 0) { + retval = 1; + goto cleanup; + } + } else { + if (handle_file(ctx, filename) != 0) { + retval = 1; + goto cleanup; + } + } + + cleanup: + if (ctx) { + duk_destroy_heap(ctx); + } + + return retval; + + usage: + fprintf(stderr, "Usage: evloop [-c] \n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Uses an Ecmascript based eventloop (ecma_eventloop.js) by default.\n"); + fprintf(stderr, "If -c option given, uses a C based eventloop (c_eventloop.{c,js}).\n"); + fprintf(stderr, "If is '-', the entire STDIN executed.\n"); + fflush(stderr); + exit(1); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/ncurses.c b/lib/duktape-2.2.1/examples/eventloop/ncurses.c new file mode 100644 index 0000000..7734fcc --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/ncurses.c @@ -0,0 +1,105 @@ +/* + * Ncurses bindings example. + * + * VALGRIND NOTE: when you use ncurses, there seems to be no way to get a + * clean valgrind run. Even if ncurses state is properly shut down, there + * will still be some residual leaks. + * + * Debian: install libncurses5-dev + */ + +#include +#include "duktape.h" + +static int ncurses_initscr(duk_context *ctx) { + WINDOW *win; + + win = initscr(); + duk_push_pointer(ctx, (void *) win); + return 1; +} + +static int ncurses_endwin(duk_context *ctx) { + int rc; + + rc = endwin(); + duk_push_int(ctx, rc); + return 1; +} + +static int ncurses_delscreen(duk_context *ctx) { + /* XXX: no screen management now */ + (void) ctx; + return 0; +} + +static int ncurses_getmaxyx(duk_context *ctx) { + int row, col; + + getmaxyx(stdscr, row, col); + + duk_push_array(ctx); + duk_push_int(ctx, row); + duk_put_prop_index(ctx, -2, 0); + duk_push_int(ctx, col); + duk_put_prop_index(ctx, -2, 1); + return 1; +} + +static int ncurses_printw(duk_context *ctx) { + int rc; + const char *str; + + str = duk_to_string(ctx, 0); + rc = printw("%s", str); + duk_push_int(ctx, rc); + return 1; +} + +static int ncurses_mvprintw(duk_context *ctx) { + int y = duk_to_int(ctx, 0); + int x = duk_to_int(ctx, 1); + const char *str = duk_to_string(ctx, 2); + int rc; + + rc = mvprintw(y, x, "%s", str); + duk_push_int(ctx, rc); + return 1; +} + +static int ncurses_refresh(duk_context *ctx) { + int rc; + + rc = refresh(); + duk_push_int(ctx, rc); + return 1; +} + +static int ncurses_getch(duk_context *ctx) { + int rc; + + rc = getch(); + duk_push_int(ctx, rc); + return 1; +} + +static duk_function_list_entry ncurses_funcs[] = { + { "initscr", ncurses_initscr, 0 }, + { "endwin", ncurses_endwin, 0 }, + { "delscreen", ncurses_delscreen, 0 }, + { "getmaxyx", ncurses_getmaxyx, 0 }, + { "printw", ncurses_printw, 1 }, + { "mvprintw", ncurses_mvprintw, 3 }, + { "refresh", ncurses_refresh, 0 }, + { "getch", ncurses_getch, 0 }, + { NULL, NULL, 0 } +}; + +void ncurses_register(duk_context *ctx) { + /* Set global 'Ncurses'. */ + duk_push_global_object(ctx); + duk_push_object(ctx); + duk_put_function_list(ctx, -1, ncurses_funcs); + duk_put_prop_string(ctx, -2, "Ncurses"); + duk_pop(ctx); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/poll.c b/lib/duktape-2.2.1/examples/eventloop/poll.c new file mode 100644 index 0000000..a32b883 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/poll.c @@ -0,0 +1,111 @@ +/* + * C wrapper for poll(). + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "duktape.h" + +static int poll_poll(duk_context *ctx) { + int timeout = duk_to_int(ctx, 1); + int i, n, nchanged; + int fd, rc; + struct pollfd fds[20]; + struct timespec ts; + + memset(fds, 0, sizeof(fds)); + + n = 0; + duk_enum(ctx, 0, 0 /*enum_flags*/); + while (duk_next(ctx, -1, 0)) { + if ((size_t) n >= sizeof(fds) / sizeof(struct pollfd)) { + return -1; + } + + /* [... enum key] */ + duk_dup_top(ctx); /* -> [... enum key key] */ + duk_get_prop(ctx, 0); /* -> [... enum key val] */ + fd = duk_to_int(ctx, -2); + + duk_push_string(ctx, "events"); + duk_get_prop(ctx, -2); /* -> [... enum key val events] */ + + fds[n].fd = fd; + fds[n].events = duk_to_int(ctx, -1); + fds[n].revents = 0; + + duk_pop_n(ctx, 3); /* -> [... enum] */ + + n++; + } + /* leave enum on stack */ + + memset(&ts, 0, sizeof(ts)); + ts.tv_nsec = (timeout % 1000) * 1000000; + ts.tv_sec = timeout / 1000; + + /*rc = ppoll(fds, n, &ts, NULL);*/ + rc = poll(fds, n, timeout); + if (rc < 0) { + (void) duk_error(ctx, DUK_ERR_ERROR, "%s (errno=%d)", strerror(errno), errno); + } + + duk_push_array(ctx); + nchanged = 0; + for (i = 0; i < n; i++) { + /* update revents */ + + if (fds[i].revents) { + duk_push_int(ctx, fds[i].fd); /* -> [... retarr fd] */ + duk_put_prop_index(ctx, -2, nchanged); + nchanged++; + } + + duk_push_int(ctx, fds[i].fd); /* -> [... retarr key] */ + duk_get_prop(ctx, 0); /* -> [... retarr val] */ + duk_push_string(ctx, "revents"); + duk_push_int(ctx, fds[i].revents); /* -> [... retarr val "revents" fds[i].revents] */ + duk_put_prop(ctx, -3); /* -> [... retarr val] */ + duk_pop(ctx); + } + + /* [retarr] */ + + return 1; +} + +static duk_function_list_entry poll_funcs[] = { + { "poll", poll_poll, 2 }, + { NULL, NULL, 0 } +}; + +static duk_number_list_entry poll_consts[] = { + { "POLLIN", (double) POLLIN }, + { "POLLPRI", (double) POLLPRI }, + { "POLLOUT", (double) POLLOUT }, +#if 0 + /* Linux 2.6.17 and upwards, requires _GNU_SOURCE etc, not added + * now because we don't use it. + */ + { "POLLRDHUP", (double) POLLRDHUP }, +#endif + { "POLLERR", (double) POLLERR }, + { "POLLHUP", (double) POLLHUP }, + { "POLLNVAL", (double) POLLNVAL }, + { NULL, 0.0 } +}; + +void poll_register(duk_context *ctx) { + /* Set global 'Poll' with functions and constants. */ + duk_push_global_object(ctx); + duk_push_object(ctx); + duk_put_function_list(ctx, -1, poll_funcs); + duk_put_number_list(ctx, -1, poll_consts); + duk_put_prop_string(ctx, -2, "Poll"); + duk_pop(ctx); +} diff --git a/lib/duktape-2.2.1/examples/eventloop/server-socket-test.js b/lib/duktape-2.2.1/examples/eventloop/server-socket-test.js new file mode 100644 index 0000000..68510af --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/server-socket-test.js @@ -0,0 +1,34 @@ + +var HOST = 'localhost' +var PORT = 12345; +var EXIT_TIMEOUT = 300e3; + +print('automatic exit after ' + (EXIT_TIMEOUT / 1e3) + ' seconds'); +setTimeout(function () { + print('exit timer'); + EventLoop.requestExit(); +}, EXIT_TIMEOUT); + +print('listen on ' + HOST + ':' + PORT); +EventLoop.server(HOST, PORT, function (fd, addr, port) { + print('new connection on fd ' + fd + ' from ' + addr + ':' + port); + EventLoop.setReader(fd, function (fd, data) { + var b, i, n, x; + + // Handle socket data carefully: if you convert it to a string, + // it may not be valid UTF-8 etc. Here we operate on the data + // directly in the buffer. + + b = data.valueOf(); // ensure we get a plain buffer + n = b.length; + for (i = 0; i < n; i++) { + x = b[i]; + if (x >= 0x61 && x <= 0x7a) { + b[i] = x - 0x20; // uppercase + } + } + + print('read data on fd ' + fd + ', length ' + data.length); + EventLoop.write(fd, data); + }); +}); diff --git a/lib/duktape-2.2.1/examples/eventloop/socket.c b/lib/duktape-2.2.1/examples/eventloop/socket.c new file mode 100644 index 0000000..055e380 --- /dev/null +++ b/lib/duktape-2.2.1/examples/eventloop/socket.c @@ -0,0 +1,286 @@ +/* + * TCP sockets binding example. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "duktape.h" + +#define ERROR_FROM_ERRNO(ctx) do { \ + (void) duk_error(ctx, DUK_ERR_ERROR, "%s (errno=%d)", strerror(errno), errno); \ + } while (0) + +static void set_nonblocking(duk_context *ctx, int fd) { + int rc; + int flags; + + rc = fcntl(fd, F_GETFL); + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } + flags = rc; + + flags |= O_NONBLOCK; + + rc = fcntl(fd, F_SETFL, flags); + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } +} + +static void set_reuseaddr(duk_context *ctx, int fd) { + int val; + int rc; + + val = 1; + rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &val, sizeof(val)); + if (rc != 0) { + ERROR_FROM_ERRNO(ctx); + } +} + +#if defined(__APPLE__) +static void set_nosigpipe(duk_context *ctx, int fd) { + int val; + int rc; + + val = 1; + rc = setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (const void *) &val, sizeof(val)); + if (rc != 0) { + ERROR_FROM_ERRNO(ctx); + } +} +#endif + +static int socket_create_server_socket(duk_context *ctx) { + const char *addr = duk_to_string(ctx, 0); + int port = duk_to_int(ctx, 1); + int sock; + struct sockaddr_in sockaddr; + struct hostent *ent; + struct in_addr **addr_list; + struct in_addr *addr_inet; + int i; + int rc; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + ERROR_FROM_ERRNO(ctx); + } + + set_nonblocking(ctx, sock); + set_reuseaddr(ctx, sock); +#if defined(__APPLE__) + set_nosigpipe(ctx, sock); +#endif + + ent = gethostbyname(addr); + if (!ent) { + ERROR_FROM_ERRNO(ctx); + } + + addr_list = (struct in_addr **) ent->h_addr_list; + addr_inet = NULL; + for (i = 0; addr_list[i]; i++) { + addr_inet = addr_list[i]; + break; + } + if (!addr_inet) { + (void) duk_error(ctx, DUK_ERR_ERROR, "cannot resolve %s", addr); + } + + memset(&sockaddr, 0, sizeof(sockaddr)); + sockaddr.sin_family = AF_INET; + sockaddr.sin_port = htons(port); + sockaddr.sin_addr = *addr_inet; + + rc = bind(sock, (const struct sockaddr *) &sockaddr, sizeof(sockaddr)); + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } + + rc = listen(sock, 10 /*backlog*/); + if (rc < 0) { + (void) close(sock); + ERROR_FROM_ERRNO(ctx); + } + + duk_push_int(ctx, sock); + return 1; +} + +static int socket_close(duk_context *ctx) { + int sock = duk_to_int(ctx, 0); + int rc; + + rc = close(sock); + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } + return 0; +} + +static int socket_accept(duk_context *ctx) { + int sock = duk_to_int(ctx, 0); + int rc; + struct sockaddr_in addr; + socklen_t addrlen; + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addrlen = sizeof(addr); + + rc = accept(sock, (struct sockaddr *) &addr, &addrlen); + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } + + set_nonblocking(ctx, sock); +#if defined(__APPLE__) + set_nosigpipe(ctx, sock); +#endif + + if (addrlen == sizeof(addr)) { + uint32_t tmp = ntohl(addr.sin_addr.s_addr); + + duk_push_object(ctx); + + duk_push_string(ctx, "fd"); + duk_push_int(ctx, rc); + duk_put_prop(ctx, -3); + duk_push_string(ctx, "addr"); + duk_push_sprintf(ctx, "%d.%d.%d.%d", ((tmp >> 24) & 0xff), ((tmp >> 16) & 0xff), ((tmp >> 8) & 0xff), (tmp & 0xff)); + duk_put_prop(ctx, -3); + duk_push_string(ctx, "port"); + duk_push_int(ctx, ntohs(addr.sin_port)); + duk_put_prop(ctx, -3); + + return 1; + } + + return 0; +} + +static int socket_connect(duk_context *ctx) { + const char *addr = duk_to_string(ctx, 0); + int port = duk_to_int(ctx, 1); + int sock; + struct sockaddr_in sockaddr; + struct hostent *ent; + struct in_addr **addr_list; + struct in_addr *addr_inet; + int i; + int rc; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + ERROR_FROM_ERRNO(ctx); + } + + set_nonblocking(ctx, sock); +#if defined(__APPLE__) + set_nosigpipe(ctx, sock); +#endif + + ent = gethostbyname(addr); + if (!ent) { + ERROR_FROM_ERRNO(ctx); + } + + addr_list = (struct in_addr **) ent->h_addr_list; + addr_inet = NULL; + for (i = 0; addr_list[i]; i++) { + addr_inet = addr_list[i]; + break; + } + if (!addr_inet) { + (void) duk_error(ctx, DUK_ERR_ERROR, "cannot resolve %s", addr); + } + + memset(&sockaddr, 0, sizeof(sockaddr)); + sockaddr.sin_family = AF_INET; + sockaddr.sin_port = htons(port); + sockaddr.sin_addr = *addr_inet; + + rc = connect(sock, (const struct sockaddr *) &sockaddr, (socklen_t) sizeof(sockaddr)); + if (rc < 0) { + if (errno == EINPROGRESS) { +#if 0 + fprintf(stderr, "connect() returned EINPROGRESS as expected, need to poll writability\n"); + fflush(stderr); +#endif + } else { + ERROR_FROM_ERRNO(ctx); + } + } + + duk_push_int(ctx, sock); + return 1; +} + +static int socket_read(duk_context *ctx) { + int sock = duk_to_int(ctx, 0); + char readbuf[1024]; + int rc; + void *data; + + rc = recvfrom(sock, (void *) readbuf, sizeof(readbuf), 0, NULL, NULL); + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } + + data = duk_push_fixed_buffer(ctx, rc); + memcpy(data, readbuf, rc); + return 1; +} + +static int socket_write(duk_context *ctx) { + int sock = duk_to_int(ctx, 0); + const char *data; + size_t len; + ssize_t rc; + + data = duk_to_buffer(ctx, 1, &len); + + /* MSG_NOSIGNAL: avoid SIGPIPE */ +#if defined(__APPLE__) + rc = sendto(sock, (void *) data, len, 0, NULL, 0); +#else + rc = sendto(sock, (void *) data, len, MSG_NOSIGNAL, NULL, 0); +#endif + if (rc < 0) { + ERROR_FROM_ERRNO(ctx); + } + + duk_push_int(ctx, rc); + return 1; +} + +static duk_function_list_entry socket_funcs[] = { + { "createServerSocket", socket_create_server_socket, 2 }, + { "close", socket_close, 1 }, + { "accept", socket_accept, 1 }, + { "connect", socket_connect, 2 }, + { "read", socket_read, 1 }, + { "write", socket_write, 2 }, + { NULL, NULL, 0 } +}; + +void socket_register(duk_context *ctx) { + /* Set global 'Socket'. */ + duk_push_global_object(ctx); + duk_push_object(ctx); + duk_put_function_list(ctx, -1, socket_funcs); + duk_put_prop_string(ctx, -2, "Socket"); + duk_pop(ctx); +} diff --git a/lib/duktape-2.2.1/examples/guide/README.rst b/lib/duktape-2.2.1/examples/guide/README.rst new file mode 100644 index 0000000..1933094 --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/README.rst @@ -0,0 +1,5 @@ +=========================== +Duktape guide example files +=========================== + +Examples used in the Duktape guide. diff --git a/lib/duktape-2.2.1/examples/guide/fib.js b/lib/duktape-2.2.1/examples/guide/fib.js new file mode 100644 index 0000000..2b2982f --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/fib.js @@ -0,0 +1,16 @@ +// fib.js +function fib(n) { + if (n == 0) { return 0; } + if (n == 1) { return 1; } + return fib(n-1) + fib(n-2); +} + +function test() { + var res = []; + for (i = 0; i < 20; i++) { + res.push(fib(i)); + } + print(res.join(' ')); +} + +test(); diff --git a/lib/duktape-2.2.1/examples/guide/prime.js b/lib/duktape-2.2.1/examples/guide/prime.js new file mode 100644 index 0000000..8959754 --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/prime.js @@ -0,0 +1,32 @@ +// prime.js + +// Pure Ecmascript version of low level helper +function primeCheckEcmascript(val, limit) { + for (var i = 2; i <= limit; i++) { + if ((val % i) == 0) { return false; } + } + return true; +} + +// Select available helper at load time +var primeCheckHelper = (this.primeCheckNative || primeCheckEcmascript); + +// Check 'val' for primality +function primeCheck(val) { + if (val == 1 || val == 2) { return true; } + var limit = Math.ceil(Math.sqrt(val)); + while (limit * limit < val) { limit += 1; } + return primeCheckHelper(val, limit); +} + +// Find primes below one million ending in '9999'. +function primeTest() { + var res = []; + + print('Have native helper: ' + (primeCheckHelper !== primeCheckEcmascript)); + for (var i = 1; i < 1000000; i++) { + if (primeCheck(i) && (i % 10000) == 9999) { res.push(i); } + } + print(res.join(' ')); +} + diff --git a/lib/duktape-2.2.1/examples/guide/primecheck.c b/lib/duktape-2.2.1/examples/guide/primecheck.c new file mode 100644 index 0000000..addcc56 --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/primecheck.c @@ -0,0 +1,81 @@ +/* primecheck.c */ +#include +#include +#include +#include "duktape.h" + +/* For brevity assumes a maximum file length of 16kB. */ +static void push_file_as_string(duk_context *ctx, const char *filename) { + FILE *f; + size_t len; + char buf[16384]; + + f = fopen(filename, "rb"); + if (f) { + len = fread((void *) buf, 1, sizeof(buf), f); + fclose(f); + duk_push_lstring(ctx, (const char *) buf, (duk_size_t) len); + } else { + duk_push_undefined(ctx); + } +} + +static duk_ret_t native_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_to_string(ctx, -1)); + return 0; +} + +static duk_ret_t native_prime_check(duk_context *ctx) { + int val = duk_require_int(ctx, 0); + int lim = duk_require_int(ctx, 1); + int i; + + for (i = 2; i <= lim; i++) { + if (val % i == 0) { + duk_push_false(ctx); + return 1; + } + } + + duk_push_true(ctx); + return 1; +} + +int main(int argc, const char *argv[]) { + duk_context *ctx = NULL; + + (void) argc; (void) argv; + + ctx = duk_create_heap_default(); + if (!ctx) { + printf("Failed to create a Duktape heap.\n"); + exit(1); + } + + duk_push_global_object(ctx); + duk_push_c_function(ctx, native_print, DUK_VARARGS); + duk_put_prop_string(ctx, -2, "print"); + duk_push_c_function(ctx, native_prime_check, 2 /*nargs*/); + duk_put_prop_string(ctx, -2, "primeCheckNative"); + + push_file_as_string(ctx, "prime.js"); + if (duk_peval(ctx) != 0) { + printf("Error running: %s\n", duk_safe_to_string(ctx, -1)); + goto finished; + } + duk_pop(ctx); /* ignore result */ + + duk_get_prop_string(ctx, -1, "primeTest"); + if (duk_pcall(ctx, 0) != 0) { + printf("Error: %s\n", duk_safe_to_string(ctx, -1)); + } + duk_pop(ctx); /* ignore result */ + + finished: + duk_destroy_heap(ctx); + + exit(0); +} diff --git a/lib/duktape-2.2.1/examples/guide/process.js b/lib/duktape-2.2.1/examples/guide/process.js new file mode 100644 index 0000000..62b5011 --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/process.js @@ -0,0 +1,12 @@ +// process.js +function processLine(line) { + return line.trim() + .replace(/[<>&"'\u0000-\u001F\u007E-\uFFFF]/g, function(x) { + // escape HTML characters + return '&#' + x.charCodeAt(0) + ';' + }) + .replace(/\*(.*?)\*/g, function(x, m) { + // automatically bold text between stars + return '' + m + ''; + }); +} diff --git a/lib/duktape-2.2.1/examples/guide/processlines.c b/lib/duktape-2.2.1/examples/guide/processlines.c new file mode 100644 index 0000000..244e651 --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/processlines.c @@ -0,0 +1,78 @@ +/* processlines.c */ +#include +#include +#include +#include "duktape.h" + +/* For brevity assumes a maximum file length of 16kB. */ +static void push_file_as_string(duk_context *ctx, const char *filename) { + FILE *f; + size_t len; + char buf[16384]; + + f = fopen(filename, "rb"); + if (f) { + len = fread((void *) buf, 1, sizeof(buf), f); + fclose(f); + duk_push_lstring(ctx, (const char *) buf, (duk_size_t) len); + } else { + duk_push_undefined(ctx); + } +} + +int main(int argc, const char *argv[]) { + duk_context *ctx = NULL; + char line[4096]; + size_t idx; + int ch; + + (void) argc; (void) argv; + + ctx = duk_create_heap_default(); + if (!ctx) { + printf("Failed to create a Duktape heap.\n"); + exit(1); + } + + push_file_as_string(ctx, "process.js"); + if (duk_peval(ctx) != 0) { + printf("Error: %s\n", duk_safe_to_string(ctx, -1)); + goto finished; + } + duk_pop(ctx); /* ignore result */ + + memset(line, 0, sizeof(line)); + idx = 0; + for (;;) { + if (idx >= sizeof(line)) { + printf("Line too long\n"); + exit(1); + } + + ch = fgetc(stdin); + if (ch == 0x0a) { + line[idx++] = '\0'; + + duk_push_global_object(ctx); + duk_get_prop_string(ctx, -1 /*index*/, "processLine"); + duk_push_string(ctx, line); + if (duk_pcall(ctx, 1 /*nargs*/) != 0) { + printf("Error: %s\n", duk_safe_to_string(ctx, -1)); + } else { + printf("%s\n", duk_safe_to_string(ctx, -1)); + } + duk_pop(ctx); /* pop result/error */ + + idx = 0; + } else if (ch == EOF) { + break; + } else { + line[idx++] = (char) ch; + } + } + + finished: + duk_destroy_heap(ctx); + + exit(0); +} diff --git a/lib/duktape-2.2.1/examples/guide/uppercase.c b/lib/duktape-2.2.1/examples/guide/uppercase.c new file mode 100644 index 0000000..03d0869 --- /dev/null +++ b/lib/duktape-2.2.1/examples/guide/uppercase.c @@ -0,0 +1,42 @@ +/* uppercase.c */ +#include +#include +#include "duktape.h" + +static int dummy_upper_case(duk_context *ctx) { + size_t sz; + const char *val = duk_require_lstring(ctx, 0, &sz); + size_t i; + + /* We're going to need 'sz' additional entries on the stack. */ + duk_require_stack(ctx, sz); + + for (i = 0; i < sz; i++) { + char ch = val[i]; + if (ch >= 'a' && ch <= 'z') { + ch = ch - 'a' + 'A'; + } + duk_push_lstring(ctx, (const char *) &ch, 1); + } + + duk_concat(ctx, sz); + return 1; +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + + if (argc < 2) { exit(1); } + + ctx = duk_create_heap_default(); + if (!ctx) { exit(1); } + + duk_push_c_function(ctx, dummy_upper_case, 1); + duk_push_string(ctx, argv[1]); + duk_call(ctx, 1); + printf("%s -> %s\n", argv[1], duk_to_string(ctx, -1)); + duk_pop(ctx); + + duk_destroy_heap(ctx); + return 0; +} diff --git a/lib/duktape-2.2.1/examples/hello/README.rst b/lib/duktape-2.2.1/examples/hello/README.rst new file mode 100644 index 0000000..7afef53 --- /dev/null +++ b/lib/duktape-2.2.1/examples/hello/README.rst @@ -0,0 +1,5 @@ +=================== +Hello world example +=================== + +Very simple example, most useful for compilation tests. diff --git a/lib/duktape-2.2.1/examples/hello/hello.c b/lib/duktape-2.2.1/examples/hello/hello.c new file mode 100644 index 0000000..1c5faff --- /dev/null +++ b/lib/duktape-2.2.1/examples/hello/hello.c @@ -0,0 +1,46 @@ +/* + * Very simple example program + */ + +#include "duktape.h" + +static duk_ret_t native_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 0; +} + +static duk_ret_t native_adder(duk_context *ctx) { + int i; + int n = duk_get_top(ctx); /* #args */ + double res = 0.0; + + for (i = 0; i < n; i++) { + res += duk_to_number(ctx, i); + } + + duk_push_number(ctx, res); + return 1; /* one return value */ +} + +int main(int argc, char *argv[]) { + duk_context *ctx = duk_create_heap_default(); + + (void) argc; (void) argv; /* suppress warning */ + + duk_push_c_function(ctx, native_print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + duk_push_c_function(ctx, native_adder, DUK_VARARGS); + duk_put_global_string(ctx, "adder"); + + duk_eval_string(ctx, "print('Hello world!');"); + + duk_eval_string(ctx, "print('2+3=' + adder(2, 3));"); + duk_pop(ctx); /* pop eval result */ + + duk_destroy_heap(ctx); + + return 0; +} diff --git a/lib/duktape-2.2.1/examples/jxpretty/README.rst b/lib/duktape-2.2.1/examples/jxpretty/README.rst new file mode 100644 index 0000000..5ab43a8 --- /dev/null +++ b/lib/duktape-2.2.1/examples/jxpretty/README.rst @@ -0,0 +1,5 @@ +================ +Jxpretty example +================ + +Simple command line utility to pretty print JSON in the JX format. diff --git a/lib/duktape-2.2.1/examples/jxpretty/jxpretty.c b/lib/duktape-2.2.1/examples/jxpretty/jxpretty.c new file mode 100644 index 0000000..0a5ddba --- /dev/null +++ b/lib/duktape-2.2.1/examples/jxpretty/jxpretty.c @@ -0,0 +1,76 @@ +/* + * Pretty print JSON from stdin into indented JX. + */ + +#include +#include +#include "duktape.h" + +static duk_ret_t duk__print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 0; +} + +static duk_ret_t do_jxpretty(duk_context *ctx, void *udata) { + FILE *f = stdin; + char buf[4096]; + size_t ret; + + (void) udata; + + for (;;) { + if (ferror(f)) { + duk_error(ctx, DUK_ERR_ERROR, "ferror() on stdin"); + } + if (feof(f)) { + break; + } + + ret = fread(buf, 1, sizeof(buf), f); +#if 0 + fprintf(stderr, "Read: %ld\n", (long) ret); + fflush(stderr); +#endif + if (ret == 0) { + break; + } + + duk_require_stack(ctx, 1); + duk_push_lstring(ctx, (const char *) buf, ret); + } + + duk_concat(ctx, duk_get_top(ctx)); + + duk_eval_string(ctx, "(function (v) { print(Duktape.enc('jx', JSON.parse(v), null, 4)); })"); + duk_insert(ctx, -2); + duk_call(ctx, 1); + + return 0; +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + duk_int_t rc; + + /* suppress warnings */ + (void) argc; + (void) argv; + + ctx = duk_create_heap_default(); + + duk_push_c_function(ctx, duk__print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + rc = duk_safe_call(ctx, do_jxpretty, NULL, 0 /*nargs*/, 1 /*nrets*/); + if (rc) { + fprintf(stderr, "ERROR: %s\n", duk_safe_to_string(ctx, -1)); + fflush(stderr); + } + + duk_destroy_heap(ctx); + + return 0; +} diff --git a/lib/duktape-2.2.1/examples/sandbox/README.rst b/lib/duktape-2.2.1/examples/sandbox/README.rst new file mode 100644 index 0000000..24df0a2 --- /dev/null +++ b/lib/duktape-2.2.1/examples/sandbox/README.rst @@ -0,0 +1,5 @@ +=============== +Sandbox example +=============== + +Very simple, minimal sandboxing example. diff --git a/lib/duktape-2.2.1/examples/sandbox/sandbox.c b/lib/duktape-2.2.1/examples/sandbox/sandbox.c new file mode 100644 index 0000000..c8ad483 --- /dev/null +++ b/lib/duktape-2.2.1/examples/sandbox/sandbox.c @@ -0,0 +1,266 @@ +/* + * Sandboxing example + * + * Uses custom memory allocation functions which keep track of total amount + * of memory allocated, imposing a maximum total allocation size. + */ + +#include +#include +#include "duktape.h" + +/* + * Memory allocator which backs to standard library memory functions but + * keeps a small header to track current allocation size. + * + * Many other sandbox allocation models are useful, e.g. preallocated pools. + */ + +typedef struct { + /* The double value in the union is there to ensure alignment is + * good for IEEE doubles too. In many 32-bit environments 4 bytes + * would be sufficiently aligned and the double value is unnecessary. + */ + union { + size_t sz; + double d; + } u; +} alloc_hdr; + +static size_t total_allocated = 0; +static size_t max_allocated = 256 * 1024; /* 256kB sandbox */ + +static void sandbox_dump_memstate(void) { +#if 0 + fprintf(stderr, "Total allocated: %ld\n", (long) total_allocated); + fflush(stderr); +#endif +} + +static void *sandbox_alloc(void *udata, duk_size_t size) { + alloc_hdr *hdr; + + (void) udata; /* Suppress warning. */ + + if (size == 0) { + return NULL; + } + + if (total_allocated + size > max_allocated) { + fprintf(stderr, "Sandbox maximum allocation size reached, %ld requested in sandbox_alloc\n", + (long) size); + fflush(stderr); + return NULL; + } + + hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr)); + if (!hdr) { + return NULL; + } + hdr->u.sz = size; + total_allocated += size; + sandbox_dump_memstate(); + return (void *) (hdr + 1); +} + +static void *sandbox_realloc(void *udata, void *ptr, duk_size_t size) { + alloc_hdr *hdr; + size_t old_size; + void *t; + + (void) udata; /* Suppress warning. */ + + /* Handle the ptr-NULL vs. size-zero cases explicitly to minimize + * platform assumptions. You can get away with much less in specific + * well-behaving environments. + */ + + if (ptr) { + hdr = (alloc_hdr *) (((char *) ptr) - sizeof(alloc_hdr)); + old_size = hdr->u.sz; + + if (size == 0) { + total_allocated -= old_size; + free((void *) hdr); + sandbox_dump_memstate(); + return NULL; + } else { + if (total_allocated - old_size + size > max_allocated) { + fprintf(stderr, "Sandbox maximum allocation size reached, %ld requested in sandbox_realloc\n", + (long) size); + fflush(stderr); + return NULL; + } + + t = realloc((void *) hdr, size + sizeof(alloc_hdr)); + if (!t) { + return NULL; + } + hdr = (alloc_hdr *) t; + total_allocated -= old_size; + total_allocated += size; + hdr->u.sz = size; + sandbox_dump_memstate(); + return (void *) (hdr + 1); + } + } else { + if (size == 0) { + return NULL; + } else { + if (total_allocated + size > max_allocated) { + fprintf(stderr, "Sandbox maximum allocation size reached, %ld requested in sandbox_realloc\n", + (long) size); + fflush(stderr); + return NULL; + } + + hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr)); + if (!hdr) { + return NULL; + } + hdr->u.sz = size; + total_allocated += size; + sandbox_dump_memstate(); + return (void *) (hdr + 1); + } + } +} + +static void sandbox_free(void *udata, void *ptr) { + alloc_hdr *hdr; + + (void) udata; /* Suppress warning. */ + + if (!ptr) { + return; + } + hdr = (alloc_hdr *) (((char *) ptr) - sizeof(alloc_hdr)); + total_allocated -= hdr->u.sz; + free((void *) hdr); + sandbox_dump_memstate(); +} + +/* + * Sandbox setup and test + */ + +static duk_ret_t duk__print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 0; +} + +static duk_ret_t do_sandbox_test(duk_context *ctx, void *udata) { + FILE *f; + char buf[4096]; + size_t ret; + const char *globobj; + + (void) udata; + + /* + * Setup sandbox + */ + + /* Minimal print() provider. */ + duk_push_c_function(ctx, duk__print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + globobj = + "({\n" + " print: print,\n" + " Math: {\n" + " max: Math.max\n" + " }\n" + "})\n"; +#if 1 + fprintf(stderr, "Sandbox global object:\n----------------\n%s----------------\n", globobj); + fflush(stderr); +#endif + duk_eval_string(ctx, globobj); + duk_set_global_object(ctx); + + /* + * Execute code from specified file + */ + + f = fopen(duk_require_string(ctx, -1), "rb"); + if (!f) { + duk_error(ctx, DUK_ERR_ERROR, "failed to open file"); + } + + for (;;) { + if (ferror(f)) { + fclose(f); + duk_error(ctx, DUK_ERR_ERROR, "ferror when reading file"); + } + if (feof(f)) { + break; + } + + ret = fread(buf, 1, sizeof(buf), f); + if (ret == 0) { + break; + } + + duk_push_lstring(ctx, (const char *) buf, ret); + } + + duk_concat(ctx, duk_get_top(ctx) - 1); /* -1 for filename */ + + /* -> [ ... filename source ] */ + + duk_insert(ctx, -2); + + /* -> [ ... source filename ] */ + + duk_compile(ctx, 0 /*flags*/); /* Compile as program */ + duk_call(ctx, 0 /*nargs*/); + + return 0; +} + +/* + * Main + */ + +static void sandbox_fatal(void *udata, const char *msg) { + (void) udata; /* Suppress warning. */ + fprintf(stderr, "FATAL: %s\n", (msg ? msg : "no message")); + fflush(stderr); + exit(1); /* must not return */ +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + duk_int_t rc; + + if (argc < 2) { + fprintf(stderr, "Usage: sandbox \n"); + fflush(stderr); + exit(1); + } + + ctx = duk_create_heap(sandbox_alloc, + sandbox_realloc, + sandbox_free, + NULL, + sandbox_fatal); + + duk_push_string(ctx, argv[1]); + rc = duk_safe_call(ctx, do_sandbox_test, NULL, 1 /*nargs*/, 1 /*nrets*/); + if (rc) { + fprintf(stderr, "ERROR: %s\n", duk_safe_to_string(ctx, -1)); + fflush(stderr); + } + + duk_destroy_heap(ctx); + + /* Should be zero. */ + fprintf(stderr, "Final allocation: %ld\n", (long) total_allocated); + fflush(stderr); + + return 1; +} diff --git a/lib/duktape-2.2.1/extras/README.rst b/lib/duktape-2.2.1/extras/README.rst new file mode 100644 index 0000000..1b70160 --- /dev/null +++ b/lib/duktape-2.2.1/extras/README.rst @@ -0,0 +1,13 @@ +============== +Duktape extras +============== + +Extra modules and utilities. Extras provide functionality that doesn't +comfortably fit into the main Duktape library, perhaps for footprint or +portability reasons, but are still useful for most users. + +Extras are maintained and will be bug fixed. However, they don't have the +same semantic versioning guarantees like the main Duktape library. Extras +may be dropped without warning as Duktape is versioned. For instance, if +an extra breaks due to Duktape changes and there is no time to fix it, the +missing extra won't block a release and will be dropped. diff --git a/lib/duktape-2.2.1/extras/alloc-pool/Makefile b/lib/duktape-2.2.1/extras/alloc-pool/Makefile new file mode 100644 index 0000000..2720897 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/Makefile @@ -0,0 +1,41 @@ +# For manual testing; say 'make' in extras/alloc-pool and run ./test. + +DEFS= +#DEFS+='-DDUK_ALLOC_POOL_DEBUG' + +.PHONY: test +test: + rm -rf ./prep + echo 'DUK_USE_FATAL_HANDLER:' > opts.yaml + echo ' verbatim: "#define DUK_USE_FATAL_HANDLER(udata,msg) my_fatal((msg))"' >> opts.yaml + python2 ../../tools/configure.py \ + --output-directory ./prep \ + --option-file ./opts.yaml \ + --fixup-line 'extern void my_fatal(const char *msg);' + gcc -std=c99 -Wall -Wextra -m32 -Os -otest \ + -I./prep ./prep/duktape.c \ + $(DEFS) \ + duk_alloc_pool.c test.c \ + -lm + ./test 'print("foo", "bar", 1, 2, 3)' + ./test 'alert("foo", "bar", 1, 2, 3)' + +.PHONY: ptrcomptest +ptrcomptest: + rm -rf ./prep + echo 'DUK_USE_FATAL_HANDLER:' > opts.yaml + echo ' verbatim: "#define DUK_USE_FATAL_HANDLER(udata,msg) my_fatal((msg))"' >> opts.yaml + python2 ../../tools/configure.py \ + --output-directory ./prep \ + --option-file ./opts.yaml \ + --fixup-line 'extern void my_fatal(const char *msg);' \ + --option-file ../../config/examples/low_memory.yaml \ + --option-file ptrcomp.yaml \ + --fixup-file ptrcomp_fixup.h + gcc -std=c99 -Wall -Wextra -m32 -Os -optrcomptest \ + -I. -I./prep ./prep/duktape.c \ + $(DEFS) \ + duk_alloc_pool.c test.c \ + -lm + ./ptrcomptest 'print("foo", "bar", 1, 2, 3)' + ./ptrcomptest 'alert("foo", "bar", 1, 2, 3)' diff --git a/lib/duktape-2.2.1/extras/alloc-pool/README.rst b/lib/duktape-2.2.1/extras/alloc-pool/README.rst new file mode 100644 index 0000000..9e579a9 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/README.rst @@ -0,0 +1,38 @@ +===================================== +Pool allocator for low memory targets +===================================== + +A simple pool allocator which satisfies allocations from preallocated pools +containing blocks of a certain size. The caller provides a continuous memory +region and a pool configuration when initializing the allocator. + +The pool configuration specifies the block sizes used, and parameters to +control how many entries are allocated for each block size. The parameters +are specified with respect to an arbitrary floating point scaling parameter +``t`` as follows:: + + bytes = A*t + B + count = floor(bytes / block_size) + = floor((A*t + B) / block_size) + + A: constant which indicates how quickly more bytes are assigned for this + block size as the total allocation grows + + B: constant which indicates the base allocation for this block size, i.e. + the allocated needed by Duktape initialization + +Pool initialization finds the largest floating point ``t`` which still fits in +the memory region provided. Any leftover bytes are sprinkled to the pools to +minimize wasted space. + +A pool configuration can be written manually (by trial and error) or using +some automatic tooling such as ``pool_simulator.py``. + +When using pointer compression only a single global pool is supported. This +reduces code footprint and is usually sufficient in low memory targets. + +Pointer compression functions are defined as inline functions in +``duk_alloc_pool.h`` to allow the compiler to inline pointer compression when +appropriate. As a side effect ``duk_config.h`` must include +``duk_alloc_pool.h`` so that the declarations are visible when compiling +Duktape. diff --git a/lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.c b/lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.c new file mode 100644 index 0000000..750fa71 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.c @@ -0,0 +1,612 @@ +/* + * Pool allocator for low memory targets. + */ + +#include +#include +#include +#include +#include +#include "duktape.h" +#include "duk_alloc_pool.h" + +/* Define to enable some debug printfs. */ +/* #define DUK_ALLOC_POOL_DEBUG */ + +/* Define to enable approximate waste tracking. */ +/* #define DUK_ALLOC_POOL_TRACK_WASTE */ + +/* Define to track global highwater for used and waste bytes. VERY SLOW, only + * useful for manual testing. + */ +/* #define DUK_ALLOC_POOL_TRACK_HIGHWATER */ + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) +#if 0 /* This extern declaration is provided by duktape.h, array provided by duktape.c. */ +extern const void * const duk_rom_compressed_pointers[]; +#endif +const void *duk_alloc_pool_romptr_low = NULL; +const void *duk_alloc_pool_romptr_high = NULL; +static void duk__alloc_pool_romptr_init(void); +#endif + +#if defined(DUK_USE_HEAPPTR16) +void *duk_alloc_pool_ptrcomp_base = NULL; +#endif + +#if defined(DUK_ALLOC_POOL_DEBUG) +static void duk__alloc_pool_dprintf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} +#endif + +/* + * Pool initialization + */ + +void *duk_alloc_pool_init(char *buffer, + size_t size, + const duk_pool_config *configs, + duk_pool_state *states, + int num_pools, + duk_pool_global *global) { + double t_min, t_max, t_curr, x; + int step, i, j, n; + size_t total; + char *p; + + /* XXX: check that 'size' is not too large when using pointer + * compression. + */ + + /* To optimize pool counts first come up with a 't' which still allows + * total pool size to fit within user provided region. After that + * sprinkle any remaining bytes to the counts. Binary search with a + * fixed step count; last round uses 't_min' as 't_curr' to ensure it + * succeeds. + */ + + t_min = 0.0; /* Unless config is insane, this should always be "good". */ + t_max = 1e6; + + for (step = 0; ; step++) { + if (step >= 100) { + /* Force "known good", rerun config, and break out. + * Deals with rounding corner cases where t_curr is + * persistently "bad" even though t_min is a valid + * solution. + */ + t_curr = t_min; + } else { + t_curr = (t_min + t_max) / 2.0; + } + + for (i = 0, total = 0; i < num_pools; i++) { + states[i].size = configs[i].size; + + /* Target bytes = A*t + B ==> target count = (A*t + B) / block_size. + * Rely on A and B being small enough so that 'x' won't wrap. + */ + x = ((double) configs[i].a * t_curr + (double) configs[i].b) / (double) configs[i].size; + + states[i].count = (unsigned int) x; + total += (size_t) states[i].size * (size_t) states[i].count; + if (total > size) { + goto bad; + } + } + + /* t_curr is good. */ +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: step=%d, t=[%lf %lf %lf] -> total %ld/%ld (good)\n", + step, t_min, t_curr, t_max, (long) total, (long) size); +#endif + if (step >= 100) { + /* Keep state[] initialization state. The state was + * created using the highest 't_min'. + */ + break; + } + t_min = t_curr; + continue; + + bad: + /* t_curr is bad. */ +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: step=%d, t=[%lf %lf %lf] -> total %ld/%ld (bad)\n", + step, t_min, t_curr, t_max, (long) total, (long) size); +#endif + + if (step >= 1000) { + /* Cannot find any good solution; shouldn't happen + * unless config is bad or 'size' is so small that + * even a baseline allocation won't fit. + */ + return NULL; + } + t_max = t_curr; + /* continue */ + } + + /* The base configuration is now good; sprinkle any leftovers to + * pools in descending order. Note that for good t_curr, 'total' + * indicates allocated bytes so far and 'size - total' indicates + * leftovers. + */ + for (i = num_pools - 1; i >= 0; i--) { + while (size - total >= states[i].size) { + /* Ignore potential wrapping of states[i].count as the count + * is 32 bits and shouldn't wrap in practice. + */ + states[i].count++; + total += states[i].size; +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: sprinkle %ld bytes (%ld left after) to pool index %ld, new count %ld\n", + (long) states[i].size, (long) (size - total), (long) i, (long) states[i].count); +#endif + } + } + + /* Pool counts are final. Allocate the user supplied region based + * on the final counts, initialize free lists for each block size, + * and otherwise finalize 'state' for use. + */ + p = buffer; + global->num_pools = num_pools; + global->states = states; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: global highwater mark tracking enabled, THIS IS VERY SLOW!\n"); +#endif + global->hwm_used_bytes = 0U; + global->hwm_waste_bytes = 0U; +#endif +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: approximate waste tracking enabled\n"); +#endif +#endif + +#if defined(DUK_USE_HEAPPTR16) + /* Register global base value for pointer compression, assumes + * a single active pool -4 allows a single subtract to be used and + * still ensures no non-NULL pointer encodes to zero. + */ + duk_alloc_pool_ptrcomp_base = (void *) (p - 4); +#endif + + for (i = 0; i < num_pools; i++) { + n = (int) states[i].count; + if (n > 0) { + states[i].first = (duk_pool_free *) p; + for (j = 0; j < n; j++) { + char *p_next = p + states[i].size; + ((duk_pool_free *) p)->next = + (j == n - 1) ? (duk_pool_free *) NULL : (duk_pool_free *) p_next; + p = p_next; + } + } else { + states[i].first = (duk_pool_free *) NULL; + } + states[i].alloc_end = p; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + states[i].hwm_used_count = 0; +#endif + /* All members of 'state' now initialized. */ + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: block size %5ld, count %5ld, %8ld total bytes, " + "end %p\n", + (long) states[i].size, (long) states[i].count, + (long) states[i].size * (long) states[i].count, + (void *) states[i].alloc_end); +#endif + } + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) + /* ROM pointer compression precomputation. Assumes a single active + * pool. + */ + duk__alloc_pool_romptr_init(); +#endif + + /* Use 'global' as udata. */ + return (void *) global; +} + +/* + * Misc helpers + */ + +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +static void duk__alloc_pool_set_waste_marker(void *ptr, size_t used, size_t size) { + /* Rely on the base pointer and size being divisible by 4 and thus + * aligned. Use 32-bit markers: a 4-byte resolution is good enough, + * and comparing 32 bits at a time makes false waste estimates less + * likely than when comparing as bytes. + */ + duk_uint32_t *p, *p_start, *p_end; + size_t used_round; + + used_round = (used + 3U) & ~0x03U; /* round up to 4 */ + p_end = (duk_uint32_t *) ((duk_uint8_t *) ptr + size); + p_start = (duk_uint32_t *) ((duk_uint8_t *) ptr + used_round); + p = (duk_uint32_t *) p_start; + while (p != p_end) { + *p++ = DUK_ALLOC_POOL_WASTE_MARKER; + } +} +#else /* DUK_ALLOC_POOL_TRACK_WASTE */ +static void duk__alloc_pool_set_waste_marker(void *ptr, size_t used, size_t size) { + (void) ptr; (void) used; (void) size; +} +#endif /* DUK_ALLOC_POOL_TRACK_WASTE */ + +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +static size_t duk__alloc_pool_get_waste_estimate(void *ptr, size_t size) { + duk_uint32_t *p, *p_end, *p_start; + + /* Assumes size is >= 4. */ + p_start = (duk_uint32_t *) ptr; + p_end = (duk_uint32_t *) ((duk_uint8_t *) ptr + size); + p = p_end; + + /* This scan may cause harmless valgrind complaints: there may be + * uninitialized bytes within the legitimate allocation or between + * the start of the waste marker and the end of the allocation. + */ + do { + p--; + if (*p == DUK_ALLOC_POOL_WASTE_MARKER) { + ; + } else { + return (size_t) (p_end - p - 1) * 4U; + } + } while (p != p_start); + + return size; +} +#else /* DUK_ALLOC_POOL_TRACK_WASTE */ +static size_t duk__alloc_pool_get_waste_estimate(void *ptr, size_t size) { + (void) ptr; (void) size; + return 0; +} +#endif /* DUK_ALLOC_POOL_TRACK_WASTE */ + +static int duk__alloc_pool_ptr_in_freelist(duk_pool_state *s, void *ptr) { + duk_pool_free *curr; + + for (curr = s->first; curr != NULL; curr = curr->next) { + if ((void *) curr == ptr) { + return 1; + } + } + return 0; +} + +void duk_alloc_pool_get_pool_stats(duk_pool_state *s, duk_pool_stats *res) { + void *curr; + size_t free_count; + size_t used_count; + size_t waste_bytes; + + curr = s->alloc_end - (s->size * s->count); + free_count = 0U; + waste_bytes = 0U; + while (curr != s->alloc_end) { + if (duk__alloc_pool_ptr_in_freelist(s, curr)) { + free_count++; + } else { + waste_bytes += duk__alloc_pool_get_waste_estimate(curr, s->size); + } + curr = curr + s->size; + } + used_count = (size_t) (s->count - free_count); + + res->used_count = used_count; + res->used_bytes = (size_t) (used_count * s->size); + res->free_count = free_count; + res->free_bytes = (size_t) (free_count * s->size); + res->waste_bytes = waste_bytes; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + res->hwm_used_count = s->hwm_used_count; +#else + res->hwm_used_count = 0U; +#endif +} + +void duk_alloc_pool_get_global_stats(duk_pool_global *g, duk_pool_global_stats *res) { + int i; + size_t total_used = 0U; + size_t total_free = 0U; + size_t total_waste = 0U; + + for (i = 0; i < g->num_pools; i++) { + duk_pool_state *s = &g->states[i]; + duk_pool_stats stats; + + duk_alloc_pool_get_pool_stats(s, &stats); + + total_used += stats.used_bytes; + total_free += stats.free_bytes; + total_waste += stats.waste_bytes; + } + + res->used_bytes = total_used; + res->free_bytes = total_free; + res->waste_bytes = total_waste; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + res->hwm_used_bytes = g->hwm_used_bytes; + res->hwm_waste_bytes = g->hwm_waste_bytes; +#else + res->hwm_used_bytes = 0U; + res->hwm_waste_bytes = 0U; +#endif +} + +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) +static void duk__alloc_pool_update_highwater(duk_pool_global *g) { + int i; + size_t total_used = 0U; + size_t total_free = 0U; + size_t total_waste = 0U; + + /* Per pool highwater used count, useful to checking if a pool is + * too small. + */ + for (i = 0; i < g->num_pools; i++) { + duk_pool_state *s = &g->states[i]; + duk_pool_stats stats; + + duk_alloc_pool_get_pool_stats(s, &stats); + if (stats.used_count > s->hwm_used_count) { +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk__alloc_pool_update_highwater: pool %ld (%ld bytes) highwater updated: count %ld -> %ld\n", + (long) i, (long) s->size, + (long) s->hwm_used_count, (long) stats.used_count); +#endif + s->hwm_used_count = stats.used_count; + } + + total_used += stats.used_bytes; + total_free += stats.free_bytes; + total_waste += stats.waste_bytes; + } + + /* Global highwater mark for used and waste bytes. Both fields are + * updated from the same snapshot based on highest used count. + * This is VERY, VERY slow and only useful for development. + * (Note that updating HWM states for pools individually and then + * summing them won't create a consistent global snapshot. There + * are still easy ways to make this much, much faster.) + */ + if (total_used > g->hwm_used_bytes) { +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk__alloc_pool_update_highwater: global highwater updated: used=%ld, bytes=%ld -> " + "used=%ld, bytes=%ld\n", + (long) g->hwm_used_bytes, (long) g->hwm_waste_bytes, + (long) total_used, (long) total_waste); +#endif + g->hwm_used_bytes = total_used; + g->hwm_waste_bytes = total_waste; + } +} +#else /* DUK_ALLOC_POOL_TRACK_HIGHWATER */ +static void duk__alloc_pool_update_highwater(duk_pool_global *g) { + (void) g; +} +#endif /* DUK_ALLOC_POOL_TRACK_HIGHWATER */ + +/* + * Allocation providers + */ + +void *duk_alloc_pool(void *udata, duk_size_t size) { + duk_pool_global *g = (duk_pool_global *) udata; + int i, n; + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool: %p %ld\n", udata, (long) size); +#endif + + if (size == 0) { + return NULL; + } + + for (i = 0, n = g->num_pools; i < n; i++) { + duk_pool_state *st = g->states + i; + + if (size <= st->size) { + duk_pool_free *res = st->first; + if (res != NULL) { + st->first = res->next; + duk__alloc_pool_set_waste_marker((void *) res, size, st->size); + duk__alloc_pool_update_highwater(g); + return (void *) res; + } + } + + /* Allocation doesn't fit or no free entries, try to borrow + * from the next block size. There's no support for preventing + * a borrow at present. + */ + } + + return NULL; +} + +void *duk_realloc_pool(void *udata, void *ptr, duk_size_t size) { + duk_pool_global *g = (duk_pool_global *) udata; + int i, j, n; + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_realloc_pool: %p %p %ld\n", udata, ptr, (long) size); +#endif + + if (ptr == NULL) { + return duk_alloc_pool(udata, size); + } + if (size == 0) { + duk_free_pool(udata, ptr); + return NULL; + } + + /* Non-NULL pointers are necessarily from the pool so we should + * always be able to find the allocation. + */ + + for (i = 0, n = g->num_pools; i < n; i++) { + duk_pool_state *st = g->states + i; + char *new_ptr; + + /* Because 'ptr' is assumed to be in the pool and pools are + * allocated in sequence, it suffices to check for end pointer + * only. + */ + if ((char *) ptr >= st->alloc_end) { + continue; + } + + if (size <= st->size) { + /* Allocation still fits existing allocation. Check if + * we can shrink the allocation to a smaller block size + * (smallest possible). + */ + for (j = 0; j < i; j++) { + duk_pool_state *st2 = g->states + j; + + if (size <= st2->size) { + new_ptr = (char *) st2->first; + if (new_ptr != NULL) { +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_realloc_pool: shrink, block size %ld -> %ld\n", + (long) st->size, (long) st2->size); +#endif + st2->first = ((duk_pool_free *) new_ptr)->next; + memcpy((void *) new_ptr, (const void *) ptr, (size_t) size); + ((duk_pool_free *) ptr)->next = st->first; + st->first = (duk_pool_free *) ptr; + duk__alloc_pool_set_waste_marker((void *) new_ptr, size, st2->size); + duk__alloc_pool_update_highwater(g); + return (void *) new_ptr; + } + } + } + + /* Failed to shrink; return existing pointer. */ + duk__alloc_pool_set_waste_marker((void *) ptr, size, st->size); + return ptr; + } + + /* Find first free larger block. */ + for (j = i + 1; j < n; j++) { + duk_pool_state *st2 = g->states + j; + + if (size <= st2->size) { + new_ptr = (char *) st2->first; + if (new_ptr != NULL) { + st2->first = ((duk_pool_free *) new_ptr)->next; + memcpy((void *) new_ptr, (const void *) ptr, (size_t) st->size); + ((duk_pool_free *) ptr)->next = st->first; + st->first = (duk_pool_free *) ptr; + duk__alloc_pool_set_waste_marker((void *) new_ptr, size, st2->size); + duk__alloc_pool_update_highwater(g); + return (void *) new_ptr; + } + } + } + + /* Failed to resize. */ + return NULL; + } + + /* We should never be here because 'ptr' should be a valid pool + * entry and thus always found above. + */ + return NULL; +} + +void duk_free_pool(void *udata, void *ptr) { + duk_pool_global *g = (duk_pool_global *) udata; + int i, n; + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_free_pool: %p %p\n", udata, ptr); +#endif + + if (ptr == NULL) { + return; + } + + for (i = 0, n = g->num_pools; i < n; i++) { + duk_pool_state *st = g->states + i; + + /* Enough to check end address only. */ + if ((char *) ptr >= st->alloc_end) { + continue; + } + + ((duk_pool_free *) ptr)->next = st->first; + st->first = (duk_pool_free *) ptr; +#if 0 /* never necessary when freeing */ + duk__alloc_pool_update_highwater(g); +#endif + return; + } + + /* We should never be here because 'ptr' should be a valid pool + * entry and thus always found above. + */ +} + +/* + * Pointer compression + */ + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) +static void duk__alloc_pool_romptr_init(void) { + /* Scan ROM pointer range for faster detection of "is 'p' a ROM pointer" + * later on. + */ + const void * const * ptrs = (const void * const *) duk_rom_compressed_pointers; + duk_alloc_pool_romptr_low = duk_alloc_pool_romptr_high = (const void *) *ptrs; + while (*ptrs) { + if (*ptrs > duk_alloc_pool_romptr_high) { + duk_alloc_pool_romptr_high = (const void *) *ptrs; + } + if (*ptrs < duk_alloc_pool_romptr_low) { + duk_alloc_pool_romptr_low = (const void *) *ptrs; + } + ptrs++; + } +} +#endif + +/* Encode/decode functions are defined in the header to allow inlining. */ + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) +duk_uint16_t duk_alloc_pool_enc16_rom(void *ptr) { + /* The if-condition should be the fastest possible check + * for "is 'ptr' in ROM?". If pointer is in ROM, we'd like + * to compress it quickly. Here we just scan a ~1K array + * which is very bad for performance. + */ + const void * const * ptrs = duk_rom_compressed_pointers; + while (*ptrs) { + if (*ptrs == ptr) { + return DUK_ALLOC_POOL_ROMPTR_FIRST + (duk_uint16_t) (ptrs - duk_rom_compressed_pointers); + } + ptrs++; + } + + /* We should really never be here: Duktape should only be + * compressing pointers which are in the ROM compressed + * pointers list, which are known at 'make dist' time. + * We go on, causing a pointer compression error. + */ + return 0; +} +#endif diff --git a/lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.h b/lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.h new file mode 100644 index 0000000..286ec01 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/duk_alloc_pool.h @@ -0,0 +1,223 @@ +#if !defined(DUK_ALLOC_POOL_H_INCLUDED) +#define DUK_ALLOC_POOL_H_INCLUDED + +#include "duktape.h" + +/* 32-bit (big endian) marker used at the end of pool entries so that wasted + * space can be detected. Waste tracking must be enabled explicitly. + */ +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +#define DUK_ALLOC_POOL_WASTE_MARKER 0xedcb2345UL +#endif + +/* Pointer compression with ROM strings/objects: + * + * For now, use DUK_USE_ROM_OBJECTS to signal the need for compressed ROM + * pointers. DUK_USE_ROM_PTRCOMP_FIRST is provided for the ROM pointer + * compression range minimum to avoid duplication in user code. + */ +#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16) +#define DUK_ALLOC_POOL_ROMPTR_COMPRESSION +#define DUK_ALLOC_POOL_ROMPTR_FIRST DUK_USE_ROM_PTRCOMP_FIRST + +/* This extern declaration is provided by duktape.h, array provided by duktape.c. + * Because duk_config.h may include this file (to get the inline functions) we + * need to forward declare this also here. + */ +extern const void * const duk_rom_compressed_pointers[]; +#endif + +/* Pool configuration for a certain block size. */ +typedef struct { + unsigned int size; /* must be divisible by 4 and >= sizeof(void *) */ + unsigned int a; /* bytes (not count) to allocate: a*t + b, t is an arbitrary scale parameter */ + unsigned int b; +} duk_pool_config; + +/* Freelist entry, must fit into the smallest block size. */ +struct duk_pool_free; +typedef struct duk_pool_free duk_pool_free; +struct duk_pool_free { + duk_pool_free *next; +}; + +/* Pool state for a certain block size. */ +typedef struct { + duk_pool_free *first; + char *alloc_end; + unsigned int size; + unsigned int count; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + unsigned int hwm_used_count; +#endif +} duk_pool_state; + +/* Statistics for a certain pool. */ +typedef struct { + size_t used_count; + size_t used_bytes; + size_t free_count; + size_t free_bytes; + size_t waste_bytes; + size_t hwm_used_count; +} duk_pool_stats; + +/* Top level state for all pools. Pointer to this struct is used as the allocator + * userdata pointer. + */ +typedef struct { + int num_pools; + duk_pool_state *states; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + size_t hwm_used_bytes; + size_t hwm_waste_bytes; +#endif +} duk_pool_global; + +/* Statistics for the entire set of pools. */ +typedef struct { + size_t used_bytes; + size_t free_bytes; + size_t waste_bytes; + size_t hwm_used_bytes; + size_t hwm_waste_bytes; +} duk_pool_global_stats; + +/* Initialize a pool allocator, arguments: + * - buffer and size: continuous region to use for pool, must align to 4 + * - config: configuration for pools in ascending block size + * - state: state for pools, matches config order + * - num_pools: number of entries in 'config' and 'state' + * - global: global state structure + * + * The 'config', 'state', and 'global' pointers must be valid beyond the init + * call, as long as the pool is used. + * + * Returns a void pointer to be used as userdata for the allocator functions. + * Concretely the return value will be "(void *) global", i.e. the global + * state struct. If pool init fails, the return value will be NULL. + */ +void *duk_alloc_pool_init(char *buffer, + size_t size, + const duk_pool_config *configs, + duk_pool_state *states, + int num_pools, + duk_pool_global *global); + +/* Duktape allocation providers. Typing matches Duktape requirements. */ +void *duk_alloc_pool(void *udata, duk_size_t size); +void *duk_realloc_pool(void *udata, void *ptr, duk_size_t size); +void duk_free_pool(void *udata, void *ptr); + +/* Stats. */ +void duk_alloc_pool_get_pool_stats(duk_pool_state *s, duk_pool_stats *res); +void duk_alloc_pool_get_global_stats(duk_pool_global *g, duk_pool_global_stats *res); + +/* Duktape pointer compression global state (assumes single pool). */ +#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16) +extern const void *duk_alloc_pool_romptr_low; +extern const void *duk_alloc_pool_romptr_high; +duk_uint16_t duk_alloc_pool_enc16_rom(void *ptr); +#endif +#if defined(DUK_USE_HEAPPTR16) +extern void *duk_alloc_pool_ptrcomp_base; +#endif + +#if 0 +duk_uint16_t duk_alloc_pool_enc16(void *ptr); +void *duk_alloc_pool_dec16(duk_uint16_t val); +#endif + +/* Inlined pointer compression functions. Gcc and clang -Os won't in + * practice inline these without an "always inline" attribute because it's + * more size efficient (by a few kB) to use explicit calls instead. Having + * these defined inline here allows performance optimized builds to inline + * pointer compression operations. + * + * Pointer compression assumes there's a single globally registered memory + * pool which makes pointer compression more efficient. This would be easy + * to fix by adding a userdata pointer to the compression functions and + * plumbing the heap userdata from the compression/decompression macros. + */ + +/* DUK_ALWAYS_INLINE is not a public API symbol so it may go away in even a + * minor update. But it's pragmatic for this extra because it handles many + * compilers via duk_config.h detection. Check that the macro exists so that + * if it's gone, we can still compile. + */ +#if defined(DUK_ALWAYS_INLINE) +#define DUK__ALLOC_POOL_ALWAYS_INLINE DUK_ALWAYS_INLINE +#else +#define DUK__ALLOC_POOL_ALWAYS_INLINE /* nop */ +#endif + +#if defined(DUK_USE_HEAPPTR16) +static DUK__ALLOC_POOL_ALWAYS_INLINE duk_uint16_t duk_alloc_pool_enc16(void *ptr) { + if (ptr == NULL) { + /* With 'return 0' gcc and clang -Os generate inefficient code. + * For example, gcc -Os generates: + * + * 0804911d : + * 804911d: 55 push %ebp + * 804911e: 85 c0 test %eax,%eax + * 8049120: 89 e5 mov %esp,%ebp + * 8049122: 74 0b je 804912f + * 8049124: 2b 05 e4 90 07 08 sub 0x80790e4,%eax + * 804912a: c1 e8 02 shr $0x2,%eax + * 804912d: eb 02 jmp 8049131 + * 804912f: 31 c0 xor %eax,%eax + * 8049131: 5d pop %ebp + * 8049132: c3 ret + * + * The NULL path checks %eax for zero; if it is zero, a zero + * is unnecessarily loaded into %eax again. The non-zero path + * has an unnecessary jump as a side effect of this. + * + * Using 'return (duk_uint16_t) (intptr_t) ptr;' generates similarly + * inefficient code; not sure how to make the result better. + */ + return 0; + } +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) + if (ptr >= duk_alloc_pool_romptr_low && ptr <= duk_alloc_pool_romptr_high) { + /* This is complex enough now to need a separate function. */ + return duk_alloc_pool_enc16_rom(ptr); + } +#endif + return (duk_uint16_t) (((size_t) ((char *) ptr - (char *) duk_alloc_pool_ptrcomp_base)) >> 2); +} + +static DUK__ALLOC_POOL_ALWAYS_INLINE void *duk_alloc_pool_dec16(duk_uint16_t val) { + if (val == 0) { + /* As with enc16 the gcc and clang -Os output is inefficient, + * e.g. gcc -Os: + * + * 08049133 : + * 8049133: 55 push %ebp + * 8049134: 66 85 c0 test %ax,%ax + * 8049137: 89 e5 mov %esp,%ebp + * 8049139: 74 0e je 8049149 + * 804913b: 8b 15 e4 90 07 08 mov 0x80790e4,%edx + * 8049141: 0f b7 c0 movzwl %ax,%eax + * 8049144: 8d 04 82 lea (%edx,%eax,4),%eax + * 8049147: eb 02 jmp 804914b + * 8049149: 31 c0 xor %eax,%eax + * 804914b: 5d pop %ebp + * 804914c: c3 ret + */ + return NULL; + } +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) + if (val >= DUK_ALLOC_POOL_ROMPTR_FIRST) { + /* This is a blind lookup, could check index validity. + * Duktape should never decompress a pointer which would + * be out-of-bounds here. + */ + return (void *) (intptr_t) (duk_rom_compressed_pointers[val - DUK_ALLOC_POOL_ROMPTR_FIRST]); + } +#endif + return (void *) ((char *) duk_alloc_pool_ptrcomp_base + (((size_t) val) << 2)); +} +#endif + +#endif /* DUK_ALLOC_POOL_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/extras/alloc-pool/ptrcomp.yaml b/lib/duktape-2.2.1/extras/alloc-pool/ptrcomp.yaml new file mode 100644 index 0000000..9ce58f4 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/ptrcomp.yaml @@ -0,0 +1,16 @@ +DUK_USE_REFCOUNT16: true +DUK_USE_STRHASH16: true +DUK_USE_STRLEN16: true +DUK_USE_BUFLEN16: true +DUK_USE_OBJSIZES16: true +DUK_USE_HSTRING_CLEN: false +DUK_USE_HOBJECT_HASH_PART: false +DUK_USE_HEAPPTR16: true +DUK_USE_HEAPPTR_ENC16: + verbatim: "#define DUK_USE_HEAPPTR_ENC16(ud,p) duk_alloc_pool_enc16((p))" +DUK_USE_HEAPPTR_DEC16: + verbatim: "#define DUK_USE_HEAPPTR_DEC16(ud,p) duk_alloc_pool_dec16((p))" + +#DUK_USE_ROM_OBJECTS: true +#DUK_USE_ROM_STRINGS: true +#DUK_USE_ROM_GLOBAL_INHERIT: true diff --git a/lib/duktape-2.2.1/extras/alloc-pool/ptrcomp_fixup.h b/lib/duktape-2.2.1/extras/alloc-pool/ptrcomp_fixup.h new file mode 100644 index 0000000..fec0ff5 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/ptrcomp_fixup.h @@ -0,0 +1,2 @@ +/* To provide declarations for inline pointer compression functions. */ +#include "duk_alloc_pool.h" diff --git a/lib/duktape-2.2.1/extras/alloc-pool/test.c b/lib/duktape-2.2.1/extras/alloc-pool/test.c new file mode 100644 index 0000000..f272244 --- /dev/null +++ b/lib/duktape-2.2.1/extras/alloc-pool/test.c @@ -0,0 +1,114 @@ +#include +#include +#include "duktape.h" +#include "duk_alloc_pool.h" + +void my_fatal(const char *msg) { + fprintf(stderr, "*** FATAL: %s\n", msg ? msg : "no message"); + fflush(stderr); + abort(); +} + +static duk_ret_t my_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_safe_to_string(ctx, -1)); + return 1; +} + +static void dump_pool_state(duk_pool_global *g) { + int i; + long total_size = 0; + long total_used = 0; + + for (i = 0; i < g->num_pools; i++) { + duk_pool_state *st = g->states + i; + int free, used; + duk_pool_free *f; + + for (free = 0, f = st->first; f; f = f->next) { + free++; + } + used = st->count - free; + printf("Pool %2d: block size %5d, count %4d/%4d, bytes %6d/%6d\n", + i, (int) st->size, used, (int) st->count, + (int) st->size * used, (int) st->size * (int) st->count); + + total_size += (long) st->size * (long) st->count; + total_used += (long) st->size * (long) used; + } + printf("=== Total: %ld/%ld, free %ld\n", + (long) total_used, (long) total_size, (long) (total_size - total_used)); +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + int i; + int exitcode = 0; + + /* NOTE! This pool configuration is NOT a good pool configuration + * for practical use (and is not intended to be one). A production + * pool configuration should be created using measurements. + */ + const duk_pool_config pool_configs[15] = { + { 16, 20, 200 }, + { 20, 40, 100 }, + { 24, 40, 100 }, + { 32, 60, 50 }, + { 40, 60, 50 }, + { 48, 60, 50 }, + { 56, 60, 50 }, + { 64, 60, 50 }, + { 80, 60, 50 }, + { 256, 100, 10 }, + { 1024, 20, 2 }, + { 2048, 20, 2 }, + { 4096, 100, 2 }, + { 6144, 60, 2 }, + { 8192, 100, 2 }, + }; + duk_pool_state pool_states[15]; /* Count must match pool_configs[]. */ + duk_pool_global pool_global; + + char buffer[200000]; + void *pool_udata; + + pool_udata = duk_alloc_pool_init(buffer, sizeof(buffer), pool_configs, pool_states, sizeof(pool_configs) / sizeof(duk_pool_config), &pool_global); + if (!pool_udata) { + return 1; + } + + printf("Pool after pool init:\n"); + dump_pool_state(&pool_global); + + ctx = duk_create_heap(duk_alloc_pool, duk_realloc_pool, duk_free_pool, pool_udata, NULL); + if (!ctx) { + return 1; + } + + printf("Pool after Duktape heap creation:\n"); + dump_pool_state(&pool_global); + + duk_push_c_function(ctx, my_print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + duk_push_c_function(ctx, my_print, DUK_VARARGS); + duk_put_global_string(ctx, "alert"); + printf("top after init: %ld\n", (long) duk_get_top(ctx)); + + for (i = 1; i < argc; i++) { + printf("Evaling: %s\n", argv[i]); + if (duk_peval_string(ctx, argv[i]) != 0) { + exitcode = 1; + } + printf("--> %s\n", duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + } + + printf("Pool after evaling code:\n"); + dump_pool_state(&pool_global); + + printf("Done\n"); + duk_destroy_heap(ctx); + return exitcode; +} diff --git a/lib/duktape-2.2.1/extras/console/Makefile b/lib/duktape-2.2.1/extras/console/Makefile new file mode 100644 index 0000000..10d2e71 --- /dev/null +++ b/lib/duktape-2.2.1/extras/console/Makefile @@ -0,0 +1,11 @@ +# For manual testing; say 'make' in extras/print-alert and run ./test. + +.PHONY: test +test: + gcc -std=c99 -Wall -Wextra -o $@ -I../../src/ -I. ../../src/duktape.c duk_console.c test.c -lm + ./test 'console.assert(true, "not shown");' + ./test 'console.assert(false, "shown", { foo: 123 });' + ./test 'console.log(1, 2, 3, { foo: "bar" });' + ./test 'a={}; b={}; a.ref=b; console.log(a,b); b.ref=a; console.log(a,b)' # circular ref + ./test 'console.trace(1, 2, 3)' + ./test 'console.dir({ foo: 123, bar: [ "foo", "bar" ]});' diff --git a/lib/duktape-2.2.1/extras/console/README.rst b/lib/duktape-2.2.1/extras/console/README.rst new file mode 100644 index 0000000..f660382 --- /dev/null +++ b/lib/duktape-2.2.1/extras/console/README.rst @@ -0,0 +1,30 @@ +========================= +Minimal 'console' binding +========================= + +Duktape doesn't provide a ``console`` binding (for example ``console.log``) +by default because it would be a portability issue for some targets. Instead, +an application should provide its own ``console`` binding. This directory +contains an example binding: + +* Add ``duk_console.c`` to list of C sources to compile. + +* Ensure ``duk_console.h`` is in the include path. + +* Include the extra header in calling code and initialize the bindings:: + + #include "duktape.h" + #include "duk_console.h" + + /* After initializing the Duktape heap or when creating a new + * thread with a new global environment: + */ + duk_console_init(ctx, 0 /*flags*/); + + Use the ``DUK_CONSOLE_PROXY_WRAPPER`` to enable a Proxy wrapper for the + console object. The wrapper allows all undefined methods (for example, + ``console.foo``) to be handled as no-ops instead of throwing an error. + See ``duk_console.h`` for full flags list. + +* After these steps, ``console`` will be registered to the global object + and is ready to use. diff --git a/lib/duktape-2.2.1/extras/console/duk_console.c b/lib/duktape-2.2.1/extras/console/duk_console.c new file mode 100644 index 0000000..9a29903 --- /dev/null +++ b/lib/duktape-2.2.1/extras/console/duk_console.c @@ -0,0 +1,163 @@ +/* + * Minimal 'console' binding. + * + * https://github.com/DeveloperToolsWG/console-object/blob/master/api.md + * https://developers.google.com/web/tools/chrome-devtools/debug/console/console-reference + * https://developer.mozilla.org/en/docs/Web/API/console + */ + +#include +#include +#include "duktape.h" +#include "duk_console.h" + +/* XXX: Add some form of log level filtering. */ + +/* XXX: For now logs everything to stdout, V8/Node.js logs debug/info level + * to stdout, warn and above to stderr. Should this extra do the same? + */ + +/* XXX: Should all output be written via e.g. console.write(formattedMsg)? + * This would make it easier for user code to redirect all console output + * to a custom backend. + */ + +/* XXX: Init console object using duk_def_prop() when that call is available. */ + +static duk_ret_t duk__console_log_helper(duk_context *ctx, const char *error_name) { + duk_idx_t i, n; + duk_uint_t flags; + + flags = (duk_uint_t) duk_get_current_magic(ctx); + + n = duk_get_top(ctx); + + duk_get_global_string(ctx, "console"); + duk_get_prop_string(ctx, -1, "format"); + + for (i = 0; i < n; i++) { + if (duk_check_type_mask(ctx, i, DUK_TYPE_MASK_OBJECT)) { + /* Slow path formatting. */ + duk_dup(ctx, -1); /* console.format */ + duk_dup(ctx, i); + duk_call(ctx, 1); + duk_replace(ctx, i); /* arg[i] = console.format(arg[i]); */ + } + } + + duk_pop_2(ctx); + + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, n); + + if (error_name) { + duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", duk_require_string(ctx, -1)); + duk_push_string(ctx, "name"); + duk_push_string(ctx, error_name); + duk_def_prop(ctx, -3, DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE); /* to get e.g. 'Trace: 1 2 3' */ + duk_get_prop_string(ctx, -1, "stack"); + } + + fprintf(stdout, "%s\n", duk_to_string(ctx, -1)); + if (flags & DUK_CONSOLE_FLUSH) { + fflush(stdout); + } + return 0; +} + +static duk_ret_t duk__console_assert(duk_context *ctx) { + if (duk_to_boolean(ctx, 0)) { + return 0; + } + duk_remove(ctx, 0); + + return duk__console_log_helper(ctx, "AssertionError"); +} + +static duk_ret_t duk__console_log(duk_context *ctx) { + return duk__console_log_helper(ctx, NULL); +} + +static duk_ret_t duk__console_trace(duk_context *ctx) { + return duk__console_log_helper(ctx, "Trace"); +} + +static duk_ret_t duk__console_info(duk_context *ctx) { + return duk__console_log_helper(ctx, NULL); +} + +static duk_ret_t duk__console_warn(duk_context *ctx) { + return duk__console_log_helper(ctx, NULL); +} + +static duk_ret_t duk__console_error(duk_context *ctx) { + return duk__console_log_helper(ctx, "Error"); +} + +static duk_ret_t duk__console_dir(duk_context *ctx) { + /* For now, just share the formatting of .log() */ + return duk__console_log_helper(ctx, 0); +} + +static void duk__console_reg_vararg_func(duk_context *ctx, duk_c_function func, const char *name, duk_uint_t flags) { + duk_push_c_function(ctx, func, DUK_VARARGS); + duk_push_string(ctx, "name"); + duk_push_string(ctx, name); + duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE); /* Improve stacktraces by displaying function name */ + duk_set_magic(ctx, -1, (duk_int_t) flags); + duk_put_prop_string(ctx, -2, name); +} + +void duk_console_init(duk_context *ctx, duk_uint_t flags) { + duk_push_object(ctx); + + /* Custom function to format objects; user can replace. + * For now, try JX-formatting and if that fails, fall back + * to ToString(v). + */ + duk_eval_string(ctx, + "(function (E) {" + "return function format(v){" + "try{" + "return E('jx',v);" + "}catch(e){" + "return String(v);" /* String() allows symbols, ToString() internal algorithm doesn't. */ + "}" + "};" + "})(Duktape.enc)"); + duk_put_prop_string(ctx, -2, "format"); + + duk__console_reg_vararg_func(ctx, duk__console_assert, "assert", flags); + duk__console_reg_vararg_func(ctx, duk__console_log, "log", flags); + duk__console_reg_vararg_func(ctx, duk__console_log, "debug", flags); /* alias to console.log */ + duk__console_reg_vararg_func(ctx, duk__console_trace, "trace", flags); + duk__console_reg_vararg_func(ctx, duk__console_info, "info", flags); + duk__console_reg_vararg_func(ctx, duk__console_warn, "warn", flags); + duk__console_reg_vararg_func(ctx, duk__console_error, "error", flags); + duk__console_reg_vararg_func(ctx, duk__console_error, "exception", flags); /* alias to console.error */ + duk__console_reg_vararg_func(ctx, duk__console_dir, "dir", flags); + + duk_put_global_string(ctx, "console"); + + /* Proxy wrapping: ensures any undefined console method calls are + * ignored silently. This is required specifically by the + * DeveloperToolsWG proposal (and is implemented also by Firefox: + * https://bugzilla.mozilla.org/show_bug.cgi?id=629607). + */ + + if (flags & DUK_CONSOLE_PROXY_WRAPPER) { + /* Tolerate errors: Proxy may be disabled. */ + duk_peval_string_noresult(ctx, + "(function(){" + "var D=function(){};" + "console=new Proxy(console,{" + "get:function(t,k){" + "var v=t[k];" + "return typeof v==='function'?v:D;" + "}" + "});" + "})();" + ); + } +} diff --git a/lib/duktape-2.2.1/extras/console/duk_console.h b/lib/duktape-2.2.1/extras/console/duk_console.h new file mode 100644 index 0000000..1488a95 --- /dev/null +++ b/lib/duktape-2.2.1/extras/console/duk_console.h @@ -0,0 +1,14 @@ +#if !defined(DUK_CONSOLE_H_INCLUDED) +#define DUK_CONSOLE_H_INCLUDED + +#include "duktape.h" + +/* Use a proxy wrapper to make undefined methods (console.foo()) no-ops. */ +#define DUK_CONSOLE_PROXY_WRAPPER (1 << 0) + +/* Flush output after every call. */ +#define DUK_CONSOLE_FLUSH (1 << 1) + +extern void duk_console_init(duk_context *ctx, duk_uint_t flags); + +#endif /* DUK_CONSOLE_H_INCLUDED */ diff --git a/lib/duktape-2.2.1/extras/console/test.c b/lib/duktape-2.2.1/extras/console/test.c new file mode 100644 index 0000000..9dc8183 --- /dev/null +++ b/lib/duktape-2.2.1/extras/console/test.c @@ -0,0 +1,30 @@ +#include +#include "duktape.h" +#include "duk_console.h" + +int main(int argc, char *argv[]) { + duk_context *ctx; + int i; + int exitcode = 0; + + ctx = duk_create_heap_default(); + if (!ctx) { + return 1; + } + + duk_console_init(ctx, DUK_CONSOLE_PROXY_WRAPPER /*flags*/); + printf("top after init: %ld\n", (long) duk_get_top(ctx)); + + for (i = 1; i < argc; i++) { + printf("Evaling: %s\n", argv[i]); + if (duk_peval_string(ctx, argv[i]) != 0) { + exitcode = 1; + } + printf("--> %s\n", duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + } + + printf("Done\n"); + duk_destroy_heap(ctx); + return exitcode; +} diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/Makefile b/lib/duktape-2.2.1/extras/duk-v1-compat/Makefile new file mode 100644 index 0000000..2057df8 --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/Makefile @@ -0,0 +1,6 @@ +# For manual testing; say 'make' in extras/duk-v1-compat and run ./test. + +.PHONY: test +test: + gcc -std=c99 -Wall -Wextra -o $@ -I../../src/ -I. ../../src/duktape.c duk_v1_compat.c test.c -lm + ./test diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/README.rst b/lib/duktape-2.2.1/extras/duk-v1-compat/README.rst new file mode 100644 index 0000000..5b0d7d5 --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/README.rst @@ -0,0 +1,25 @@ +================================ +Duktape V1 compatibility helpers +================================ + +Provides helpers for migrating from Duktape 1.x to 2.x: + +* Add ``duk_v1_compat.c`` to list of C sources to compile. + +* Ensure ``duk_v1_compat.h`` is in the include path. + +* Include the extra header in calling code:: + + #include "duktape.h" + #include "duk_v1_compat.h" + + /* ... */ + + duk_dump_context_stdout(ctx); /* Removed in Duktape 2.x. */ + +The helpers don't restore full 1.x compatibility because some API calls such +as ``duk_safe_call()`` have changed in an incompatible manner. + +The old APIs are documented in: + +* http://duktape.org/1.5.0/api.html diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.c b/lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.c new file mode 100644 index 0000000..e4a44db --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.c @@ -0,0 +1,131 @@ +#include +#include "duktape.h" +#include "duk_v1_compat.h" + +/* + * duk_dump_context_{stdout,stderr}() + */ + +void duk_dump_context_stdout(duk_context *ctx) { + duk_push_context_dump(ctx); + fprintf(stdout, "%s\n", duk_safe_to_string(ctx, -1)); + duk_pop(ctx); +} + +void duk_dump_context_stderr(duk_context *ctx) { + duk_push_context_dump(ctx); + fprintf(stderr, "%s\n", duk_safe_to_string(ctx, -1)); + duk_pop(ctx); +} + +/* + * duk_push_string_file() and duk_push_string_file_raw() + */ + +const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags) { + FILE *f = NULL; + char *buf; + long sz; /* ANSI C typing */ + + if (!path) { + goto fail; + } + f = fopen(path, "rb"); + if (!f) { + goto fail; + } + if (fseek(f, 0, SEEK_END) < 0) { + goto fail; + } + sz = ftell(f); + if (sz < 0) { + goto fail; + } + if (fseek(f, 0, SEEK_SET) < 0) { + goto fail; + } + buf = (char *) duk_push_fixed_buffer(ctx, (duk_size_t) sz); + if ((size_t) fread(buf, 1, (size_t) sz, f) != (size_t) sz) { + duk_pop(ctx); + goto fail; + } + (void) fclose(f); /* ignore fclose() error */ + return duk_buffer_to_string(ctx, -1); + + fail: + if (f) { + (void) fclose(f); /* ignore fclose() error */ + } + + if (flags & DUK_STRING_PUSH_SAFE) { + duk_push_undefined(ctx); + } else { + (void) duk_type_error(ctx, "read file error"); + } + return NULL; +} + +/* + * duk_eval_file(), duk_compile_file(), and their variants + */ + +void duk_eval_file(duk_context *ctx, const char *path) { + duk_push_string_file_raw(ctx, path, 0); + duk_push_string(ctx, path); + duk_compile(ctx, DUK_COMPILE_EVAL); + duk_push_global_object(ctx); /* 'this' binding */ + duk_call_method(ctx, 0); +} + +void duk_eval_file_noresult(duk_context *ctx, const char *path) { + duk_eval_file(ctx, path); + duk_pop(ctx); +} + +duk_int_t duk_peval_file(duk_context *ctx, const char *path) { + duk_int_t rc; + + duk_push_string_file_raw(ctx, path, DUK_STRING_PUSH_SAFE); + duk_push_string(ctx, path); + rc = duk_pcompile(ctx, DUK_COMPILE_EVAL); + if (rc != 0) { + return rc; + } + duk_push_global_object(ctx); /* 'this' binding */ + rc = duk_pcall_method(ctx, 0); + return rc; +} + +duk_int_t duk_peval_file_noresult(duk_context *ctx, const char *path) { + duk_int_t rc; + + rc = duk_peval_file(ctx, path); + duk_pop(ctx); + return rc; +} + +void duk_compile_file(duk_context *ctx, duk_uint_t flags, const char *path) { + duk_push_string_file_raw(ctx, path, 0); + duk_push_string(ctx, path); + duk_compile(ctx, flags); +} + +duk_int_t duk_pcompile_file(duk_context *ctx, duk_uint_t flags, const char *path) { + duk_int_t rc; + + duk_push_string_file_raw(ctx, path, DUK_STRING_PUSH_SAFE); + duk_push_string(ctx, path); + rc = duk_pcompile(ctx, flags); + return rc; +} + +/* + * duk_to_defaultvalue() + */ + +void duk_to_defaultvalue(duk_context *ctx, duk_idx_t idx, duk_int_t hint) { + duk_require_type_mask(ctx, idx, DUK_TYPE_MASK_OBJECT | + DUK_TYPE_MASK_BUFFER | + DUK_TYPE_MASK_LIGHTFUNC); + duk_to_primitive(ctx, idx, hint); +} diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.h b/lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.h new file mode 100644 index 0000000..884883c --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/duk_v1_compat.h @@ -0,0 +1,28 @@ +#if !defined(DUK_V1_COMPAT_INCLUDED) +#define DUK_V1_COMPAT_INCLUDED + +#include "duktape.h" + +/* Straight flag rename */ +#if !defined(DUK_ENUM_INCLUDE_INTERNAL) +#define DUK_ENUM_INCLUDE_INTERNAL DUK_ENUM_INCLUDE_HIDDEN +#endif + +/* Flags for duk_push_string_file_raw() */ +#define DUK_STRING_PUSH_SAFE (1 << 0) /* no error if file does not exist */ + +extern void duk_dump_context_stdout(duk_context *ctx); +extern void duk_dump_context_stderr(duk_context *ctx); +extern const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags); +extern void duk_eval_file(duk_context *ctx, const char *path); +extern void duk_eval_file_noresult(duk_context *ctx, const char *path); +extern duk_int_t duk_peval_file(duk_context *ctx, const char *path); +extern duk_int_t duk_peval_file_noresult(duk_context *ctx, const char *path); +extern void duk_compile_file(duk_context *ctx, duk_uint_t flags, const char *path); +extern duk_int_t duk_pcompile_file(duk_context *ctx, duk_uint_t flags, const char *path); +extern void duk_to_defaultvalue(duk_context *ctx, duk_idx_t idx, duk_int_t hint); + +#define duk_push_string_file(ctx,path) \ + duk_push_string_file_raw((ctx), (path), 0) + +#endif /* DUK_V1_COMPAT_INCLUDED */ diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/test.c b/lib/duktape-2.2.1/extras/duk-v1-compat/test.c new file mode 100644 index 0000000..82e97b4 --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/test.c @@ -0,0 +1,104 @@ +#include +#include "duktape.h" +#include "duk_v1_compat.h" + +static duk_ret_t my_print(duk_context *ctx) { + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, duk_get_top(ctx) - 1); + printf("%s\n", duk_to_string(ctx, -1)); + fflush(stdout); + return 0; +} + +int main(int argc, char *argv[]) { + duk_context *ctx; + int i; + duk_int_t rc; + + ctx = duk_create_heap_default(); + if (!ctx) { + return 1; + } + + /* Minimal print() provider. */ + duk_push_c_function(ctx, my_print, DUK_VARARGS); + duk_put_global_string(ctx, "print"); + + printf("top after init: %ld\n", (long) duk_get_top(ctx)); + + for (i = 1; i < argc; i++) { + printf("Evaling: %s\n", argv[i]); + (void) duk_peval_string(ctx, argv[i]); + printf("--> %s\n", duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + } + + /* Test duk_dump_context_{stdout,stderr}() */ + + duk_push_string(ctx, "dump to stdout"); + duk_dump_context_stdout(ctx); + duk_pop(ctx); + + duk_push_string(ctx, "dump to stderr"); + duk_dump_context_stderr(ctx); + duk_pop(ctx); + + /* Test duk_eval_file() and related. */ + + printf("top before duk_eval_file(): %ld\n", (long) duk_get_top(ctx)); + duk_eval_file(ctx, "test_eval1.js"); + printf("top after duk_eval_file(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %s\n", duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + + printf("top before duk_eval_file_noresult(): %ld\n", (long) duk_get_top(ctx)); + duk_eval_file_noresult(ctx, "test_eval1.js"); + printf("top after duk_eval_file_noresult(): %ld\n", (long) duk_get_top(ctx)); + + printf("top before duk_peval_file(): %ld\n", (long) duk_get_top(ctx)); + rc = duk_peval_file(ctx, "test_eval1.js"); + printf("top after duk_peval_file(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %ld, %s\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + + printf("top before duk_peval_file(): %ld\n", (long) duk_get_top(ctx)); + rc = duk_peval_file(ctx, "test_eval2.js"); + printf("top after duk_peval_file(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %ld, %s\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + + printf("top before duk_peval_file_noresult(): %ld\n", (long) duk_get_top(ctx)); + rc = duk_peval_file_noresult(ctx, "test_eval1.js"); + printf("top after duk_peval_file_noresult(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %ld\n", (long) rc); + + printf("top before duk_peval_file_noresult(): %ld\n", (long) duk_get_top(ctx)); + rc = duk_peval_file_noresult(ctx, "test_eval2.js"); + printf("top after duk_peval_file_noresult(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %ld\n", (long) rc); + + /* Test duk_compile_file() and related. */ + + printf("top before duk_compile_file(): %ld\n", (long) duk_get_top(ctx)); + duk_compile_file(ctx, 0, "test_compile1.js"); + printf("top after duk_compile_file(): %ld\n", (long) duk_get_top(ctx)); + duk_call(ctx, 0); + duk_pop(ctx); + + printf("top before duk_pcompile_file(): %ld\n", (long) duk_get_top(ctx)); + rc = duk_pcompile_file(ctx, 0, "test_compile1.js"); + printf("top after duk_pcompile_file(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %ld: %s\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + + printf("top before duk_pcompile_file(): %ld\n", (long) duk_get_top(ctx)); + rc = duk_pcompile_file(ctx, 0, "test_compile2.js"); + printf("top after duk_pcompile_file(): %ld\n", (long) duk_get_top(ctx)); + printf(" --> %ld: %s\n", (long) rc, duk_safe_to_string(ctx, -1)); + duk_pop(ctx); + + printf("Done\n"); + duk_destroy_heap(ctx); + return 0; +} diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/test_compile1.js b/lib/duktape-2.2.1/extras/duk-v1-compat/test_compile1.js new file mode 100644 index 0000000..92ee80c --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/test_compile1.js @@ -0,0 +1,3 @@ +// File to compile, no error +print('Hello from test_compile1.js'); +print(new Error('test error for traceback (shows filename)').stack); diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/test_compile2.js b/lib/duktape-2.2.1/extras/duk-v1-compat/test_compile2.js new file mode 100644 index 0000000..1cb1ffc --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/test_compile2.js @@ -0,0 +1,3 @@ +// File to compile, syntax error +print('Hello from test_compile2.js'); += y +; diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/test_eval1.js b/lib/duktape-2.2.1/extras/duk-v1-compat/test_eval1.js new file mode 100644 index 0000000..e2ee178 --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/test_eval1.js @@ -0,0 +1,4 @@ +// File to eval, no error +print('Hello from test_eval1.js'); +print(new Error('test error for traceback (shows filename)').stack); +123; diff --git a/lib/duktape-2.2.1/extras/duk-v1-compat/test_eval2.js b/lib/duktape-2.2.1/extras/duk-v1-compat/test_eval2.js new file mode 100644 index 0000000..443eb2c --- /dev/null +++ b/lib/duktape-2.2.1/extras/duk-v1-compat/test_eval2.js @@ -0,0 +1,4 @@ +// File to eval, throws error +print('Hello from test_eval2.js'); +print(new Error('test error for traceback (shows filename)').stack); +throw new Error('aiee'); diff --git a/lib/duktape-2.2.1/extras/logging/Makefile b/lib/duktape-2.2.1/extras/logging/Makefile new file mode 100644 index 0000000..21333aa --- /dev/null +++ b/lib/duktape-2.2.1/extras/logging/Makefile @@ -0,0 +1,12 @@ +# For manual testing; say 'make' in extras/logging and run ./test. +.PHONY: test +test: + gcc -std=c99 -Wall -Wextra -otest -I../../src ../../src/duktape.c duk_logging.c test.c -lm + ./test 'L = new Duktape.Logger(); L.trace("testing"); L.l = 0; L.trace("testing 2");' + ./test 'L = new Duktape.Logger(); L.debug("testing"); L.l = 1; L.debug("testing 2");' + ./test 'L = new Duktape.Logger(); L.info("testing");' + ./test 'L = new Duktape.Logger(); L.warn("testing");' + ./test 'L = new Duktape.Logger(); L.error("testing");' + ./test 'L = new Duktape.Logger(); L.fatal("testing");' + ./test 'L = new Duktape.Logger(); L.info("testing"); L.n = "loggerName"; L.info("new name");' + ./test 'L = new Duktape.Logger("argname"); L.info("testing");' diff --git a/lib/duktape-2.2.1/extras/logging/README.rst b/lib/duktape-2.2.1/extras/logging/README.rst new file mode 100644 index 0000000..eb87481 --- /dev/null +++ b/lib/duktape-2.2.1/extras/logging/README.rst @@ -0,0 +1,33 @@ +======================================== +Duktape 1.x compatible logging framework +======================================== + +The default ``Duktape.Logger`` object and the logging related C API calls +(``duk_log()``, ``duk_log_va()``) were removed in Duktape 2.x because they +depended on stdout/stderr and were thus a portability issue for some targets +(there were also other issues, such as the logging framework not always +matching user expectations). This directory contains Duktape 1.x compatible +``Duktape.Logger`` object and logging API calls: + +* Add ``duk_logging.c`` to list of C sources to compile. + +* Ensure ``duk_logging.h`` is in the include path. + +* Include the extra header in calling code and initialize the bindings:: + + #include "duktape.h" + #include "duk_logging.h" + + /* After initializing the Duktape heap or when creating a new + * thread with a new global environment: + */ + duk_logging_init(ctx, 0 /*flags*/); + + See ``duk_logging.h`` for available flags. + +* After these steps, ``Duktape.Logger`` will be registered to the ``Duktape`` + object and is ready to use. + +See https://github.com/svaarala/duktape/blob/master/doc/logging.rst and +http://wiki.duktape.org/HowtoLogging.html for more information on the +logging framework design and functionality. diff --git a/lib/duktape-2.2.1/extras/logging/duk_logging.c b/lib/duktape-2.2.1/extras/logging/duk_logging.c new file mode 100644 index 0000000..9be2c1c --- /dev/null +++ b/lib/duktape-2.2.1/extras/logging/duk_logging.c @@ -0,0 +1,380 @@ +/* + * Logging support + */ + +#include +#include +#include +#include "duktape.h" +#include "duk_logging.h" + +/* XXX: uses stderr always for now, configurable? */ + +#define DUK_LOGGING_FLUSH /* Duktape 1.x: flush stderr */ + +/* 3-letter log level strings. */ +static const char duk__log_level_strings[] = { + 'T', 'R', 'C', 'D', 'B', 'G', 'I', 'N', 'F', + 'W', 'R', 'N', 'E', 'R', 'R', 'F', 'T', 'L' +}; + +/* Log method names. */ +static const char *duk__log_method_names[] = { + "trace", "debug", "info", "warn", "error", "fatal" +}; + +/* Constructor. */ +static duk_ret_t duk__logger_constructor(duk_context *ctx) { + duk_idx_t nargs; + + /* Calling as a non-constructor is not meaningful. */ + if (!duk_is_constructor_call(ctx)) { + return DUK_RET_TYPE_ERROR; + } + + nargs = duk_get_top(ctx); + duk_set_top(ctx, 1); + + duk_push_this(ctx); + + /* [ name this ] */ + + if (nargs == 0) { + /* Automatic defaulting of logger name from caller. This + * would work poorly with tail calls, but constructor calls + * are currently never tail calls, so tail calls are not an + * issue now. + */ + + duk_inspect_callstack_entry(ctx, -2); + if (duk_is_object(ctx, -1)) { + if (duk_get_prop_string(ctx, -1, "function")) { + if (duk_get_prop_string(ctx, -1, "fileName")) { + if (duk_is_string(ctx, -1)) { + duk_replace(ctx, 0); + } + } + } + } + /* Leave values on stack on purpose, ignored below. */ + + /* Stripping the filename might be a good idea + * ("/foo/bar/quux.js" -> logger name "quux"), + * but now used verbatim. + */ + } + /* The stack is unbalanced here on purpose; we only rely on the + * initial two values: [ name this ]. + */ + + if (duk_is_string(ctx, 0)) { + duk_dup(ctx, 0); + duk_put_prop_string(ctx, 1, "n"); + } else { + /* don't set 'n' at all, inherited value is used as name */ + } + + duk_compact(ctx, 1); + + return 0; /* keep default instance */ +} + +/* Default function to format objects. Tries to use toLogString() but falls + * back to toString(). Any errors are propagated out without catching. + */ +static duk_ret_t duk__logger_prototype_fmt(duk_context *ctx) { + if (duk_get_prop_string(ctx, 0, "toLogString")) { + /* [ arg toLogString ] */ + + duk_dup(ctx, 0); + duk_call_method(ctx, 0); + + /* [ arg result ] */ + return 1; + } + + /* [ arg undefined ] */ + duk_pop(ctx); + duk_to_string(ctx, 0); + return 1; +} + +/* Default function to write a formatted log line. Writes to stderr, + * appending a newline to the log line. + * + * The argument is a buffer; avoid coercing the buffer to a string to + * avoid string table traffic. + */ +static duk_ret_t duk__logger_prototype_raw(duk_context *ctx) { + const char *data; + duk_size_t data_len; + + data = (const char *) duk_require_buffer(ctx, 0, &data_len); + fwrite((const void *) data, 1, data_len, stderr); + fputc((int) '\n', stderr); +#if defined(DUK_LOGGING_FLUSH) + fflush(stderr); +#endif + return 0; +} + +/* Log frontend shared helper, magic value indicates log level. Provides + * frontend functions: trace(), debug(), info(), warn(), error(), fatal(). + * This needs to have small footprint, reasonable performance, minimal + * memory churn, etc. + */ +static duk_ret_t duk__logger_prototype_log_shared(duk_context *ctx) { + duk_double_t now; + duk_time_components comp; + duk_small_int_t entry_lev; + duk_small_int_t logger_lev; + duk_int_t nargs; + duk_int_t i; + duk_size_t tot_len; + const duk_uint8_t *arg_str; + duk_size_t arg_len; + duk_uint8_t *buf, *p; + const duk_uint8_t *q; + duk_uint8_t date_buf[32]; /* maximum format length is 24+1 (NUL), round up. */ + duk_size_t date_len; + duk_small_int_t rc; + + /* XXX: sanitize to printable (and maybe ASCII) */ + /* XXX: better multiline */ + + /* + * Logger arguments are: + * + * magic: log level (0-5) + * this: logger + * stack: plain log args + * + * We want to minimize memory churn so a two-pass approach + * is used: first pass formats arguments and computes final + * string length, second pass copies strings into a buffer + * allocated directly with the correct size. If the backend + * function plays nice, it won't coerce the buffer to a string + * (and thus intern it). + */ + + entry_lev = duk_get_current_magic(ctx); + if (entry_lev < DUK_LOG_TRACE || entry_lev > DUK_LOG_FATAL) { + /* Should never happen, check just in case. */ + return 0; + } + nargs = duk_get_top(ctx); + + /* [ arg1 ... argN this ] */ + + /* + * Log level check + */ + + duk_push_this(ctx); + + duk_get_prop_string(ctx, -1, "l"); + logger_lev = (duk_small_int_t) duk_get_int(ctx, -1); + if (entry_lev < logger_lev) { + return 0; + } + /* log level could be popped but that's not necessary */ + + now = duk_get_now(ctx); + duk_time_to_components(ctx, now, &comp); + sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", + (int) comp.year, (int) comp.month + 1, (int) comp.day, + (int) comp.hours, (int) comp.minutes, (int) comp.seconds, + (int) comp.milliseconds); + + date_len = strlen((const char *) date_buf); + + duk_get_prop_string(ctx, -2, "n"); + duk_to_string(ctx, -1); + + /* [ arg1 ... argN this loggerLevel loggerName ] */ + + /* + * Pass 1 + */ + + /* Line format: