├── .gitignore ├── .vscode └── launch.json ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md ├── data └── model │ ├── credits.txt │ ├── diffuse.jpg │ └── mesh.obj ├── src ├── demo.cpp ├── demo.h ├── lib.cpp ├── lib.h ├── main.cpp ├── shaders │ ├── mesh.frag.glsl │ └── mesh.vert.glsl ├── vk.cpp └── vk.h └── third-party ├── CMakeLists.txt ├── glfw ├── context.c ├── egl_context.c ├── glfw3.h ├── glfw3native.h ├── glx_context.c ├── init.c ├── input.c ├── internal.h ├── linux_joystick.c ├── linux_joystick.h ├── mappings.h ├── monitor.c ├── null_init.c ├── null_joystick.c ├── null_joystick.h ├── null_monitor.c ├── null_platform.h ├── null_window.c ├── osmesa_context.c ├── platform.c ├── platform.h ├── posix_module.c ├── posix_poll.c ├── posix_poll.h ├── posix_thread.c ├── posix_thread.h ├── posix_time.c ├── posix_time.h ├── vulkan.c ├── wgl_context.c ├── win32_init.c ├── win32_joystick.c ├── win32_joystick.h ├── win32_module.c ├── win32_monitor.c ├── win32_platform.h ├── win32_thread.c ├── win32_thread.h ├── win32_time.c ├── win32_time.h ├── win32_window.c ├── window.c ├── x11_init.c ├── x11_monitor.c ├── x11_platform.h ├── x11_window.c ├── xkb_unicode.c └── xkb_unicode.h ├── imgui ├── LICENSE.txt ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_glfw.cpp ├── imgui_impl_glfw.h ├── imgui_impl_vulkan.cpp ├── imgui_impl_vulkan.h ├── imgui_internal.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h └── imstb_truetype.h ├── stb_image.h ├── tiny_obj_loader.h ├── vma ├── LICENSE.txt └── vk_mem_alloc.h ├── volk ├── LICENSE.md ├── README.md ├── volk.c └── volk.h └── vulkan ├── vk_enum_string_helper.h ├── vk_platform.h ├── vulkan.h ├── vulkan_core.h ├── vulkan_win32.h ├── vulkan_xcb.h └── vulkan_xlib.h /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | build/ 3 | imgui.ini 4 | data/* 5 | !data/model 6 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(Windows) Launch", 6 | "type": "cppvsdbg", 7 | "request": "launch", 8 | "program": "${workspaceFolder}/build/${command:cmake.buildType}/vulkan-base.exe", 9 | "args": [], 10 | "stopAtEntry": false, 11 | "cwd": "${workspaceFolder}", 12 | "environment": [], 13 | "console": "integratedTerminal" 14 | }, 15 | { 16 | "name": "(gdb) Launch", 17 | "type": "cppdbg", 18 | "request": "launch", 19 | "program": "${workspaceFolder}/build/${command:cmake.buildType}/vulkan-base", 20 | "args": [], 21 | "stopAtEntry": false, 22 | "cwd": "${workspaceFolder}", 23 | "environment": [], 24 | "externalConsole": false, 25 | "MIMode": "gdb", 26 | "setupCommands": [ 27 | { 28 | "description": "Enable pretty-printing for gdb", 29 | "text": "-enable-pretty-printing", 30 | "ignoreFailures": true 31 | }, 32 | { 33 | "description": "Set Disassembly Flavor to Intel", 34 | "text": "-gdb-set disassembly-flavor intel", 35 | "ignoreFailures": true 36 | } 37 | ] 38 | }, 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(vulkan-base) 3 | 4 | set(PROGRAM_SOURCE 5 | src/demo.cpp 6 | src/demo.h 7 | src/lib.cpp 8 | src/lib.h 9 | src/main.cpp 10 | src/vk.cpp 11 | src/vk.h 12 | ) 13 | set(SHADER_SOURCE 14 | src/shaders/mesh.vert.glsl 15 | src/shaders/mesh.frag.glsl 16 | ) 17 | 18 | set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE) 19 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 20 | source_group("" FILES ${PROGRAM_SOURCE}) 21 | source_group(TREE "${CMAKE_SOURCE_DIR}/src/shaders" PREFIX shaders FILES ${SHADER_SOURCE}) 22 | 23 | if (MSVC) 24 | add_compile_definitions(_CRT_SECURE_NO_WARNINGS) 25 | add_compile_options(/MP /W3) 26 | # Match MSVC Release 27 | add_compile_options($<$:/Zi>) 28 | add_compile_options($<$:/GL>) 29 | add_compile_options($<$:/Gy>) 30 | add_link_options($<$:/DEBUG>) 31 | add_link_options($<$:/OPT:REF>) 32 | add_link_options($<$:/OPT:ICF>) 33 | add_link_options($<$:/LTCG>) 34 | else() 35 | add_compile_options(-Wall -Wextra) 36 | endif() 37 | 38 | add_executable(vulkan-base ${PROGRAM_SOURCE} ${SHADER_SOURCE}) 39 | target_compile_features(vulkan-base PRIVATE cxx_std_20) 40 | add_subdirectory(third-party) 41 | target_link_libraries(vulkan-base third-party) 42 | 43 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 44 | target_compile_options(vulkan-base PRIVATE 45 | -Wno-unused-parameter 46 | -Wno-missing-field-initializers 47 | ) 48 | endif() 49 | 50 | set_target_properties(vulkan-base PROPERTIES 51 | VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 52 | VS_DPI_AWARE "PerMonitor" 53 | ) 54 | set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT vulkan-base) 55 | 56 | function(add_shader SHADER) 57 | get_filename_component(BASE_NAME ${SHADER} NAME_WLE) 58 | set(SPV_FILE "${CMAKE_SOURCE_DIR}/data/spirv/${BASE_NAME}.spv") 59 | set(SHADER_FILE "${CMAKE_SOURCE_DIR}/${SHADER}") 60 | add_custom_command( 61 | OUTPUT "${SPV_FILE}" 62 | COMMAND "$ENV{VULKAN_SDK}/bin/glslangValidator" "${SHADER_FILE}" -V --target-env vulkan1.2 -o "${SPV_FILE}" 63 | COMMAND "$ENV{VULKAN_SDK}/bin/spirv-opt" ${SPV_FILE} -O --strip-debug -o "${SPV_FILE}" 64 | MAIN_DEPENDENCY "${SHADER_FILE}" 65 | ) 66 | endfunction() 67 | 68 | foreach(SHADER ${SHADER_SOURCE}) 69 | add_shader(${SHADER}) 70 | endforeach() 71 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "vs", 6 | "binaryDir": "${sourceDir}/build", 7 | "installDir": "${sourceDir}/install", 8 | "generator": "Visual Studio 17 2022", 9 | "architecture": { 10 | "value": "x64", 11 | "strategy": "external" 12 | }, 13 | "condition": { 14 | "type": "equals", 15 | "lhs": "${hostSystemName}", 16 | "rhs": "Windows" 17 | } 18 | }, 19 | { 20 | "name": "ninja", 21 | "binaryDir": "${sourceDir}/build", 22 | "installDir": "${sourceDir}/install", 23 | "generator": "Ninja Multi-Config", 24 | "condition": { 25 | "type": "equals", 26 | "lhs": "${hostSystemName}", 27 | "rhs": "Linux" 28 | } 29 | } 30 | ], 31 | "buildPresets": [ 32 | { 33 | "name": "vs-debug", 34 | "displayName": "Debug", 35 | "configurePreset": "vs", 36 | "configuration": "Debug" 37 | }, 38 | { 39 | "name": "vs-release", 40 | "displayName": "Release", 41 | "configurePreset": "vs", 42 | "configuration": "Release" 43 | }, 44 | { 45 | "name": "ninja-debug", 46 | "displayName": "Debug", 47 | "configurePreset": "ninja", 48 | "configuration": "Debug" 49 | }, 50 | { 51 | "name": "ninja-release", 52 | "displayName": "Release", 53 | "configurePreset": "ninja", 54 | "configuration": "Release" 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2022 Artem Kharytoniuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🌋 vulkan-base 🖖 2 | 3 | This is a basic Vulkan application that renders a textured 3D model. 4 | The program shows how to use the following features: 5 | * setup of rasterization pipeline 6 | * timestamp queries 7 | * debug labels 8 | * imgui integration. 9 | 10 | Prerequisites: 11 | * CMake 12 | * Vulkan SDK (VULKAN_SDK environment variable should be set) 13 | 14 | Build steps: 15 | 16 | 1. `cmake -S . -B build` 17 | 2. `cmake --build build` 18 | 19 | Supported platforms: Windows, Linux. 20 | 21 | In order to enable Vulkan validation layers specify ```--validation-layers``` command line argument. 22 | 23 | For basic Vulkan ray tracing check this repository: https://github.com/kennyalive/vulkan-ray-tracing 24 | 25 | ![vulkan-base](https://user-images.githubusercontent.com/4964024/64047691-c812e280-cb6f-11e9-8f26-76c4ee8860cd.png) 26 | -------------------------------------------------------------------------------- /data/model/credits.txt: -------------------------------------------------------------------------------- 1 | Digimon 3D Craniummon https://sketchfab.com/models/36d1022f74fd40ba8d98972c71174b8a 2 | by Gigano Regulus https://sketchfab.com/Gigano_Regulus 3 | CC BY 4.0 License https://creativecommons.org/licenses/by/4.0/ 4 | -------------------------------------------------------------------------------- /data/model/diffuse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyalive/vulkan-base/27bcaad9d519cc2f9c5cde4872742d4a5212eee6/data/model/diffuse.jpg -------------------------------------------------------------------------------- /src/demo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "lib.h" 4 | #include "vk.h" 5 | #include 6 | 7 | struct GLFWwindow; 8 | 9 | class Vk_Demo { 10 | public: 11 | void initialize(GLFWwindow* glfw_window); 12 | void shutdown(); 13 | void release_resolution_dependent_resources(); 14 | void restore_resolution_dependent_resources(); 15 | bool vsync_enabled() const { return vsync; } 16 | void run_frame(); 17 | 18 | private: 19 | void do_imgui(); 20 | void draw_frame(); 21 | 22 | private: 23 | using Clock = std::chrono::high_resolution_clock; 24 | using Time = std::chrono::time_point; 25 | 26 | bool show_ui = true; 27 | bool vsync = true; 28 | bool animate = false; 29 | 30 | Time last_frame_time{}; 31 | double sim_time = 0; 32 | Vector3 camera_pos = Vector3(0, 0.5, 3.0); 33 | 34 | Vk_GPU_Time_Keeper time_keeper; 35 | struct { 36 | Vk_GPU_Time_Interval* frame; 37 | } gpu_times{}; 38 | 39 | Vk_Image depth_buffer_image; 40 | VkDescriptorSetLayout descriptor_set_layout; 41 | VkPipelineLayout pipeline_layout; 42 | VkPipeline pipeline; 43 | Vk_Buffer descriptor_buffer; 44 | void* mapped_descriptor_buffer_ptr = nullptr; 45 | Vk_Buffer uniform_buffer; 46 | void* mapped_uniform_buffer = nullptr; 47 | Vk_Image texture; 48 | VkSampler sampler; 49 | 50 | struct { 51 | Vk_Buffer vertex_buffer; 52 | Vk_Buffer index_buffer; 53 | uint32_t vertex_count = 0; 54 | uint32_t index_count = 0; 55 | void destroy() { 56 | vertex_buffer.destroy(); 57 | index_buffer.destroy(); 58 | vertex_count = 0; 59 | index_count = 0; 60 | } 61 | } gpu_mesh; 62 | }; 63 | -------------------------------------------------------------------------------- /src/lib.cpp: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | 3 | #define TINYOBJLOADER_IMPLEMENTATION 4 | #include "tiny_obj_loader.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void error(const std::string& message) 12 | { 13 | printf("%s\n", message.c_str()); 14 | throw std::runtime_error(message); 15 | } 16 | 17 | // The place where program's resources are located (models, textures, spirv binaries). 18 | // This location can be configured with --data-dir command line option. 19 | std::string g_data_dir = "./data"; 20 | 21 | std::string get_resource_path(const std::string& path_relative_data_directory) 22 | { 23 | return (std::filesystem::path(g_data_dir) / path_relative_data_directory).string(); 24 | } 25 | 26 | std::vector read_binary_file(const std::string& file_name) 27 | { 28 | std::ifstream file(file_name, std::ios_base::in | std::ios_base::binary); 29 | if (!file) 30 | error("failed to open file: " + file_name); 31 | 32 | // get file size 33 | file.seekg(0, std::ios_base::end); 34 | std::streampos file_size = file.tellg(); 35 | file.seekg(0, std::ios_base::beg); 36 | 37 | if (file_size == std::streampos(-1) || !file) 38 | error("failed to read file stats: " + file_name); 39 | 40 | // read file content 41 | std::vector file_content(static_cast(file_size)); 42 | file.read(reinterpret_cast(file_content.data()), file_size); 43 | if (!file) 44 | error("failed to read file content: " + file_name); 45 | 46 | return file_content; 47 | } 48 | 49 | uint64_t elapsed_milliseconds(Timestamp timestamp) 50 | { 51 | auto duration = std::chrono::steady_clock::now() - timestamp.t; 52 | auto milliseconds = std::chrono::duration_cast(duration).count(); 53 | return (uint64_t)milliseconds; 54 | } 55 | 56 | uint64_t elapsed_nanoseconds(Timestamp timestamp) 57 | { 58 | auto duration = std::chrono::steady_clock::now() - timestamp.t; 59 | auto nanoseconds = std::chrono::duration_cast(duration).count(); 60 | return (uint64_t)nanoseconds; 61 | } 62 | 63 | const Matrix3x4 Matrix3x4::identity = [] { 64 | Matrix3x4 m{}; 65 | m.a[0][0] = m.a[1][1] = m.a[2][2] = 1.f; 66 | return m; 67 | }(); 68 | 69 | const Matrix4x4 Matrix4x4::identity = [] { 70 | Matrix4x4 m{}; 71 | m.a[0][0] = m.a[1][1] = m.a[2][2] = m.a[3][3] = 1.f; 72 | return m; 73 | }(); 74 | 75 | void Matrix3x4::set_column(int column_index, Vector3 c) { 76 | assert(column_index >= 0 && column_index < 4); 77 | a[0][column_index] = c.x; 78 | a[1][column_index] = c.y; 79 | a[2][column_index] = c.z; 80 | } 81 | 82 | Vector3 Matrix3x4::get_column(int c) const { 83 | assert(c >= 0 && c < 4); 84 | return Vector3(a[0][c], a[1][c], a[2][c]); 85 | } 86 | 87 | void Matrix3x4::set_row(int row_index, Vector4 r) { 88 | assert(row_index >= 0 && row_index < 3); 89 | a[row_index][0] = r.x; 90 | a[row_index][1] = r.y; 91 | a[row_index][2] = r.z; 92 | a[row_index][3] = r.w; 93 | } 94 | 95 | Vector4 Matrix3x4::get_row(int row) const { 96 | assert(row >= 0 && row < 3); 97 | return Vector4(a[row][0], a[row][1], a[row][2], a[row][3]); 98 | } 99 | 100 | Matrix3x4 operator*(const Matrix3x4& m1, const Matrix3x4& m2) { 101 | Matrix3x4 m; 102 | m.a[0][0] = m1.a[0][0] * m2.a[0][0] + m1.a[0][1] * m2.a[1][0] + m1.a[0][2] * m2.a[2][0]; 103 | m.a[0][1] = m1.a[0][0] * m2.a[0][1] + m1.a[0][1] * m2.a[1][1] + m1.a[0][2] * m2.a[2][1]; 104 | m.a[0][2] = m1.a[0][0] * m2.a[0][2] + m1.a[0][1] * m2.a[1][2] + m1.a[0][2] * m2.a[2][2]; 105 | m.a[0][3] = m1.a[0][0] * m2.a[0][3] + m1.a[0][1] * m2.a[1][3] + m1.a[0][2] * m2.a[2][3] + m1.a[0][3]; 106 | 107 | m.a[1][0] = m1.a[1][0] * m2.a[0][0] + m1.a[1][1] * m2.a[1][0] + m1.a[1][2] * m2.a[2][0]; 108 | m.a[1][1] = m1.a[1][0] * m2.a[0][1] + m1.a[1][1] * m2.a[1][1] + m1.a[1][2] * m2.a[2][1]; 109 | m.a[1][2] = m1.a[1][0] * m2.a[0][2] + m1.a[1][1] * m2.a[1][2] + m1.a[1][2] * m2.a[2][2]; 110 | m.a[1][3] = m1.a[1][0] * m2.a[0][3] + m1.a[1][1] * m2.a[1][3] + m1.a[1][2] * m2.a[2][3] + m1.a[1][3]; 111 | 112 | m.a[2][0] = m1.a[2][0] * m2.a[0][0] + m1.a[2][1] * m2.a[1][0] + m1.a[2][2] * m2.a[2][0]; 113 | m.a[2][1] = m1.a[2][0] * m2.a[0][1] + m1.a[2][1] * m2.a[1][1] + m1.a[2][2] * m2.a[2][1]; 114 | m.a[2][2] = m1.a[2][0] * m2.a[0][2] + m1.a[2][1] * m2.a[1][2] + m1.a[2][2] * m2.a[2][2]; 115 | m.a[2][3] = m1.a[2][0] * m2.a[0][3] + m1.a[2][1] * m2.a[1][3] + m1.a[2][2] * m2.a[2][3] + m1.a[2][3]; 116 | return m; 117 | } 118 | 119 | Matrix4x4 operator*(const Matrix4x4& m1, const Matrix3x4& m2) { 120 | Matrix4x4 m; 121 | m.a[0][0] = m1.a[0][0] * m2.a[0][0] + m1.a[0][1] * m2.a[1][0] + m1.a[0][2] * m2.a[2][0]; 122 | m.a[0][1] = m1.a[0][0] * m2.a[0][1] + m1.a[0][1] * m2.a[1][1] + m1.a[0][2] * m2.a[2][1]; 123 | m.a[0][2] = m1.a[0][0] * m2.a[0][2] + m1.a[0][1] * m2.a[1][2] + m1.a[0][2] * m2.a[2][2]; 124 | m.a[0][3] = m1.a[0][0] * m2.a[0][3] + m1.a[0][1] * m2.a[1][3] + m1.a[0][2] * m2.a[2][3] + m1.a[0][3]; 125 | 126 | m.a[1][0] = m1.a[1][0] * m2.a[0][0] + m1.a[1][1] * m2.a[1][0] + m1.a[1][2] * m2.a[2][0]; 127 | m.a[1][1] = m1.a[1][0] * m2.a[0][1] + m1.a[1][1] * m2.a[1][1] + m1.a[1][2] * m2.a[2][1]; 128 | m.a[1][2] = m1.a[1][0] * m2.a[0][2] + m1.a[1][1] * m2.a[1][2] + m1.a[1][2] * m2.a[2][2]; 129 | m.a[1][3] = m1.a[1][0] * m2.a[0][3] + m1.a[1][1] * m2.a[1][3] + m1.a[1][2] * m2.a[2][3] + m1.a[1][3]; 130 | 131 | m.a[2][0] = m1.a[2][0] * m2.a[0][0] + m1.a[2][1] * m2.a[1][0] + m1.a[2][2] * m2.a[2][0]; 132 | m.a[2][1] = m1.a[2][0] * m2.a[0][1] + m1.a[2][1] * m2.a[1][1] + m1.a[2][2] * m2.a[2][1]; 133 | m.a[2][2] = m1.a[2][0] * m2.a[0][2] + m1.a[2][1] * m2.a[1][2] + m1.a[2][2] * m2.a[2][2]; 134 | m.a[2][3] = m1.a[2][0] * m2.a[0][3] + m1.a[2][1] * m2.a[1][3] + m1.a[2][2] * m2.a[2][3] + m1.a[2][3]; 135 | 136 | m.a[3][0] = m1.a[3][0] * m2.a[0][0] + m1.a[3][1] * m2.a[1][0] + m1.a[3][2] * m2.a[2][0]; 137 | m.a[3][1] = m1.a[3][0] * m2.a[0][1] + m1.a[3][1] * m2.a[1][1] + m1.a[3][2] * m2.a[2][1]; 138 | m.a[3][2] = m1.a[3][0] * m2.a[0][2] + m1.a[3][1] * m2.a[1][2] + m1.a[3][2] * m2.a[2][2]; 139 | m.a[3][3] = m1.a[3][0] * m2.a[0][3] + m1.a[3][1] * m2.a[1][3] + m1.a[3][2] * m2.a[2][3] + m1.a[3][3]; 140 | return m; 141 | } 142 | 143 | Matrix3x4 get_inverse(const Matrix3x4& m) { 144 | Vector3 x_axis = m.get_column(0); 145 | Vector3 y_axis = m.get_column(1); 146 | Vector3 z_axis = m.get_column(2); 147 | Vector3 origin = m.get_column(3); 148 | 149 | Matrix3x4 m_inv; 150 | m_inv.set_row(0, Vector4(x_axis, -dot(x_axis, origin))); 151 | m_inv.set_row(1, Vector4(y_axis, -dot(y_axis, origin))); 152 | m_inv.set_row(2, Vector4(z_axis, -dot(z_axis, origin))); 153 | return m_inv; 154 | } 155 | 156 | Matrix3x4 rotate_x(const Matrix3x4& m, float angle) { 157 | float cs = std::cos(angle); 158 | float sn = std::sin(angle); 159 | 160 | Matrix3x4 m2; 161 | m2.a[0][0] = m.a[0][0]; 162 | m2.a[0][1] = m.a[0][1]; 163 | m2.a[0][2] = m.a[0][2]; 164 | m2.a[0][3] = m.a[0][3]; 165 | 166 | m2.a[1][0] = cs * m.a[1][0] - sn * m.a[2][0]; 167 | m2.a[1][1] = cs * m.a[1][1] - sn * m.a[2][1]; 168 | m2.a[1][2] = cs * m.a[1][2] - sn * m.a[2][2]; 169 | m2.a[1][3] = cs * m.a[1][3] - sn * m.a[2][3]; 170 | 171 | m2.a[2][0] = sn * m.a[1][0] + cs * m.a[2][0]; 172 | m2.a[2][1] = sn * m.a[1][1] + cs * m.a[2][1]; 173 | m2.a[2][2] = sn * m.a[1][2] + cs * m.a[2][2]; 174 | m2.a[2][3] = sn * m.a[1][3] + cs * m.a[2][3]; 175 | return m2; 176 | } 177 | 178 | Matrix3x4 rotate_y(const Matrix3x4& m, float angle) { 179 | float cs = std::cos(angle); 180 | float sn = std::sin(angle); 181 | 182 | Matrix3x4 m2; 183 | m2.a[0][0] = cs * m.a[0][0] + sn * m.a[2][0]; 184 | m2.a[0][1] = cs * m.a[0][1] + sn * m.a[2][1]; 185 | m2.a[0][2] = cs * m.a[0][2] + sn * m.a[2][2]; 186 | m2.a[0][3] = cs * m.a[0][3] + sn * m.a[2][3]; 187 | 188 | m2.a[1][0] = m.a[1][0]; 189 | m2.a[1][1] = m.a[1][1]; 190 | m2.a[1][2] = m.a[1][2]; 191 | m2.a[1][3] = m.a[1][3]; 192 | 193 | m2.a[2][0] = -sn * m.a[0][0] + cs * m.a[2][0]; 194 | m2.a[2][1] = -sn * m.a[0][1] + cs * m.a[2][1]; 195 | m2.a[2][2] = -sn * m.a[0][2] + cs * m.a[2][2]; 196 | m2.a[2][3] = -sn * m.a[0][3] + cs * m.a[2][3]; 197 | return m2; 198 | } 199 | 200 | Matrix3x4 rotate_z(const Matrix3x4& m, float angle) { 201 | float cs = std::cos(angle); 202 | float sn = std::sin(angle); 203 | 204 | Matrix3x4 m2; 205 | m2.a[0][0] = cs * m.a[0][0] - sn * m.a[1][0]; 206 | m2.a[0][1] = cs * m.a[0][1] - sn * m.a[1][1]; 207 | m2.a[0][2] = cs * m.a[0][2] - sn * m.a[1][2]; 208 | m2.a[0][3] = cs * m.a[0][3] - sn * m.a[1][3]; 209 | 210 | m2.a[1][0] = sn * m.a[0][0] + cs * m.a[1][0]; 211 | m2.a[1][1] = sn * m.a[0][1] + cs * m.a[1][1]; 212 | m2.a[1][2] = sn * m.a[0][2] + cs * m.a[1][2]; 213 | m2.a[1][3] = sn * m.a[0][3] + cs * m.a[1][3]; 214 | 215 | m2.a[2][0] = m.a[2][0]; 216 | m2.a[2][1] = m.a[2][1]; 217 | m2.a[2][2] = m.a[2][2]; 218 | m2.a[2][3] = m.a[2][3]; 219 | return m2; 220 | } 221 | 222 | Matrix3x4 look_at_transform(Vector3 from, Vector3 to, Vector3 up) { 223 | assert(up.is_normalized()); 224 | 225 | Vector3 f = to - from; 226 | float d = f.length(); 227 | 228 | // degenerated cases, just return matrix with identity orientation 229 | if (d < 1e-5f || std::abs(dot(f, up) - 1.f) < 1e-3f) { 230 | Matrix3x4 m = Matrix3x4::identity; 231 | m.set_column(3, from); 232 | return m; 233 | } 234 | 235 | f /= d; 236 | Vector3 r = cross(f, up).normalized(); 237 | Vector3 u = cross(r, f); 238 | 239 | Matrix3x4 m; 240 | m.set_row(0, Vector4(r, -dot(from, r))); 241 | m.set_row(1, Vector4(u, -dot(from, u))); 242 | m.set_row(2, Vector4(-f, -dot(from, -f))); 243 | return m; 244 | } 245 | 246 | Matrix4x4 perspective_transform_opengl_z01(float fovy_radians, float aspect_ratio, float near, float far) { 247 | float h = std::tan(fovy_radians / 2.f) * near; 248 | float w = aspect_ratio * h; 249 | 250 | Matrix4x4 proj{}; 251 | proj.a[0][0] = near / w; 252 | proj.a[1][1] = -near / h; 253 | proj.a[2][2] = -far / (far - near); 254 | proj.a[2][3] = -far * near / (far - near); 255 | proj.a[3][2] = -1.f; 256 | return proj; 257 | } 258 | 259 | Vector3 transform_point(const Matrix3x4& m, Vector3 p) { 260 | Vector3 p2; 261 | p2.x = m.a[0][0] * p.x + m.a[0][1] * p.y + m.a[0][2] * p.z + m.a[0][3]; 262 | p2.y = m.a[1][0] * p.x + m.a[1][1] * p.y + m.a[1][2] * p.z + m.a[1][3]; 263 | p2.z = m.a[2][0] * p.x + m.a[2][1] * p.y + m.a[2][2] * p.z + m.a[2][3]; 264 | return p2; 265 | } 266 | 267 | Vector3 transform_vector(const Matrix3x4& m, Vector3 v) { 268 | Vector3 v2; 269 | v2.x = m.a[0][0] * v.x + m.a[0][1] * v.y + m.a[0][2] * v.z; 270 | v2.y = m.a[1][0] * v.x + m.a[1][1] * v.y + m.a[1][2] * v.z; 271 | v2.z = m.a[2][0] * v.x + m.a[2][1] * v.y + m.a[2][2] * v.z; 272 | return v2; 273 | } 274 | 275 | Triangle_Mesh load_obj_model(const std::string& path, float additional_scale) { 276 | tinyobj::attrib_t attrib; 277 | std::vector shapes; 278 | std::vector materials; 279 | std::string err; 280 | 281 | if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, path.c_str())) 282 | error("failed to load obj model: " + path); 283 | 284 | assert(shapes.size() == 1); 285 | const tinyobj::mesh_t& obj_mesh = shapes[0].mesh; 286 | 287 | for (uint8_t num_face_vertices : obj_mesh.num_face_vertices) 288 | assert(num_face_vertices == 3); 289 | 290 | struct Index_Hasher { 291 | size_t operator()(const tinyobj::index_t& index) const { 292 | size_t hash = 0; 293 | hash_combine(hash, index.vertex_index); 294 | hash_combine(hash, index.normal_index); 295 | hash_combine(hash, index.texcoord_index); 296 | return hash; 297 | } 298 | }; 299 | struct Index_Comparator { 300 | bool operator()(const tinyobj::index_t& a, const tinyobj::index_t& b) const { 301 | return 302 | a.vertex_index == b.vertex_index && 303 | a.normal_index == b.normal_index && 304 | a.texcoord_index == b.texcoord_index; 305 | } 306 | }; 307 | std::unordered_map index_mapping; 308 | 309 | Vector3 mesh_min(Infinity); 310 | Vector3 mesh_max(-Infinity); 311 | 312 | Triangle_Mesh mesh; 313 | mesh.indices.reserve(obj_mesh.indices.size()); 314 | 315 | for (const tinyobj::index_t& index : obj_mesh.indices) { 316 | auto it = index_mapping.find(index); 317 | if (it == index_mapping.end()) { 318 | it = index_mapping.insert(std::make_pair(index, (int)mesh.vertices.size())).first; 319 | 320 | // add new vertex 321 | Vertex vertex; 322 | assert(index.vertex_index != -1); 323 | vertex.pos = { 324 | attrib.vertices[3 * index.vertex_index + 0], 325 | attrib.vertices[3 * index.vertex_index + 1], 326 | attrib.vertices[3 * index.vertex_index + 2] 327 | }; 328 | if (index.texcoord_index != -1) { 329 | vertex.uv = { 330 | attrib.texcoords[2 * index.texcoord_index + 0], 331 | 1.f - attrib.texcoords[2 * index.texcoord_index + 1] 332 | }; 333 | } 334 | mesh.vertices.push_back(vertex); 335 | 336 | // update mesh bounds 337 | mesh_min.x = std::min(mesh_min.x, vertex.pos.x); 338 | mesh_min.y = std::min(mesh_min.y, vertex.pos.y); 339 | mesh_min.z = std::min(mesh_min.z, vertex.pos.z); 340 | mesh_max.x = std::max(mesh_max.x, vertex.pos.x); 341 | mesh_max.y = std::max(mesh_max.y, vertex.pos.y); 342 | mesh_max.z = std::max(mesh_max.z, vertex.pos.z); 343 | } 344 | mesh.indices.push_back(it->second); 345 | } 346 | 347 | // scale and center the mesh 348 | Vector3 diag = mesh_max - mesh_min; 349 | float max_size = std::max(diag.x, std::max(diag.y, diag.z)); 350 | float scale = (2.f / max_size) * additional_scale; 351 | 352 | Vector3 center = (mesh_min + mesh_max) * 0.5f; 353 | for (auto& v : mesh.vertices) { 354 | v.pos -= center; 355 | v.pos *= scale; 356 | } 357 | return mesh; 358 | } 359 | -------------------------------------------------------------------------------- /src/lib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | constexpr float Pi = 3.14159265f; 12 | constexpr float Infinity = std::numeric_limits::infinity(); 13 | 14 | inline float radians(float degrees) { 15 | constexpr float deg_2_rad = Pi / 180.f; 16 | return degrees * deg_2_rad; 17 | } 18 | 19 | inline float degrees(float radians) { 20 | constexpr float rad_2_deg = 180.f / Pi; 21 | return radians * rad_2_deg; 22 | } 23 | 24 | void error(const std::string& message); 25 | std::string get_resource_path(const std::string& path_relative_data_directory); 26 | std::vector read_binary_file(const std::string& file_name); 27 | 28 | struct Timestamp { 29 | Timestamp() : t(std::chrono::steady_clock::now()) {} 30 | std::chrono::time_point t; 31 | }; 32 | uint64_t elapsed_milliseconds(Timestamp timestamp); 33 | uint64_t elapsed_nanoseconds(Timestamp timestamp); 34 | 35 | // Boost hash combine. 36 | template 37 | inline void hash_combine(std::size_t& seed, T value) { 38 | std::hash hasher; 39 | seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 40 | } 41 | 42 | inline float srgb_encode(float f) { 43 | if (f <= 0.0031308f) 44 | return 12.92f * f; 45 | else 46 | return 1.055f * std::pow(f, 1.f/2.4f) - 0.055f; 47 | } 48 | 49 | template 50 | inline T round_up(T k, T alignment) { 51 | return (k + alignment - 1) & ~(alignment - 1); 52 | } 53 | 54 | #if 0 55 | #define START_TIMER { Timestamp t; 56 | #define STOP_TIMER(message) \ 57 | auto d = elapsed_nanoseconds(t); \ 58 | static Timestamp t0; \ 59 | if (elapsed_milliseconds(t0) > 1000) { \ 60 | t0 = Timestamp(); \ 61 | printf(message ## " time = %lld microseconds\n", d / 1000); } } 62 | 63 | #else 64 | #define START_TIMER 65 | #define STOP_TIMER(...) 66 | #endif 67 | 68 | struct Vector4; 69 | 70 | struct Vector3 { 71 | float x, y, z; 72 | 73 | Vector3() 74 | : x(0.f), y(0.f), z(0.f) {} 75 | 76 | constexpr explicit Vector3(float v) 77 | : x(v), y(v), z(v) {} 78 | 79 | explicit Vector3(Vector4 v); 80 | 81 | Vector3(float x, float y, float z) 82 | : x(x), y(y), z(z) {} 83 | 84 | bool operator==(Vector3 v) const { 85 | return x == v.x && y == v.y && z == v.z; 86 | } 87 | 88 | bool operator!=(Vector3 v) const { 89 | return !(*this == v); 90 | } 91 | 92 | Vector3 operator-() const { 93 | return Vector3(-x, -y, -z); 94 | } 95 | 96 | float operator[](int index) const { 97 | return (&x)[index]; 98 | } 99 | 100 | float& operator[](int index) { 101 | return (&x)[index]; 102 | } 103 | 104 | Vector3& operator+=(const Vector3& v) { 105 | x += v.x; 106 | y += v.y; 107 | z += v.z; 108 | return *this; 109 | } 110 | 111 | Vector3& operator-=(const Vector3& v) { 112 | x -= v.x; 113 | y -= v.y; 114 | z -= v.z; 115 | return *this; 116 | } 117 | 118 | Vector3& operator*=(const Vector3& v) { 119 | x *= v.x; 120 | y *= v.y; 121 | z *= v.z; 122 | return *this; 123 | } 124 | 125 | Vector3& operator*=(float t) { 126 | x *= t; 127 | y *= t; 128 | z *= t; 129 | return *this; 130 | } 131 | 132 | Vector3& operator/=(float t) { 133 | x /= t; 134 | y /= t; 135 | z /= t; 136 | return *this; 137 | } 138 | 139 | Vector3 operator/(float t) const { 140 | return Vector3(x / t, y / t, z / t); 141 | } 142 | 143 | float length() const { 144 | return std::sqrt(squared_length()); 145 | } 146 | 147 | float squared_length() const { 148 | return x * x + y * y + z * z; 149 | } 150 | 151 | Vector3 normalized() const { 152 | return *this / length(); 153 | } 154 | 155 | void normalize() { 156 | *this /= length(); 157 | } 158 | 159 | bool is_normalized(float epsilon = 1e-3f) const { 160 | return std::abs(length() - 1.f) < epsilon; 161 | } 162 | }; 163 | 164 | struct Vector2 { 165 | float x, y; 166 | 167 | Vector2() 168 | : x(0.f), y(0.f) {} 169 | 170 | constexpr explicit Vector2(float v) 171 | : x(v), y(v) {} 172 | 173 | Vector2(float x, float y) 174 | : x(x), y(y) {} 175 | 176 | bool operator==(Vector2 v) const { 177 | return x == v.x && y == v.y; 178 | } 179 | 180 | bool operator!=(Vector2 v) const { 181 | return !(*this == v); 182 | } 183 | 184 | float operator[](int index) const { 185 | return (&x)[index]; 186 | } 187 | 188 | float& operator[](int index) { 189 | return (&x)[index]; 190 | } 191 | }; 192 | 193 | struct Vector4 { 194 | float x, y, z, w; 195 | 196 | Vector4() 197 | : x(0.f), y(0.f), z(0.f), w(0.f) {} 198 | 199 | constexpr explicit Vector4(float v) 200 | : x(v), y(v), z(v), w(v) {} 201 | 202 | Vector4(float x, float y, float z, float w) 203 | : x(x), y(y), z(z), w(w) {} 204 | 205 | Vector4(Vector3 xyz, float w) 206 | : x(xyz.x), y(xyz.y), z(xyz.z), w(w) {} 207 | 208 | bool operator==(Vector4 v) const { 209 | return x == v.x && y == v.y && z == v.z && w == v.w; 210 | } 211 | 212 | bool operator!=(Vector4 v) const { 213 | return !(*this == v); 214 | } 215 | 216 | float operator[](int index) const { 217 | return (&x)[index]; 218 | } 219 | 220 | float& operator[](int index) { 221 | return (&x)[index]; 222 | } 223 | }; 224 | 225 | inline Vector3::Vector3(Vector4 v) 226 | : x(v.x), y(v.y), z(v.z) 227 | {} 228 | 229 | inline Vector3 operator+(const Vector3& v1, const Vector3& v2) { 230 | return Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); 231 | } 232 | 233 | inline Vector3 operator-(const Vector3& v1, const Vector3& v2) { 234 | return Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); 235 | } 236 | 237 | inline Vector3 operator*(const Vector3& v1, const Vector3& v2) { 238 | return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); 239 | } 240 | 241 | inline Vector3 operator*(const Vector3& v, float t) { 242 | return Vector3(v.x * t, v.y * t, v.z * t); 243 | } 244 | 245 | inline Vector3 operator*(float t, const Vector3& v) { 246 | return v * t; 247 | } 248 | 249 | inline float dot(const Vector3& v1, const Vector3& v2) { 250 | return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; 251 | } 252 | 253 | inline Vector3 cross(const Vector3& v1, const Vector3& v2) { 254 | return Vector3( 255 | v1.y * v2.z - v1.z * v2.y, 256 | v1.z * v2.x - v1.x * v2.z, 257 | v1.x * v2.y - v1.y * v2.x); 258 | } 259 | 260 | struct Matrix3x4 { 261 | float a[3][4]; 262 | static const Matrix3x4 identity; 263 | 264 | void set_column(int column_index, Vector3 c); 265 | Vector3 get_column(int column) const; 266 | void set_row(int row_index, Vector4 r); 267 | Vector4 get_row(int row) const; 268 | }; 269 | 270 | struct Matrix4x4 { 271 | float a[4][4]; 272 | static const Matrix4x4 identity; 273 | }; 274 | 275 | Matrix3x4 operator*(const Matrix3x4& m1, const Matrix3x4& m2); 276 | Matrix4x4 operator*(const Matrix4x4& m1, const Matrix3x4& m2); 277 | 278 | // assumption is that matrix contains only rotation and translation. 279 | Matrix3x4 get_inverse(const Matrix3x4& m); 280 | 281 | // rotate_[axis] functions premultiply a given matrix by corresponding rotation matrix. 282 | Matrix3x4 rotate_x(const Matrix3x4& m, float angle); 283 | Matrix3x4 rotate_y(const Matrix3x4& m, float angle); 284 | Matrix3x4 rotate_z(const Matrix3x4& m, float angle); 285 | 286 | // Computes world space->eye space transform that positions the camera at point 'from' 287 | // and orients its direction towards the point 'to'. 'up' unit vector specifies reference up direction. 288 | Matrix3x4 look_at_transform(Vector3 from, Vector3 to, Vector3 up); 289 | 290 | // Computes traditional perspective matrix that transforms position vector (x,y,z,1) to 291 | // obtain clip coordinates (xc, yc, zc, wc) that can be transformed to normalized deviced 292 | // coordinates (NDC) by perspective division (xd, yd, zd) = (xc/wc, yc/wc, zc/wc). 293 | // Eye-space z-axis points towards the viewer (OpenGL style), right-handed coordinate system. 294 | // z coordinate is mapped to 0 and 1 for near and far planes correspondingly. y axis in NDC 295 | // space points top-down with regard to eye space vertical direction (to match Vulkan viewport). 296 | Matrix4x4 perspective_transform_opengl_z01(float fovy_radians, float aspect_ratio, float near, float far); 297 | 298 | Vector3 transform_point(const Matrix3x4& m, Vector3 p); 299 | Vector3 transform_vector(const Matrix3x4& m, Vector3 v); 300 | 301 | struct Vertex { 302 | Vector3 pos; 303 | Vector2 uv; 304 | }; 305 | 306 | struct Triangle_Mesh { 307 | std::vector vertices; 308 | std::vector indices; 309 | }; 310 | 311 | Triangle_Mesh load_obj_model(const std::string& path, float additional_scale); 312 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "demo.h" 2 | #include "glfw/glfw3.h" 3 | #include 4 | #include 5 | 6 | static bool parse_command_line(int argc, char** argv) { 7 | bool found_unknown_option = false; 8 | for (int i = 1; i < argc; i++) { 9 | if (strcmp(argv[i], "--data-dir") == 0) { 10 | if (i == argc - 1) { 11 | printf("--data-dir value is missing\n"); 12 | } 13 | else { 14 | extern std::string g_data_dir; 15 | g_data_dir = argv[i + 1]; 16 | i++; 17 | } 18 | } 19 | else if (strcmp(argv[i], "--help") == 0) { 20 | printf("%-25s Path to the data directory. Default is ./data.\n", "--data-dir"); 21 | printf("%-25s Shows this information.\n", "--help"); 22 | return false; 23 | } 24 | else 25 | found_unknown_option = true; 26 | } 27 | if (found_unknown_option) 28 | printf("Use --help to list all options.\n"); 29 | return true; 30 | } 31 | 32 | static int window_width = 720; 33 | static int window_height = 720; 34 | 35 | static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 36 | if (action == GLFW_PRESS) { 37 | if (key == GLFW_KEY_ESCAPE) { 38 | glfwSetWindowShouldClose(window, GLFW_TRUE); 39 | } else if (key == GLFW_KEY_F11 || (key == GLFW_KEY_ENTER && mods == GLFW_MOD_ALT)) { 40 | static int last_window_xpos, last_window_ypos; 41 | static int last_window_width, last_window_height; 42 | 43 | VK_CHECK(vkDeviceWaitIdle(vk.device)); 44 | GLFWmonitor* monitor = glfwGetWindowMonitor(window); 45 | if (monitor == nullptr) { 46 | glfwGetWindowPos(window, &last_window_xpos, &last_window_ypos); 47 | last_window_width = window_width; 48 | last_window_height = window_height; 49 | 50 | monitor = glfwGetPrimaryMonitor(); 51 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 52 | glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); 53 | } else { 54 | glfwSetWindowMonitor(window, nullptr, last_window_xpos, last_window_ypos, last_window_width, last_window_height, 0); 55 | } 56 | } 57 | } 58 | } 59 | 60 | static void glfw_error_callback(int error, const char* description) { 61 | fprintf(stderr, "GLFW error: %s\n", description); 62 | } 63 | 64 | int main(int argc, char** argv) { 65 | if (!parse_command_line(argc, argv)) { 66 | return 0; 67 | } 68 | glfwSetErrorCallback(glfw_error_callback); 69 | if (!glfwInit()) { 70 | error("glfwInit failed"); 71 | } 72 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); 73 | GLFWwindow* glfw_window = glfwCreateWindow(window_width, window_height, "Vulkan demo", nullptr, nullptr); 74 | assert(glfw_window != nullptr); 75 | glfwSetKeyCallback(glfw_window, glfw_key_callback); 76 | 77 | Vk_Demo demo{}; 78 | demo.initialize(glfw_window); 79 | 80 | bool prev_vsync = demo.vsync_enabled(); 81 | 82 | bool window_active = true; 83 | 84 | while (!glfwWindowShouldClose(glfw_window)) { 85 | if (window_active) 86 | demo.run_frame(); 87 | 88 | glfwPollEvents(); 89 | 90 | int width, height; 91 | glfwGetWindowSize(glfw_window, &width, &height); 92 | 93 | bool recreate_swapchain = false; 94 | if (prev_vsync != demo.vsync_enabled()) { 95 | prev_vsync = demo.vsync_enabled(); 96 | recreate_swapchain = true; 97 | } else if (width != window_width || height != window_height) { 98 | window_width = width; 99 | window_height = height; 100 | recreate_swapchain = true; 101 | } 102 | 103 | window_active = (width != 0 && height != 0); 104 | 105 | if (!window_active) 106 | continue; 107 | 108 | if (recreate_swapchain) { 109 | VK_CHECK(vkDeviceWaitIdle(vk.device)); 110 | demo.release_resolution_dependent_resources(); 111 | vk_destroy_swapchain(); 112 | vk_create_swapchain(demo.vsync_enabled()); 113 | demo.restore_resolution_dependent_resources(); 114 | recreate_swapchain = false; 115 | } 116 | } 117 | 118 | demo.shutdown(); 119 | glfwTerminate(); 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /src/shaders/mesh.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | layout(row_major) uniform; 3 | 4 | layout(location=0) in vec2 frag_uv; 5 | layout(location = 0) out vec4 color_attachment0; 6 | 7 | layout(binding=1) uniform texture2D image; 8 | layout(binding=2) uniform sampler image_sampler; 9 | 10 | void main() { 11 | color_attachment0 = texture(sampler2D(image, image_sampler), frag_uv); 12 | } 13 | -------------------------------------------------------------------------------- /src/shaders/mesh.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | layout(row_major) uniform; 3 | 4 | layout(location=0) in vec4 in_position; 5 | layout(location=1) in vec2 in_uv; 6 | layout(location = 0) out vec2 frag_uv; 7 | 8 | layout(std140, binding=0) uniform Uniform_Block { 9 | mat4x4 model_view_proj; 10 | }; 11 | 12 | void main() { 13 | frag_uv = in_uv; 14 | gl_Position = model_view_proj * in_position; 15 | } 16 | -------------------------------------------------------------------------------- /third-party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(THIRD_PARTY_SOURCE 2 | # glfw 3 | glfw/context.c 4 | glfw/egl_context.c 5 | glfw/glx_context.c 6 | glfw/init.c 7 | glfw/input.c 8 | glfw/linux_joystick.c 9 | glfw/monitor.c 10 | glfw/null_init.c 11 | glfw/null_joystick.c 12 | glfw/null_monitor.c 13 | glfw/null_window.c 14 | glfw/osmesa_context.c 15 | glfw/platform.c 16 | glfw/posix_module.c 17 | glfw/posix_poll.c 18 | glfw/posix_thread.c 19 | glfw/posix_time.c 20 | glfw/vulkan.c 21 | glfw/wgl_context.c 22 | glfw/win32_init.c 23 | glfw/win32_joystick.c 24 | glfw/win32_module.c 25 | glfw/win32_monitor.c 26 | glfw/win32_thread.c 27 | glfw/win32_time.c 28 | glfw/win32_window.c 29 | glfw/window.c 30 | glfw/x11_init.c 31 | glfw/x11_monitor.c 32 | glfw/x11_window.c 33 | glfw/xkb_unicode.c 34 | # imgui 35 | imgui/imconfig.h 36 | imgui/imgui.cpp 37 | imgui/imgui.h 38 | imgui/imgui_demo.cpp 39 | imgui/imgui_draw.cpp 40 | imgui/imgui_internal.h 41 | imgui/imgui_tables.cpp 42 | imgui/imgui_widgets.cpp 43 | imgui/imgui_impl_glfw.cpp 44 | imgui/imgui_impl_glfw.h 45 | imgui/imgui_impl_vulkan.cpp 46 | imgui/imgui_impl_vulkan.h 47 | # volk 48 | volk/volk.c 49 | volk/volk.h 50 | ) 51 | source_group(TREE "${CMAKE_SOURCE_DIR}/third-party" FILES ${THIRD_PARTY_SOURCE}) 52 | 53 | add_library(third-party ${THIRD_PARTY_SOURCE}) 54 | target_compile_features(third-party PRIVATE cxx_std_17) 55 | target_include_directories(third-party PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 56 | 57 | if (CMAKE_SYSTEM_NAME STREQUAL "Windows") 58 | target_compile_definitions(third-party PUBLIC _GLFW_WIN32 VK_USE_PLATFORM_WIN32_KHR IMGUI_IMPL_VULKAN_USE_VOLK) 59 | elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") 60 | target_compile_definitions(third-party PUBLIC _GLFW_X11 VK_USE_PLATFORM_XCB_KHR IMGUI_IMPL_VULKAN_USE_VOLK) 61 | else() 62 | message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") 63 | endif() 64 | 65 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 66 | target_compile_options(third-party PRIVATE 67 | -Wno-unused-parameter 68 | -Wno-sign-compare 69 | -Wno-missing-field-initializers 70 | ) 71 | target_compile_options(third-party INTERFACE 72 | -Wno-unused-variable 73 | -Wno-parentheses 74 | -Wno-shift-negative-value 75 | -Wno-implicit-fallthrough 76 | ) 77 | endif() 78 | -------------------------------------------------------------------------------- /third-party/glfw/linux_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_LINUX_JOYSTICK) 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #ifndef SYN_DROPPED // < v2.6.39 kernel headers 46 | // Workaround for CentOS-6, which is supported till 2020-11-30, but still on v2.6.32 47 | #define SYN_DROPPED 3 48 | #endif 49 | 50 | // Apply an EV_KEY event to the specified joystick 51 | // 52 | static void handleKeyEvent(_GLFWjoystick* js, int code, int value) 53 | { 54 | _glfwInputJoystickButton(js, 55 | js->linjs.keyMap[code - BTN_MISC], 56 | value ? GLFW_PRESS : GLFW_RELEASE); 57 | } 58 | 59 | // Apply an EV_ABS event to the specified joystick 60 | // 61 | static void handleAbsEvent(_GLFWjoystick* js, int code, int value) 62 | { 63 | const int index = js->linjs.absMap[code]; 64 | 65 | if (code >= ABS_HAT0X && code <= ABS_HAT3Y) 66 | { 67 | static const char stateMap[3][3] = 68 | { 69 | { GLFW_HAT_CENTERED, GLFW_HAT_UP, GLFW_HAT_DOWN }, 70 | { GLFW_HAT_LEFT, GLFW_HAT_LEFT_UP, GLFW_HAT_LEFT_DOWN }, 71 | { GLFW_HAT_RIGHT, GLFW_HAT_RIGHT_UP, GLFW_HAT_RIGHT_DOWN }, 72 | }; 73 | 74 | const int hat = (code - ABS_HAT0X) / 2; 75 | const int axis = (code - ABS_HAT0X) % 2; 76 | int* state = js->linjs.hats[hat]; 77 | 78 | // NOTE: Looking at several input drivers, it seems all hat events use 79 | // -1 for left / up, 0 for centered and 1 for right / down 80 | if (value == 0) 81 | state[axis] = 0; 82 | else if (value < 0) 83 | state[axis] = 1; 84 | else if (value > 0) 85 | state[axis] = 2; 86 | 87 | _glfwInputJoystickHat(js, index, stateMap[state[0]][state[1]]); 88 | } 89 | else 90 | { 91 | const struct input_absinfo* info = &js->linjs.absInfo[code]; 92 | float normalized = value; 93 | 94 | const int range = info->maximum - info->minimum; 95 | if (range) 96 | { 97 | // Normalize to 0.0 -> 1.0 98 | normalized = (normalized - info->minimum) / range; 99 | // Normalize to -1.0 -> 1.0 100 | normalized = normalized * 2.0f - 1.0f; 101 | } 102 | 103 | _glfwInputJoystickAxis(js, index, normalized); 104 | } 105 | } 106 | 107 | // Poll state of absolute axes 108 | // 109 | static void pollAbsState(_GLFWjoystick* js) 110 | { 111 | for (int code = 0; code < ABS_CNT; code++) 112 | { 113 | if (js->linjs.absMap[code] < 0) 114 | continue; 115 | 116 | struct input_absinfo* info = &js->linjs.absInfo[code]; 117 | 118 | if (ioctl(js->linjs.fd, EVIOCGABS(code), info) < 0) 119 | continue; 120 | 121 | handleAbsEvent(js, code, info->value); 122 | } 123 | } 124 | 125 | #define isBitSet(bit, arr) (arr[(bit) / 8] & (1 << ((bit) % 8))) 126 | 127 | // Attempt to open the specified joystick device 128 | // 129 | static GLFWbool openJoystickDevice(const char* path) 130 | { 131 | for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) 132 | { 133 | if (!_glfw.joysticks[jid].connected) 134 | continue; 135 | if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) 136 | return GLFW_FALSE; 137 | } 138 | 139 | _GLFWjoystickLinux linjs = {0}; 140 | linjs.fd = open(path, O_RDONLY | O_NONBLOCK); 141 | if (linjs.fd == -1) 142 | return GLFW_FALSE; 143 | 144 | char evBits[(EV_CNT + 7) / 8] = {0}; 145 | char keyBits[(KEY_CNT + 7) / 8] = {0}; 146 | char absBits[(ABS_CNT + 7) / 8] = {0}; 147 | struct input_id id; 148 | 149 | if (ioctl(linjs.fd, EVIOCGBIT(0, sizeof(evBits)), evBits) < 0 || 150 | ioctl(linjs.fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) < 0 || 151 | ioctl(linjs.fd, EVIOCGBIT(EV_ABS, sizeof(absBits)), absBits) < 0 || 152 | ioctl(linjs.fd, EVIOCGID, &id) < 0) 153 | { 154 | _glfwInputError(GLFW_PLATFORM_ERROR, 155 | "Linux: Failed to query input device: %s", 156 | strerror(errno)); 157 | close(linjs.fd); 158 | return GLFW_FALSE; 159 | } 160 | 161 | // Ensure this device supports the events expected of a joystick 162 | if (!isBitSet(EV_ABS, evBits)) 163 | { 164 | close(linjs.fd); 165 | return GLFW_FALSE; 166 | } 167 | 168 | char name[256] = ""; 169 | 170 | if (ioctl(linjs.fd, EVIOCGNAME(sizeof(name)), name) < 0) 171 | strncpy(name, "Unknown", sizeof(name)); 172 | 173 | char guid[33] = ""; 174 | 175 | // Generate a joystick GUID that matches the SDL 2.0.5+ one 176 | if (id.vendor && id.product && id.version) 177 | { 178 | sprintf(guid, "%02x%02x0000%02x%02x0000%02x%02x0000%02x%02x0000", 179 | id.bustype & 0xff, id.bustype >> 8, 180 | id.vendor & 0xff, id.vendor >> 8, 181 | id.product & 0xff, id.product >> 8, 182 | id.version & 0xff, id.version >> 8); 183 | } 184 | else 185 | { 186 | sprintf(guid, "%02x%02x0000%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x00", 187 | id.bustype & 0xff, id.bustype >> 8, 188 | name[0], name[1], name[2], name[3], 189 | name[4], name[5], name[6], name[7], 190 | name[8], name[9], name[10]); 191 | } 192 | 193 | int axisCount = 0, buttonCount = 0, hatCount = 0; 194 | 195 | for (int code = BTN_MISC; code < KEY_CNT; code++) 196 | { 197 | if (!isBitSet(code, keyBits)) 198 | continue; 199 | 200 | linjs.keyMap[code - BTN_MISC] = buttonCount; 201 | buttonCount++; 202 | } 203 | 204 | for (int code = 0; code < ABS_CNT; code++) 205 | { 206 | linjs.absMap[code] = -1; 207 | if (!isBitSet(code, absBits)) 208 | continue; 209 | 210 | if (code >= ABS_HAT0X && code <= ABS_HAT3Y) 211 | { 212 | linjs.absMap[code] = hatCount; 213 | hatCount++; 214 | // Skip the Y axis 215 | code++; 216 | } 217 | else 218 | { 219 | if (ioctl(linjs.fd, EVIOCGABS(code), &linjs.absInfo[code]) < 0) 220 | continue; 221 | 222 | linjs.absMap[code] = axisCount; 223 | axisCount++; 224 | } 225 | } 226 | 227 | _GLFWjoystick* js = 228 | _glfwAllocJoystick(name, guid, axisCount, buttonCount, hatCount); 229 | if (!js) 230 | { 231 | close(linjs.fd); 232 | return GLFW_FALSE; 233 | } 234 | 235 | strncpy(linjs.path, path, sizeof(linjs.path) - 1); 236 | memcpy(&js->linjs, &linjs, sizeof(linjs)); 237 | 238 | pollAbsState(js); 239 | 240 | _glfwInputJoystick(js, GLFW_CONNECTED); 241 | return GLFW_TRUE; 242 | } 243 | 244 | #undef isBitSet 245 | 246 | // Frees all resources associated with the specified joystick 247 | // 248 | static void closeJoystick(_GLFWjoystick* js) 249 | { 250 | _glfwInputJoystick(js, GLFW_DISCONNECTED); 251 | close(js->linjs.fd); 252 | _glfwFreeJoystick(js); 253 | } 254 | 255 | // Lexically compare joysticks by name; used by qsort 256 | // 257 | static int compareJoysticks(const void* fp, const void* sp) 258 | { 259 | const _GLFWjoystick* fj = fp; 260 | const _GLFWjoystick* sj = sp; 261 | return strcmp(fj->linjs.path, sj->linjs.path); 262 | } 263 | 264 | 265 | ////////////////////////////////////////////////////////////////////////// 266 | ////// GLFW internal API ////// 267 | ////////////////////////////////////////////////////////////////////////// 268 | 269 | void _glfwDetectJoystickConnectionLinux(void) 270 | { 271 | if (_glfw.linjs.inotify <= 0) 272 | return; 273 | 274 | ssize_t offset = 0; 275 | char buffer[16384]; 276 | const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer)); 277 | 278 | while (size > offset) 279 | { 280 | regmatch_t match; 281 | const struct inotify_event* e = (struct inotify_event*) (buffer + offset); 282 | 283 | offset += sizeof(struct inotify_event) + e->len; 284 | 285 | if (regexec(&_glfw.linjs.regex, e->name, 1, &match, 0) != 0) 286 | continue; 287 | 288 | char path[PATH_MAX]; 289 | snprintf(path, sizeof(path), "/dev/input/%s", e->name); 290 | 291 | if (e->mask & (IN_CREATE | IN_ATTRIB)) 292 | openJoystickDevice(path); 293 | else if (e->mask & IN_DELETE) 294 | { 295 | for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) 296 | { 297 | if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) 298 | { 299 | closeJoystick(_glfw.joysticks + jid); 300 | break; 301 | } 302 | } 303 | } 304 | } 305 | } 306 | 307 | 308 | ////////////////////////////////////////////////////////////////////////// 309 | ////// GLFW platform API ////// 310 | ////////////////////////////////////////////////////////////////////////// 311 | 312 | GLFWbool _glfwInitJoysticksLinux(void) 313 | { 314 | const char* dirname = "/dev/input"; 315 | 316 | _glfw.linjs.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); 317 | if (_glfw.linjs.inotify > 0) 318 | { 319 | // HACK: Register for IN_ATTRIB to get notified when udev is done 320 | // This works well in practice but the true way is libudev 321 | 322 | _glfw.linjs.watch = inotify_add_watch(_glfw.linjs.inotify, 323 | dirname, 324 | IN_CREATE | IN_ATTRIB | IN_DELETE); 325 | } 326 | 327 | // Continue without device connection notifications if inotify fails 328 | 329 | if (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) != 0) 330 | { 331 | _glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex"); 332 | return GLFW_FALSE; 333 | } 334 | 335 | int count = 0; 336 | 337 | DIR* dir = opendir(dirname); 338 | if (dir) 339 | { 340 | struct dirent* entry; 341 | 342 | while ((entry = readdir(dir))) 343 | { 344 | regmatch_t match; 345 | 346 | if (regexec(&_glfw.linjs.regex, entry->d_name, 1, &match, 0) != 0) 347 | continue; 348 | 349 | char path[PATH_MAX]; 350 | 351 | snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name); 352 | 353 | if (openJoystickDevice(path)) 354 | count++; 355 | } 356 | 357 | closedir(dir); 358 | } 359 | 360 | // Continue with no joysticks if enumeration fails 361 | 362 | qsort(_glfw.joysticks, count, sizeof(_GLFWjoystick), compareJoysticks); 363 | return GLFW_TRUE; 364 | } 365 | 366 | void _glfwTerminateJoysticksLinux(void) 367 | { 368 | for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) 369 | { 370 | _GLFWjoystick* js = _glfw.joysticks + jid; 371 | if (js->connected) 372 | closeJoystick(js); 373 | } 374 | 375 | if (_glfw.linjs.inotify > 0) 376 | { 377 | if (_glfw.linjs.watch > 0) 378 | inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch); 379 | 380 | close(_glfw.linjs.inotify); 381 | regfree(&_glfw.linjs.regex); 382 | } 383 | } 384 | 385 | GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode) 386 | { 387 | // Read all queued events (non-blocking) 388 | for (;;) 389 | { 390 | struct input_event e; 391 | 392 | errno = 0; 393 | if (read(js->linjs.fd, &e, sizeof(e)) < 0) 394 | { 395 | // Reset the joystick slot if the device was disconnected 396 | if (errno == ENODEV) 397 | closeJoystick(js); 398 | 399 | break; 400 | } 401 | 402 | if (e.type == EV_SYN) 403 | { 404 | if (e.code == SYN_DROPPED) 405 | _glfw.linjs.dropped = GLFW_TRUE; 406 | else if (e.code == SYN_REPORT) 407 | { 408 | _glfw.linjs.dropped = GLFW_FALSE; 409 | pollAbsState(js); 410 | } 411 | } 412 | 413 | if (_glfw.linjs.dropped) 414 | continue; 415 | 416 | if (e.type == EV_KEY) 417 | handleKeyEvent(js, e.code, e.value); 418 | else if (e.type == EV_ABS) 419 | handleAbsEvent(js, e.code, e.value); 420 | } 421 | 422 | return js->connected; 423 | } 424 | 425 | const char* _glfwGetMappingNameLinux(void) 426 | { 427 | return "Linux"; 428 | } 429 | 430 | void _glfwUpdateGamepadGUIDLinux(char* guid) 431 | { 432 | } 433 | 434 | #endif // GLFW_BUILD_LINUX_JOYSTICK 435 | 436 | -------------------------------------------------------------------------------- /third-party/glfw/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GLFW_LINUX_JOYSTICK_STATE _GLFWjoystickLinux linjs; 32 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs; 33 | 34 | // Linux-specific joystick data 35 | // 36 | typedef struct _GLFWjoystickLinux 37 | { 38 | int fd; 39 | char path[PATH_MAX]; 40 | int keyMap[KEY_CNT - BTN_MISC]; 41 | int absMap[ABS_CNT]; 42 | struct input_absinfo absInfo[ABS_CNT]; 43 | int hats[4][2]; 44 | } _GLFWjoystickLinux; 45 | 46 | // Linux-specific joystick API data 47 | // 48 | typedef struct _GLFWlibraryLinux 49 | { 50 | int inotify; 51 | int watch; 52 | regex_t regex; 53 | GLFWbool dropped; 54 | } _GLFWlibraryLinux; 55 | 56 | void _glfwDetectJoystickConnectionLinux(void); 57 | 58 | GLFWbool _glfwInitJoysticksLinux(void); 59 | void _glfwTerminateJoysticksLinux(void); 60 | GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode); 61 | const char* _glfwGetMappingNameLinux(void); 62 | void _glfwUpdateGamepadGUIDLinux(char* guid); 63 | 64 | -------------------------------------------------------------------------------- /third-party/glfw/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) 40 | { 41 | const _GLFWplatform null = 42 | { 43 | GLFW_PLATFORM_NULL, 44 | _glfwInitNull, 45 | _glfwTerminateNull, 46 | _glfwGetCursorPosNull, 47 | _glfwSetCursorPosNull, 48 | _glfwSetCursorModeNull, 49 | _glfwSetRawMouseMotionNull, 50 | _glfwRawMouseMotionSupportedNull, 51 | _glfwCreateCursorNull, 52 | _glfwCreateStandardCursorNull, 53 | _glfwDestroyCursorNull, 54 | _glfwSetCursorNull, 55 | _glfwGetScancodeNameNull, 56 | _glfwGetKeyScancodeNull, 57 | _glfwSetClipboardStringNull, 58 | _glfwGetClipboardStringNull, 59 | _glfwInitJoysticksNull, 60 | _glfwTerminateJoysticksNull, 61 | _glfwPollJoystickNull, 62 | _glfwGetMappingNameNull, 63 | _glfwUpdateGamepadGUIDNull, 64 | _glfwFreeMonitorNull, 65 | _glfwGetMonitorPosNull, 66 | _glfwGetMonitorContentScaleNull, 67 | _glfwGetMonitorWorkareaNull, 68 | _glfwGetVideoModesNull, 69 | _glfwGetVideoModeNull, 70 | _glfwGetGammaRampNull, 71 | _glfwSetGammaRampNull, 72 | _glfwCreateWindowNull, 73 | _glfwDestroyWindowNull, 74 | _glfwSetWindowTitleNull, 75 | _glfwSetWindowIconNull, 76 | _glfwGetWindowPosNull, 77 | _glfwSetWindowPosNull, 78 | _glfwGetWindowSizeNull, 79 | _glfwSetWindowSizeNull, 80 | _glfwSetWindowSizeLimitsNull, 81 | _glfwSetWindowAspectRatioNull, 82 | _glfwGetFramebufferSizeNull, 83 | _glfwGetWindowFrameSizeNull, 84 | _glfwGetWindowContentScaleNull, 85 | _glfwIconifyWindowNull, 86 | _glfwRestoreWindowNull, 87 | _glfwMaximizeWindowNull, 88 | _glfwShowWindowNull, 89 | _glfwHideWindowNull, 90 | _glfwRequestWindowAttentionNull, 91 | _glfwFocusWindowNull, 92 | _glfwSetWindowMonitorNull, 93 | _glfwWindowFocusedNull, 94 | _glfwWindowIconifiedNull, 95 | _glfwWindowVisibleNull, 96 | _glfwWindowMaximizedNull, 97 | _glfwWindowHoveredNull, 98 | _glfwFramebufferTransparentNull, 99 | _glfwGetWindowOpacityNull, 100 | _glfwSetWindowResizableNull, 101 | _glfwSetWindowDecoratedNull, 102 | _glfwSetWindowFloatingNull, 103 | _glfwSetWindowOpacityNull, 104 | _glfwSetWindowMousePassthroughNull, 105 | _glfwPollEventsNull, 106 | _glfwWaitEventsNull, 107 | _glfwWaitEventsTimeoutNull, 108 | _glfwPostEmptyEventNull, 109 | _glfwGetEGLPlatformNull, 110 | _glfwGetEGLNativeDisplayNull, 111 | _glfwGetEGLNativeWindowNull, 112 | _glfwGetRequiredInstanceExtensionsNull, 113 | _glfwGetPhysicalDevicePresentationSupportNull, 114 | _glfwCreateWindowSurfaceNull, 115 | }; 116 | 117 | *platform = null; 118 | return GLFW_TRUE; 119 | } 120 | 121 | int _glfwInitNull(void) 122 | { 123 | _glfwPollMonitorsNull(); 124 | return GLFW_TRUE; 125 | } 126 | 127 | void _glfwTerminateNull(void) 128 | { 129 | free(_glfw.null.clipboardString); 130 | _glfwTerminateOSMesa(); 131 | _glfwTerminateEGL(); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /third-party/glfw/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | GLFWbool _glfwInitJoysticksNull(void) 37 | { 38 | return GLFW_TRUE; 39 | } 40 | 41 | void _glfwTerminateJoysticksNull(void) 42 | { 43 | } 44 | 45 | GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode) 46 | { 47 | return GLFW_FALSE; 48 | } 49 | 50 | const char* _glfwGetMappingNameNull(void) 51 | { 52 | return ""; 53 | } 54 | 55 | void _glfwUpdateGamepadGUIDNull(char* guid) 56 | { 57 | } 58 | 59 | -------------------------------------------------------------------------------- /third-party/glfw/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | GLFWbool _glfwInitJoysticksNull(void); 28 | void _glfwTerminateJoysticksNull(void); 29 | GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode); 30 | const char* _glfwGetMappingNameNull(void); 31 | void _glfwUpdateGamepadGUIDNull(char* guid); 32 | 33 | -------------------------------------------------------------------------------- /third-party/glfw/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | // The the sole (fake) video mode of our (sole) fake monitor 37 | // 38 | static GLFWvidmode getVideoMode(void) 39 | { 40 | GLFWvidmode mode; 41 | mode.width = 1920; 42 | mode.height = 1080; 43 | mode.redBits = 8; 44 | mode.greenBits = 8; 45 | mode.blueBits = 8; 46 | mode.refreshRate = 60; 47 | return mode; 48 | } 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | ////// GLFW internal API ////// 52 | ////////////////////////////////////////////////////////////////////////// 53 | 54 | void _glfwPollMonitorsNull(void) 55 | { 56 | const float dpi = 141.f; 57 | const GLFWvidmode mode = getVideoMode(); 58 | _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0", 59 | (int) (mode.width * 25.4f / dpi), 60 | (int) (mode.height * 25.4f / dpi)); 61 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST); 62 | } 63 | 64 | ////////////////////////////////////////////////////////////////////////// 65 | ////// GLFW platform API ////// 66 | ////////////////////////////////////////////////////////////////////////// 67 | 68 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor) 69 | { 70 | _glfwFreeGammaArrays(&monitor->null.ramp); 71 | } 72 | 73 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos) 74 | { 75 | if (xpos) 76 | *xpos = 0; 77 | if (ypos) 78 | *ypos = 0; 79 | } 80 | 81 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, 82 | float* xscale, float* yscale) 83 | { 84 | if (xscale) 85 | *xscale = 1.f; 86 | if (yscale) 87 | *yscale = 1.f; 88 | } 89 | 90 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, 91 | int* xpos, int* ypos, 92 | int* width, int* height) 93 | { 94 | const GLFWvidmode mode = getVideoMode(); 95 | 96 | if (xpos) 97 | *xpos = 0; 98 | if (ypos) 99 | *ypos = 10; 100 | if (width) 101 | *width = mode.width; 102 | if (height) 103 | *height = mode.height - 10; 104 | } 105 | 106 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found) 107 | { 108 | GLFWvidmode* mode = _glfw_calloc(1, sizeof(GLFWvidmode)); 109 | *mode = getVideoMode(); 110 | *found = 1; 111 | return mode; 112 | } 113 | 114 | void _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode) 115 | { 116 | *mode = getVideoMode(); 117 | } 118 | 119 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 120 | { 121 | if (!monitor->null.ramp.size) 122 | { 123 | unsigned int i; 124 | 125 | _glfwAllocGammaArrays(&monitor->null.ramp, 256); 126 | 127 | for (i = 0; i < monitor->null.ramp.size; i++) 128 | { 129 | const float gamma = 2.2f; 130 | float value; 131 | value = i / (float) (monitor->null.ramp.size - 1); 132 | value = powf(value, 1.f / gamma) * 65535.f + 0.5f; 133 | value = _glfw_fminf(value, 65535.f); 134 | 135 | monitor->null.ramp.red[i] = (unsigned short) value; 136 | monitor->null.ramp.green[i] = (unsigned short) value; 137 | monitor->null.ramp.blue[i] = (unsigned short) value; 138 | } 139 | } 140 | 141 | _glfwAllocGammaArrays(ramp, monitor->null.ramp.size); 142 | memcpy(ramp->red, monitor->null.ramp.red, sizeof(short) * ramp->size); 143 | memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size); 144 | memcpy(ramp->blue, monitor->null.ramp.blue, sizeof(short) * ramp->size); 145 | return GLFW_TRUE; 146 | } 147 | 148 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 149 | { 150 | if (monitor->null.ramp.size != ramp->size) 151 | { 152 | _glfwInputError(GLFW_PLATFORM_ERROR, 153 | "Null: Gamma ramp size must match current ramp size"); 154 | return; 155 | } 156 | 157 | memcpy(monitor->null.ramp.red, ramp->red, sizeof(short) * ramp->size); 158 | memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size); 159 | memcpy(monitor->null.ramp.blue, ramp->blue, sizeof(short) * ramp->size); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /third-party/glfw/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLFW_NULL_WINDOW_STATE _GLFWwindowNull null; 29 | #define GLFW_NULL_LIBRARY_WINDOW_STATE _GLFWlibraryNull null; 30 | #define GLFW_NULL_MONITOR_STATE _GLFWmonitorNull null; 31 | 32 | #define GLFW_NULL_CONTEXT_STATE 33 | #define GLFW_NULL_CURSOR_STATE 34 | #define GLFW_NULL_LIBRARY_CONTEXT_STATE 35 | 36 | 37 | // Null-specific per-window data 38 | // 39 | typedef struct _GLFWwindowNull 40 | { 41 | int xpos; 42 | int ypos; 43 | int width; 44 | int height; 45 | char* title; 46 | GLFWbool visible; 47 | GLFWbool iconified; 48 | GLFWbool maximized; 49 | GLFWbool resizable; 50 | GLFWbool decorated; 51 | GLFWbool floating; 52 | GLFWbool transparent; 53 | float opacity; 54 | } _GLFWwindowNull; 55 | 56 | // Null-specific per-monitor data 57 | // 58 | typedef struct _GLFWmonitorNull 59 | { 60 | GLFWgammaramp ramp; 61 | } _GLFWmonitorNull; 62 | 63 | // Null-specific global data 64 | // 65 | typedef struct _GLFWlibraryNull 66 | { 67 | int xcursor; 68 | int ycursor; 69 | char* clipboardString; 70 | _GLFWwindow* focusedWindow; 71 | } _GLFWlibraryNull; 72 | 73 | void _glfwPollMonitorsNull(void); 74 | 75 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform); 76 | int _glfwInitNull(void); 77 | void _glfwTerminateNull(void); 78 | 79 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor); 80 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos); 81 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, float* xscale, float* yscale); 82 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); 83 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found); 84 | void _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode); 85 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp); 86 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); 87 | 88 | GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); 89 | void _glfwDestroyWindowNull(_GLFWwindow* window); 90 | void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title); 91 | void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images); 92 | void _glfwSetWindowMonitorNull(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); 93 | void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos); 94 | void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos); 95 | void _glfwGetWindowSizeNull(_GLFWwindow* window, int* width, int* height); 96 | void _glfwSetWindowSizeNull(_GLFWwindow* window, int width, int height); 97 | void _glfwSetWindowSizeLimitsNull(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); 98 | void _glfwSetWindowAspectRatioNull(_GLFWwindow* window, int n, int d); 99 | void _glfwGetFramebufferSizeNull(_GLFWwindow* window, int* width, int* height); 100 | void _glfwGetWindowFrameSizeNull(_GLFWwindow* window, int* left, int* top, int* right, int* bottom); 101 | void _glfwGetWindowContentScaleNull(_GLFWwindow* window, float* xscale, float* yscale); 102 | void _glfwIconifyWindowNull(_GLFWwindow* window); 103 | void _glfwRestoreWindowNull(_GLFWwindow* window); 104 | void _glfwMaximizeWindowNull(_GLFWwindow* window); 105 | GLFWbool _glfwWindowMaximizedNull(_GLFWwindow* window); 106 | GLFWbool _glfwWindowHoveredNull(_GLFWwindow* window); 107 | GLFWbool _glfwFramebufferTransparentNull(_GLFWwindow* window); 108 | void _glfwSetWindowResizableNull(_GLFWwindow* window, GLFWbool enabled); 109 | void _glfwSetWindowDecoratedNull(_GLFWwindow* window, GLFWbool enabled); 110 | void _glfwSetWindowFloatingNull(_GLFWwindow* window, GLFWbool enabled); 111 | void _glfwSetWindowMousePassthroughNull(_GLFWwindow* window, GLFWbool enabled); 112 | float _glfwGetWindowOpacityNull(_GLFWwindow* window); 113 | void _glfwSetWindowOpacityNull(_GLFWwindow* window, float opacity); 114 | void _glfwSetRawMouseMotionNull(_GLFWwindow *window, GLFWbool enabled); 115 | GLFWbool _glfwRawMouseMotionSupportedNull(void); 116 | void _glfwShowWindowNull(_GLFWwindow* window); 117 | void _glfwRequestWindowAttentionNull(_GLFWwindow* window); 118 | void _glfwRequestWindowAttentionNull(_GLFWwindow* window); 119 | void _glfwHideWindowNull(_GLFWwindow* window); 120 | void _glfwFocusWindowNull(_GLFWwindow* window); 121 | GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window); 122 | GLFWbool _glfwWindowIconifiedNull(_GLFWwindow* window); 123 | GLFWbool _glfwWindowVisibleNull(_GLFWwindow* window); 124 | void _glfwPollEventsNull(void); 125 | void _glfwWaitEventsNull(void); 126 | void _glfwWaitEventsTimeoutNull(double timeout); 127 | void _glfwPostEmptyEventNull(void); 128 | void _glfwGetCursorPosNull(_GLFWwindow* window, double* xpos, double* ypos); 129 | void _glfwSetCursorPosNull(_GLFWwindow* window, double x, double y); 130 | void _glfwSetCursorModeNull(_GLFWwindow* window, int mode); 131 | GLFWbool _glfwCreateCursorNull(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); 132 | GLFWbool _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape); 133 | void _glfwDestroyCursorNull(_GLFWcursor* cursor); 134 | void _glfwSetCursorNull(_GLFWwindow* window, _GLFWcursor* cursor); 135 | void _glfwSetClipboardStringNull(const char* string); 136 | const char* _glfwGetClipboardStringNull(void); 137 | const char* _glfwGetScancodeNameNull(int scancode); 138 | int _glfwGetKeyScancodeNull(int key); 139 | 140 | EGLenum _glfwGetEGLPlatformNull(EGLint** attribs); 141 | EGLNativeDisplayType _glfwGetEGLNativeDisplayNull(void); 142 | EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window); 143 | 144 | void _glfwGetRequiredInstanceExtensionsNull(char** extensions); 145 | GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); 146 | VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); 147 | 148 | void _glfwPollMonitorsNull(void); 149 | 150 | -------------------------------------------------------------------------------- /third-party/glfw/osmesa_context.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "internal.h" 35 | 36 | 37 | static void makeContextCurrentOSMesa(_GLFWwindow* window) 38 | { 39 | if (window) 40 | { 41 | int width, height; 42 | _glfw.platform.getFramebufferSize(window, &width, &height); 43 | 44 | // Check to see if we need to allocate a new buffer 45 | if ((window->context.osmesa.buffer == NULL) || 46 | (width != window->context.osmesa.width) || 47 | (height != window->context.osmesa.height)) 48 | { 49 | _glfw_free(window->context.osmesa.buffer); 50 | 51 | // Allocate the new buffer (width * height * 8-bit RGBA) 52 | window->context.osmesa.buffer = _glfw_calloc(4, (size_t) width * height); 53 | window->context.osmesa.width = width; 54 | window->context.osmesa.height = height; 55 | } 56 | 57 | if (!OSMesaMakeCurrent(window->context.osmesa.handle, 58 | window->context.osmesa.buffer, 59 | GL_UNSIGNED_BYTE, 60 | width, height)) 61 | { 62 | _glfwInputError(GLFW_PLATFORM_ERROR, 63 | "OSMesa: Failed to make context current"); 64 | return; 65 | } 66 | } 67 | 68 | _glfwPlatformSetTls(&_glfw.contextSlot, window); 69 | } 70 | 71 | static GLFWglproc getProcAddressOSMesa(const char* procname) 72 | { 73 | return (GLFWglproc) OSMesaGetProcAddress(procname); 74 | } 75 | 76 | static void destroyContextOSMesa(_GLFWwindow* window) 77 | { 78 | if (window->context.osmesa.handle) 79 | { 80 | OSMesaDestroyContext(window->context.osmesa.handle); 81 | window->context.osmesa.handle = NULL; 82 | } 83 | 84 | if (window->context.osmesa.buffer) 85 | { 86 | _glfw_free(window->context.osmesa.buffer); 87 | window->context.osmesa.width = 0; 88 | window->context.osmesa.height = 0; 89 | } 90 | } 91 | 92 | static void swapBuffersOSMesa(_GLFWwindow* window) 93 | { 94 | // No double buffering on OSMesa 95 | } 96 | 97 | static void swapIntervalOSMesa(int interval) 98 | { 99 | // No swap interval on OSMesa 100 | } 101 | 102 | static int extensionSupportedOSMesa(const char* extension) 103 | { 104 | // OSMesa does not have extensions 105 | return GLFW_FALSE; 106 | } 107 | 108 | 109 | ////////////////////////////////////////////////////////////////////////// 110 | ////// GLFW internal API ////// 111 | ////////////////////////////////////////////////////////////////////////// 112 | 113 | GLFWbool _glfwInitOSMesa(void) 114 | { 115 | int i; 116 | const char* sonames[] = 117 | { 118 | #if defined(_GLFW_OSMESA_LIBRARY) 119 | _GLFW_OSMESA_LIBRARY, 120 | #elif defined(_WIN32) 121 | "libOSMesa.dll", 122 | "OSMesa.dll", 123 | #elif defined(__APPLE__) 124 | "libOSMesa.8.dylib", 125 | #elif defined(__CYGWIN__) 126 | "libOSMesa-8.so", 127 | #elif defined(__OpenBSD__) || defined(__NetBSD__) 128 | "libOSMesa.so", 129 | #else 130 | "libOSMesa.so.8", 131 | "libOSMesa.so.6", 132 | #endif 133 | NULL 134 | }; 135 | 136 | if (_glfw.osmesa.handle) 137 | return GLFW_TRUE; 138 | 139 | for (i = 0; sonames[i]; i++) 140 | { 141 | _glfw.osmesa.handle = _glfwPlatformLoadModule(sonames[i]); 142 | if (_glfw.osmesa.handle) 143 | break; 144 | } 145 | 146 | if (!_glfw.osmesa.handle) 147 | { 148 | _glfwInputError(GLFW_API_UNAVAILABLE, "OSMesa: Library not found"); 149 | return GLFW_FALSE; 150 | } 151 | 152 | _glfw.osmesa.CreateContextExt = (PFN_OSMesaCreateContextExt) 153 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaCreateContextExt"); 154 | _glfw.osmesa.CreateContextAttribs = (PFN_OSMesaCreateContextAttribs) 155 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaCreateContextAttribs"); 156 | _glfw.osmesa.DestroyContext = (PFN_OSMesaDestroyContext) 157 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaDestroyContext"); 158 | _glfw.osmesa.MakeCurrent = (PFN_OSMesaMakeCurrent) 159 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaMakeCurrent"); 160 | _glfw.osmesa.GetColorBuffer = (PFN_OSMesaGetColorBuffer) 161 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaGetColorBuffer"); 162 | _glfw.osmesa.GetDepthBuffer = (PFN_OSMesaGetDepthBuffer) 163 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaGetDepthBuffer"); 164 | _glfw.osmesa.GetProcAddress = (PFN_OSMesaGetProcAddress) 165 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaGetProcAddress"); 166 | 167 | if (!_glfw.osmesa.CreateContextExt || 168 | !_glfw.osmesa.DestroyContext || 169 | !_glfw.osmesa.MakeCurrent || 170 | !_glfw.osmesa.GetColorBuffer || 171 | !_glfw.osmesa.GetDepthBuffer || 172 | !_glfw.osmesa.GetProcAddress) 173 | { 174 | _glfwInputError(GLFW_PLATFORM_ERROR, 175 | "OSMesa: Failed to load required entry points"); 176 | 177 | _glfwTerminateOSMesa(); 178 | return GLFW_FALSE; 179 | } 180 | 181 | return GLFW_TRUE; 182 | } 183 | 184 | void _glfwTerminateOSMesa(void) 185 | { 186 | if (_glfw.osmesa.handle) 187 | { 188 | _glfwPlatformFreeModule(_glfw.osmesa.handle); 189 | _glfw.osmesa.handle = NULL; 190 | } 191 | } 192 | 193 | #define SET_ATTRIB(a, v) \ 194 | { \ 195 | assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ 196 | attribs[index++] = a; \ 197 | attribs[index++] = v; \ 198 | } 199 | 200 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 201 | const _GLFWctxconfig* ctxconfig, 202 | const _GLFWfbconfig* fbconfig) 203 | { 204 | OSMesaContext share = NULL; 205 | const int accumBits = fbconfig->accumRedBits + 206 | fbconfig->accumGreenBits + 207 | fbconfig->accumBlueBits + 208 | fbconfig->accumAlphaBits; 209 | 210 | if (ctxconfig->client == GLFW_OPENGL_ES_API) 211 | { 212 | _glfwInputError(GLFW_API_UNAVAILABLE, 213 | "OSMesa: OpenGL ES is not available on OSMesa"); 214 | return GLFW_FALSE; 215 | } 216 | 217 | if (ctxconfig->share) 218 | share = ctxconfig->share->context.osmesa.handle; 219 | 220 | if (OSMesaCreateContextAttribs) 221 | { 222 | int index = 0, attribs[40]; 223 | 224 | SET_ATTRIB(OSMESA_FORMAT, OSMESA_RGBA); 225 | SET_ATTRIB(OSMESA_DEPTH_BITS, fbconfig->depthBits); 226 | SET_ATTRIB(OSMESA_STENCIL_BITS, fbconfig->stencilBits); 227 | SET_ATTRIB(OSMESA_ACCUM_BITS, accumBits); 228 | 229 | if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) 230 | { 231 | SET_ATTRIB(OSMESA_PROFILE, OSMESA_CORE_PROFILE); 232 | } 233 | else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) 234 | { 235 | SET_ATTRIB(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); 236 | } 237 | 238 | if (ctxconfig->major != 1 || ctxconfig->minor != 0) 239 | { 240 | SET_ATTRIB(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); 241 | SET_ATTRIB(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); 242 | } 243 | 244 | if (ctxconfig->forward) 245 | { 246 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 247 | "OSMesa: Forward-compatible contexts not supported"); 248 | return GLFW_FALSE; 249 | } 250 | 251 | SET_ATTRIB(0, 0); 252 | 253 | window->context.osmesa.handle = 254 | OSMesaCreateContextAttribs(attribs, share); 255 | } 256 | else 257 | { 258 | if (ctxconfig->profile) 259 | { 260 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 261 | "OSMesa: OpenGL profiles unavailable"); 262 | return GLFW_FALSE; 263 | } 264 | 265 | window->context.osmesa.handle = 266 | OSMesaCreateContextExt(OSMESA_RGBA, 267 | fbconfig->depthBits, 268 | fbconfig->stencilBits, 269 | accumBits, 270 | share); 271 | } 272 | 273 | if (window->context.osmesa.handle == NULL) 274 | { 275 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 276 | "OSMesa: Failed to create context"); 277 | return GLFW_FALSE; 278 | } 279 | 280 | window->context.makeCurrent = makeContextCurrentOSMesa; 281 | window->context.swapBuffers = swapBuffersOSMesa; 282 | window->context.swapInterval = swapIntervalOSMesa; 283 | window->context.extensionSupported = extensionSupportedOSMesa; 284 | window->context.getProcAddress = getProcAddressOSMesa; 285 | window->context.destroy = destroyContextOSMesa; 286 | 287 | return GLFW_TRUE; 288 | } 289 | 290 | #undef SET_ATTRIB 291 | 292 | 293 | ////////////////////////////////////////////////////////////////////////// 294 | ////// GLFW native API ////// 295 | ////////////////////////////////////////////////////////////////////////// 296 | 297 | GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* handle, int* width, 298 | int* height, int* format, void** buffer) 299 | { 300 | void* mesaBuffer; 301 | GLint mesaWidth, mesaHeight, mesaFormat; 302 | _GLFWwindow* window = (_GLFWwindow*) handle; 303 | assert(window != NULL); 304 | 305 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 306 | 307 | if (window->context.source != GLFW_OSMESA_CONTEXT_API) 308 | { 309 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 310 | return GLFW_FALSE; 311 | } 312 | 313 | if (!OSMesaGetColorBuffer(window->context.osmesa.handle, 314 | &mesaWidth, &mesaHeight, 315 | &mesaFormat, &mesaBuffer)) 316 | { 317 | _glfwInputError(GLFW_PLATFORM_ERROR, 318 | "OSMesa: Failed to retrieve color buffer"); 319 | return GLFW_FALSE; 320 | } 321 | 322 | if (width) 323 | *width = mesaWidth; 324 | if (height) 325 | *height = mesaHeight; 326 | if (format) 327 | *format = mesaFormat; 328 | if (buffer) 329 | *buffer = mesaBuffer; 330 | 331 | return GLFW_TRUE; 332 | } 333 | 334 | GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* handle, 335 | int* width, int* height, 336 | int* bytesPerValue, 337 | void** buffer) 338 | { 339 | void* mesaBuffer; 340 | GLint mesaWidth, mesaHeight, mesaBytes; 341 | _GLFWwindow* window = (_GLFWwindow*) handle; 342 | assert(window != NULL); 343 | 344 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 345 | 346 | if (window->context.source != GLFW_OSMESA_CONTEXT_API) 347 | { 348 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 349 | return GLFW_FALSE; 350 | } 351 | 352 | if (!OSMesaGetDepthBuffer(window->context.osmesa.handle, 353 | &mesaWidth, &mesaHeight, 354 | &mesaBytes, &mesaBuffer)) 355 | { 356 | _glfwInputError(GLFW_PLATFORM_ERROR, 357 | "OSMesa: Failed to retrieve depth buffer"); 358 | return GLFW_FALSE; 359 | } 360 | 361 | if (width) 362 | *width = mesaWidth; 363 | if (height) 364 | *height = mesaHeight; 365 | if (bytesPerValue) 366 | *bytesPerValue = mesaBytes; 367 | if (buffer) 368 | *buffer = mesaBuffer; 369 | 370 | return GLFW_TRUE; 371 | } 372 | 373 | GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* handle) 374 | { 375 | _GLFWwindow* window = (_GLFWwindow*) handle; 376 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 377 | 378 | if (window->context.source != GLFW_OSMESA_CONTEXT_API) 379 | { 380 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 381 | return NULL; 382 | } 383 | 384 | return window->context.osmesa.handle; 385 | } 386 | 387 | -------------------------------------------------------------------------------- /third-party/glfw/platform.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | // These construct a string literal from individual numeric constants 33 | #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r 34 | #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r) 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | static const struct 41 | { 42 | int ID; 43 | GLFWbool (*connect)(int,_GLFWplatform*); 44 | } supportedPlatforms[] = 45 | { 46 | #if defined(_GLFW_WIN32) 47 | { GLFW_PLATFORM_WIN32, _glfwConnectWin32 }, 48 | #endif 49 | #if defined(_GLFW_COCOA) 50 | { GLFW_PLATFORM_COCOA, _glfwConnectCocoa }, 51 | #endif 52 | #if defined(_GLFW_X11) 53 | { GLFW_PLATFORM_X11, _glfwConnectX11 }, 54 | #endif 55 | #if defined(_GLFW_WAYLAND) 56 | { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland }, 57 | #endif 58 | }; 59 | 60 | GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform) 61 | { 62 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 63 | size_t i; 64 | 65 | if (desiredID != GLFW_ANY_PLATFORM && 66 | desiredID != GLFW_PLATFORM_WIN32 && 67 | desiredID != GLFW_PLATFORM_COCOA && 68 | desiredID != GLFW_PLATFORM_WAYLAND && 69 | desiredID != GLFW_PLATFORM_X11 && 70 | desiredID != GLFW_PLATFORM_NULL) 71 | { 72 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", desiredID); 73 | return GLFW_FALSE; 74 | } 75 | 76 | // Only allow the Null platform if specifically requested 77 | if (desiredID == GLFW_PLATFORM_NULL) 78 | return _glfwConnectNull(desiredID, platform); 79 | else if (count == 0) 80 | { 81 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform"); 82 | return GLFW_FALSE; 83 | } 84 | 85 | if (desiredID == GLFW_ANY_PLATFORM) 86 | { 87 | // If there is exactly one platform available for auto-selection, let it emit the 88 | // error on failure as the platform-specific error description may be more helpful 89 | if (count == 1) 90 | return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform); 91 | 92 | for (i = 0; i < count; i++) 93 | { 94 | if (supportedPlatforms[i].connect(desiredID, platform)) 95 | return GLFW_TRUE; 96 | } 97 | 98 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform"); 99 | } 100 | else 101 | { 102 | for (i = 0; i < count; i++) 103 | { 104 | if (supportedPlatforms[i].ID == desiredID) 105 | return supportedPlatforms[i].connect(desiredID, platform); 106 | } 107 | 108 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported"); 109 | } 110 | 111 | return GLFW_FALSE; 112 | } 113 | 114 | ////////////////////////////////////////////////////////////////////////// 115 | ////// GLFW public API ////// 116 | ////////////////////////////////////////////////////////////////////////// 117 | 118 | GLFWAPI int glfwGetPlatform(void) 119 | { 120 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 121 | return _glfw.platform.platformID; 122 | } 123 | 124 | GLFWAPI int glfwPlatformSupported(int platformID) 125 | { 126 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 127 | size_t i; 128 | 129 | if (platformID != GLFW_PLATFORM_WIN32 && 130 | platformID != GLFW_PLATFORM_COCOA && 131 | platformID != GLFW_PLATFORM_WAYLAND && 132 | platformID != GLFW_PLATFORM_X11 && 133 | platformID != GLFW_PLATFORM_NULL) 134 | { 135 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", platformID); 136 | return GLFW_FALSE; 137 | } 138 | 139 | if (platformID == GLFW_PLATFORM_NULL) 140 | return GLFW_TRUE; 141 | 142 | for (i = 0; i < count; i++) 143 | { 144 | if (platformID == supportedPlatforms[i].ID) 145 | return GLFW_TRUE; 146 | } 147 | 148 | return GLFW_FALSE; 149 | } 150 | 151 | GLFWAPI const char* glfwGetVersionString(void) 152 | { 153 | return _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, 154 | GLFW_VERSION_MINOR, 155 | GLFW_VERSION_REVISION) 156 | #if defined(_GLFW_WIN32) 157 | " Win32 WGL" 158 | #endif 159 | #if defined(_GLFW_COCOA) 160 | " Cocoa NSGL" 161 | #endif 162 | #if defined(_GLFW_WAYLAND) 163 | " Wayland" 164 | #endif 165 | #if defined(_GLFW_X11) 166 | " X11 GLX" 167 | #endif 168 | " Null" 169 | " EGL" 170 | " OSMesa" 171 | #if defined(__MINGW64_VERSION_MAJOR) 172 | " MinGW-w64" 173 | #elif defined(__MINGW32__) 174 | " MinGW" 175 | #elif defined(_MSC_VER) 176 | " VisualC" 177 | #endif 178 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 179 | " hybrid-GPU" 180 | #endif 181 | #if defined(_POSIX_MONOTONIC_CLOCK) 182 | " monotonic" 183 | #endif 184 | #if defined(_GLFW_BUILD_DLL) 185 | #if defined(_WIN32) 186 | " DLL" 187 | #elif defined(__APPLE__) 188 | " dynamic" 189 | #else 190 | " shared" 191 | #endif 192 | #endif 193 | ; 194 | } 195 | 196 | -------------------------------------------------------------------------------- /third-party/glfw/platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #if defined(GLFW_BUILD_WIN32_TIMER) || \ 29 | defined(GLFW_BUILD_WIN32_MODULE) || \ 30 | defined(GLFW_BUILD_WIN32_THREAD) || \ 31 | defined(GLFW_BUILD_COCOA_TIMER) || \ 32 | defined(GLFW_BUILD_POSIX_TIMER) || \ 33 | defined(GLFW_BUILD_POSIX_MODULE) || \ 34 | defined(GLFW_BUILD_POSIX_THREAD) || \ 35 | defined(GLFW_BUILD_POSIX_POLL) || \ 36 | defined(GLFW_BUILD_LINUX_JOYSTICK) 37 | #error "You must not define these; define zero or more _GLFW_ macros instead" 38 | #endif 39 | 40 | #include "null_platform.h" 41 | 42 | #if defined(_GLFW_WIN32) 43 | #include "win32_platform.h" 44 | #else 45 | #define GLFW_WIN32_WINDOW_STATE 46 | #define GLFW_WIN32_MONITOR_STATE 47 | #define GLFW_WIN32_CURSOR_STATE 48 | #define GLFW_WIN32_LIBRARY_WINDOW_STATE 49 | #define GLFW_WGL_CONTEXT_STATE 50 | #define GLFW_WGL_LIBRARY_CONTEXT_STATE 51 | #endif 52 | 53 | #if defined(_GLFW_COCOA) 54 | #include "cocoa_platform.h" 55 | #else 56 | #define GLFW_COCOA_WINDOW_STATE 57 | #define GLFW_COCOA_MONITOR_STATE 58 | #define GLFW_COCOA_CURSOR_STATE 59 | #define GLFW_COCOA_LIBRARY_WINDOW_STATE 60 | #define GLFW_NSGL_CONTEXT_STATE 61 | #define GLFW_NSGL_LIBRARY_CONTEXT_STATE 62 | #endif 63 | 64 | #if defined(_GLFW_WAYLAND) 65 | #include "wl_platform.h" 66 | #else 67 | #define GLFW_WAYLAND_WINDOW_STATE 68 | #define GLFW_WAYLAND_MONITOR_STATE 69 | #define GLFW_WAYLAND_CURSOR_STATE 70 | #define GLFW_WAYLAND_LIBRARY_WINDOW_STATE 71 | #endif 72 | 73 | #if defined(_GLFW_X11) 74 | #include "x11_platform.h" 75 | #else 76 | #define GLFW_X11_WINDOW_STATE 77 | #define GLFW_X11_MONITOR_STATE 78 | #define GLFW_X11_CURSOR_STATE 79 | #define GLFW_X11_LIBRARY_WINDOW_STATE 80 | #define GLFW_GLX_CONTEXT_STATE 81 | #define GLFW_GLX_LIBRARY_CONTEXT_STATE 82 | #endif 83 | 84 | #include "null_joystick.h" 85 | 86 | #if defined(_GLFW_WIN32) 87 | #include "win32_joystick.h" 88 | #else 89 | #define GLFW_WIN32_JOYSTICK_STATE 90 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 91 | #endif 92 | 93 | #if defined(_GLFW_COCOA) 94 | #include "cocoa_joystick.h" 95 | #else 96 | #define GLFW_COCOA_JOYSTICK_STATE 97 | #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE 98 | #endif 99 | 100 | #if (defined(_GLFW_X11) || defined(_GLFW_WAYLAND)) && defined(__linux__) 101 | #define GLFW_BUILD_LINUX_JOYSTICK 102 | #endif 103 | 104 | #if defined(GLFW_BUILD_LINUX_JOYSTICK) 105 | #include "linux_joystick.h" 106 | #else 107 | #define GLFW_LINUX_JOYSTICK_STATE 108 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE 109 | #endif 110 | 111 | #define GLFW_PLATFORM_WINDOW_STATE \ 112 | GLFW_WIN32_WINDOW_STATE \ 113 | GLFW_COCOA_WINDOW_STATE \ 114 | GLFW_WAYLAND_WINDOW_STATE \ 115 | GLFW_X11_WINDOW_STATE \ 116 | GLFW_NULL_WINDOW_STATE \ 117 | 118 | #define GLFW_PLATFORM_MONITOR_STATE \ 119 | GLFW_WIN32_MONITOR_STATE \ 120 | GLFW_COCOA_MONITOR_STATE \ 121 | GLFW_WAYLAND_MONITOR_STATE \ 122 | GLFW_X11_MONITOR_STATE \ 123 | GLFW_NULL_MONITOR_STATE \ 124 | 125 | #define GLFW_PLATFORM_CURSOR_STATE \ 126 | GLFW_WIN32_CURSOR_STATE \ 127 | GLFW_COCOA_CURSOR_STATE \ 128 | GLFW_WAYLAND_CURSOR_STATE \ 129 | GLFW_X11_CURSOR_STATE \ 130 | GLFW_NULL_CURSOR_STATE \ 131 | 132 | #define GLFW_PLATFORM_JOYSTICK_STATE \ 133 | GLFW_WIN32_JOYSTICK_STATE \ 134 | GLFW_COCOA_JOYSTICK_STATE \ 135 | GLFW_LINUX_JOYSTICK_STATE 136 | 137 | #define GLFW_PLATFORM_LIBRARY_WINDOW_STATE \ 138 | GLFW_WIN32_LIBRARY_WINDOW_STATE \ 139 | GLFW_COCOA_LIBRARY_WINDOW_STATE \ 140 | GLFW_WAYLAND_LIBRARY_WINDOW_STATE \ 141 | GLFW_X11_LIBRARY_WINDOW_STATE \ 142 | GLFW_NULL_LIBRARY_WINDOW_STATE \ 143 | 144 | #define GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 145 | GLFW_WIN32_LIBRARY_JOYSTICK_STATE \ 146 | GLFW_COCOA_LIBRARY_JOYSTICK_STATE \ 147 | GLFW_LINUX_LIBRARY_JOYSTICK_STATE 148 | 149 | #define GLFW_PLATFORM_CONTEXT_STATE \ 150 | GLFW_WGL_CONTEXT_STATE \ 151 | GLFW_NSGL_CONTEXT_STATE \ 152 | GLFW_GLX_CONTEXT_STATE 153 | 154 | #define GLFW_PLATFORM_LIBRARY_CONTEXT_STATE \ 155 | GLFW_WGL_LIBRARY_CONTEXT_STATE \ 156 | GLFW_NSGL_LIBRARY_CONTEXT_STATE \ 157 | GLFW_GLX_LIBRARY_CONTEXT_STATE 158 | 159 | #if defined(_WIN32) 160 | #define GLFW_BUILD_WIN32_THREAD 161 | #else 162 | #define GLFW_BUILD_POSIX_THREAD 163 | #endif 164 | 165 | #if defined(GLFW_BUILD_WIN32_THREAD) 166 | #include "win32_thread.h" 167 | #define GLFW_PLATFORM_TLS_STATE GLFW_WIN32_TLS_STATE 168 | #define GLFW_PLATFORM_MUTEX_STATE GLFW_WIN32_MUTEX_STATE 169 | #elif defined(GLFW_BUILD_POSIX_THREAD) 170 | #include "posix_thread.h" 171 | #define GLFW_PLATFORM_TLS_STATE GLFW_POSIX_TLS_STATE 172 | #define GLFW_PLATFORM_MUTEX_STATE GLFW_POSIX_MUTEX_STATE 173 | #endif 174 | 175 | #if defined(_WIN32) 176 | #define GLFW_BUILD_WIN32_TIMER 177 | #elif defined(__APPLE__) 178 | #define GLFW_BUILD_COCOA_TIMER 179 | #else 180 | #define GLFW_BUILD_POSIX_TIMER 181 | #endif 182 | 183 | #if defined(GLFW_BUILD_WIN32_TIMER) 184 | #include "win32_time.h" 185 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_WIN32_LIBRARY_TIMER_STATE 186 | #elif defined(GLFW_BUILD_COCOA_TIMER) 187 | #include "cocoa_time.h" 188 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_COCOA_LIBRARY_TIMER_STATE 189 | #elif defined(GLFW_BUILD_POSIX_TIMER) 190 | #include "posix_time.h" 191 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_POSIX_LIBRARY_TIMER_STATE 192 | #endif 193 | 194 | #if defined(_WIN32) 195 | #define GLFW_BUILD_WIN32_MODULE 196 | #else 197 | #define GLFW_BUILD_POSIX_MODULE 198 | #endif 199 | 200 | #if defined(_GLFW_WAYLAND) || defined(_GLFW_X11) 201 | #define GLFW_BUILD_POSIX_POLL 202 | #endif 203 | 204 | -------------------------------------------------------------------------------- /third-party/glfw/posix_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #if defined(GLFW_BUILD_POSIX_MODULE) 32 | 33 | #include 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | void* _glfwPlatformLoadModule(const char* path) 40 | { 41 | return dlopen(path, RTLD_LAZY | RTLD_LOCAL); 42 | } 43 | 44 | void _glfwPlatformFreeModule(void* module) 45 | { 46 | dlclose(module); 47 | } 48 | 49 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 50 | { 51 | return dlsym(module, name); 52 | } 53 | 54 | #endif // GLFW_BUILD_POSIX_MODULE 55 | 56 | -------------------------------------------------------------------------------- /third-party/glfw/posix_poll.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2022 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #define _GNU_SOURCE 30 | 31 | #include "internal.h" 32 | 33 | #if defined(GLFW_BUILD_POSIX_POLL) 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout) 40 | { 41 | for (;;) 42 | { 43 | if (timeout) 44 | { 45 | const uint64_t base = _glfwPlatformGetTimerValue(); 46 | 47 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) 48 | const time_t seconds = (time_t) *timeout; 49 | const long nanoseconds = (long) ((*timeout - seconds) * 1e9); 50 | const struct timespec ts = { seconds, nanoseconds }; 51 | const int result = ppoll(fds, count, &ts, NULL); 52 | #elif defined(__NetBSD__) 53 | const time_t seconds = (time_t) *timeout; 54 | const long nanoseconds = (long) ((*timeout - seconds) * 1e9); 55 | const struct timespec ts = { seconds, nanoseconds }; 56 | const int result = pollts(fds, count, &ts, NULL); 57 | #else 58 | const int milliseconds = (int) (*timeout * 1e3); 59 | const int result = poll(fds, count, milliseconds); 60 | #endif 61 | const int error = errno; // clock_gettime may overwrite our error 62 | 63 | *timeout -= (_glfwPlatformGetTimerValue() - base) / 64 | (double) _glfwPlatformGetTimerFrequency(); 65 | 66 | if (result > 0) 67 | return GLFW_TRUE; 68 | else if (result == -1 && error != EINTR && error != EAGAIN) 69 | return GLFW_FALSE; 70 | else if (*timeout <= 0.0) 71 | return GLFW_FALSE; 72 | } 73 | else 74 | { 75 | const int result = poll(fds, count, -1); 76 | if (result > 0) 77 | return GLFW_TRUE; 78 | else if (result == -1 && errno != EINTR && errno != EAGAIN) 79 | return GLFW_FALSE; 80 | } 81 | } 82 | } 83 | 84 | #endif // GLFW_BUILD_POSIX_POLL 85 | 86 | -------------------------------------------------------------------------------- /third-party/glfw/posix_poll.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2022 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include 30 | 31 | GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout); 32 | 33 | -------------------------------------------------------------------------------- /third-party/glfw/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_POSIX_THREAD) 33 | 34 | #include 35 | #include 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW platform API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 43 | { 44 | assert(tls->posix.allocated == GLFW_FALSE); 45 | 46 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 47 | { 48 | _glfwInputError(GLFW_PLATFORM_ERROR, 49 | "POSIX: Failed to create context TLS"); 50 | return GLFW_FALSE; 51 | } 52 | 53 | tls->posix.allocated = GLFW_TRUE; 54 | return GLFW_TRUE; 55 | } 56 | 57 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 58 | { 59 | if (tls->posix.allocated) 60 | pthread_key_delete(tls->posix.key); 61 | memset(tls, 0, sizeof(_GLFWtls)); 62 | } 63 | 64 | void* _glfwPlatformGetTls(_GLFWtls* tls) 65 | { 66 | assert(tls->posix.allocated == GLFW_TRUE); 67 | return pthread_getspecific(tls->posix.key); 68 | } 69 | 70 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 71 | { 72 | assert(tls->posix.allocated == GLFW_TRUE); 73 | pthread_setspecific(tls->posix.key, value); 74 | } 75 | 76 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 77 | { 78 | assert(mutex->posix.allocated == GLFW_FALSE); 79 | 80 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 81 | { 82 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 83 | return GLFW_FALSE; 84 | } 85 | 86 | return mutex->posix.allocated = GLFW_TRUE; 87 | } 88 | 89 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 90 | { 91 | if (mutex->posix.allocated) 92 | pthread_mutex_destroy(&mutex->posix.handle); 93 | memset(mutex, 0, sizeof(_GLFWmutex)); 94 | } 95 | 96 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 97 | { 98 | assert(mutex->posix.allocated == GLFW_TRUE); 99 | pthread_mutex_lock(&mutex->posix.handle); 100 | } 101 | 102 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 103 | { 104 | assert(mutex->posix.allocated == GLFW_TRUE); 105 | pthread_mutex_unlock(&mutex->posix.handle); 106 | } 107 | 108 | #endif // GLFW_BUILD_POSIX_THREAD 109 | 110 | -------------------------------------------------------------------------------- /third-party/glfw/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_POSIX_TLS_STATE _GLFWtlsPOSIX posix; 31 | #define GLFW_POSIX_MUTEX_STATE _GLFWmutexPOSIX posix; 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | } _GLFWtlsPOSIX; 41 | 42 | // POSIX-specific mutex data 43 | // 44 | typedef struct _GLFWmutexPOSIX 45 | { 46 | GLFWbool allocated; 47 | pthread_mutex_t handle; 48 | } _GLFWmutexPOSIX; 49 | 50 | -------------------------------------------------------------------------------- /third-party/glfw/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_POSIX_TIMER) 33 | 34 | #include 35 | #include 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW platform API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | void _glfwPlatformInitTimer(void) 43 | { 44 | _glfw.timer.posix.clock = CLOCK_REALTIME; 45 | _glfw.timer.posix.frequency = 1000000000; 46 | 47 | #if defined(_POSIX_MONOTONIC_CLOCK) 48 | struct timespec ts; 49 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 50 | _glfw.timer.posix.clock = CLOCK_MONOTONIC; 51 | #endif 52 | } 53 | 54 | uint64_t _glfwPlatformGetTimerValue(void) 55 | { 56 | struct timespec ts; 57 | clock_gettime(_glfw.timer.posix.clock, &ts); 58 | return (uint64_t) ts.tv_sec * _glfw.timer.posix.frequency + (uint64_t) ts.tv_nsec; 59 | } 60 | 61 | uint64_t _glfwPlatformGetTimerFrequency(void) 62 | { 63 | return _glfw.timer.posix.frequency; 64 | } 65 | 66 | #endif // GLFW_BUILD_POSIX_TIMER 67 | 68 | -------------------------------------------------------------------------------- /third-party/glfw/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLFW_POSIX_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix; 29 | 30 | #include 31 | #include 32 | 33 | 34 | // POSIX-specific global timer data 35 | // 36 | typedef struct _GLFWtimerPOSIX 37 | { 38 | clockid_t clock; 39 | uint64_t frequency; 40 | } _GLFWtimerPOSIX; 41 | 42 | -------------------------------------------------------------------------------- /third-party/glfw/vulkan.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #define _GLFW_FIND_LOADER 1 37 | #define _GLFW_REQUIRE_LOADER 2 38 | 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | ////// GLFW internal API ////// 42 | ////////////////////////////////////////////////////////////////////////// 43 | 44 | GLFWbool _glfwInitVulkan(int mode) 45 | { 46 | VkResult err; 47 | VkExtensionProperties* ep; 48 | PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties; 49 | uint32_t i, count; 50 | 51 | if (_glfw.vk.available) 52 | return GLFW_TRUE; 53 | 54 | if (_glfw.hints.init.vulkanLoader) 55 | _glfw.vk.GetInstanceProcAddr = _glfw.hints.init.vulkanLoader; 56 | else 57 | { 58 | #if defined(_GLFW_VULKAN_LIBRARY) 59 | _glfw.vk.handle = _glfwPlatformLoadModule(_GLFW_VULKAN_LIBRARY); 60 | #elif defined(_GLFW_WIN32) 61 | _glfw.vk.handle = _glfwPlatformLoadModule("vulkan-1.dll"); 62 | #elif defined(_GLFW_COCOA) 63 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.1.dylib"); 64 | if (!_glfw.vk.handle) 65 | _glfw.vk.handle = _glfwLoadLocalVulkanLoaderCocoa(); 66 | #elif defined(__OpenBSD__) || defined(__NetBSD__) 67 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so"); 68 | #else 69 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so.1"); 70 | #endif 71 | if (!_glfw.vk.handle) 72 | { 73 | if (mode == _GLFW_REQUIRE_LOADER) 74 | _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found"); 75 | 76 | return GLFW_FALSE; 77 | } 78 | 79 | _glfw.vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) 80 | _glfwPlatformGetModuleSymbol(_glfw.vk.handle, "vkGetInstanceProcAddr"); 81 | if (!_glfw.vk.GetInstanceProcAddr) 82 | { 83 | _glfwInputError(GLFW_API_UNAVAILABLE, 84 | "Vulkan: Loader does not export vkGetInstanceProcAddr"); 85 | 86 | _glfwTerminateVulkan(); 87 | return GLFW_FALSE; 88 | } 89 | } 90 | 91 | vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties) 92 | vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties"); 93 | if (!vkEnumerateInstanceExtensionProperties) 94 | { 95 | _glfwInputError(GLFW_API_UNAVAILABLE, 96 | "Vulkan: Failed to retrieve vkEnumerateInstanceExtensionProperties"); 97 | 98 | _glfwTerminateVulkan(); 99 | return GLFW_FALSE; 100 | } 101 | 102 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); 103 | if (err) 104 | { 105 | // NOTE: This happens on systems with a loader but without any Vulkan ICD 106 | if (mode == _GLFW_REQUIRE_LOADER) 107 | { 108 | _glfwInputError(GLFW_API_UNAVAILABLE, 109 | "Vulkan: Failed to query instance extension count: %s", 110 | _glfwGetVulkanResultString(err)); 111 | } 112 | 113 | _glfwTerminateVulkan(); 114 | return GLFW_FALSE; 115 | } 116 | 117 | ep = _glfw_calloc(count, sizeof(VkExtensionProperties)); 118 | 119 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep); 120 | if (err) 121 | { 122 | _glfwInputError(GLFW_API_UNAVAILABLE, 123 | "Vulkan: Failed to query instance extensions: %s", 124 | _glfwGetVulkanResultString(err)); 125 | 126 | _glfw_free(ep); 127 | _glfwTerminateVulkan(); 128 | return GLFW_FALSE; 129 | } 130 | 131 | for (i = 0; i < count; i++) 132 | { 133 | if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0) 134 | _glfw.vk.KHR_surface = GLFW_TRUE; 135 | else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0) 136 | _glfw.vk.KHR_win32_surface = GLFW_TRUE; 137 | else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0) 138 | _glfw.vk.MVK_macos_surface = GLFW_TRUE; 139 | else if (strcmp(ep[i].extensionName, "VK_EXT_metal_surface") == 0) 140 | _glfw.vk.EXT_metal_surface = GLFW_TRUE; 141 | else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0) 142 | _glfw.vk.KHR_xlib_surface = GLFW_TRUE; 143 | else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0) 144 | _glfw.vk.KHR_xcb_surface = GLFW_TRUE; 145 | else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0) 146 | _glfw.vk.KHR_wayland_surface = GLFW_TRUE; 147 | } 148 | 149 | _glfw_free(ep); 150 | 151 | _glfw.vk.available = GLFW_TRUE; 152 | 153 | _glfw.platform.getRequiredInstanceExtensions(_glfw.vk.extensions); 154 | 155 | return GLFW_TRUE; 156 | } 157 | 158 | void _glfwTerminateVulkan(void) 159 | { 160 | if (_glfw.vk.handle) 161 | _glfwPlatformFreeModule(_glfw.vk.handle); 162 | } 163 | 164 | const char* _glfwGetVulkanResultString(VkResult result) 165 | { 166 | switch (result) 167 | { 168 | case VK_SUCCESS: 169 | return "Success"; 170 | case VK_NOT_READY: 171 | return "A fence or query has not yet completed"; 172 | case VK_TIMEOUT: 173 | return "A wait operation has not completed in the specified time"; 174 | case VK_EVENT_SET: 175 | return "An event is signaled"; 176 | case VK_EVENT_RESET: 177 | return "An event is unsignaled"; 178 | case VK_INCOMPLETE: 179 | return "A return array was too small for the result"; 180 | case VK_ERROR_OUT_OF_HOST_MEMORY: 181 | return "A host memory allocation has failed"; 182 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: 183 | return "A device memory allocation has failed"; 184 | case VK_ERROR_INITIALIZATION_FAILED: 185 | return "Initialization of an object could not be completed for implementation-specific reasons"; 186 | case VK_ERROR_DEVICE_LOST: 187 | return "The logical or physical device has been lost"; 188 | case VK_ERROR_MEMORY_MAP_FAILED: 189 | return "Mapping of a memory object has failed"; 190 | case VK_ERROR_LAYER_NOT_PRESENT: 191 | return "A requested layer is not present or could not be loaded"; 192 | case VK_ERROR_EXTENSION_NOT_PRESENT: 193 | return "A requested extension is not supported"; 194 | case VK_ERROR_FEATURE_NOT_PRESENT: 195 | return "A requested feature is not supported"; 196 | case VK_ERROR_INCOMPATIBLE_DRIVER: 197 | return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible"; 198 | case VK_ERROR_TOO_MANY_OBJECTS: 199 | return "Too many objects of the type have already been created"; 200 | case VK_ERROR_FORMAT_NOT_SUPPORTED: 201 | return "A requested format is not supported on this device"; 202 | case VK_ERROR_SURFACE_LOST_KHR: 203 | return "A surface is no longer available"; 204 | case VK_SUBOPTIMAL_KHR: 205 | return "A swapchain no longer matches the surface properties exactly, but can still be used"; 206 | case VK_ERROR_OUT_OF_DATE_KHR: 207 | return "A surface has changed in such a way that it is no longer compatible with the swapchain"; 208 | case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: 209 | return "The display used by a swapchain does not use the same presentable image layout"; 210 | case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: 211 | return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API"; 212 | case VK_ERROR_VALIDATION_FAILED_EXT: 213 | return "A validation layer found an error"; 214 | default: 215 | return "ERROR: UNKNOWN VULKAN ERROR"; 216 | } 217 | } 218 | 219 | 220 | ////////////////////////////////////////////////////////////////////////// 221 | ////// GLFW public API ////// 222 | ////////////////////////////////////////////////////////////////////////// 223 | 224 | GLFWAPI int glfwVulkanSupported(void) 225 | { 226 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 227 | return _glfwInitVulkan(_GLFW_FIND_LOADER); 228 | } 229 | 230 | GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) 231 | { 232 | assert(count != NULL); 233 | 234 | *count = 0; 235 | 236 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 237 | 238 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 239 | return NULL; 240 | 241 | if (!_glfw.vk.extensions[0]) 242 | return NULL; 243 | 244 | *count = 2; 245 | return (const char**) _glfw.vk.extensions; 246 | } 247 | 248 | GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, 249 | const char* procname) 250 | { 251 | GLFWvkproc proc; 252 | assert(procname != NULL); 253 | 254 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 255 | 256 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 257 | return NULL; 258 | 259 | // NOTE: Vulkan 1.0 and 1.1 vkGetInstanceProcAddr cannot return itself 260 | if (strcmp(procname, "vkGetInstanceProcAddr") == 0) 261 | return (GLFWvkproc) vkGetInstanceProcAddr; 262 | 263 | proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname); 264 | if (!proc) 265 | { 266 | if (_glfw.vk.handle) 267 | proc = (GLFWvkproc) _glfwPlatformGetModuleSymbol(_glfw.vk.handle, procname); 268 | } 269 | 270 | return proc; 271 | } 272 | 273 | GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, 274 | VkPhysicalDevice device, 275 | uint32_t queuefamily) 276 | { 277 | assert(instance != VK_NULL_HANDLE); 278 | assert(device != VK_NULL_HANDLE); 279 | 280 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 281 | 282 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 283 | return GLFW_FALSE; 284 | 285 | if (!_glfw.vk.extensions[0]) 286 | { 287 | _glfwInputError(GLFW_API_UNAVAILABLE, 288 | "Vulkan: Window surface creation extensions not found"); 289 | return GLFW_FALSE; 290 | } 291 | 292 | return _glfw.platform.getPhysicalDevicePresentationSupport(instance, 293 | device, 294 | queuefamily); 295 | } 296 | 297 | GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, 298 | GLFWwindow* handle, 299 | const VkAllocationCallbacks* allocator, 300 | VkSurfaceKHR* surface) 301 | { 302 | _GLFWwindow* window = (_GLFWwindow*) handle; 303 | assert(instance != VK_NULL_HANDLE); 304 | assert(window != NULL); 305 | assert(surface != NULL); 306 | 307 | *surface = VK_NULL_HANDLE; 308 | 309 | _GLFW_REQUIRE_INIT_OR_RETURN(VK_ERROR_INITIALIZATION_FAILED); 310 | 311 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 312 | return VK_ERROR_INITIALIZATION_FAILED; 313 | 314 | if (!_glfw.vk.extensions[0]) 315 | { 316 | _glfwInputError(GLFW_API_UNAVAILABLE, 317 | "Vulkan: Window surface creation extensions not found"); 318 | return VK_ERROR_EXTENSION_NOT_PRESENT; 319 | } 320 | 321 | if (window->context.client != GLFW_NO_API) 322 | { 323 | _glfwInputError(GLFW_INVALID_VALUE, 324 | "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API"); 325 | return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; 326 | } 327 | 328 | return _glfw.platform.createWindowSurface(instance, window, allocator, surface); 329 | } 330 | 331 | -------------------------------------------------------------------------------- /third-party/glfw/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_WIN32_JOYSTICK_STATE _GLFWjoystickWin32 win32; 28 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 29 | 30 | // Joystick element (axis, button or slider) 31 | // 32 | typedef struct _GLFWjoyobjectWin32 33 | { 34 | int offset; 35 | int type; 36 | } _GLFWjoyobjectWin32; 37 | 38 | // Win32-specific per-joystick data 39 | // 40 | typedef struct _GLFWjoystickWin32 41 | { 42 | _GLFWjoyobjectWin32* objects; 43 | int objectCount; 44 | IDirectInputDevice8W* device; 45 | DWORD index; 46 | GUID guid; 47 | } _GLFWjoystickWin32; 48 | 49 | void _glfwDetectJoystickConnectionWin32(void); 50 | void _glfwDetectJoystickDisconnectionWin32(void); 51 | 52 | -------------------------------------------------------------------------------- /third-party/glfw/win32_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // Please use C89 style variable declarations in this file because VS 2010 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #if defined(GLFW_BUILD_WIN32_MODULE) 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void* _glfwPlatformLoadModule(const char* path) 38 | { 39 | return LoadLibraryA(path); 40 | } 41 | 42 | void _glfwPlatformFreeModule(void* module) 43 | { 44 | FreeLibrary((HMODULE) module); 45 | } 46 | 47 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 48 | { 49 | return (GLFWproc) GetProcAddress((HMODULE) module, name); 50 | } 51 | 52 | #endif // GLFW_BUILD_WIN32_MODULE 53 | 54 | -------------------------------------------------------------------------------- /third-party/glfw/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_WIN32_THREAD) 33 | 34 | #include 35 | 36 | 37 | ////////////////////////////////////////////////////////////////////////// 38 | ////// GLFW platform API ////// 39 | ////////////////////////////////////////////////////////////////////////// 40 | 41 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 42 | { 43 | assert(tls->win32.allocated == GLFW_FALSE); 44 | 45 | tls->win32.index = TlsAlloc(); 46 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 47 | { 48 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index"); 49 | return GLFW_FALSE; 50 | } 51 | 52 | tls->win32.allocated = GLFW_TRUE; 53 | return GLFW_TRUE; 54 | } 55 | 56 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 57 | { 58 | if (tls->win32.allocated) 59 | TlsFree(tls->win32.index); 60 | memset(tls, 0, sizeof(_GLFWtls)); 61 | } 62 | 63 | void* _glfwPlatformGetTls(_GLFWtls* tls) 64 | { 65 | assert(tls->win32.allocated == GLFW_TRUE); 66 | return TlsGetValue(tls->win32.index); 67 | } 68 | 69 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 70 | { 71 | assert(tls->win32.allocated == GLFW_TRUE); 72 | TlsSetValue(tls->win32.index, value); 73 | } 74 | 75 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 76 | { 77 | assert(mutex->win32.allocated == GLFW_FALSE); 78 | InitializeCriticalSection(&mutex->win32.section); 79 | return mutex->win32.allocated = GLFW_TRUE; 80 | } 81 | 82 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 83 | { 84 | if (mutex->win32.allocated) 85 | DeleteCriticalSection(&mutex->win32.section); 86 | memset(mutex, 0, sizeof(_GLFWmutex)); 87 | } 88 | 89 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 90 | { 91 | assert(mutex->win32.allocated == GLFW_TRUE); 92 | EnterCriticalSection(&mutex->win32.section); 93 | } 94 | 95 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 96 | { 97 | assert(mutex->win32.allocated == GLFW_TRUE); 98 | LeaveCriticalSection(&mutex->win32.section); 99 | } 100 | 101 | #endif // GLFW_BUILD_WIN32_THREAD 102 | 103 | -------------------------------------------------------------------------------- /third-party/glfw/win32_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32; 31 | #define GLFW_WIN32_MUTEX_STATE _GLFWmutexWin32 win32; 32 | 33 | // Win32-specific thread local storage data 34 | // 35 | typedef struct _GLFWtlsWin32 36 | { 37 | GLFWbool allocated; 38 | DWORD index; 39 | } _GLFWtlsWin32; 40 | 41 | // Win32-specific mutex data 42 | // 43 | typedef struct _GLFWmutexWin32 44 | { 45 | GLFWbool allocated; 46 | CRITICAL_SECTION section; 47 | } _GLFWmutexWin32; 48 | 49 | -------------------------------------------------------------------------------- /third-party/glfw/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_WIN32_TIMER) 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW platform API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | void _glfwPlatformInitTimer(void) 39 | { 40 | QueryPerformanceFrequency((LARGE_INTEGER*) &_glfw.timer.win32.frequency); 41 | } 42 | 43 | uint64_t _glfwPlatformGetTimerValue(void) 44 | { 45 | uint64_t value; 46 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 47 | return value; 48 | } 49 | 50 | uint64_t _glfwPlatformGetTimerFrequency(void) 51 | { 52 | return _glfw.timer.win32.frequency; 53 | } 54 | 55 | #endif // GLFW_BUILD_WIN32_TIMER 56 | 57 | -------------------------------------------------------------------------------- /third-party/glfw/win32_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_WIN32_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32; 31 | 32 | // Win32-specific global timer data 33 | // 34 | typedef struct _GLFWtimerWin32 35 | { 36 | uint64_t frequency; 37 | } _GLFWtimerWin32; 38 | 39 | -------------------------------------------------------------------------------- /third-party/glfw/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_INVALID_CODEPOINT 0xffffffffu 28 | 29 | uint32_t _glfwKeySym2Unicode(unsigned int keysym); 30 | 31 | -------------------------------------------------------------------------------- /third-party/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2024 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /third-party/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty. 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | // May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included. 54 | //#define IMGUI_INCLUDE_IMGUI_USER_H 55 | //#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h" 56 | 57 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 58 | //#define IMGUI_USE_BGRA_PACKED_COLOR 59 | 60 | //---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 61 | //#define IMGUI_USE_WCHAR32 62 | 63 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 64 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 65 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 66 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 67 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. 68 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 69 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 70 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 71 | 72 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 73 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 74 | //#define IMGUI_USE_STB_SPRINTF 75 | 76 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 77 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 78 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 79 | //#define IMGUI_ENABLE_FREETYPE 80 | 81 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 82 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 83 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 84 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 85 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 86 | 87 | //---- Use stb_truetype to build and rasterize the font atlas (default) 88 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 89 | //#define IMGUI_ENABLE_STB_TRUETYPE 90 | 91 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 92 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 93 | /* 94 | #define IM_VEC2_CLASS_EXTRA \ 95 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 96 | operator MyVec2() const { return MyVec2(x,y); } 97 | 98 | #define IM_VEC4_CLASS_EXTRA \ 99 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 100 | operator MyVec4() const { return MyVec4(x,y,z,w); } 101 | */ 102 | //---- ...Or use Dear ImGui's own very basic math operators. 103 | //#define IMGUI_DEFINE_MATH_OPERATORS 104 | 105 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 106 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 107 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 108 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 109 | //#define ImDrawIdx unsigned int 110 | 111 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 112 | //struct ImDrawList; 113 | //struct ImDrawCmd; 114 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 115 | //#define ImDrawCallback MyImDrawCallback 116 | 117 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 118 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 119 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 120 | //#define IM_DEBUG_BREAK __debugbreak() 121 | 122 | //---- Debug Tools: Enable slower asserts 123 | //#define IMGUI_DEBUG_PARANOID 124 | 125 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 126 | /* 127 | namespace ImGui 128 | { 129 | void MyFunction(const char* name, MyMatrix44* mtx); 130 | } 131 | */ 132 | -------------------------------------------------------------------------------- /third-party/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). 8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 9 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). 11 | 12 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 13 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 14 | // Learn about Dear ImGui: 15 | // - FAQ https://dearimgui.com/faq 16 | // - Getting Started https://dearimgui.com/getting-started 17 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 18 | // - Introduction, links and more at the top of imgui.cpp 19 | 20 | #pragma once 21 | #include "imgui.h" // IMGUI_IMPL_API 22 | #ifndef IMGUI_DISABLE 23 | 24 | struct GLFWwindow; 25 | struct GLFWmonitor; 26 | 27 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 28 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 29 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 30 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 31 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 32 | 33 | // Emscripten related initialization phase methods 34 | #ifdef __EMSCRIPTEN__ 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector); 36 | #endif 37 | 38 | // GLFW callbacks install 39 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. 40 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. 41 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 42 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 43 | 44 | // GFLW callbacks options: 45 | // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); 47 | 48 | // GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks) 49 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 50 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 51 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 52 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 53 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 54 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 55 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 56 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 57 | 58 | #endif // #ifndef IMGUI_DISABLE 59 | -------------------------------------------------------------------------------- /third-party/imgui/imgui_impl_vulkan.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for Vulkan 2 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 3 | 4 | // Implemented features: 5 | // [!] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions. 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | 8 | // Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'. 9 | // See imgui_impl_vulkan.cpp file for details. 10 | 11 | // The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification. 12 | // IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/ 13 | 14 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 15 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 16 | // Learn about Dear ImGui: 17 | // - FAQ https://dearimgui.com/faq 18 | // - Getting Started https://dearimgui.com/getting-started 19 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 20 | // - Introduction, links and more at the top of imgui.cpp 21 | 22 | // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. 23 | // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. 24 | // You will use those if you want to use this rendering backend in your engine/app. 25 | // - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by 26 | // the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. 27 | // Read comments in imgui_impl_vulkan.h. 28 | 29 | #pragma once 30 | #ifndef IMGUI_DISABLE 31 | #include "imgui.h" // IMGUI_IMPL_API 32 | 33 | // [Configuration] in order to use a custom Vulkan function loader: 34 | // (1) You'll need to disable default Vulkan function prototypes. 35 | // We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag. 36 | // In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit: 37 | // - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file 38 | // - Or as a compilation flag in your build system 39 | // - Or uncomment here (not recommended because you'd be modifying imgui sources!) 40 | // - Do not simply add it in a .cpp file! 41 | // (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function. 42 | // If you have no idea what this is, leave it alone! 43 | //#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES 44 | 45 | // Convenience support for Volk 46 | // (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().) 47 | //#define IMGUI_IMPL_VULKAN_USE_VOLK 48 | 49 | #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) 50 | #define VK_NO_PROTOTYPES 51 | #endif 52 | #if defined(VK_USE_PLATFORM_WIN32_KHR) && !defined(NOMINMAX) 53 | #define NOMINMAX 54 | #endif 55 | 56 | // Vulkan includes 57 | #ifdef IMGUI_IMPL_VULKAN_USE_VOLK 58 | #include 59 | #else 60 | #include 61 | #endif 62 | #if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering) 63 | #define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING 64 | #endif 65 | 66 | // Initialization data, for ImGui_ImplVulkan_Init() 67 | // - VkDescriptorPool should be created with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 68 | // and must contain a pool size large enough to hold an ImGui VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptor. 69 | // - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure. 70 | // [Please zero-clear before use!] 71 | struct ImGui_ImplVulkan_InitInfo 72 | { 73 | VkInstance Instance; 74 | VkPhysicalDevice PhysicalDevice; 75 | VkDevice Device; 76 | uint32_t QueueFamily; 77 | VkQueue Queue; 78 | VkDescriptorPool DescriptorPool; // See requirements in note above 79 | VkRenderPass RenderPass; // Ignored if using dynamic rendering 80 | uint32_t MinImageCount; // >= 2 81 | uint32_t ImageCount; // >= MinImageCount 82 | VkSampleCountFlagBits MSAASamples; // 0 defaults to VK_SAMPLE_COUNT_1_BIT 83 | 84 | // (Optional) 85 | VkPipelineCache PipelineCache; 86 | uint32_t Subpass; 87 | 88 | // (Optional) Dynamic Rendering 89 | // Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3. 90 | bool UseDynamicRendering; 91 | #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING 92 | VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; 93 | #endif 94 | 95 | // (Optional) Allocation, Debugging 96 | const VkAllocationCallbacks* Allocator; 97 | void (*CheckVkResultFn)(VkResult err); 98 | VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory. 99 | }; 100 | 101 | // Called by user code 102 | IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info); 103 | IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown(); 104 | IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(); 105 | IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE); 106 | IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(); 107 | IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontsTexture(); 108 | IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated) 109 | 110 | // Register a texture (VkDescriptorSet == ImTextureID) 111 | // FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem 112 | // Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions. 113 | IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout); 114 | IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set); 115 | 116 | // Optional: load Vulkan functions with a custom function loader 117 | // This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES 118 | IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr); 119 | 120 | //------------------------------------------------------------------------- 121 | // Internal / Miscellaneous Vulkan Helpers 122 | // (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.) 123 | //------------------------------------------------------------------------- 124 | // You probably do NOT need to use or care about those functions. 125 | // Those functions only exist because: 126 | // 1) they facilitate the readability and maintenance of the multiple main.cpp examples files. 127 | // 2) the multi-viewport / platform window implementation needs them internally. 128 | // Generally we avoid exposing any kind of superfluous high-level helpers in the bindings, 129 | // but it is too much code to duplicate everywhere so we exceptionally expose them. 130 | // 131 | // Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.). 132 | // You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work. 133 | // (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions) 134 | //------------------------------------------------------------------------- 135 | 136 | struct ImGui_ImplVulkanH_Frame; 137 | struct ImGui_ImplVulkanH_Window; 138 | 139 | // Helpers 140 | IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count); 141 | IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator); 142 | IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space); 143 | IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count); 144 | IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode); 145 | 146 | // Helper structure to hold the data needed by one rendering frame 147 | // (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) 148 | // [Please zero-clear before use!] 149 | struct ImGui_ImplVulkanH_Frame 150 | { 151 | VkCommandPool CommandPool; 152 | VkCommandBuffer CommandBuffer; 153 | VkFence Fence; 154 | VkImage Backbuffer; 155 | VkImageView BackbufferView; 156 | VkFramebuffer Framebuffer; 157 | }; 158 | 159 | struct ImGui_ImplVulkanH_FrameSemaphores 160 | { 161 | VkSemaphore ImageAcquiredSemaphore; 162 | VkSemaphore RenderCompleteSemaphore; 163 | }; 164 | 165 | // Helper structure to hold the data needed by one rendering context into one OS window 166 | // (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) 167 | struct ImGui_ImplVulkanH_Window 168 | { 169 | int Width; 170 | int Height; 171 | VkSwapchainKHR Swapchain; 172 | VkSurfaceKHR Surface; 173 | VkSurfaceFormatKHR SurfaceFormat; 174 | VkPresentModeKHR PresentMode; 175 | VkRenderPass RenderPass; 176 | VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo 177 | bool UseDynamicRendering; 178 | bool ClearEnable; 179 | VkClearValue ClearValue; 180 | uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount) 181 | uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count) 182 | uint32_t SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR 183 | uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data) 184 | ImGui_ImplVulkanH_Frame* Frames; 185 | ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores; 186 | 187 | ImGui_ImplVulkanH_Window() 188 | { 189 | memset((void*)this, 0, sizeof(*this)); 190 | PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this. 191 | ClearEnable = true; 192 | } 193 | }; 194 | 195 | #endif // #ifndef IMGUI_DISABLE 196 | -------------------------------------------------------------------------------- /third-party/vma/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /third-party/volk/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2022 Arseny Kapoulkine 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /third-party/volk/README.md: -------------------------------------------------------------------------------- 1 | # 🐺 volk [![Build Status](https://github.com/zeux/volk/workflows/build/badge.svg)](https://github.com/zeux/volk/actions) 2 | 3 | ## Purpose 4 | 5 | volk is a meta-loader for Vulkan. It allows you to dynamically load entrypoints required to use Vulkan 6 | without linking to vulkan-1.dll or statically linking Vulkan loader. Additionally, volk simplifies the use of Vulkan extensions by automatically loading all associated entrypoints. Finally, volk enables loading 7 | Vulkan entrypoints directly from the driver which can increase performance by skipping loader dispatch overhead. 8 | 9 | volk is written in C89 and supports Windows, Linux, Android and macOS (via MoltenVK). 10 | 11 | ## Building 12 | 13 | There are multiple ways to use volk in your project: 14 | 15 | 1. You can just add `volk.c` to your build system. Note that the usual preprocessor defines that enable Vulkan's platform-specific functions (VK_USE_PLATFORM_WIN32_KHR, VK_USE_PLATFORM_XLIB_KHR, VK_USE_PLATFORM_MACOS_MVK, etc) must be passed as desired to the compiler when building `volk.c`. 16 | 2. You can use volk in header-only fashion. Include `volk.h` wherever you want to use Vulkan functions. In exactly one source file, define `VOLK_IMPLEMENTATION` before including `volk.h`. Do not build `volk.c` at all in this case. This method of integrating volk makes it possible to set the platform defines mentioned above with arbitrary (preprocessor) logic in your code. 17 | 3. You can use provided CMake files, with the usage detailed below. 18 | 19 | ## Basic usage 20 | 21 | To use volk, you have to include `volk.h` instead of `vulkan/vulkan.h`; this is necessary to use function definitions from volk. 22 | 23 | If some files in your application include `vulkan/vulkan.h` and don't include `volk.h`, this can result in symbol conflicts; consider defining `VK_NO_PROTOTYPES` when compiling code that uses Vulkan to make sure this doesn't happen. It's also important to make sure that `vulkan-1` is not linked into the application, as this results in symbol name conflicts as well. 24 | 25 | To initialize volk, call this function first: 26 | 27 | ```c++ 28 | VkResult volkInitialize(); 29 | ``` 30 | 31 | This will attempt to load Vulkan loader from the system; if this function returns `VK_SUCCESS` you can proceed to create Vulkan instance. 32 | If this function fails, this means Vulkan loader isn't installed on your system. 33 | 34 | After creating the Vulkan instance using Vulkan API, call this function: 35 | 36 | ```c++ 37 | void volkLoadInstance(VkInstance instance); 38 | ``` 39 | 40 | This function will load all required Vulkan entrypoints, including all extensions; you can use Vulkan from here on as usual. 41 | 42 | ## Optimizing device calls 43 | 44 | If you use volk as described in the previous section, all device-related function calls, such as `vkCmdDraw`, will go through Vulkan loader dispatch code. 45 | This allows you to transparently support multiple VkDevice objects in the same application, but comes at a price of dispatch overhead which can be as high as 7% depending on the driver and application. 46 | 47 | To avoid this, you have two options: 48 | 49 | 1. For applications that use just one VkDevice object, load device-related Vulkan entrypoints directly from the driver with this function: 50 | 51 | ```c++ 52 | void volkLoadDevice(VkDevice device); 53 | ``` 54 | 55 | 2. For applications that use multiple VkDevice objects, load device-related Vulkan entrypoints into a table: 56 | 57 | ```c++ 58 | void volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device); 59 | ``` 60 | 61 | The second option requires you to change the application code to store one `VolkDeviceTable` per `VkDevice` and call functions from this table instead. 62 | 63 | Device entrypoints are loaded using `vkGetDeviceProcAddr`; when no layers are present, this commonly results in most function pointers pointing directly at the driver functions, minimizing the call overhead. When layers are loaded, the entrypoints will point at the implementations in the first applicable layer, so this is compatible with any layers including validation layers. 64 | 65 | Since `volkLoadDevice` overwrites some function pointers with device-specific versions, you can choose to use `volkLoadInstanceOnly` instead of `volkLoadInstance`; when using table-based interface this can also help enforce the usage of the function tables as `volkLoadInstanceOnly` will leave device-specific functions as `NULL`. 66 | 67 | ## CMake support 68 | 69 | If your project uses CMake, volk provides you with targets corresponding to the different use cases: 70 | 71 | 1. Target `volk` is a static library. Any platform defines can be passed to the compiler by setting `VOLK_STATIC_DEFINES`. Example: 72 | ```cmake 73 | if (WIN32) 74 | set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR) 75 | elseif() 76 | ... 77 | endif() 78 | add_subdirectory(volk) 79 | target_link_library(my_application PRIVATE volk) 80 | ``` 81 | 2. Target `volk_headers` is an interface target for the header-only style. Example: 82 | ```cmake 83 | add_subdirectory(volk) 84 | target_link_library(my_application PRIVATE volk_headers) 85 | ``` 86 | and in the code: 87 | ```c 88 | /* ...any logic setting VK_USE_PLATFORM_WIN32_KHR and friends... */ 89 | #define VOLK_IMPLEMENTATION 90 | #include "volk.h" 91 | ``` 92 | 93 | The above example use `add_subdirectory` to include volk into CMake's build tree. This is a good choice if you copy the volk files into your project tree or as a git submodule. 94 | 95 | Volk also supports installation and config-file packages. Installation is disabled by default (so as to not pollute user projects with install rules), and can be enabled by passing `-DVOLK_INSTALL=ON` to CMake. Once installed, do something like `find_package(volk CONFIG REQUIRED)` in your project's CMakeLists.txt. The imported volk targets are called `volk::volk` and `volk::volk_headers`. 96 | 97 | ## License 98 | 99 | This library is available to anybody free of charge, under the terms of MIT License (see LICENSE.md). 100 | -------------------------------------------------------------------------------- /third-party/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright 2014-2022 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | 11 | #ifndef VK_PLATFORM_H_ 12 | #define VK_PLATFORM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif // __cplusplus 18 | 19 | /* 20 | *************************************************************************************************** 21 | * Platform-specific directives and type declarations 22 | *************************************************************************************************** 23 | */ 24 | 25 | /* Platform-specific calling convention macros. 26 | * 27 | * Platforms should define these so that Vulkan clients call Vulkan commands 28 | * with the same calling conventions that the Vulkan implementation expects. 29 | * 30 | * VKAPI_ATTR - Placed before the return type in function declarations. 31 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 32 | * VKAPI_CALL - Placed after the return type in function declarations. 33 | * Useful for MSVC-style calling convention syntax. 34 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 35 | * 36 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 37 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 38 | */ 39 | #if defined(_WIN32) 40 | // On Windows, Vulkan commands use the stdcall convention 41 | #define VKAPI_ATTR 42 | #define VKAPI_CALL __stdcall 43 | #define VKAPI_PTR VKAPI_CALL 44 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 45 | #error "Vulkan is not supported for the 'armeabi' NDK ABI" 46 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 47 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 48 | // calling convention, i.e. float parameters are passed in registers. This 49 | // is true even if the rest of the application passes floats on the stack, 50 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 51 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 52 | #define VKAPI_CALL 53 | #define VKAPI_PTR VKAPI_ATTR 54 | #else 55 | // On other platforms, use the default calling convention 56 | #define VKAPI_ATTR 57 | #define VKAPI_CALL 58 | #define VKAPI_PTR 59 | #endif 60 | 61 | #if !defined(VK_NO_STDDEF_H) 62 | #include 63 | #endif // !defined(VK_NO_STDDEF_H) 64 | 65 | #if !defined(VK_NO_STDINT_H) 66 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 67 | typedef signed __int8 int8_t; 68 | typedef unsigned __int8 uint8_t; 69 | typedef signed __int16 int16_t; 70 | typedef unsigned __int16 uint16_t; 71 | typedef signed __int32 int32_t; 72 | typedef unsigned __int32 uint32_t; 73 | typedef signed __int64 int64_t; 74 | typedef unsigned __int64 uint64_t; 75 | #else 76 | #include 77 | #endif 78 | #endif // !defined(VK_NO_STDINT_H) 79 | 80 | #ifdef __cplusplus 81 | } // extern "C" 82 | #endif // __cplusplus 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /third-party/vulkan/vulkan.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_H_ 2 | #define VULKAN_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2022 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | #include "vk_platform.h" 11 | #include "vulkan_core.h" 12 | 13 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 14 | #include "vulkan_android.h" 15 | #endif 16 | 17 | #ifdef VK_USE_PLATFORM_FUCHSIA 18 | #include 19 | #include "vulkan_fuchsia.h" 20 | #endif 21 | 22 | #ifdef VK_USE_PLATFORM_IOS_MVK 23 | #include "vulkan_ios.h" 24 | #endif 25 | 26 | 27 | #ifdef VK_USE_PLATFORM_MACOS_MVK 28 | #include "vulkan_macos.h" 29 | #endif 30 | 31 | #ifdef VK_USE_PLATFORM_METAL_EXT 32 | #include "vulkan_metal.h" 33 | #endif 34 | 35 | #ifdef VK_USE_PLATFORM_VI_NN 36 | #include "vulkan_vi.h" 37 | #endif 38 | 39 | 40 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 41 | #include "vulkan_wayland.h" 42 | #endif 43 | 44 | 45 | #ifdef VK_USE_PLATFORM_WIN32_KHR 46 | #include 47 | #include "vulkan_win32.h" 48 | #endif 49 | 50 | 51 | #ifdef VK_USE_PLATFORM_XCB_KHR 52 | #include 53 | #include "vulkan_xcb.h" 54 | #endif 55 | 56 | 57 | #ifdef VK_USE_PLATFORM_XLIB_KHR 58 | #include 59 | #include "vulkan_xlib.h" 60 | #endif 61 | 62 | 63 | #ifdef VK_USE_PLATFORM_DIRECTFB_EXT 64 | #include 65 | #include "vulkan_directfb.h" 66 | #endif 67 | 68 | 69 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT 70 | #include 71 | #include 72 | #include "vulkan_xlib_xrandr.h" 73 | #endif 74 | 75 | 76 | #ifdef VK_USE_PLATFORM_GGP 77 | #include 78 | #include "vulkan_ggp.h" 79 | #endif 80 | 81 | 82 | #ifdef VK_USE_PLATFORM_SCREEN_QNX 83 | #include 84 | #include "vulkan_screen.h" 85 | #endif 86 | 87 | #ifdef VK_ENABLE_BETA_EXTENSIONS 88 | #include "vulkan_beta.h" 89 | #endif 90 | 91 | #endif // VULKAN_H_ 92 | -------------------------------------------------------------------------------- /third-party/vulkan/vulkan_win32.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WIN32_H_ 2 | #define VULKAN_WIN32_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2022 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | #define VK_KHR_win32_surface 1 23 | #define VK_KHR_WIN32_SURFACE_SPEC_VERSION 6 24 | #define VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface" 25 | typedef VkFlags VkWin32SurfaceCreateFlagsKHR; 26 | typedef struct VkWin32SurfaceCreateInfoKHR { 27 | VkStructureType sType; 28 | const void* pNext; 29 | VkWin32SurfaceCreateFlagsKHR flags; 30 | HINSTANCE hinstance; 31 | HWND hwnd; 32 | } VkWin32SurfaceCreateInfoKHR; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); 36 | 37 | #ifndef VK_NO_PROTOTYPES 38 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR( 39 | VkInstance instance, 40 | const VkWin32SurfaceCreateInfoKHR* pCreateInfo, 41 | const VkAllocationCallbacks* pAllocator, 42 | VkSurfaceKHR* pSurface); 43 | 44 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR( 45 | VkPhysicalDevice physicalDevice, 46 | uint32_t queueFamilyIndex); 47 | #endif 48 | 49 | 50 | #define VK_KHR_external_memory_win32 1 51 | #define VK_KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 52 | #define VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_KHR_external_memory_win32" 53 | typedef struct VkImportMemoryWin32HandleInfoKHR { 54 | VkStructureType sType; 55 | const void* pNext; 56 | VkExternalMemoryHandleTypeFlagBits handleType; 57 | HANDLE handle; 58 | LPCWSTR name; 59 | } VkImportMemoryWin32HandleInfoKHR; 60 | 61 | typedef struct VkExportMemoryWin32HandleInfoKHR { 62 | VkStructureType sType; 63 | const void* pNext; 64 | const SECURITY_ATTRIBUTES* pAttributes; 65 | DWORD dwAccess; 66 | LPCWSTR name; 67 | } VkExportMemoryWin32HandleInfoKHR; 68 | 69 | typedef struct VkMemoryWin32HandlePropertiesKHR { 70 | VkStructureType sType; 71 | void* pNext; 72 | uint32_t memoryTypeBits; 73 | } VkMemoryWin32HandlePropertiesKHR; 74 | 75 | typedef struct VkMemoryGetWin32HandleInfoKHR { 76 | VkStructureType sType; 77 | const void* pNext; 78 | VkDeviceMemory memory; 79 | VkExternalMemoryHandleTypeFlagBits handleType; 80 | } VkMemoryGetWin32HandleInfoKHR; 81 | 82 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 83 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, HANDLE handle, VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); 84 | 85 | #ifndef VK_NO_PROTOTYPES 86 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleKHR( 87 | VkDevice device, 88 | const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, 89 | HANDLE* pHandle); 90 | 91 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandlePropertiesKHR( 92 | VkDevice device, 93 | VkExternalMemoryHandleTypeFlagBits handleType, 94 | HANDLE handle, 95 | VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); 96 | #endif 97 | 98 | 99 | #define VK_KHR_win32_keyed_mutex 1 100 | #define VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION 1 101 | #define VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_KHR_win32_keyed_mutex" 102 | typedef struct VkWin32KeyedMutexAcquireReleaseInfoKHR { 103 | VkStructureType sType; 104 | const void* pNext; 105 | uint32_t acquireCount; 106 | const VkDeviceMemory* pAcquireSyncs; 107 | const uint64_t* pAcquireKeys; 108 | const uint32_t* pAcquireTimeouts; 109 | uint32_t releaseCount; 110 | const VkDeviceMemory* pReleaseSyncs; 111 | const uint64_t* pReleaseKeys; 112 | } VkWin32KeyedMutexAcquireReleaseInfoKHR; 113 | 114 | 115 | 116 | #define VK_KHR_external_semaphore_win32 1 117 | #define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_SPEC_VERSION 1 118 | #define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME "VK_KHR_external_semaphore_win32" 119 | typedef struct VkImportSemaphoreWin32HandleInfoKHR { 120 | VkStructureType sType; 121 | const void* pNext; 122 | VkSemaphore semaphore; 123 | VkSemaphoreImportFlags flags; 124 | VkExternalSemaphoreHandleTypeFlagBits handleType; 125 | HANDLE handle; 126 | LPCWSTR name; 127 | } VkImportSemaphoreWin32HandleInfoKHR; 128 | 129 | typedef struct VkExportSemaphoreWin32HandleInfoKHR { 130 | VkStructureType sType; 131 | const void* pNext; 132 | const SECURITY_ATTRIBUTES* pAttributes; 133 | DWORD dwAccess; 134 | LPCWSTR name; 135 | } VkExportSemaphoreWin32HandleInfoKHR; 136 | 137 | typedef struct VkD3D12FenceSubmitInfoKHR { 138 | VkStructureType sType; 139 | const void* pNext; 140 | uint32_t waitSemaphoreValuesCount; 141 | const uint64_t* pWaitSemaphoreValues; 142 | uint32_t signalSemaphoreValuesCount; 143 | const uint64_t* pSignalSemaphoreValues; 144 | } VkD3D12FenceSubmitInfoKHR; 145 | 146 | typedef struct VkSemaphoreGetWin32HandleInfoKHR { 147 | VkStructureType sType; 148 | const void* pNext; 149 | VkSemaphore semaphore; 150 | VkExternalSemaphoreHandleTypeFlagBits handleType; 151 | } VkSemaphoreGetWin32HandleInfoKHR; 152 | 153 | typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreWin32HandleKHR)(VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); 154 | typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreWin32HandleKHR)(VkDevice device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 155 | 156 | #ifndef VK_NO_PROTOTYPES 157 | VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreWin32HandleKHR( 158 | VkDevice device, 159 | const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); 160 | 161 | VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreWin32HandleKHR( 162 | VkDevice device, 163 | const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, 164 | HANDLE* pHandle); 165 | #endif 166 | 167 | 168 | #define VK_KHR_external_fence_win32 1 169 | #define VK_KHR_EXTERNAL_FENCE_WIN32_SPEC_VERSION 1 170 | #define VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME "VK_KHR_external_fence_win32" 171 | typedef struct VkImportFenceWin32HandleInfoKHR { 172 | VkStructureType sType; 173 | const void* pNext; 174 | VkFence fence; 175 | VkFenceImportFlags flags; 176 | VkExternalFenceHandleTypeFlagBits handleType; 177 | HANDLE handle; 178 | LPCWSTR name; 179 | } VkImportFenceWin32HandleInfoKHR; 180 | 181 | typedef struct VkExportFenceWin32HandleInfoKHR { 182 | VkStructureType sType; 183 | const void* pNext; 184 | const SECURITY_ATTRIBUTES* pAttributes; 185 | DWORD dwAccess; 186 | LPCWSTR name; 187 | } VkExportFenceWin32HandleInfoKHR; 188 | 189 | typedef struct VkFenceGetWin32HandleInfoKHR { 190 | VkStructureType sType; 191 | const void* pNext; 192 | VkFence fence; 193 | VkExternalFenceHandleTypeFlagBits handleType; 194 | } VkFenceGetWin32HandleInfoKHR; 195 | 196 | typedef VkResult (VKAPI_PTR *PFN_vkImportFenceWin32HandleKHR)(VkDevice device, const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); 197 | typedef VkResult (VKAPI_PTR *PFN_vkGetFenceWin32HandleKHR)(VkDevice device, const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 198 | 199 | #ifndef VK_NO_PROTOTYPES 200 | VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceWin32HandleKHR( 201 | VkDevice device, 202 | const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); 203 | 204 | VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceWin32HandleKHR( 205 | VkDevice device, 206 | const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, 207 | HANDLE* pHandle); 208 | #endif 209 | 210 | 211 | #define VK_NV_external_memory_win32 1 212 | #define VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 213 | #define VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_NV_external_memory_win32" 214 | typedef struct VkImportMemoryWin32HandleInfoNV { 215 | VkStructureType sType; 216 | const void* pNext; 217 | VkExternalMemoryHandleTypeFlagsNV handleType; 218 | HANDLE handle; 219 | } VkImportMemoryWin32HandleInfoNV; 220 | 221 | typedef struct VkExportMemoryWin32HandleInfoNV { 222 | VkStructureType sType; 223 | const void* pNext; 224 | const SECURITY_ATTRIBUTES* pAttributes; 225 | DWORD dwAccess; 226 | } VkExportMemoryWin32HandleInfoNV; 227 | 228 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleNV)(VkDevice device, VkDeviceMemory memory, VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE* pHandle); 229 | 230 | #ifndef VK_NO_PROTOTYPES 231 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( 232 | VkDevice device, 233 | VkDeviceMemory memory, 234 | VkExternalMemoryHandleTypeFlagsNV handleType, 235 | HANDLE* pHandle); 236 | #endif 237 | 238 | 239 | #define VK_NV_win32_keyed_mutex 1 240 | #define VK_NV_WIN32_KEYED_MUTEX_SPEC_VERSION 2 241 | #define VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_NV_win32_keyed_mutex" 242 | typedef struct VkWin32KeyedMutexAcquireReleaseInfoNV { 243 | VkStructureType sType; 244 | const void* pNext; 245 | uint32_t acquireCount; 246 | const VkDeviceMemory* pAcquireSyncs; 247 | const uint64_t* pAcquireKeys; 248 | const uint32_t* pAcquireTimeoutMilliseconds; 249 | uint32_t releaseCount; 250 | const VkDeviceMemory* pReleaseSyncs; 251 | const uint64_t* pReleaseKeys; 252 | } VkWin32KeyedMutexAcquireReleaseInfoNV; 253 | 254 | 255 | 256 | #define VK_EXT_full_screen_exclusive 1 257 | #define VK_EXT_FULL_SCREEN_EXCLUSIVE_SPEC_VERSION 4 258 | #define VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME "VK_EXT_full_screen_exclusive" 259 | 260 | typedef enum VkFullScreenExclusiveEXT { 261 | VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT = 0, 262 | VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT = 1, 263 | VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT = 2, 264 | VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT = 3, 265 | VK_FULL_SCREEN_EXCLUSIVE_MAX_ENUM_EXT = 0x7FFFFFFF 266 | } VkFullScreenExclusiveEXT; 267 | typedef struct VkSurfaceFullScreenExclusiveInfoEXT { 268 | VkStructureType sType; 269 | void* pNext; 270 | VkFullScreenExclusiveEXT fullScreenExclusive; 271 | } VkSurfaceFullScreenExclusiveInfoEXT; 272 | 273 | typedef struct VkSurfaceCapabilitiesFullScreenExclusiveEXT { 274 | VkStructureType sType; 275 | void* pNext; 276 | VkBool32 fullScreenExclusiveSupported; 277 | } VkSurfaceCapabilitiesFullScreenExclusiveEXT; 278 | 279 | typedef struct VkSurfaceFullScreenExclusiveWin32InfoEXT { 280 | VkStructureType sType; 281 | const void* pNext; 282 | HMONITOR hmonitor; 283 | } VkSurfaceFullScreenExclusiveWin32InfoEXT; 284 | 285 | typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes); 286 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain); 287 | typedef VkResult (VKAPI_PTR *PFN_vkReleaseFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain); 288 | typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModes2EXT)(VkDevice device, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkDeviceGroupPresentModeFlagsKHR* pModes); 289 | 290 | #ifndef VK_NO_PROTOTYPES 291 | VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModes2EXT( 292 | VkPhysicalDevice physicalDevice, 293 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, 294 | uint32_t* pPresentModeCount, 295 | VkPresentModeKHR* pPresentModes); 296 | 297 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireFullScreenExclusiveModeEXT( 298 | VkDevice device, 299 | VkSwapchainKHR swapchain); 300 | 301 | VKAPI_ATTR VkResult VKAPI_CALL vkReleaseFullScreenExclusiveModeEXT( 302 | VkDevice device, 303 | VkSwapchainKHR swapchain); 304 | 305 | VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModes2EXT( 306 | VkDevice device, 307 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, 308 | VkDeviceGroupPresentModeFlagsKHR* pModes); 309 | #endif 310 | 311 | 312 | #define VK_NV_acquire_winrt_display 1 313 | #define VK_NV_ACQUIRE_WINRT_DISPLAY_SPEC_VERSION 1 314 | #define VK_NV_ACQUIRE_WINRT_DISPLAY_EXTENSION_NAME "VK_NV_acquire_winrt_display" 315 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireWinrtDisplayNV)(VkPhysicalDevice physicalDevice, VkDisplayKHR display); 316 | typedef VkResult (VKAPI_PTR *PFN_vkGetWinrtDisplayNV)(VkPhysicalDevice physicalDevice, uint32_t deviceRelativeId, VkDisplayKHR* pDisplay); 317 | 318 | #ifndef VK_NO_PROTOTYPES 319 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireWinrtDisplayNV( 320 | VkPhysicalDevice physicalDevice, 321 | VkDisplayKHR display); 322 | 323 | VKAPI_ATTR VkResult VKAPI_CALL vkGetWinrtDisplayNV( 324 | VkPhysicalDevice physicalDevice, 325 | uint32_t deviceRelativeId, 326 | VkDisplayKHR* pDisplay); 327 | #endif 328 | 329 | #ifdef __cplusplus 330 | } 331 | #endif 332 | 333 | #endif 334 | -------------------------------------------------------------------------------- /third-party/vulkan/vulkan_xcb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XCB_H_ 2 | #define VULKAN_XCB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2022 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | #define VK_KHR_xcb_surface 1 23 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 24 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 25 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 26 | typedef struct VkXcbSurfaceCreateInfoKHR { 27 | VkStructureType sType; 28 | const void* pNext; 29 | VkXcbSurfaceCreateFlagsKHR flags; 30 | xcb_connection_t* connection; 31 | xcb_window_t window; 32 | } VkXcbSurfaceCreateInfoKHR; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 36 | 37 | #ifndef VK_NO_PROTOTYPES 38 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 39 | VkInstance instance, 40 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 41 | const VkAllocationCallbacks* pAllocator, 42 | VkSurfaceKHR* pSurface); 43 | 44 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 45 | VkPhysicalDevice physicalDevice, 46 | uint32_t queueFamilyIndex, 47 | xcb_connection_t* connection, 48 | xcb_visualid_t visual_id); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /third-party/vulkan/vulkan_xlib.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_H_ 2 | #define VULKAN_XLIB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2022 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | #define VK_KHR_xlib_surface 1 23 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 24 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 25 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 26 | typedef struct VkXlibSurfaceCreateInfoKHR { 27 | VkStructureType sType; 28 | const void* pNext; 29 | VkXlibSurfaceCreateFlagsKHR flags; 30 | Display* dpy; 31 | Window window; 32 | } VkXlibSurfaceCreateInfoKHR; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 36 | 37 | #ifndef VK_NO_PROTOTYPES 38 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 39 | VkInstance instance, 40 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 41 | const VkAllocationCallbacks* pAllocator, 42 | VkSurfaceKHR* pSurface); 43 | 44 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 45 | VkPhysicalDevice physicalDevice, 46 | uint32_t queueFamilyIndex, 47 | Display* dpy, 48 | VisualID visualID); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | --------------------------------------------------------------------------------