├── .gitattributes ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── base ├── CMakeLists.txt ├── VulkanAndroid.cpp ├── VulkanAndroid.h ├── VulkanBuffer.hpp ├── VulkanDebug.cpp ├── VulkanDebug.h ├── VulkanDevice.hpp ├── VulkanFrameBuffer.hpp ├── VulkanHeightmap.hpp ├── VulkanInitializers.hpp ├── VulkanModel.hpp ├── VulkanSwapChain.hpp ├── VulkanTextOverlay.hpp ├── VulkanTexture.hpp ├── VulkanTools.cpp ├── VulkanTools.h ├── benchmark.hpp ├── camera.hpp ├── frustum.hpp ├── keycodes.hpp ├── threadpool.hpp ├── vulkanexamplebase.cpp └── vulkanexamplebase.h ├── data ├── shaders │ ├── base │ │ ├── textoverlay.frag │ │ ├── textoverlay.frag.spv │ │ ├── textoverlay.vert │ │ └── textoverlay.vert.spv │ ├── composition.frag │ ├── composition.frag.spv │ ├── composition.vert │ ├── composition.vert.spv │ ├── debug.frag │ ├── debug.vert │ ├── deferred.frag │ ├── deferred.frag.spv │ ├── deferred.vert │ ├── deferred.vert.spv │ ├── map.frag │ ├── map.frag.spv │ ├── map.vert │ └── map.vert.spv └── texturesets │ └── default.ktx ├── external ├── assimp │ └── assimp │ │ ├── .editorconfig │ │ ├── Compiler │ │ ├── poppack1.h │ │ ├── pstdint.h │ │ └── pushpack1.h │ │ ├── DefaultLogger.hpp │ │ ├── Exporter.hpp │ │ ├── IOStream.hpp │ │ ├── IOSystem.hpp │ │ ├── Importer.hpp │ │ ├── LogStream.hpp │ │ ├── Logger.hpp │ │ ├── NullLogger.hpp │ │ ├── ProgressHandler.hpp │ │ ├── ai_assert.h │ │ ├── anim.h │ │ ├── camera.h │ │ ├── cexport.h │ │ ├── cfileio.h │ │ ├── cimport.h │ │ ├── color4.h │ │ ├── color4.inl │ │ ├── config.h │ │ ├── defs.h │ │ ├── importerdesc.h │ │ ├── light.h │ │ ├── material.h │ │ ├── material.inl │ │ ├── matrix3x3.h │ │ ├── matrix3x3.inl │ │ ├── matrix4x4.h │ │ ├── matrix4x4.inl │ │ ├── mesh.h │ │ ├── metadata.h │ │ ├── port │ │ └── AndroidJNI │ │ │ └── AndroidJNIIOSystem.h │ │ ├── postprocess.h │ │ ├── quaternion.h │ │ ├── quaternion.inl │ │ ├── scene.h │ │ ├── texture.h │ │ ├── types.h │ │ ├── vector2.h │ │ ├── vector2.inl │ │ ├── vector3.h │ │ ├── vector3.inl │ │ └── version.h ├── imgui │ ├── LICENSE │ ├── README.md │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_internal.h │ ├── stb_rect_pack.h │ ├── stb_textedit.h │ └── stb_truetype.h ├── stb │ └── stb_font_consolas_24_latin1.inl └── vulkan │ ├── vk_platform.h │ ├── vk_sdk_platform.h │ └── vulkan.h └── source ├── Player.cpp ├── Player.h ├── generator ├── BspPartition.cpp ├── BspPartition.h ├── Cell.cpp ├── Cell.h ├── Dungeon.cpp ├── Dungeon.h ├── Room.cpp └── Room.h └── main.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | 65 | # Exclude dirs from githug language statis 66 | data/* linguist-vendored=true 67 | external/* linguist-vendored=true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | build/ 16 | bld/ 17 | [Bb]in/ 18 | [Oo]bj/ 19 | 20 | # CMake 21 | CMakeCache.txt 22 | CMakeFiles 23 | CMakeScripts 24 | Makefile 25 | cmake_install.cmake 26 | install_manifest.txt 27 | 28 | # Roslyn cache directories 29 | *.ide/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | #NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | *_i.c 45 | *_p.c 46 | *_i.h 47 | *.ilk 48 | *.meta 49 | *.obj 50 | *.pch 51 | *.pdb 52 | *.pgc 53 | *.pgd 54 | *.rsp 55 | *.sbr 56 | *.tlb 57 | *.tli 58 | *.tlh 59 | *.tmp 60 | *.tmp_proj 61 | *.log 62 | *.vspscc 63 | *.vssscc 64 | .builds 65 | *.pidb 66 | *.svclog 67 | *.scc 68 | 69 | # Chutzpah Test files 70 | _Chutzpah* 71 | 72 | # Visual C++ cache files 73 | ipch/ 74 | *.aps 75 | *.ncb 76 | *.opensdf 77 | *.opendb 78 | *.sdf 79 | *.cachefile 80 | *.VC.db 81 | *.VC.VC.opendb 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | *.vspx 87 | 88 | # TFS 2012 Local Workspace 89 | $tf/ 90 | 91 | # Guidance Automation Toolkit 92 | *.gpState 93 | 94 | # ReSharper is a .NET coding add-in 95 | _ReSharper*/ 96 | *.[Rr]e[Ss]harper 97 | *.DotSettings.user 98 | 99 | # JustCode is a .NET coding addin-in 100 | .JustCode 101 | 102 | # TeamCity is a build add-in 103 | _TeamCity* 104 | 105 | # DotCover is a Code Coverage Tool 106 | *.dotCover 107 | 108 | # NCrunch 109 | _NCrunch_* 110 | .*crunch*.local.xml 111 | 112 | # MightyMoose 113 | *.mm.* 114 | AutoTest.Net/ 115 | 116 | # Web workbench (sass) 117 | .sass-cache/ 118 | 119 | # Installshield output folder 120 | [Ee]xpress/ 121 | 122 | # DocProject is a documentation generator add-in 123 | DocProject/buildhelp/ 124 | DocProject/Help/*.HxT 125 | DocProject/Help/*.HxC 126 | DocProject/Help/*.hhc 127 | DocProject/Help/*.hhk 128 | DocProject/Help/*.hhp 129 | DocProject/Help/Html2 130 | DocProject/Help/html 131 | 132 | # Click-Once directory 133 | publish/ 134 | 135 | # Publish Web Output 136 | *.[Pp]ublish.xml 137 | *.azurePubxml 138 | ## TODO: Comment the next line if you want to checkin your 139 | ## web deploy settings but do note that will include unencrypted 140 | ## passwords 141 | *.pubxml 142 | 143 | # NuGet Packages 144 | packages/* 145 | *.nupkg 146 | ## TODO: If the tool you use requires repositories.config 147 | ## uncomment the next line 148 | #!packages/repositories.config 149 | 150 | # Enable "build/" folder in the NuGet Packages folder since 151 | # NuGet packages use it for MSBuild targets. 152 | # This line needs to be after the ignore of the build folder 153 | # (and the packages folder if the line above has been uncommented) 154 | !packages/build/ 155 | 156 | # Windows Azure Build Output 157 | csx/ 158 | *.build.csdef 159 | 160 | # Windows Store app package directory 161 | AppPackages/ 162 | 163 | # Others 164 | sql/ 165 | *.Cache 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | 176 | # RIA/Silverlight projects 177 | Generated_Code/ 178 | 179 | # Backup & report files from converting an old project file 180 | # to a newer Visual Studio version. Backup files are not needed, 181 | # because we have git ;-) 182 | _UpgradeReport_Files/ 183 | Backup*/ 184 | UpgradeLog*.XML 185 | UpgradeLog*.htm 186 | 187 | # SQL Server files 188 | *.mdf 189 | *.ldf 190 | 191 | # Business Intelligence projects 192 | *.rdl.data 193 | *.bim.layout 194 | *.bim_*.settings 195 | 196 | # Microsoft Fakes 197 | FakesAssemblies/ 198 | 199 | .vs/ 200 | 201 | # Don't ignore 3d models in obj format 202 | !data/models/*.obj 203 | !data/models/lowpoly/*.obj 204 | !data/models/voyager/*.obj 205 | 206 | # DLLs in bin 207 | !bin/*.dll 208 | 209 | # Android validation layer libraries 210 | android/layers/*/*.so 211 | 212 | # Downloadable assets 213 | vulkan_asset_pack.* 214 | data/textures/hdr/*.* 215 | data/readme.txt 216 | data/models/cerberus/*.* 217 | !data/textures/hdr/README.md 218 | 219 | *.args.json -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/glm"] 2 | path = external/glm 3 | url = https://github.com/g-truc/glm 4 | [submodule "external/gli"] 5 | path = external/gli 6 | url = https://github.com/g-truc/gli 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 2 | cmake_policy(VERSION 2.8) 3 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") 4 | 5 | set(NAME vulkanDungeonCrawler) 6 | 7 | project(${NAME}) 8 | 9 | include_directories(external) 10 | include_directories(external/glm) 11 | include_directories(external/gli) 12 | include_directories(external/assimp) 13 | include_directories(external/imgui) 14 | include_directories(base) 15 | 16 | OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF) 17 | OPTION(USE_WAYLAND_WSI "Build the project using Wayland swapchain" OFF) 18 | 19 | set(RESOURCE_INSTALL_DIR "" CACHE PATH "Path to install resources to (leave empty for running uninstalled)") 20 | 21 | # Use FindVulkan module added with CMAKE 3.7 22 | if (NOT CMAKE_VERSION VERSION_LESS 3.7.0) 23 | message(STATUS "Using module to find Vulkan") 24 | find_package(Vulkan) 25 | endif() 26 | 27 | IF(WIN32) 28 | IF (NOT Vulkan_FOUND) 29 | find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan PATHS ${CMAKE_SOURCE_DIR}/libs/vulkan) 30 | IF (Vulkan_LIBRARY) 31 | set(Vulkan_FOUND ON) 32 | MESSAGE("Using bundled Vulkan library version") 33 | ENDIF() 34 | ENDIF() 35 | find_library(ASSIMP_LIBRARIES NAMES assimp libassimp.dll.a PATHS ${CMAKE_SOURCE_DIR}/libs/assimp) 36 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR") 37 | ELSE(WIN32) 38 | IF (NOT Vulkan_FOUND) 39 | find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib" "${CMAKE_SOURCE_DIR}/libs/vulkan" REQUIRED) 40 | IF (Vulkan_LIBRARY) 41 | set(Vulkan_FOUND ON) 42 | MESSAGE("Using bundled Vulkan library version") 43 | ENDIF() 44 | ENDIF() 45 | find_package(ASSIMP REQUIRED) 46 | find_package(Threads REQUIRED) 47 | IF(USE_D2D_WSI) 48 | MESSAGE("Using direct to display extension...") 49 | add_definitions(-D_DIRECT2DISPLAY) 50 | ELSEIF(USE_WAYLAND_WSI) 51 | find_package(Wayland REQUIRED) 52 | if (NOT WAYLAND_FOUND) 53 | message(FATAL_ERROR "Wayland development package not found") 54 | endif () 55 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WAYLAND_KHR") 56 | include_directories(${WAYLAND_INCLUDE_DIR}) 57 | ELSE(USE_D2D_WSI) 58 | find_package(XCB REQUIRED) 59 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR") 60 | ENDIF(USE_D2D_WSI) 61 | # Todo : android? 62 | ENDIF(WIN32) 63 | 64 | IF (NOT Vulkan_FOUND) 65 | message(FATAL_ERROR "Could not find Vulkan library!") 66 | ELSE() 67 | message(STATUS ${Vulkan_LIBRARY}) 68 | ENDIF() 69 | 70 | # Set preprocessor defines 71 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -D_USE_MATH_DEFINES") 72 | 73 | # Clang specific stuff 74 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 75 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum") 76 | endif() 77 | 78 | # Debug flags 79 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") 80 | if(CMAKE_COMPILER_IS_GNUCXX) 81 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra -Wundef") 82 | endif(CMAKE_COMPILER_IS_GNUCXX) 83 | 84 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 85 | add_definitions(-std=c++11) 86 | 87 | file(GLOB SOURCE *.cpp ) 88 | 89 | # Function for building single example 90 | function(buildExample EXAMPLE_NAME) 91 | # Main 92 | file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_NAME}/*.cpp) 93 | SET(MAIN_CPP source/main.cpp) 94 | # Add shaders 95 | set(SHADER_DIR data/shaders/${EXAMPLE_NAME}) 96 | file(GLOB SHADERS "${SHADER_DIR}/*.vert" "${SHADER_DIR}/*.frag" "${SHADER_DIR}/*.geom" "${SHADER_DIR}/*.tesc" "${SHADER_DIR}/*.tese") 97 | source_group("Shaders" FILES ${SHADERS}) 98 | if(WIN32) 99 | add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${SHADERS}) 100 | target_link_libraries(${EXAMPLE_NAME} base ${Vulkan_LIBRARY} ${ASSIMP_LIBRARIES} ${WINLIBS}) 101 | else(WIN32) 102 | add_executable(${EXAMPLE_NAME} ${MAIN_CPP} ${SOURCE} ${SHADERS}) 103 | target_link_libraries(${EXAMPLE_NAME} base ) 104 | endif(WIN32) 105 | 106 | if(RESOURCE_INSTALL_DIR) 107 | install(TARGETS ${EXAMPLE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) 108 | endif() 109 | endfunction(buildExample) 110 | 111 | # Build all examples 112 | function(buildExamples) 113 | foreach(EXAMPLE ${EXAMPLES}) 114 | buildExample(${EXAMPLE}) 115 | endforeach(EXAMPLE) 116 | endfunction(buildExamples) 117 | 118 | if(RESOURCE_INSTALL_DIR) 119 | add_definitions(-DVK_EXAMPLE_DATA_DIR=\"${RESOURCE_INSTALL_DIR}/\") 120 | install(DIRECTORY data/ DESTINATION ${RESOURCE_INSTALL_DIR}/) 121 | else() 122 | add_definitions(-DVK_EXAMPLE_DATA_DIR=\"${CMAKE_SOURCE_DIR}/data/\") 123 | endif() 124 | 125 | # Compiler specific stuff 126 | IF(MSVC) 127 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") 128 | ENDIF(MSVC) 129 | 130 | IF(WIN32) 131 | # Nothing here (yet) 132 | ELSE(WIN32) 133 | link_libraries(${XCB_LIBRARIES} ${Vulkan_LIBRARY} ${Vulkan_LIBRARY} ${ASSIMP_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 134 | ENDIF(WIN32) 135 | 136 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/") 137 | 138 | add_subdirectory(base) 139 | 140 | set(EXAMPLES 141 | main 142 | ) 143 | 144 | buildExamples() 145 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sascha Willems 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 | # VulkanDungeonCrawler 2 | Playing around with Vulkan and random dungeon generation 3 | 4 | ## Note 5 | This is a personal playground, code may or may not compile and I won't take any pull requests for now. 6 | 7 | ## TODO 8 | - Visibility checks for dungeon cells 9 | - Frustum culling 10 | - Line of sight 11 | - Dynamic command buffer rebuilding 12 | - Based on visibility checks 13 | - Multi threaded 14 | - Different texture sets 15 | - With their own descriptor sets 16 | - gfx 17 | - Normal mapping / parallax mapping 18 | - Shadows 19 | - Proper dungeon crawling movement 20 | - Some basic gameplay 21 | - Better random dungeon generator 22 | - Smaller rooms 23 | - Special rooms 24 | - Doors and keys 25 | - Level entry and exit 26 | - User interface -------------------------------------------------------------------------------- /base/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB BASE_SRC *.cpp) 2 | file(GLOB BASE_HEADERS *.hpp) 3 | 4 | if(WIN32) 5 | add_library(base STATIC ${BASE_SRC}) 6 | target_link_libraries(base ${Vulkan_LIBRARY} ${ASSIMP_LIBRARIES} ${WINLIBS}) 7 | else(WIN32) 8 | add_library(base STATIC ${BASE_SRC}) 9 | target_link_libraries(base ${Vulkan_LIBRARY} ${ASSIMP_LIBRARIES} ${XCB_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 10 | endif(WIN32) -------------------------------------------------------------------------------- /base/VulkanAndroid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Android Vulkan function pointer prototypes 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifndef VULKANANDROID_H 12 | #define VULKANANDROID_H 13 | 14 | // Vulkan needs to be loaded dynamically on android 15 | 16 | #pragma once 17 | 18 | #ifndef VULKANANDROID_HPP 19 | #define VULKANANDROID_HPP 20 | 21 | #include "vulkan/vulkan.h" 22 | 23 | #if defined(__ANDROID__) 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | // Missing from the NDK 31 | namespace std 32 | { 33 | template 34 | std::unique_ptr make_unique(Args&&... args) 35 | { 36 | return std::unique_ptr(new T(std::forward(args)...)); 37 | } 38 | } 39 | 40 | // Global reference to android application object 41 | extern android_app* androidApp; 42 | 43 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "vulkanExample", __VA_ARGS__)) 44 | #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "vulkanExample", __VA_ARGS__)) 45 | #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "vulkanExample", __VA_ARGS__)) 46 | #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "vulkanExample", __VA_ARGS__)) 47 | 48 | // Function pointer prototypes 49 | // Not complete, just the functions used in the caps viewer! 50 | extern PFN_vkCreateInstance vkCreateInstance; 51 | extern PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr; 52 | extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; 53 | extern PFN_vkCreateDevice vkCreateDevice; 54 | extern PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices; 55 | extern PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties; 56 | extern PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties; 57 | extern PFN_vkEnumerateDeviceLayerProperties vkEnumerateDeviceLayerProperties; 58 | extern PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties; 59 | extern PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures; 60 | extern PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties; 61 | extern PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties; 62 | extern PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties; 63 | extern PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties; 64 | extern PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier; 65 | extern PFN_vkCreateShaderModule vkCreateShaderModule; 66 | extern PFN_vkCreateBuffer vkCreateBuffer; 67 | extern PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements; 68 | extern PFN_vkMapMemory vkMapMemory; 69 | extern PFN_vkUnmapMemory vkUnmapMemory; 70 | extern PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges; 71 | extern PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges; 72 | extern PFN_vkBindBufferMemory vkBindBufferMemory; 73 | extern PFN_vkDestroyBuffer vkDestroyBuffer; 74 | extern PFN_vkAllocateMemory vkAllocateMemory; 75 | extern PFN_vkBindImageMemory vkBindImageMemory; 76 | extern PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout; 77 | extern PFN_vkCmdCopyBuffer vkCmdCopyBuffer; 78 | extern PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage; 79 | extern PFN_vkCmdCopyImage vkCmdCopyImage; 80 | extern PFN_vkCmdBlitImage vkCmdBlitImage; 81 | extern PFN_vkCmdClearAttachments vkCmdClearAttachments; 82 | extern PFN_vkCreateSampler vkCreateSampler; 83 | extern PFN_vkDestroySampler vkDestroySampler; 84 | extern PFN_vkDestroyImage vkDestroyImage; 85 | extern PFN_vkFreeMemory vkFreeMemory; 86 | extern PFN_vkCreateRenderPass vkCreateRenderPass; 87 | extern PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass; 88 | extern PFN_vkCmdEndRenderPass vkCmdEndRenderPass; 89 | extern PFN_vkCmdNextSubpass vkCmdNextSubpass; 90 | extern PFN_vkCmdExecuteCommands vkCmdExecuteCommands; 91 | extern PFN_vkCreateImage vkCreateImage; 92 | extern PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; 93 | extern PFN_vkCreateImageView vkCreateImageView; 94 | extern PFN_vkDestroyImageView vkDestroyImageView; 95 | extern PFN_vkCreateSemaphore vkCreateSemaphore; 96 | extern PFN_vkDestroySemaphore vkDestroySemaphore; 97 | extern PFN_vkCreateFence vkCreateFence; 98 | extern PFN_vkDestroyFence vkDestroyFence; 99 | extern PFN_vkWaitForFences vkWaitForFences; 100 | extern PFN_vkResetFences vkResetFences; 101 | extern PFN_vkCreateCommandPool vkCreateCommandPool; 102 | extern PFN_vkDestroyCommandPool vkDestroyCommandPool; 103 | extern PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers; 104 | extern PFN_vkBeginCommandBuffer vkBeginCommandBuffer; 105 | extern PFN_vkEndCommandBuffer vkEndCommandBuffer; 106 | extern PFN_vkGetDeviceQueue vkGetDeviceQueue; 107 | extern PFN_vkQueueSubmit vkQueueSubmit; 108 | extern PFN_vkQueueWaitIdle vkQueueWaitIdle; 109 | extern PFN_vkDeviceWaitIdle vkDeviceWaitIdle; 110 | extern PFN_vkCreateFramebuffer vkCreateFramebuffer; 111 | extern PFN_vkCreatePipelineCache vkCreatePipelineCache; 112 | extern PFN_vkCreatePipelineLayout vkCreatePipelineLayout; 113 | extern PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines; 114 | extern PFN_vkCreateComputePipelines vkCreateComputePipelines; 115 | extern PFN_vkCreateDescriptorPool vkCreateDescriptorPool; 116 | extern PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout; 117 | extern PFN_vkAllocateDescriptorSets vkAllocateDescriptorSets; 118 | extern PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets; 119 | extern PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets; 120 | extern PFN_vkCmdBindPipeline vkCmdBindPipeline; 121 | extern PFN_vkCmdBindVertexBuffers vkCmdBindVertexBuffers; 122 | extern PFN_vkCmdBindIndexBuffer vkCmdBindIndexBuffer; 123 | extern PFN_vkCmdSetViewport vkCmdSetViewport; 124 | extern PFN_vkCmdSetScissor vkCmdSetScissor; 125 | extern PFN_vkCmdSetLineWidth vkCmdSetLineWidth; 126 | extern PFN_vkCmdSetDepthBias vkCmdSetDepthBias; 127 | extern PFN_vkCmdPushConstants vkCmdPushConstants; 128 | extern PFN_vkCmdDrawIndexed vkCmdDrawIndexed; 129 | extern PFN_vkCmdDraw vkCmdDraw; 130 | extern PFN_vkCmdDrawIndexedIndirect vkCmdDrawIndexedIndirect; 131 | extern PFN_vkCmdDrawIndirect vkCmdDrawIndirect; 132 | extern PFN_vkCmdDispatch vkCmdDispatch; 133 | extern PFN_vkDestroyPipeline vkDestroyPipeline; 134 | extern PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout; 135 | extern PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout; 136 | extern PFN_vkDestroyDevice vkDestroyDevice; 137 | extern PFN_vkDestroyInstance vkDestroyInstance; 138 | extern PFN_vkDestroyDescriptorPool vkDestroyDescriptorPool; 139 | extern PFN_vkFreeCommandBuffers vkFreeCommandBuffers; 140 | extern PFN_vkDestroyRenderPass vkDestroyRenderPass; 141 | extern PFN_vkDestroyFramebuffer vkDestroyFramebuffer; 142 | extern PFN_vkDestroyShaderModule vkDestroyShaderModule; 143 | extern PFN_vkDestroyPipelineCache vkDestroyPipelineCache; 144 | extern PFN_vkCreateQueryPool vkCreateQueryPool; 145 | extern PFN_vkDestroyQueryPool vkDestroyQueryPool; 146 | extern PFN_vkGetQueryPoolResults vkGetQueryPoolResults; 147 | extern PFN_vkCmdBeginQuery vkCmdBeginQuery; 148 | extern PFN_vkCmdEndQuery vkCmdEndQuery; 149 | extern PFN_vkCmdResetQueryPool vkCmdResetQueryPool; 150 | extern PFN_vkCmdCopyQueryPoolResults vkCmdCopyQueryPoolResults; 151 | 152 | extern PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR; 153 | extern PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR; 154 | 155 | namespace vks 156 | { 157 | namespace android 158 | { 159 | /* @brief Touch control thresholds from Android NDK samples */ 160 | const int32_t DOUBLE_TAP_TIMEOUT = 300 * 1000000; 161 | const int32_t DOUBLE_TAP_SLOP = 100; 162 | 163 | /** @brief Density of the device screen (in DPI) */ 164 | extern int32_t screenDensity; 165 | 166 | bool loadVulkanLibrary(); 167 | void loadVulkanFunctions(VkInstance instance); 168 | void freeVulkanLibrary(); 169 | void getDeviceConfig(); 170 | } 171 | } 172 | 173 | #endif 174 | 175 | #endif // VULKANANDROID_HPP 176 | 177 | 178 | #endif // VULKANANDROID_H 179 | -------------------------------------------------------------------------------- /base/VulkanBuffer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Vulkan buffer class 3 | * 4 | * Encapsulates a Vulkan buffer 5 | * 6 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 7 | * 8 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #include "vulkan/vulkan.h" 16 | #include "VulkanTools.h" 17 | 18 | namespace vks 19 | { 20 | /** 21 | * @brief Encapsulates access to a Vulkan buffer backed up by device memory 22 | * @note To be filled by an external source like the VulkanDevice 23 | */ 24 | struct Buffer 25 | { 26 | VkDevice device; 27 | VkBuffer buffer = VK_NULL_HANDLE; 28 | VkDeviceMemory memory = VK_NULL_HANDLE; 29 | VkDescriptorBufferInfo descriptor; 30 | VkDeviceSize size = 0; 31 | VkDeviceSize alignment = 0; 32 | void* mapped = nullptr; 33 | 34 | /** @brief Usage flags to be filled by external source at buffer creation (to query at some later point) */ 35 | VkBufferUsageFlags usageFlags; 36 | /** @brief Memory propertys flags to be filled by external source at buffer creation (to query at some later point) */ 37 | VkMemoryPropertyFlags memoryPropertyFlags; 38 | 39 | /** 40 | * Map a memory range of this buffer. If successful, mapped points to the specified buffer range. 41 | * 42 | * @param size (Optional) Size of the memory range to map. Pass VK_WHOLE_SIZE to map the complete buffer range. 43 | * @param offset (Optional) Byte offset from beginning 44 | * 45 | * @return VkResult of the buffer mapping call 46 | */ 47 | VkResult map(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0) 48 | { 49 | return vkMapMemory(device, memory, offset, size, 0, &mapped); 50 | } 51 | 52 | /** 53 | * Unmap a mapped memory range 54 | * 55 | * @note Does not return a result as vkUnmapMemory can't fail 56 | */ 57 | void unmap() 58 | { 59 | if (mapped) 60 | { 61 | vkUnmapMemory(device, memory); 62 | mapped = nullptr; 63 | } 64 | } 65 | 66 | /** 67 | * Attach the allocated memory block to the buffer 68 | * 69 | * @param offset (Optional) Byte offset (from the beginning) for the memory region to bind 70 | * 71 | * @return VkResult of the bindBufferMemory call 72 | */ 73 | VkResult bind(VkDeviceSize offset = 0) 74 | { 75 | return vkBindBufferMemory(device, buffer, memory, offset); 76 | } 77 | 78 | /** 79 | * Setup the default descriptor for this buffer 80 | * 81 | * @param size (Optional) Size of the memory range of the descriptor 82 | * @param offset (Optional) Byte offset from beginning 83 | * 84 | */ 85 | void setupDescriptor(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0) 86 | { 87 | descriptor.offset = offset; 88 | descriptor.buffer = buffer; 89 | descriptor.range = size; 90 | } 91 | 92 | /** 93 | * Copies the specified data to the mapped buffer 94 | * 95 | * @param data Pointer to the data to copy 96 | * @param size Size of the data to copy in machine units 97 | * 98 | */ 99 | void copyTo(void* data, VkDeviceSize size) 100 | { 101 | assert(mapped); 102 | memcpy(mapped, data, size); 103 | } 104 | 105 | /** 106 | * Flush a memory range of the buffer to make it visible to the device 107 | * 108 | * @note Only required for non-coherent memory 109 | * 110 | * @param size (Optional) Size of the memory range to flush. Pass VK_WHOLE_SIZE to flush the complete buffer range. 111 | * @param offset (Optional) Byte offset from beginning 112 | * 113 | * @return VkResult of the flush call 114 | */ 115 | VkResult flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0) 116 | { 117 | VkMappedMemoryRange mappedRange = {}; 118 | mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; 119 | mappedRange.memory = memory; 120 | mappedRange.offset = offset; 121 | mappedRange.size = size; 122 | return vkFlushMappedMemoryRanges(device, 1, &mappedRange); 123 | } 124 | 125 | /** 126 | * Invalidate a memory range of the buffer to make it visible to the host 127 | * 128 | * @note Only required for non-coherent memory 129 | * 130 | * @param size (Optional) Size of the memory range to invalidate. Pass VK_WHOLE_SIZE to invalidate the complete buffer range. 131 | * @param offset (Optional) Byte offset from beginning 132 | * 133 | * @return VkResult of the invalidate call 134 | */ 135 | VkResult invalidate(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0) 136 | { 137 | VkMappedMemoryRange mappedRange = {}; 138 | mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; 139 | mappedRange.memory = memory; 140 | mappedRange.offset = offset; 141 | mappedRange.size = size; 142 | return vkInvalidateMappedMemoryRanges(device, 1, &mappedRange); 143 | } 144 | 145 | /** 146 | * Release all Vulkan resources held by this buffer 147 | */ 148 | void destroy() 149 | { 150 | if (buffer) 151 | { 152 | vkDestroyBuffer(device, buffer, nullptr); 153 | } 154 | if (memory) 155 | { 156 | vkFreeMemory(device, memory, nullptr); 157 | } 158 | } 159 | 160 | }; 161 | } -------------------------------------------------------------------------------- /base/VulkanDebug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "vulkan/vulkan.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #ifdef _WIN32 14 | #include 15 | #include 16 | #include 17 | #endif 18 | #ifdef __ANDROID__ 19 | #include "VulkanAndroid.h" 20 | #endif 21 | #define GLM_FORCE_RADIANS 22 | #define GLM_FORCE_DEPTH_ZERO_TO_ONE 23 | #include 24 | 25 | namespace vks 26 | { 27 | namespace debug 28 | { 29 | // Default validation layers 30 | extern int validationLayerCount; 31 | extern const char *validationLayerNames[]; 32 | 33 | // Default debug callback 34 | VkBool32 messageCallback( 35 | VkDebugReportFlagsEXT flags, 36 | VkDebugReportObjectTypeEXT objType, 37 | uint64_t srcObject, 38 | size_t location, 39 | int32_t msgCode, 40 | const char* pLayerPrefix, 41 | const char* pMsg, 42 | void* pUserData); 43 | 44 | // Load debug function pointers and set debug callback 45 | // if callBack is NULL, default message callback will be used 46 | void setupDebugging( 47 | VkInstance instance, 48 | VkDebugReportFlagsEXT flags, 49 | VkDebugReportCallbackEXT callBack); 50 | // Clear debug callback 51 | void freeDebugCallback(VkInstance instance); 52 | } 53 | 54 | // Setup and functions for the VK_EXT_debug_marker_extension 55 | // Extension spec can be found at https://github.com/KhronosGroup/Vulkan-Docs/blob/1.0-VK_EXT_debug_marker/doc/specs/vulkan/appendices/VK_EXT_debug_marker.txt 56 | // Note that the extension will only be present if run from an offline debugging application 57 | // The actual check for extension presence and enabling it on the device is done in the example base class 58 | // See VulkanExampleBase::createInstance and VulkanExampleBase::createDevice (base/vulkanexamplebase.cpp) 59 | namespace debugmarker 60 | { 61 | // Set to true if function pointer for the debug marker are available 62 | extern bool active; 63 | 64 | // Get function pointers for the debug report extensions from the device 65 | void setup(VkDevice device); 66 | 67 | // Sets the debug name of an object 68 | // All Objects in Vulkan are represented by their 64-bit handles which are passed into this function 69 | // along with the object type 70 | void setObjectName(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name); 71 | 72 | // Set the tag for an object 73 | void setObjectTag(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag); 74 | 75 | // Start a new debug marker region 76 | void beginRegion(VkCommandBuffer cmdbuffer, const char* pMarkerName, glm::vec4 color); 77 | 78 | // Insert a new debug marker into the command buffer 79 | void insert(VkCommandBuffer cmdbuffer, std::string markerName, glm::vec4 color); 80 | 81 | // End the current debug marker region 82 | void endRegion(VkCommandBuffer cmdBuffer); 83 | 84 | // Object specific naming functions 85 | void setCommandBufferName(VkDevice device, VkCommandBuffer cmdBuffer, const char * name); 86 | void setQueueName(VkDevice device, VkQueue queue, const char * name); 87 | void setImageName(VkDevice device, VkImage image, const char * name); 88 | void setSamplerName(VkDevice device, VkSampler sampler, const char * name); 89 | void setBufferName(VkDevice device, VkBuffer buffer, const char * name); 90 | void setDeviceMemoryName(VkDevice device, VkDeviceMemory memory, const char * name); 91 | void setShaderModuleName(VkDevice device, VkShaderModule shaderModule, const char * name); 92 | void setPipelineName(VkDevice device, VkPipeline pipeline, const char * name); 93 | void setPipelineLayoutName(VkDevice device, VkPipelineLayout pipelineLayout, const char * name); 94 | void setRenderPassName(VkDevice device, VkRenderPass renderPass, const char * name); 95 | void setFramebufferName(VkDevice device, VkFramebuffer framebuffer, const char * name); 96 | void setDescriptorSetLayoutName(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const char * name); 97 | void setDescriptorSetName(VkDevice device, VkDescriptorSet descriptorSet, const char * name); 98 | void setSemaphoreName(VkDevice device, VkSemaphore semaphore, const char * name); 99 | void setFenceName(VkDevice device, VkFence fence, const char * name); 100 | void setEventName(VkDevice device, VkEvent _event, const char * name); 101 | }; 102 | } 103 | -------------------------------------------------------------------------------- /base/VulkanHeightmap.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Heightmap terrain generator 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "vulkan/vulkan.h" 14 | #include "VulkanDevice.hpp" 15 | #include "VulkanBuffer.hpp" 16 | 17 | namespace vks 18 | { 19 | class HeightMap 20 | { 21 | private: 22 | uint16_t *heightdata; 23 | uint32_t dim; 24 | uint32_t scale; 25 | 26 | vks::VulkanDevice *device = nullptr; 27 | VkQueue copyQueue = VK_NULL_HANDLE; 28 | public: 29 | enum Topology { topologyTriangles, topologyQuads }; 30 | 31 | float heightScale = 1.0f; 32 | float uvScale = 1.0f; 33 | 34 | vks::Buffer vertexBuffer; 35 | vks::Buffer indexBuffer; 36 | 37 | struct Vertex { 38 | glm::vec3 pos; 39 | glm::vec3 normal; 40 | glm::vec2 uv; 41 | }; 42 | 43 | size_t vertexBufferSize = 0; 44 | size_t indexBufferSize = 0; 45 | uint32_t indexCount = 0; 46 | 47 | HeightMap(vks::VulkanDevice *device, VkQueue copyQueue) 48 | { 49 | this->device = device; 50 | this->copyQueue = copyQueue; 51 | }; 52 | 53 | ~HeightMap() 54 | { 55 | vertexBuffer.destroy(); 56 | indexBuffer.destroy(); 57 | delete[] heightdata; 58 | } 59 | 60 | float getHeight(uint32_t x, uint32_t y) 61 | { 62 | glm::ivec2 rpos = glm::ivec2(x, y) * glm::ivec2(scale); 63 | rpos.x = std::max(0, std::min(rpos.x, (int)dim - 1)); 64 | rpos.y = std::max(0, std::min(rpos.y, (int)dim - 1)); 65 | rpos /= glm::ivec2(scale); 66 | return *(heightdata + (rpos.x + rpos.y * dim) * scale) / 65535.0f * heightScale; 67 | } 68 | 69 | #if defined(__ANDROID__) 70 | void loadFromFile(const std::string filename, uint32_t patchsize, glm::vec3 scale, Topology topology, AAssetManager* assetManager) 71 | #else 72 | void loadFromFile(const std::string filename, uint32_t patchsize, glm::vec3 scale, Topology topology) 73 | #endif 74 | { 75 | assert(device); 76 | assert(copyQueue != VK_NULL_HANDLE); 77 | 78 | #if defined(__ANDROID__) 79 | AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING); 80 | assert(asset); 81 | size_t size = AAsset_getLength(asset); 82 | assert(size > 0); 83 | void *textureData = malloc(size); 84 | AAsset_read(asset, textureData, size); 85 | AAsset_close(asset); 86 | gli::texture2d heightTex(gli::load((const char*)textureData, size)); 87 | free(textureData); 88 | #else 89 | gli::texture2d heightTex(gli::load(filename)); 90 | #endif 91 | dim = static_cast(heightTex.extent().x); 92 | heightdata = new uint16_t[dim * dim]; 93 | memcpy(heightdata, heightTex.data(), heightTex.size()); 94 | this->scale = dim / patchsize; 95 | this->heightScale = scale.y; 96 | 97 | // Generate vertices 98 | 99 | Vertex * vertices = new Vertex[patchsize * patchsize * 4]; 100 | 101 | const float wx = 2.0f; 102 | const float wy = 2.0f; 103 | 104 | for (uint32_t x = 0; x < patchsize; x++) 105 | { 106 | for (uint32_t y = 0; y < patchsize; y++) 107 | { 108 | uint32_t index = (x + y * patchsize); 109 | vertices[index].pos[0] = (x * wx + wx / 2.0f - (float)patchsize * wx / 2.0f) * scale.x; 110 | vertices[index].pos[1] = -getHeight(x, y); 111 | vertices[index].pos[2] = (y * wy + wy / 2.0f - (float)patchsize * wy / 2.0f) * scale.z; 112 | vertices[index].uv = glm::vec2((float)x / patchsize, (float)y / patchsize) * uvScale; 113 | } 114 | } 115 | 116 | for (uint32_t y = 0; y < patchsize; y++) 117 | { 118 | for (uint32_t x = 0; x < patchsize; x++) 119 | { 120 | float dx = getHeight(x < patchsize - 1 ? x + 1 : x, y) - getHeight(x > 0 ? x - 1 : x, y); 121 | if (x == 0 || x == patchsize - 1) 122 | dx *= 2.0f; 123 | 124 | float dy = getHeight(x, y < patchsize - 1 ? y + 1 : y) - getHeight(x, y > 0 ? y - 1 : y); 125 | if (y == 0 || y == patchsize - 1) 126 | dy *= 2.0f; 127 | 128 | glm::vec3 A = glm::vec3(1.0f, 0.0f, dx); 129 | glm::vec3 B = glm::vec3(0.0f, 1.0f, dy); 130 | 131 | glm::vec3 normal = (glm::normalize(glm::cross(A, B)) + 1.0f) * 0.5f; 132 | 133 | vertices[x + y * patchsize].normal = glm::vec3(normal.x, normal.z, normal.y); 134 | } 135 | } 136 | 137 | // Generate indices 138 | 139 | const uint32_t w = (patchsize - 1); 140 | uint32_t *indices; 141 | 142 | switch (topology) 143 | { 144 | // Indices for triangles 145 | case topologyTriangles: 146 | { 147 | indices = new uint32_t[w * w * 6]; 148 | for (uint32_t x = 0; x < w; x++) 149 | { 150 | for (uint32_t y = 0; y < w; y++) 151 | { 152 | uint32_t index = (x + y * w) * 6; 153 | indices[index] = (x + y * patchsize); 154 | indices[index + 1] = indices[index] + patchsize; 155 | indices[index + 2] = indices[index + 1] + 1; 156 | 157 | indices[index + 3] = indices[index + 1] + 1; 158 | indices[index + 4] = indices[index] + 1; 159 | indices[index + 5] = indices[index]; 160 | } 161 | } 162 | indexCount = (patchsize - 1) * (patchsize - 1) * 6; 163 | indexBufferSize = (w * w * 6) * sizeof(uint32_t); 164 | break; 165 | } 166 | // Indices for quad patches (tessellation) 167 | case topologyQuads: 168 | { 169 | 170 | indices = new uint32_t[w * w * 4]; 171 | for (uint32_t x = 0; x < w; x++) 172 | { 173 | for (uint32_t y = 0; y < w; y++) 174 | { 175 | uint32_t index = (x + y * w) * 4; 176 | indices[index] = (x + y * patchsize); 177 | indices[index + 1] = indices[index] + patchsize; 178 | indices[index + 2] = indices[index + 1] + 1; 179 | indices[index + 3] = indices[index] + 1; 180 | } 181 | } 182 | indexCount = (patchsize - 1) * (patchsize - 1) * 4; 183 | indexBufferSize = (w * w * 4) * sizeof(uint32_t); 184 | break; 185 | } 186 | 187 | } 188 | 189 | assert(indexBufferSize > 0); 190 | 191 | vertexBufferSize = (patchsize * patchsize * 4) * sizeof(Vertex); 192 | 193 | // Generate Vulkan buffers 194 | 195 | vks::Buffer vertexStaging, indexStaging; 196 | 197 | // Create staging buffers 198 | device->createBuffer( 199 | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, 200 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 201 | &vertexStaging, 202 | vertexBufferSize, 203 | vertices); 204 | 205 | device->createBuffer( 206 | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, 207 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 208 | &indexStaging, 209 | indexBufferSize, 210 | indices); 211 | 212 | // Device local (target) buffer 213 | device->createBuffer( 214 | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, 215 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 216 | &vertexBuffer, 217 | vertexBufferSize); 218 | 219 | device->createBuffer( 220 | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, 221 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 222 | &indexBuffer, 223 | indexBufferSize); 224 | 225 | // Copy from staging buffers 226 | VkCommandBuffer copyCmd = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); 227 | 228 | VkBufferCopy copyRegion = {}; 229 | 230 | copyRegion.size = vertexBufferSize; 231 | vkCmdCopyBuffer( 232 | copyCmd, 233 | vertexStaging.buffer, 234 | vertexBuffer.buffer, 235 | 1, 236 | ©Region); 237 | 238 | copyRegion.size = indexBufferSize; 239 | vkCmdCopyBuffer( 240 | copyCmd, 241 | indexStaging.buffer, 242 | indexBuffer.buffer, 243 | 1, 244 | ©Region); 245 | 246 | device->flushCommandBuffer(copyCmd, copyQueue, true); 247 | 248 | vkDestroyBuffer(device->logicalDevice, vertexStaging.buffer, nullptr); 249 | vkFreeMemory(device->logicalDevice, vertexStaging.memory, nullptr); 250 | vkDestroyBuffer(device->logicalDevice, indexStaging.buffer, nullptr); 251 | vkFreeMemory(device->logicalDevice, indexStaging.memory, nullptr); 252 | } 253 | }; 254 | } 255 | -------------------------------------------------------------------------------- /base/VulkanTools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Assorted Vulkan helper functions 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #include "vulkan/vulkan.h" 12 | #include "VulkanInitializers.hpp" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #if defined(_WIN32) 26 | #include 27 | #include 28 | #include 29 | #elif defined(__ANDROID__) 30 | #include "VulkanAndroid.h" 31 | #include 32 | #endif 33 | 34 | // Custom define for better code readability 35 | #define VK_FLAGS_NONE 0 36 | // Default fence timeout in nanoseconds 37 | #define DEFAULT_FENCE_TIMEOUT 100000000000 38 | 39 | // Macro to check and display Vulkan return results 40 | #if defined(__ANDROID__) 41 | #define VK_CHECK_RESULT(f) \ 42 | { \ 43 | VkResult res = (f); \ 44 | if (res != VK_SUCCESS) \ 45 | { \ 46 | LOGE("Fatal : VkResult is \" %s \" in %s at line %d", vks::tools::errorString(res).c_str(), __FILE__, __LINE__); \ 47 | assert(res == VK_SUCCESS); \ 48 | } \ 49 | } 50 | #else 51 | #define VK_CHECK_RESULT(f) \ 52 | { \ 53 | VkResult res = (f); \ 54 | if (res != VK_SUCCESS) \ 55 | { \ 56 | std::cout << "Fatal : VkResult is \"" << vks::tools::errorString(res) << "\" in " << __FILE__ << " at line " << __LINE__ << std::endl; \ 57 | assert(res == VK_SUCCESS); \ 58 | } \ 59 | } 60 | #endif 61 | 62 | #if defined(__ANDROID__) 63 | #define ASSET_PATH "" 64 | #else 65 | #define ASSET_PATH "./../data/" 66 | #endif 67 | 68 | namespace vks 69 | { 70 | namespace tools 71 | { 72 | /** @brief Returns an error code as a string */ 73 | std::string errorString(VkResult errorCode); 74 | 75 | /** @brief Returns the device type as a string */ 76 | std::string physicalDeviceTypeString(VkPhysicalDeviceType type); 77 | 78 | // Selected a suitable supported depth format starting with 32 bit down to 16 bit 79 | // Returns false if none of the depth formats in the list is supported by the device 80 | VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat *depthFormat); 81 | 82 | // Put an image memory barrier for setting an image layout on the sub resource into the given command buffer 83 | void setImageLayout( 84 | VkCommandBuffer cmdbuffer, 85 | VkImage image, 86 | VkImageLayout oldImageLayout, 87 | VkImageLayout newImageLayout, 88 | VkImageSubresourceRange subresourceRange, 89 | VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 90 | VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 91 | // Uses a fixed sub resource layout with first mip level and layer 92 | void setImageLayout( 93 | VkCommandBuffer cmdbuffer, 94 | VkImage image, 95 | VkImageAspectFlags aspectMask, 96 | VkImageLayout oldImageLayout, 97 | VkImageLayout newImageLayout, 98 | VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 99 | VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 100 | 101 | /** @brief Inser an image memory barrier into the command buffer */ 102 | void insertImageMemoryBarrier( 103 | VkCommandBuffer cmdbuffer, 104 | VkImage image, 105 | VkAccessFlags srcAccessMask, 106 | VkAccessFlags dstAccessMask, 107 | VkImageLayout oldImageLayout, 108 | VkImageLayout newImageLayout, 109 | VkPipelineStageFlags srcStageMask, 110 | VkPipelineStageFlags dstStageMask, 111 | VkImageSubresourceRange subresourceRange); 112 | 113 | // Display error message and exit on fatal error 114 | void exitFatal(std::string message, std::string caption, bool silent = false); 115 | 116 | // Load a SPIR-V shader (binary) 117 | #if defined(__ANDROID__) 118 | VkShaderModule loadShader(AAssetManager* assetManager, const char *fileName, VkDevice device); 119 | #else 120 | VkShaderModule loadShader(const char *fileName, VkDevice device); 121 | #endif 122 | 123 | // Load a GLSL shader (text) 124 | // Note: GLSL support requires vendor-specific extensions to be enabled and is not a core-feature of Vulkan 125 | VkShaderModule loadShaderGLSL(const char *fileName, VkDevice device, VkShaderStageFlagBits stage); 126 | 127 | /** @brief Checks if a file exists */ 128 | bool fileExists(const std::string &filename); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /base/benchmark.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Benchmark class 3 | * 4 | * Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace vks 18 | { 19 | class Benchmark { 20 | private: 21 | FILE *stream; 22 | public: 23 | bool active = false; 24 | uint32_t framesPerIteration = 1000; 25 | uint32_t iterationCount = 10; 26 | //std::vector iterationTimes; 27 | struct Iteration { 28 | std::vector frameTimes; 29 | }; 30 | std::vector iterations; 31 | std::string filename = "benchmarkresults.csv"; 32 | 33 | void run(std::function renderFunc) { 34 | active = true; 35 | #if defined(_WIN32) 36 | AttachConsole(ATTACH_PARENT_PROCESS); 37 | freopen_s(&stream, "CONOUT$", "w+", stdout); 38 | freopen_s(&stream, "CONOUT$", "w+", stderr); 39 | #endif 40 | // "Warm up" run to get more stable frame rates 41 | for (uint32_t f = 0; f < framesPerIteration; f++) { 42 | renderFunc(); 43 | } 44 | 45 | iterations.resize(iterationCount); 46 | for (uint32_t i = 0; i < iterationCount; i++) { 47 | iterations[i].frameTimes.resize(framesPerIteration); 48 | for (uint32_t f = 0; f < framesPerIteration; f++) { 49 | auto tStart = std::chrono::high_resolution_clock::now(); 50 | renderFunc(); 51 | auto tEnd = std::chrono::high_resolution_clock::now(); 52 | auto tDiff = std::chrono::duration(tEnd - tStart).count(); 53 | iterations[i].frameTimes[f] = tDiff; 54 | } 55 | } 56 | } 57 | 58 | void saveResults(std::string appinfo, std::string deviceinfo) { 59 | std::ofstream result(filename, std::ios::out); 60 | if (result.is_open()) { 61 | double tMinAll = std::numeric_limits::max(); 62 | double tMaxAll = std::numeric_limits::min(); 63 | double tAvgAll = 0.0; 64 | 65 | result << std::fixed << std::setprecision(4); 66 | result << "iteration,min(ms),max(ms),avg(ms),min(fps),max(fps),avg(fps)" << std::endl; 67 | uint32_t index = 0; 68 | for (auto iteration : iterations) { 69 | double tMin = *std::min_element(iteration.frameTimes.begin(), iteration.frameTimes.end()); 70 | double tMax = *std::max_element(iteration.frameTimes.begin(), iteration.frameTimes.end()); 71 | double tAvg = std::accumulate(iteration.frameTimes.begin(), iteration.frameTimes.end(), 0.0) / framesPerIteration; 72 | if (tMin < tMinAll) { 73 | tMinAll = tMin; 74 | } 75 | if (tMax > tMaxAll) { 76 | tMaxAll = tMax; 77 | } 78 | tAvgAll += tAvg; 79 | index++; 80 | result << index << "," << tMin << "," << tMax << "," << tAvg << "," << (1000.0 / tMax) << "," << (1000.0 / tMin) << "," << (1000.0 / tAvg) << std::endl; 81 | } 82 | 83 | tAvgAll /= static_cast(iterations.size()); 84 | result << "summary,min(ms),max(ms),avg(ms),min(fps),max(fps),avg(fps)" << std::endl; 85 | result << index << "," << tMinAll << "," << tMaxAll << "," << tAvgAll << "," << (1000.0 / tMaxAll) << "," << (1000.0 / tMinAll) << "," << (1000.0 / tAvgAll) << std::endl; 86 | 87 | // Output averages to stdout 88 | std::cout << std::fixed << std::setprecision(3); 89 | std::cout << "best : " << (1000.0 / tMinAll) << " fps (" << tMinAll << " ms)" << std::endl; 90 | std::cout << "worst: " << (1000.0 / tMaxAll) << " fps (" << tMaxAll << " ms)" << std::endl; 91 | std::cout << "avg : " << (1000.0 / tAvgAll) << " fps (" << tAvgAll << " ms)" << std::endl; 92 | std::cout << std::endl; 93 | #if defined(_WIN32) 94 | fclose(stream); 95 | FreeConsole(); 96 | #endif 97 | } 98 | } 99 | }; 100 | } -------------------------------------------------------------------------------- /base/camera.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic camera class 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #define GLM_FORCE_RADIANS 10 | #define GLM_FORCE_DEPTH_ZERO_TO_ONE 11 | #include 12 | #include 13 | #include 14 | 15 | class Camera 16 | { 17 | private: 18 | float fov; 19 | float znear, zfar; 20 | 21 | void updateViewMatrix() 22 | { 23 | glm::mat4 rotM = glm::mat4(1.0f); 24 | glm::mat4 transM; 25 | 26 | rotM = glm::rotate(rotM, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); 27 | rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)); 28 | rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); 29 | 30 | transM = glm::translate(glm::mat4(1.0f), position); 31 | 32 | if (type == CameraType::firstperson) 33 | { 34 | matrices.view = rotM * transM; 35 | } 36 | else 37 | { 38 | matrices.view = transM * rotM; 39 | } 40 | }; 41 | public: 42 | enum CameraType { lookat, firstperson }; 43 | CameraType type = CameraType::lookat; 44 | 45 | glm::vec3 rotation = glm::vec3(); 46 | glm::vec3 position = glm::vec3(); 47 | 48 | float rotationSpeed = 1.0f; 49 | float movementSpeed = 1.0f; 50 | 51 | struct 52 | { 53 | glm::mat4 perspective; 54 | glm::mat4 view; 55 | } matrices; 56 | 57 | struct 58 | { 59 | bool left = false; 60 | bool right = false; 61 | bool up = false; 62 | bool down = false; 63 | } keys; 64 | 65 | bool moving() 66 | { 67 | return keys.left || keys.right || keys.up || keys.down; 68 | } 69 | 70 | void setPerspective(float fov, float aspect, float znear, float zfar) 71 | { 72 | this->fov = fov; 73 | this->znear = znear; 74 | this->zfar = zfar; 75 | matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar); 76 | }; 77 | 78 | void updateAspectRatio(float aspect) 79 | { 80 | matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar); 81 | } 82 | 83 | void setPosition(glm::vec3 position) 84 | { 85 | this->position = position; 86 | updateViewMatrix(); 87 | } 88 | 89 | void setRotation(glm::vec3 rotation) 90 | { 91 | this->rotation = rotation; 92 | updateViewMatrix(); 93 | }; 94 | 95 | void rotate(glm::vec3 delta) 96 | { 97 | this->rotation += delta; 98 | updateViewMatrix(); 99 | } 100 | 101 | void setTranslation(glm::vec3 translation) 102 | { 103 | this->position = translation; 104 | updateViewMatrix(); 105 | }; 106 | 107 | void translate(glm::vec3 delta) 108 | { 109 | this->position += delta; 110 | updateViewMatrix(); 111 | } 112 | 113 | void update(float deltaTime) 114 | { 115 | if (type == CameraType::firstperson) 116 | { 117 | if (moving()) 118 | { 119 | glm::vec3 camFront; 120 | camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y)); 121 | camFront.y = sin(glm::radians(rotation.x)); 122 | camFront.z = cos(glm::radians(rotation.x)) * cos(glm::radians(rotation.y)); 123 | camFront = glm::normalize(camFront); 124 | 125 | float moveSpeed = deltaTime * movementSpeed; 126 | 127 | if (keys.up) 128 | position += camFront * moveSpeed; 129 | if (keys.down) 130 | position -= camFront * moveSpeed; 131 | if (keys.left) 132 | position -= glm::normalize(glm::cross(camFront, glm::vec3(0.0f, 1.0f, 0.0f))) * moveSpeed; 133 | if (keys.right) 134 | position += glm::normalize(glm::cross(camFront, glm::vec3(0.0f, 1.0f, 0.0f))) * moveSpeed; 135 | 136 | updateViewMatrix(); 137 | } 138 | } 139 | }; 140 | 141 | // Update camera passing separate axis data (gamepad) 142 | // Returns true if view or position has been changed 143 | bool updatePad(glm::vec2 axisLeft, glm::vec2 axisRight, float deltaTime) 144 | { 145 | bool retVal = false; 146 | 147 | if (type == CameraType::firstperson) 148 | { 149 | // Use the common console thumbstick layout 150 | // Left = view, right = move 151 | 152 | const float deadZone = 0.0015f; 153 | const float range = 1.0f - deadZone; 154 | 155 | glm::vec3 camFront; 156 | camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y)); 157 | camFront.y = sin(glm::radians(rotation.x)); 158 | camFront.z = cos(glm::radians(rotation.x)) * cos(glm::radians(rotation.y)); 159 | camFront = glm::normalize(camFront); 160 | 161 | float moveSpeed = deltaTime * movementSpeed * 2.0f; 162 | float rotSpeed = deltaTime * rotationSpeed * 50.0f; 163 | 164 | // Move 165 | if (fabsf(axisLeft.y) > deadZone) 166 | { 167 | float pos = (fabsf(axisLeft.y) - deadZone) / range; 168 | position -= camFront * pos * ((axisLeft.y < 0.0f) ? -1.0f : 1.0f) * moveSpeed; 169 | retVal = true; 170 | } 171 | if (fabsf(axisLeft.x) > deadZone) 172 | { 173 | float pos = (fabsf(axisLeft.x) - deadZone) / range; 174 | position += glm::normalize(glm::cross(camFront, glm::vec3(0.0f, 1.0f, 0.0f))) * pos * ((axisLeft.x < 0.0f) ? -1.0f : 1.0f) * moveSpeed; 175 | retVal = true; 176 | } 177 | 178 | // Rotate 179 | if (fabsf(axisRight.x) > deadZone) 180 | { 181 | float pos = (fabsf(axisRight.x) - deadZone) / range; 182 | rotation.y += pos * ((axisRight.x < 0.0f) ? -1.0f : 1.0f) * rotSpeed; 183 | retVal = true; 184 | } 185 | if (fabsf(axisRight.y) > deadZone) 186 | { 187 | float pos = (fabsf(axisRight.y) - deadZone) / range; 188 | rotation.x -= pos * ((axisRight.y < 0.0f) ? -1.0f : 1.0f) * rotSpeed; 189 | retVal = true; 190 | } 191 | } 192 | else 193 | { 194 | // todo: move code from example base class for look-at 195 | } 196 | 197 | if (retVal) 198 | { 199 | updateViewMatrix(); 200 | } 201 | 202 | return retVal; 203 | } 204 | 205 | }; -------------------------------------------------------------------------------- /base/frustum.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * View frustum culling class 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vks 14 | { 15 | class Frustum 16 | { 17 | public: 18 | enum side { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3, BACK = 4, FRONT = 5 }; 19 | std::array planes; 20 | 21 | void update(glm::mat4 matrix) 22 | { 23 | planes[LEFT].x = matrix[0].w + matrix[0].x; 24 | planes[LEFT].y = matrix[1].w + matrix[1].x; 25 | planes[LEFT].z = matrix[2].w + matrix[2].x; 26 | planes[LEFT].w = matrix[3].w + matrix[3].x; 27 | 28 | planes[RIGHT].x = matrix[0].w - matrix[0].x; 29 | planes[RIGHT].y = matrix[1].w - matrix[1].x; 30 | planes[RIGHT].z = matrix[2].w - matrix[2].x; 31 | planes[RIGHT].w = matrix[3].w - matrix[3].x; 32 | 33 | planes[TOP].x = matrix[0].w - matrix[0].y; 34 | planes[TOP].y = matrix[1].w - matrix[1].y; 35 | planes[TOP].z = matrix[2].w - matrix[2].y; 36 | planes[TOP].w = matrix[3].w - matrix[3].y; 37 | 38 | planes[BOTTOM].x = matrix[0].w + matrix[0].y; 39 | planes[BOTTOM].y = matrix[1].w + matrix[1].y; 40 | planes[BOTTOM].z = matrix[2].w + matrix[2].y; 41 | planes[BOTTOM].w = matrix[3].w + matrix[3].y; 42 | 43 | planes[BACK].x = matrix[0].w + matrix[0].z; 44 | planes[BACK].y = matrix[1].w + matrix[1].z; 45 | planes[BACK].z = matrix[2].w + matrix[2].z; 46 | planes[BACK].w = matrix[3].w + matrix[3].z; 47 | 48 | planes[FRONT].x = matrix[0].w - matrix[0].z; 49 | planes[FRONT].y = matrix[1].w - matrix[1].z; 50 | planes[FRONT].z = matrix[2].w - matrix[2].z; 51 | planes[FRONT].w = matrix[3].w - matrix[3].z; 52 | 53 | for (auto i = 0; i < planes.size(); i++) 54 | { 55 | float length = sqrtf(planes[i].x * planes[i].x + planes[i].y * planes[i].y + planes[i].z * planes[i].z); 56 | planes[i] /= length; 57 | } 58 | } 59 | 60 | bool checkSphere(glm::vec3 pos, float radius) 61 | { 62 | for (auto i = 0; i < planes.size(); i++) 63 | { 64 | if ((planes[i].x * pos.x) + (planes[i].y * pos.y) + (planes[i].z * pos.z) + planes[i].w <= -radius) 65 | { 66 | return false; 67 | } 68 | } 69 | return true; 70 | } 71 | 72 | uint32_t halfPlaneTest(const glm::vec3 &p, const glm::vec3 &normal, float offset) const { 73 | float dist = glm::dot(p, normal) + offset; 74 | if (dist > 0.02) { 75 | return 1; 76 | } 77 | else if (dist < -0.02) { 78 | return 0; 79 | } 80 | return 2; 81 | } 82 | 83 | inline int vectorToIndex(const glm::vec3 &v) const { 84 | int idx = 0; 85 | if (v.z >= 0) idx |= 1; 86 | if (v.y >= 0) idx |= 2; 87 | if (v.x >= 0) idx |= 4; 88 | return idx; 89 | } 90 | 91 | uint32_t checkBox(const glm::vec3 &origin, const glm::vec3 &halfDim) const { 92 | static const glm::vec3 cornerOffsets[] = { 93 | glm::vec3(-1.f,-1.f,-1.f), glm::vec3(-1.f,-1.f, 1.f), glm::vec3(-1.f, 1.f,-1.f), glm::vec3(-1.f, 1.f, 1.f), 94 | glm::vec3( 1.f,-1.f,-1.f), glm::vec3( 1.f,-1.f, 1.f), glm::vec3( 1.f, 1.f,-1.f), glm::vec3( 1.f, 1.f, 1.f) 95 | }; 96 | uint32_t ret = 1; 97 | for (uint32_t i = 0; i<6; i++) { 98 | glm::vec3 planeNormal = glm::vec3(planes[i]); 99 | uint32_t idx = vectorToIndex(planeNormal); 100 | glm::vec3 testPoint = origin + halfDim * cornerOffsets[idx]; 101 | if (halfPlaneTest(testPoint, planeNormal, planes[i].w) == 0) { 102 | ret = 0; 103 | break; 104 | } 105 | idx = vectorToIndex(-planeNormal); 106 | testPoint = origin + halfDim * cornerOffsets[idx]; 107 | if (halfPlaneTest(testPoint, planeNormal, planes[i].w) == 0) { 108 | ret |= 2; 109 | } 110 | } 111 | return ret; 112 | } 113 | 114 | }; 115 | } 116 | -------------------------------------------------------------------------------- /base/keycodes.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Key codes for multiple platforms 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #if defined(_WIN32) 12 | #define KEY_ESCAPE VK_ESCAPE 13 | #define KEY_F1 VK_F1 14 | #define KEY_F2 VK_F2 15 | #define KEY_F3 VK_F3 16 | #define KEY_F4 VK_F4 17 | #define KEY_F5 VK_F5 18 | #define KEY_W 0x57 19 | #define KEY_A 0x41 20 | #define KEY_S 0x53 21 | #define KEY_D 0x44 22 | #define KEY_E 0x45 23 | #define KEY_M 0x4D 24 | #define KEY_O 0x4F 25 | #define KEY_P 0x50 26 | #define KEY_SPACE 0x20 27 | #define KEY_KPADD 0x6B 28 | #define KEY_KPSUB 0x6D 29 | #define KEY_B 0x42 30 | #define KEY_F 0x46 31 | #define KEY_L 0x4C 32 | #define KEY_N 0x4E 33 | #define KEY_O 0x4F 34 | #define KEY_Q 0x51 35 | #define KEY_T 0x54 36 | #elif defined(__ANDROID__) 37 | // Dummy key codes 38 | #define KEY_ESCAPE 0x0 39 | #define KEY_F1 0x1 40 | #define KEY_F2 0x2 41 | #define KEY_F2 0x11 42 | #define KEY_F2 0x12 43 | #define KEY_F3 0x13 44 | #define KEY_F4 0x14 45 | #define KEY_W 0x3 46 | #define KEY_A 0x4 47 | #define KEY_S 0x5 48 | #define KEY_D 0x6 49 | #define KEY_P 0x7 50 | #define KEY_SPACE 0x8 51 | #define KEY_KPADD 0x9 52 | #define KEY_KPSUB 0xA 53 | #define KEY_B 0xB 54 | #define KEY_F 0xC 55 | #define KEY_L 0xD 56 | #define KEY_N 0xE 57 | #define KEY_O 0xF 58 | #define KEY_T 0x10 59 | 60 | #elif defined(VK_USE_PLATFORM_IOS_MVK) 61 | // Use numeric keys instead of function keys. 62 | // Use main keyboard plus/minus instead of keypad plus/minus 63 | // Use Delete key instead of Escape key. 64 | #define KEY_ESCAPE 0x33 65 | #define KEY_F1 '1' 66 | #define KEY_F2 '2' 67 | #define KEY_F3 '3' 68 | #define KEY_F4 '4' 69 | #define KEY_W 'w' 70 | #define KEY_A 'a' 71 | #define KEY_S 's' 72 | #define KEY_D 'd' 73 | #define KEY_P 'p' 74 | #define KEY_SPACE ' ' 75 | #define KEY_KPADD '+' 76 | #define KEY_KPSUB '-' 77 | #define KEY_B 'b' 78 | #define KEY_F 'f' 79 | #define KEY_L 'l' 80 | #define KEY_N 'n' 81 | #define KEY_O 'o' 82 | #define KEY_T 't' 83 | 84 | #elif defined(VK_USE_PLATFORM_MACOS_MVK) 85 | // For compatibility with iOS UX and absent keypad on MacBook: 86 | // - Use numeric keys instead of function keys 87 | // - Use main keyboard plus/minus instead of keypad plus/minus 88 | // - Use Delete key instead of Escape key 89 | #define KEY_ESCAPE 0x33 90 | #define KEY_F1 0x12 91 | #define KEY_F2 0x13 92 | #define KEY_F3 0x14 93 | #define KEY_F4 0x15 94 | #define KEY_W 0x0D 95 | #define KEY_A 0x00 96 | #define KEY_S 0x01 97 | #define KEY_D 0x02 98 | #define KEY_P 0x23 99 | #define KEY_SPACE 0x31 100 | #define KEY_KPADD 0x18 101 | #define KEY_KPSUB 0x1B 102 | #define KEY_B 0x0B 103 | #define KEY_F 0x03 104 | #define KEY_L 0x25 105 | #define KEY_N 0x2D 106 | #define KEY_O 0x1F 107 | #define KEY_T 0x11 108 | 109 | #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) 110 | #include 111 | 112 | // todo: hack for bloom example 113 | #define KEY_KPADD KEY_KPPLUS 114 | #define KEY_KPSUB KEY_KPMINUS 115 | 116 | #elif defined(__linux__) 117 | #define KEY_ESCAPE 0x9 118 | #define KEY_F1 0x43 119 | #define KEY_F2 0x44 120 | #define KEY_F3 0x45 121 | #define KEY_F4 0x46 122 | #define KEY_W 0x19 123 | #define KEY_A 0x26 124 | #define KEY_S 0x27 125 | #define KEY_D 0x28 126 | #define KEY_P 0x21 127 | #define KEY_SPACE 0x41 128 | #define KEY_KPADD 0x56 129 | #define KEY_KPSUB 0x52 130 | #define KEY_B 0x38 131 | #define KEY_F 0x29 132 | #define KEY_L 0x2E 133 | #define KEY_N 0x39 134 | #define KEY_O 0x20 135 | #define KEY_T 0x1C 136 | #endif 137 | 138 | // todo: Android gamepad keycodes outside of define for now 139 | #define GAMEPAD_BUTTON_A 0x1000 140 | #define GAMEPAD_BUTTON_B 0x1001 141 | #define GAMEPAD_BUTTON_X 0x1002 142 | #define GAMEPAD_BUTTON_Y 0x1003 143 | #define GAMEPAD_BUTTON_L1 0x1004 144 | #define GAMEPAD_BUTTON_R1 0x1005 145 | #define GAMEPAD_BUTTON_START 0x1006 146 | #define TOUCH_DOUBLE_TAP 0x1100 147 | -------------------------------------------------------------------------------- /base/threadpool.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic C++11 based thread pool with per-thread job queues 3 | * 4 | * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // make_unique is not available in C++11 17 | // Taken from Herb Sutter's blog (https://herbsutter.com/gotw/_102/) 18 | template 19 | std::unique_ptr make_unique(Args&& ...args) 20 | { 21 | return std::unique_ptr(new T(std::forward(args)...)); 22 | } 23 | 24 | namespace vks 25 | { 26 | class Thread 27 | { 28 | private: 29 | bool destroying = false; 30 | std::thread worker; 31 | std::queue> jobQueue; 32 | std::mutex queueMutex; 33 | std::condition_variable condition; 34 | 35 | // Loop through all remaining jobs 36 | void queueLoop() 37 | { 38 | while (true) 39 | { 40 | std::function job; 41 | { 42 | std::unique_lock lock(queueMutex); 43 | condition.wait(lock, [this] { return !jobQueue.empty() || destroying; }); 44 | if (destroying) 45 | { 46 | break; 47 | } 48 | job = jobQueue.front(); 49 | } 50 | 51 | job(); 52 | 53 | { 54 | std::lock_guard lock(queueMutex); 55 | jobQueue.pop(); 56 | condition.notify_one(); 57 | } 58 | } 59 | } 60 | 61 | public: 62 | Thread() 63 | { 64 | worker = std::thread(&Thread::queueLoop, this); 65 | } 66 | 67 | ~Thread() 68 | { 69 | if (worker.joinable()) 70 | { 71 | wait(); 72 | queueMutex.lock(); 73 | destroying = true; 74 | condition.notify_one(); 75 | queueMutex.unlock(); 76 | worker.join(); 77 | } 78 | } 79 | 80 | // Add a new job to the thread's queue 81 | void addJob(std::function function) 82 | { 83 | std::lock_guard lock(queueMutex); 84 | jobQueue.push(std::move(function)); 85 | condition.notify_one(); 86 | } 87 | 88 | // Wait until all work items have been finished 89 | void wait() 90 | { 91 | std::unique_lock lock(queueMutex); 92 | condition.wait(lock, [this]() { return jobQueue.empty(); }); 93 | } 94 | }; 95 | 96 | class ThreadPool 97 | { 98 | public: 99 | std::vector> threads; 100 | 101 | // Sets the number of threads to be allocted in this pool 102 | void setThreadCount(uint32_t count) 103 | { 104 | threads.clear(); 105 | for (auto i = 0; i < count; i++) 106 | { 107 | threads.push_back(make_unique()); 108 | } 109 | } 110 | 111 | // Wait until all threads have finished their work items 112 | void wait() 113 | { 114 | for (auto &thread : threads) 115 | { 116 | thread->wait(); 117 | } 118 | } 119 | }; 120 | 121 | } 122 | -------------------------------------------------------------------------------- /data/shaders/base/textoverlay.frag: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | layout (location = 0) in vec2 inUV; 4 | 5 | layout (binding = 0) uniform sampler2D samplerFont; 6 | 7 | layout (location = 0) out vec4 outFragColor; 8 | 9 | void main(void) 10 | { 11 | float color = texture(samplerFont, inUV).r; 12 | outFragColor = vec4(vec3(color), 1.0); 13 | } 14 | -------------------------------------------------------------------------------- /data/shaders/base/textoverlay.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/base/textoverlay.frag.spv -------------------------------------------------------------------------------- /data/shaders/base/textoverlay.vert: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | layout (location = 0) in vec2 inPos; 4 | layout (location = 1) in vec2 inUV; 5 | 6 | layout (location = 0) out vec2 outUV; 7 | 8 | out gl_PerVertex 9 | { 10 | vec4 gl_Position; 11 | }; 12 | 13 | void main(void) 14 | { 15 | gl_Position = vec4(inPos, 0.0, 1.0); 16 | outUV = inUV; 17 | } 18 | -------------------------------------------------------------------------------- /data/shaders/base/textoverlay.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/base/textoverlay.vert.spv -------------------------------------------------------------------------------- /data/shaders/composition.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout (set = 0, binding = 1) uniform sampler2D samplerposition; 7 | layout (set = 0, binding = 2) uniform sampler2D samplerNormal; 8 | layout (set = 0, binding = 3) uniform sampler2D samplerAlbedo; 9 | 10 | layout (location = 0) in vec2 inUV; 11 | 12 | layout (location = 0) out vec4 outFragcolor; 13 | 14 | struct Light { 15 | vec4 position; 16 | vec3 color; 17 | float radius; 18 | }; 19 | 20 | layout (binding = 4) uniform UBO 21 | { 22 | Light lights[6]; 23 | vec4 viewPos; 24 | } ubo; 25 | 26 | 27 | void main() 28 | { 29 | // Get G-Buffer values 30 | vec3 fragPos = texture(samplerposition, inUV).rgb; 31 | vec3 normal = texture(samplerNormal, inUV).rgb; 32 | vec4 albedo = texture(samplerAlbedo, inUV); 33 | 34 | #define lightCount 6 35 | #define ambient 0.0 36 | 37 | // Ambient part 38 | vec3 fragcolor = albedo.rgb * ambient; 39 | 40 | for(int i = 0; i < lightCount; ++i) 41 | { 42 | // Vector to light 43 | vec3 L = ubo.lights[i].position.xyz - fragPos; 44 | // Distance from light to fragment position 45 | float dist = length(L); 46 | 47 | // Viewer to fragment 48 | vec3 V = ubo.viewPos.xyz - fragPos; 49 | V = normalize(V); 50 | 51 | //if (dist < ubo.lights[i].radius) 52 | { 53 | // Light to fragment 54 | L = normalize(L); 55 | 56 | // Attenuation 57 | float atten = clamp(ubo.lights[i].radius / (pow(dist, 2.0) + 1.0), 0.0, 1.0); 58 | 59 | //float atten = ubo.lights[i].radius / (1.0f * (1.0 / (1.0 + (0.25 * dist * dist)))); 60 | 61 | // Diffuse part 62 | vec3 N = normalize(normal); 63 | float NdotL = max(0.0, dot(N, L)); 64 | vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten; 65 | 66 | // Specular part 67 | // Specular map values are stored in alpha of albedo mrt 68 | vec3 R = reflect(-L, N); 69 | float NdotR = max(0.0, dot(R, V)); 70 | vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 16.0) * atten; 71 | 72 | fragcolor += diff;// + spec; 73 | } 74 | } 75 | 76 | outFragcolor = vec4(fragcolor, 1.0); 77 | } -------------------------------------------------------------------------------- /data/shaders/composition.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/composition.frag.spv -------------------------------------------------------------------------------- /data/shaders/composition.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout (location = 0) out vec2 outUV; 7 | 8 | out gl_PerVertex 9 | { 10 | vec4 gl_Position; 11 | }; 12 | 13 | void main() 14 | { 15 | outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); 16 | gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f); 17 | } 18 | -------------------------------------------------------------------------------- /data/shaders/composition.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/composition.vert.spv -------------------------------------------------------------------------------- /data/shaders/debug.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout (binding = 1) uniform sampler2D samplerPosition; 7 | layout (binding = 2) uniform sampler2D samplerNormal; 8 | layout (binding = 3) uniform sampler2D samplerAlbedo; 9 | 10 | layout (location = 0) in vec3 inUV; 11 | 12 | layout (location = 0) out vec4 outFragColor; 13 | 14 | void main() 15 | { 16 | vec3 components[3]; 17 | components[0] = texture(samplerPosition, inUV.st).rgb; 18 | components[1] = texture(samplerNormal, inUV.st).rgb; 19 | components[2] = texture(samplerAlbedo, inUV.st).rgb; 20 | // Uncomment to display specular component 21 | //components[2] = vec3(texture(samplerAlbedo, inUV.st).a); 22 | 23 | // Select component depending on z coordinate of quad 24 | highp int index = int(inUV.z); 25 | outFragColor.rgb = components[index]; 26 | } -------------------------------------------------------------------------------- /data/shaders/debug.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout (location = 0) in vec3 inPos; 7 | layout (location = 1) in vec2 inUV; 8 | layout (location = 3) in vec3 inNormal; 9 | 10 | layout (binding = 0) uniform UBO 11 | { 12 | mat4 projection; 13 | mat4 model; 14 | } ubo; 15 | 16 | layout (location = 0) out vec3 outUV; 17 | 18 | out gl_PerVertex 19 | { 20 | vec4 gl_Position; 21 | }; 22 | 23 | void main() 24 | { 25 | outUV = vec3(inUV.st, inNormal.z); 26 | gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); 27 | } 28 | -------------------------------------------------------------------------------- /data/shaders/deferred.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout (set = 1, binding = 0) uniform sampler2DArray samplerColor; 7 | //layout (set = 1, binding = 1) uniform sampler2D samplerNormalMap; 8 | 9 | layout (location = 0) in vec3 inNormal; 10 | layout (location = 1) in vec3 inUV; 11 | layout (location = 2) in vec3 inColor; 12 | layout (location = 3) in vec3 inWorldPos; 13 | layout (location = 4) in vec3 inTangent; 14 | 15 | layout (location = 0) out vec4 outPosition; 16 | layout (location = 1) out vec4 outNormal; 17 | layout (location = 2) out vec4 outAlbedo; 18 | 19 | void main() 20 | { 21 | outPosition = vec4(inWorldPos, 1.0); 22 | 23 | // Calculate normal in tangent space 24 | /* 25 | vec3 N = normalize(inNormal); 26 | N.y = -N.y; 27 | vec3 T = normalize(inTangent); 28 | vec3 B = cross(N, T); 29 | mat3 TBN = mat3(T, B, N); 30 | vec3 tnorm = TBN * normalize(texture(samplerNormalMap, inUV).xyz * 2.0 - vec3(1.0)); 31 | outNormal = vec4(tnorm, 1.0); 32 | */ 33 | outNormal = vec4(normalize(inNormal), 1.0); 34 | 35 | outAlbedo = texture(samplerColor, inUV); 36 | } -------------------------------------------------------------------------------- /data/shaders/deferred.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/deferred.frag.spv -------------------------------------------------------------------------------- /data/shaders/deferred.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout (location = 0) in vec3 inPos; 7 | layout (location = 1) in vec3 inNormal; 8 | layout (location = 2) in vec3 inUV; 9 | //layout (location = 4) in vec3 inTangent; 10 | 11 | layout (set = 0, binding = 0) uniform UBO 12 | { 13 | mat4 projection; 14 | mat4 model; 15 | mat4 view; 16 | vec4 instancePos[3]; 17 | } ubo; 18 | 19 | layout (location = 0) out vec3 outNormal; 20 | layout (location = 1) out vec3 outUV; 21 | layout (location = 2) out vec3 outColor; 22 | layout (location = 3) out vec3 outWorldPos; 23 | layout (location = 4) out vec3 outTangent; 24 | 25 | layout(push_constant) uniform PushConsts { 26 | vec3 objPos; 27 | } pushConsts; 28 | 29 | out gl_PerVertex 30 | { 31 | vec4 gl_Position; 32 | }; 33 | 34 | void main() 35 | { 36 | vec3 locPos = vec3(ubo.model * vec4(inPos.xyz, 1.0)); 37 | vec4 tmpPos = vec4(locPos + pushConsts.objPos, 1.0); 38 | 39 | gl_Position = ubo.projection * ubo.view * ubo.model * tmpPos; 40 | 41 | outUV = inUV; 42 | outUV.t = 1.0 - outUV.t; 43 | 44 | // Vertex position in world space 45 | outWorldPos = vec3(ubo.model * tmpPos); 46 | // GL to Vulkan coord space 47 | outWorldPos.y = -outWorldPos.y; 48 | 49 | // Normal in world space 50 | mat3 mNormal = transpose(inverse(mat3(ubo.model))); 51 | outNormal = mNormal * normalize(inNormal); 52 | //outTangent = mNormal * normalize(inTangent); 53 | 54 | // Currently just vertex color 55 | outColor = vec3(1.0); 56 | } 57 | -------------------------------------------------------------------------------- /data/shaders/deferred.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/deferred.vert.spv -------------------------------------------------------------------------------- /data/shaders/map.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = 0) in vec3 inColor; 4 | layout (location = 0) out vec4 outFragColor; 5 | 6 | void main() 7 | { 8 | outFragColor = vec4(inColor, 0.5f); 9 | } -------------------------------------------------------------------------------- /data/shaders/map.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/map.frag.spv -------------------------------------------------------------------------------- /data/shaders/map.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = 0) in vec3 inPos; 4 | layout (location = 1) in vec3 inColor; 5 | 6 | layout (location = 0) out vec3 outColor; 7 | 8 | layout (binding = 0) uniform UBO { 9 | mat4 projection; 10 | mat4 model; 11 | } ubo; 12 | 13 | out gl_PerVertex { 14 | vec4 gl_Position; 15 | }; 16 | 17 | void main() 18 | { 19 | gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); 20 | outColor = inColor; 21 | } 22 | -------------------------------------------------------------------------------- /data/shaders/map.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/shaders/map.vert.spv -------------------------------------------------------------------------------- /data/texturesets/default.ktx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/data/texturesets/default.ktx -------------------------------------------------------------------------------- /external/assimp/assimp/.editorconfig: -------------------------------------------------------------------------------- 1 | # See for details 2 | 3 | [*.{h,hpp,inl}] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | indent_size = 4 8 | indent_style = space 9 | -------------------------------------------------------------------------------- /external/assimp/assimp/Compiler/poppack1.h: -------------------------------------------------------------------------------- 1 | 2 | // =============================================================================== 3 | // May be included multiple times - resets structure packing to the defaults 4 | // for all supported compilers. Reverts the changes made by #include 5 | // 6 | // Currently this works on the following compilers: 7 | // MSVC 7,8,9 8 | // GCC 9 | // BORLAND (complains about 'pack state changed but not reverted', but works) 10 | // =============================================================================== 11 | 12 | #ifndef AI_PUSHPACK_IS_DEFINED 13 | # error pushpack1.h must be included after poppack1.h 14 | #endif 15 | 16 | // reset packing to the original value 17 | #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) 18 | # pragma pack( pop ) 19 | #endif 20 | #undef PACK_STRUCT 21 | 22 | #undef AI_PUSHPACK_IS_DEFINED 23 | -------------------------------------------------------------------------------- /external/assimp/assimp/Compiler/pushpack1.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | // =============================================================================== 4 | // May be included multiple times - sets structure packing to 1 5 | // for all supported compilers. #include reverts the changes. 6 | // 7 | // Currently this works on the following compilers: 8 | // MSVC 7,8,9 9 | // GCC 10 | // BORLAND (complains about 'pack state changed but not reverted', but works) 11 | // Clang 12 | // 13 | // 14 | // USAGE: 15 | // 16 | // struct StructToBePacked { 17 | // } PACK_STRUCT; 18 | // 19 | // =============================================================================== 20 | 21 | #ifdef AI_PUSHPACK_IS_DEFINED 22 | # error poppack1.h must be included after pushpack1.h 23 | #endif 24 | 25 | #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) 26 | # pragma pack(push,1) 27 | # define PACK_STRUCT 28 | #elif defined( __GNUC__ ) 29 | # if !defined(HOST_MINGW) 30 | # define PACK_STRUCT __attribute__((__packed__)) 31 | # else 32 | # define PACK_STRUCT __attribute__((gcc_struct, __packed__)) 33 | # endif 34 | #else 35 | # error Compiler not supported 36 | #endif 37 | 38 | #if defined(_MSC_VER) 39 | 40 | // C4103: Packing was changed after the inclusion of the header, probably missing #pragma pop 41 | # pragma warning (disable : 4103) 42 | #endif 43 | 44 | #define AI_PUSHPACK_IS_DEFINED 45 | 46 | 47 | -------------------------------------------------------------------------------- /external/assimp/assimp/DefaultLogger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2015, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | /** @file DefaultLogger.hpp 41 | */ 42 | 43 | #ifndef INCLUDED_AI_DEFAULTLOGGER 44 | #define INCLUDED_AI_DEFAULTLOGGER 45 | 46 | #include "Logger.hpp" 47 | #include "LogStream.hpp" 48 | #include "NullLogger.hpp" 49 | #include 50 | 51 | namespace Assimp { 52 | // ------------------------------------------------------------------------------------ 53 | class IOStream; 54 | struct LogStreamInfo; 55 | 56 | /** default name of logfile */ 57 | #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt" 58 | 59 | // ------------------------------------------------------------------------------------ 60 | /** @brief CPP-API: Primary logging facility of Assimp. 61 | * 62 | * The library stores its primary #Logger as a static member of this class. 63 | * #get() returns this primary logger. By default the underlying implementation is 64 | * just a #NullLogger which rejects all log messages. By calling #create(), logging 65 | * is turned on. To capture the log output multiple log streams (#LogStream) can be 66 | * attach to the logger. Some default streams for common streaming locations (such as 67 | * a file, std::cout, OutputDebugString()) are also provided. 68 | * 69 | * If you wish to customize the logging at an even deeper level supply your own 70 | * implementation of #Logger to #set(). 71 | * @note The whole logging stuff causes a small extra overhead for all imports. */ 72 | class ASSIMP_API DefaultLogger : 73 | public Logger { 74 | 75 | public: 76 | 77 | // ---------------------------------------------------------------------- 78 | /** @brief Creates a logging instance. 79 | * @param name Name for log file. Only valid in combination 80 | * with the aiDefaultLogStream_FILE flag. 81 | * @param severity Log severity, VERBOSE turns on debug messages 82 | * @param defStreams Default log streams to be attached. Any bitwise 83 | * combination of the aiDefaultLogStream enumerated values. 84 | * If #aiDefaultLogStream_FILE is specified but an empty string is 85 | * passed for 'name', no log file is created at all. 86 | * @param io IOSystem to be used to open external files (such as the 87 | * log file). Pass NULL to rely on the default implementation. 88 | * This replaces the default #NullLogger with a #DefaultLogger instance. */ 89 | static Logger *create(const char* name = ASSIMP_DEFAULT_LOG_NAME, 90 | LogSeverity severity = NORMAL, 91 | unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE, 92 | IOSystem* io = NULL); 93 | 94 | // ---------------------------------------------------------------------- 95 | /** @brief Setup a custom #Logger implementation. 96 | * 97 | * Use this if the provided #DefaultLogger class doesn't fit into 98 | * your needs. If the provided message formatting is OK for you, 99 | * it's much easier to use #create() and to attach your own custom 100 | * output streams to it. 101 | * @param logger Pass NULL to setup a default NullLogger*/ 102 | static void set (Logger *logger); 103 | 104 | // ---------------------------------------------------------------------- 105 | /** @brief Getter for singleton instance 106 | * @return Only instance. This is never null, but it could be a 107 | * NullLogger. Use isNullLogger to check this.*/ 108 | static Logger *get(); 109 | 110 | // ---------------------------------------------------------------------- 111 | /** @brief Return whether a #NullLogger is currently active 112 | * @return true if the current logger is a #NullLogger. 113 | * Use create() or set() to setup a logger that does actually do 114 | * something else than just rejecting all log messages. */ 115 | static bool isNullLogger(); 116 | 117 | // ---------------------------------------------------------------------- 118 | /** @brief Kills the current singleton logger and replaces it with a 119 | * #NullLogger instance. */ 120 | static void kill(); 121 | 122 | // ---------------------------------------------------------------------- 123 | /** @copydoc Logger::attachStream */ 124 | bool attachStream(LogStream *pStream, 125 | unsigned int severity); 126 | 127 | // ---------------------------------------------------------------------- 128 | /** @copydoc Logger::detatchStream */ 129 | bool detatchStream(LogStream *pStream, 130 | unsigned int severity); 131 | 132 | 133 | private: 134 | 135 | // ---------------------------------------------------------------------- 136 | /** @briefPrivate construction for internal use by create(). 137 | * @param severity Logging granularity */ 138 | explicit DefaultLogger(LogSeverity severity); 139 | 140 | // ---------------------------------------------------------------------- 141 | /** @briefDestructor */ 142 | ~DefaultLogger(); 143 | 144 | private: 145 | 146 | /** @brief Logs debug infos, only been written when severity level VERBOSE is set */ 147 | void OnDebug(const char* message); 148 | 149 | /** @brief Logs an info message */ 150 | void OnInfo(const char* message); 151 | 152 | /** @brief Logs a warning message */ 153 | void OnWarn(const char* message); 154 | 155 | /** @brief Logs an error message */ 156 | void OnError(const char* message); 157 | 158 | // ---------------------------------------------------------------------- 159 | /** @brief Writes a message to all streams */ 160 | void WriteToStreams(const char* message, ErrorSeverity ErrorSev ); 161 | 162 | // ---------------------------------------------------------------------- 163 | /** @brief Returns the thread id. 164 | * @note This is an OS specific feature, if not supported, a 165 | * zero will be returned. 166 | */ 167 | unsigned int GetThreadID(); 168 | 169 | private: 170 | // Aliases for stream container 171 | typedef std::vector StreamArray; 172 | typedef std::vector::iterator StreamIt; 173 | typedef std::vector::const_iterator ConstStreamIt; 174 | 175 | //! only logging instance 176 | static Logger *m_pLogger; 177 | static NullLogger s_pNullLogger; 178 | 179 | //! Attached streams 180 | StreamArray m_StreamArray; 181 | 182 | bool noRepeatMsg; 183 | char lastMsg[MAX_LOG_MESSAGE_LENGTH*2]; 184 | size_t lastLen; 185 | }; 186 | // ------------------------------------------------------------------------------------ 187 | 188 | } // Namespace Assimp 189 | 190 | #endif // !! INCLUDED_AI_DEFAULTLOGGER 191 | -------------------------------------------------------------------------------- /external/assimp/assimp/IOStream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | /** @file IOStream.hpp 42 | * @brief File I/O wrappers for C++. 43 | */ 44 | 45 | #ifndef AI_IOSTREAM_H_INC 46 | #define AI_IOSTREAM_H_INC 47 | 48 | #include "types.h" 49 | 50 | #ifndef __cplusplus 51 | # error This header requires C++ to be used. aiFileIO.h is the \ 52 | corresponding C interface. 53 | #endif 54 | 55 | namespace Assimp { 56 | 57 | // ---------------------------------------------------------------------------------- 58 | /** @brief CPP-API: Class to handle file I/O for C++ 59 | * 60 | * Derive an own implementation from this interface to provide custom IO handling 61 | * to the Importer. If you implement this interface, be sure to also provide an 62 | * implementation for IOSystem that creates instances of your custom IO class. 63 | */ 64 | class ASSIMP_API IOStream 65 | #ifndef SWIG 66 | : public Intern::AllocateFromAssimpHeap 67 | #endif 68 | { 69 | protected: 70 | /** Constructor protected, use IOSystem::Open() to create an instance. */ 71 | IOStream(void); 72 | 73 | public: 74 | // ------------------------------------------------------------------- 75 | /** @brief Destructor. Deleting the object closes the underlying file, 76 | * alternatively you may use IOSystem::Close() to release the file. 77 | */ 78 | virtual ~IOStream(); 79 | 80 | // ------------------------------------------------------------------- 81 | /** @brief Read from the file 82 | * 83 | * See fread() for more details 84 | * This fails for write-only files */ 85 | virtual size_t Read(void* pvBuffer, 86 | size_t pSize, 87 | size_t pCount) = 0; 88 | 89 | // ------------------------------------------------------------------- 90 | /** @brief Write to the file 91 | * 92 | * See fwrite() for more details 93 | * This fails for read-only files */ 94 | virtual size_t Write(const void* pvBuffer, 95 | size_t pSize, 96 | size_t pCount) = 0; 97 | 98 | // ------------------------------------------------------------------- 99 | /** @brief Set the read/write cursor of the file 100 | * 101 | * Note that the offset is _negative_ for aiOrigin_END. 102 | * See fseek() for more details */ 103 | virtual aiReturn Seek(size_t pOffset, 104 | aiOrigin pOrigin) = 0; 105 | 106 | // ------------------------------------------------------------------- 107 | /** @brief Get the current position of the read/write cursor 108 | * 109 | * See ftell() for more details */ 110 | virtual size_t Tell() const = 0; 111 | 112 | // ------------------------------------------------------------------- 113 | /** @brief Returns filesize 114 | * Returns the filesize. */ 115 | virtual size_t FileSize() const = 0; 116 | 117 | // ------------------------------------------------------------------- 118 | /** @brief Flush the contents of the file buffer (for writers) 119 | * See fflush() for more details. 120 | */ 121 | virtual void Flush() = 0; 122 | }; //! class IOStream 123 | 124 | // ---------------------------------------------------------------------------------- 125 | inline IOStream::IOStream() 126 | { 127 | // empty 128 | } 129 | 130 | // ---------------------------------------------------------------------------------- 131 | inline IOStream::~IOStream() 132 | { 133 | // empty 134 | } 135 | // ---------------------------------------------------------------------------------- 136 | } //!namespace Assimp 137 | 138 | #endif //!!AI_IOSTREAM_H_INC 139 | -------------------------------------------------------------------------------- /external/assimp/assimp/LogStream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2015, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file LogStream.hpp 42 | * @brief Abstract base class 'LogStream', representing an output log stream. 43 | */ 44 | #ifndef INCLUDED_AI_LOGSTREAM_H 45 | #define INCLUDED_AI_LOGSTREAM_H 46 | #include "types.h" 47 | namespace Assimp { 48 | class IOSystem; 49 | 50 | // ------------------------------------------------------------------------------------ 51 | /** @brief CPP-API: Abstract interface for log stream implementations. 52 | * 53 | * Several default implementations are provided, see #aiDefaultLogStream for more 54 | * details. Writing your own implementation of LogStream is just necessary if these 55 | * are not enough for your purpose. */ 56 | class ASSIMP_API LogStream 57 | #ifndef SWIG 58 | : public Intern::AllocateFromAssimpHeap 59 | #endif 60 | { 61 | protected: 62 | /** @brief Default constructor */ 63 | LogStream() { 64 | } 65 | public: 66 | /** @brief Virtual destructor */ 67 | virtual ~LogStream() { 68 | } 69 | 70 | // ------------------------------------------------------------------- 71 | /** @brief Overwrite this for your own output methods 72 | * 73 | * Log messages *may* consist of multiple lines and you shouldn't 74 | * expect a consistent formatting. If you want custom formatting 75 | * (e.g. generate HTML), supply a custom instance of Logger to 76 | * #DefaultLogger:set(). Usually you can *expect* that a log message 77 | * is exactly one line and terminated with a single \n character. 78 | * @param message Message to be written */ 79 | virtual void write(const char* message) = 0; 80 | 81 | // ------------------------------------------------------------------- 82 | /** @brief Creates a default log stream 83 | * @param streams Type of the default stream 84 | * @param name For aiDefaultLogStream_FILE: name of the output file 85 | * @param io For aiDefaultLogStream_FILE: IOSystem to be used to open the output 86 | * file. Pass NULL for the default implementation. 87 | * @return New LogStream instance. */ 88 | static LogStream* createDefaultStream(aiDefaultLogStream stream, 89 | const char* name = "AssimpLog.txt", 90 | IOSystem* io = NULL); 91 | 92 | }; // !class LogStream 93 | // ------------------------------------------------------------------------------------ 94 | } // Namespace Assimp 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /external/assimp/assimp/NullLogger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2015, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file NullLogger.hpp 42 | * @brief Dummy logger 43 | */ 44 | 45 | #ifndef INCLUDED_AI_NULLLOGGER_H 46 | #define INCLUDED_AI_NULLLOGGER_H 47 | 48 | #include "Logger.hpp" 49 | namespace Assimp { 50 | // --------------------------------------------------------------------------- 51 | /** @brief CPP-API: Empty logging implementation. 52 | * 53 | * Does nothing! Used by default if the application hasn't requested a 54 | * custom logger via #DefaultLogger::set() or #DefaultLogger::create(); */ 55 | class ASSIMP_API NullLogger 56 | : public Logger { 57 | 58 | public: 59 | 60 | /** @brief Logs a debug message */ 61 | void OnDebug(const char* message) { 62 | (void)message; //this avoids compiler warnings 63 | } 64 | 65 | /** @brief Logs an info message */ 66 | void OnInfo(const char* message) { 67 | (void)message; //this avoids compiler warnings 68 | } 69 | 70 | /** @brief Logs a warning message */ 71 | void OnWarn(const char* message) { 72 | (void)message; //this avoids compiler warnings 73 | } 74 | 75 | /** @brief Logs an error message */ 76 | void OnError(const char* message) { 77 | (void)message; //this avoids compiler warnings 78 | } 79 | 80 | /** @brief Detach a still attached stream from logger */ 81 | bool attachStream(LogStream *pStream, unsigned int severity) { 82 | (void)pStream; (void)severity; //this avoids compiler warnings 83 | return false; 84 | } 85 | 86 | /** @brief Detach a still attached stream from logger */ 87 | bool detatchStream(LogStream *pStream, unsigned int severity) { 88 | (void)pStream; (void)severity; //this avoids compiler warnings 89 | return false; 90 | } 91 | 92 | private: 93 | }; 94 | } 95 | #endif // !! AI_NULLLOGGER_H_INCLUDED 96 | -------------------------------------------------------------------------------- /external/assimp/assimp/ProgressHandler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2015, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file ProgressHandler.hpp 42 | * @brief Abstract base class 'ProgressHandler'. 43 | */ 44 | #ifndef INCLUDED_AI_PROGRESSHANDLER_H 45 | #define INCLUDED_AI_PROGRESSHANDLER_H 46 | #include "types.h" 47 | namespace Assimp { 48 | 49 | // ------------------------------------------------------------------------------------ 50 | /** @brief CPP-API: Abstract interface for custom progress report receivers. 51 | * 52 | * Each #Importer instance maintains its own #ProgressHandler. The default 53 | * implementation provided by Assimp doesn't do anything at all. */ 54 | class ASSIMP_API ProgressHandler 55 | #ifndef SWIG 56 | : public Intern::AllocateFromAssimpHeap 57 | #endif 58 | { 59 | protected: 60 | /** @brief Default constructor */ 61 | ProgressHandler () { 62 | } 63 | public: 64 | /** @brief Virtual destructor */ 65 | virtual ~ProgressHandler () { 66 | } 67 | 68 | // ------------------------------------------------------------------- 69 | /** @brief Progress callback. 70 | * @param percentage An estimate of the current loading progress, 71 | * in percent. Or -1.f if such an estimate is not available. 72 | * 73 | * There are restriction on what you may do from within your 74 | * implementation of this method: no exceptions may be thrown and no 75 | * non-const #Importer methods may be called. It is 76 | * not generally possible to predict the number of callbacks 77 | * fired during a single import. 78 | * 79 | * @return Return false to abort loading at the next possible 80 | * occasion (loaders and Assimp are generally allowed to perform 81 | * all needed cleanup tasks prior to returning control to the 82 | * caller). If the loading is aborted, #Importer::ReadFile() 83 | * returns always NULL. 84 | * */ 85 | virtual bool Update(float percentage = -1.f) = 0; 86 | 87 | // ------------------------------------------------------------------- 88 | /** @brief Progress callback for file loading steps 89 | * @param numberOfSteps The number of total post-processing 90 | * steps 91 | * @param currentStep The index of the current post-processing 92 | * step that will run, or equal to numberOfSteps if all of 93 | * them has finished. This number is always strictly monotone 94 | * increasing, although not necessarily linearly. 95 | * 96 | * @note This is currently only used at the start and the end 97 | * of the file parsing. 98 | * */ 99 | virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { 100 | float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; 101 | Update( f * 0.5f ); 102 | } 103 | 104 | // ------------------------------------------------------------------- 105 | /** @brief Progress callback for post-processing steps 106 | * @param numberOfSteps The number of total post-processing 107 | * steps 108 | * @param currentStep The index of the current post-processing 109 | * step that will run, or equal to numberOfSteps if all of 110 | * them has finished. This number is always strictly monotone 111 | * increasing, although not necessarily linearly. 112 | * */ 113 | virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { 114 | float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; 115 | Update( f * 0.5f + 0.5f ); 116 | } 117 | 118 | }; // !class ProgressHandler 119 | // ------------------------------------------------------------------------------------ 120 | } // Namespace Assimp 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /external/assimp/assimp/ai_assert.h: -------------------------------------------------------------------------------- 1 | /** @file ai_assert.h 2 | */ 3 | #ifndef AI_DEBUG_H_INC 4 | #define AI_DEBUG_H_INC 5 | 6 | #ifdef ASSIMP_BUILD_DEBUG 7 | # include 8 | # define ai_assert(expression) assert(expression) 9 | #else 10 | # define ai_assert(expression) 11 | #endif 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /external/assimp/assimp/camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file camera.h 43 | * @brief Defines the aiCamera data structure 44 | */ 45 | 46 | #ifndef AI_CAMERA_H_INC 47 | #define AI_CAMERA_H_INC 48 | 49 | #include "types.h" 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | // --------------------------------------------------------------------------- 56 | /** Helper structure to describe a virtual camera. 57 | * 58 | * Cameras have a representation in the node graph and can be animated. 59 | * An important aspect is that the camera itself is also part of the 60 | * scenegraph. This means, any values such as the look-at vector are not 61 | * *absolute*, they're relative to the coordinate system defined 62 | * by the node which corresponds to the camera. This allows for camera 63 | * animations. For static cameras parameters like the 'look-at' or 'up' vectors 64 | * are usually specified directly in aiCamera, but beware, they could also 65 | * be encoded in the node transformation. The following (pseudo)code sample 66 | * shows how to do it:

67 | * @code 68 | * // Get the camera matrix for a camera at a specific time 69 | * // if the node hierarchy for the camera does not contain 70 | * // at least one animated node this is a static computation 71 | * get-camera-matrix (node sceneRoot, camera cam) : matrix 72 | * { 73 | * node cnd = find-node-for-camera(cam) 74 | * matrix cmt = identity() 75 | * 76 | * // as usual - get the absolute camera transformation for this frame 77 | * for each node nd in hierarchy from sceneRoot to cnd 78 | * matrix cur 79 | * if (is-animated(nd)) 80 | * cur = eval-animation(nd) 81 | * else cur = nd->mTransformation; 82 | * cmt = mult-matrices( cmt, cur ) 83 | * end for 84 | * 85 | * // now multiply with the camera's own local transform 86 | * cam = mult-matrices (cam, get-camera-matrix(cmt) ) 87 | * } 88 | * @endcode 89 | * 90 | * @note some file formats (such as 3DS, ASE) export a "target point" - 91 | * the point the camera is looking at (it can even be animated). Assimp 92 | * writes the target point as a subnode of the camera's main node, 93 | * called ".Target". However this is just additional information 94 | * then the transformation tracks of the camera main node make the 95 | * camera already look in the right direction. 96 | * 97 | */ 98 | struct aiCamera 99 | { 100 | /** The name of the camera. 101 | * 102 | * There must be a node in the scenegraph with the same name. 103 | * This node specifies the position of the camera in the scene 104 | * hierarchy and can be animated. 105 | */ 106 | C_STRUCT aiString mName; 107 | 108 | /** Position of the camera relative to the coordinate space 109 | * defined by the corresponding node. 110 | * 111 | * The default value is 0|0|0. 112 | */ 113 | C_STRUCT aiVector3D mPosition; 114 | 115 | 116 | /** 'Up' - vector of the camera coordinate system relative to 117 | * the coordinate space defined by the corresponding node. 118 | * 119 | * The 'right' vector of the camera coordinate system is 120 | * the cross product of the up and lookAt vectors. 121 | * The default value is 0|1|0. The vector 122 | * may be normalized, but it needn't. 123 | */ 124 | C_STRUCT aiVector3D mUp; 125 | 126 | 127 | /** 'LookAt' - vector of the camera coordinate system relative to 128 | * the coordinate space defined by the corresponding node. 129 | * 130 | * This is the viewing direction of the user. 131 | * The default value is 0|0|1. The vector 132 | * may be normalized, but it needn't. 133 | */ 134 | C_STRUCT aiVector3D mLookAt; 135 | 136 | 137 | /** Half horizontal field of view angle, in radians. 138 | * 139 | * The field of view angle is the angle between the center 140 | * line of the screen and the left or right border. 141 | * The default value is 1/4PI. 142 | */ 143 | float mHorizontalFOV; 144 | 145 | /** Distance of the near clipping plane from the camera. 146 | * 147 | * The value may not be 0.f (for arithmetic reasons to prevent 148 | * a division through zero). The default value is 0.1f. 149 | */ 150 | float mClipPlaneNear; 151 | 152 | /** Distance of the far clipping plane from the camera. 153 | * 154 | * The far clipping plane must, of course, be further away than the 155 | * near clipping plane. The default value is 1000.f. The ratio 156 | * between the near and the far plane should not be too 157 | * large (between 1000-10000 should be ok) to avoid floating-point 158 | * inaccuracies which could lead to z-fighting. 159 | */ 160 | float mClipPlaneFar; 161 | 162 | 163 | /** Screen aspect ratio. 164 | * 165 | * This is the ration between the width and the height of the 166 | * screen. Typical values are 4/3, 1/2 or 1/1. This value is 167 | * 0 if the aspect ratio is not defined in the source file. 168 | * 0 is also the default value. 169 | */ 170 | float mAspect; 171 | 172 | #ifdef __cplusplus 173 | 174 | aiCamera() 175 | : mUp (0.f,1.f,0.f) 176 | , mLookAt (0.f,0.f,1.f) 177 | , mHorizontalFOV (0.25f * (float)AI_MATH_PI) 178 | , mClipPlaneNear (0.1f) 179 | , mClipPlaneFar (1000.f) 180 | , mAspect (0.f) 181 | {} 182 | 183 | /** @brief Get a *right-handed* camera matrix from me 184 | * @param out Camera matrix to be filled 185 | */ 186 | void GetCameraMatrix (aiMatrix4x4& out) const 187 | { 188 | /** todo: test ... should work, but i'm not absolutely sure */ 189 | 190 | /** We don't know whether these vectors are already normalized ...*/ 191 | aiVector3D zaxis = mLookAt; zaxis.Normalize(); 192 | aiVector3D yaxis = mUp; yaxis.Normalize(); 193 | aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize(); 194 | 195 | out.a4 = -(xaxis * mPosition); 196 | out.b4 = -(yaxis * mPosition); 197 | out.c4 = -(zaxis * mPosition); 198 | 199 | out.a1 = xaxis.x; 200 | out.a2 = xaxis.y; 201 | out.a3 = xaxis.z; 202 | 203 | out.b1 = yaxis.x; 204 | out.b2 = yaxis.y; 205 | out.b3 = yaxis.z; 206 | 207 | out.c1 = zaxis.x; 208 | out.c2 = zaxis.y; 209 | out.c3 = zaxis.z; 210 | 211 | out.d1 = out.d2 = out.d3 = 0.f; 212 | out.d4 = 1.f; 213 | } 214 | 215 | #endif 216 | }; 217 | 218 | 219 | #ifdef __cplusplus 220 | } 221 | #endif 222 | 223 | #endif // AI_CAMERA_H_INC 224 | -------------------------------------------------------------------------------- /external/assimp/assimp/cfileio.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file cfileio.h 43 | * @brief Defines generic C routines to access memory-mapped files 44 | */ 45 | #ifndef AI_FILEIO_H_INC 46 | #define AI_FILEIO_H_INC 47 | 48 | #include "types.h" 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | struct aiFileIO; 53 | struct aiFile; 54 | 55 | // aiFile callbacks 56 | typedef size_t (*aiFileWriteProc) (C_STRUCT aiFile*, const char*, size_t, size_t); 57 | typedef size_t (*aiFileReadProc) (C_STRUCT aiFile*, char*, size_t,size_t); 58 | typedef size_t (*aiFileTellProc) (C_STRUCT aiFile*); 59 | typedef void (*aiFileFlushProc) (C_STRUCT aiFile*); 60 | typedef aiReturn (*aiFileSeek)(C_STRUCT aiFile*, size_t, aiOrigin); 61 | 62 | // aiFileIO callbacks 63 | typedef aiFile* (*aiFileOpenProc) (C_STRUCT aiFileIO*, const char*, const char*); 64 | typedef void (*aiFileCloseProc) (C_STRUCT aiFileIO*, C_STRUCT aiFile*); 65 | 66 | // Represents user-defined data 67 | typedef char* aiUserData; 68 | 69 | // ---------------------------------------------------------------------------------- 70 | /** @brief C-API: File system callbacks 71 | * 72 | * Provided are functions to open and close files. Supply a custom structure to 73 | * the import function. If you don't, a default implementation is used. Use custom 74 | * file systems to enable reading from other sources, such as ZIPs 75 | * or memory locations. */ 76 | struct aiFileIO 77 | { 78 | /** Function used to open a new file 79 | */ 80 | aiFileOpenProc OpenProc; 81 | 82 | /** Function used to close an existing file 83 | */ 84 | aiFileCloseProc CloseProc; 85 | 86 | /** User-defined, opaque data */ 87 | aiUserData UserData; 88 | }; 89 | 90 | // ---------------------------------------------------------------------------------- 91 | /** @brief C-API: File callbacks 92 | * 93 | * Actually, it's a data structure to wrap a set of fXXXX (e.g fopen) 94 | * replacement functions. 95 | * 96 | * The default implementation of the functions utilizes the fXXX functions from 97 | * the CRT. However, you can supply a custom implementation to Assimp by 98 | * delivering a custom aiFileIO. Use this to enable reading from other sources, 99 | * such as ZIP archives or memory locations. */ 100 | struct aiFile 101 | { 102 | /** Callback to read from a file */ 103 | aiFileReadProc ReadProc; 104 | 105 | /** Callback to write to a file */ 106 | aiFileWriteProc WriteProc; 107 | 108 | /** Callback to retrieve the current position of 109 | * the file cursor (ftell()) 110 | */ 111 | aiFileTellProc TellProc; 112 | 113 | /** Callback to retrieve the size of the file, 114 | * in bytes 115 | */ 116 | aiFileTellProc FileSizeProc; 117 | 118 | /** Callback to set the current position 119 | * of the file cursor (fseek()) 120 | */ 121 | aiFileSeek SeekProc; 122 | 123 | /** Callback to flush the file contents 124 | */ 125 | aiFileFlushProc FlushProc; 126 | 127 | /** User-defined, opaque data 128 | */ 129 | aiUserData UserData; 130 | }; 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | #endif // AI_FILEIO_H_INC 136 | -------------------------------------------------------------------------------- /external/assimp/assimp/color4.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | /** @file color4.h 42 | * @brief RGBA color structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_COLOR4D_H_INC 45 | #define AI_COLOR4D_H_INC 46 | 47 | #include "./Compiler/pushpack1.h" 48 | 49 | #ifdef __cplusplus 50 | 51 | // ---------------------------------------------------------------------------------- 52 | /** Represents a color in Red-Green-Blue space including an 53 | * alpha component. Color values range from 0 to 1. */ 54 | // ---------------------------------------------------------------------------------- 55 | template 56 | class aiColor4t 57 | { 58 | public: 59 | aiColor4t () : r(), g(), b(), a() {} 60 | aiColor4t (TReal _r, TReal _g, TReal _b, TReal _a) 61 | : r(_r), g(_g), b(_b), a(_a) {} 62 | explicit aiColor4t (TReal _r) : r(_r), g(_r), b(_r), a(_r) {} 63 | aiColor4t (const aiColor4t& o) 64 | : r(o.r), g(o.g), b(o.b), a(o.a) {} 65 | 66 | public: 67 | // combined operators 68 | const aiColor4t& operator += (const aiColor4t& o); 69 | const aiColor4t& operator -= (const aiColor4t& o); 70 | const aiColor4t& operator *= (TReal f); 71 | const aiColor4t& operator /= (TReal f); 72 | 73 | public: 74 | // comparison 75 | bool operator == (const aiColor4t& other) const; 76 | bool operator != (const aiColor4t& other) const; 77 | bool operator < (const aiColor4t& other) const; 78 | 79 | // color tuple access, rgba order 80 | inline TReal operator[](unsigned int i) const; 81 | inline TReal& operator[](unsigned int i); 82 | 83 | /** check whether a color is (close to) black */ 84 | inline bool IsBlack() const; 85 | 86 | public: 87 | 88 | // Red, green, blue and alpha color values 89 | TReal r, g, b, a; 90 | } PACK_STRUCT; // !struct aiColor4D 91 | 92 | typedef aiColor4t aiColor4D; 93 | 94 | #else 95 | 96 | struct aiColor4D { 97 | float r, g, b, a; 98 | } PACK_STRUCT; 99 | 100 | #endif // __cplusplus 101 | 102 | #include "./Compiler/poppack1.h" 103 | 104 | #endif // AI_COLOR4D_H_INC 105 | -------------------------------------------------------------------------------- /external/assimp/assimp/color4.inl: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file color4.inl 43 | * @brief Inline implementation of aiColor4t operators 44 | */ 45 | #ifndef AI_COLOR4D_INL_INC 46 | #define AI_COLOR4D_INL_INC 47 | 48 | #ifdef __cplusplus 49 | #include "color4.h" 50 | 51 | // ------------------------------------------------------------------------------------------------ 52 | template 53 | AI_FORCE_INLINE const aiColor4t& aiColor4t::operator += (const aiColor4t& o) { 54 | r += o.r; g += o.g; b += o.b; a += o.a; 55 | return *this; 56 | } 57 | // ------------------------------------------------------------------------------------------------ 58 | template 59 | AI_FORCE_INLINE const aiColor4t& aiColor4t::operator -= (const aiColor4t& o) { 60 | r -= o.r; g -= o.g; b -= o.b; a -= o.a; 61 | return *this; 62 | } 63 | // ------------------------------------------------------------------------------------------------ 64 | template 65 | AI_FORCE_INLINE const aiColor4t& aiColor4t::operator *= (TReal f) { 66 | r *= f; g *= f; b *= f; a *= f; 67 | return *this; 68 | } 69 | // ------------------------------------------------------------------------------------------------ 70 | template 71 | AI_FORCE_INLINE const aiColor4t& aiColor4t::operator /= (TReal f) { 72 | r /= f; g /= f; b /= f; a /= f; 73 | return *this; 74 | } 75 | // ------------------------------------------------------------------------------------------------ 76 | template 77 | AI_FORCE_INLINE TReal aiColor4t::operator[](unsigned int i) const { 78 | return *(&r + i); 79 | } 80 | // ------------------------------------------------------------------------------------------------ 81 | template 82 | AI_FORCE_INLINE TReal& aiColor4t::operator[](unsigned int i) { 83 | return *(&r + i); 84 | } 85 | // ------------------------------------------------------------------------------------------------ 86 | template 87 | AI_FORCE_INLINE bool aiColor4t::operator== (const aiColor4t& other) const { 88 | return r == other.r && g == other.g && b == other.b && a == other.a; 89 | } 90 | // ------------------------------------------------------------------------------------------------ 91 | template 92 | AI_FORCE_INLINE bool aiColor4t::operator!= (const aiColor4t& other) const { 93 | return r != other.r || g != other.g || b != other.b || a != other.a; 94 | } 95 | // ------------------------------------------------------------------------------------------------ 96 | template 97 | AI_FORCE_INLINE bool aiColor4t::operator< (const aiColor4t& other) const { 98 | return r < other.r || ( 99 | r == other.r && ( 100 | g < other.g || ( 101 | g == other.g && ( 102 | b < other.b || ( 103 | b == other.b && ( 104 | a < other.a 105 | ) 106 | ) 107 | ) 108 | ) 109 | ) 110 | ); 111 | } 112 | // ------------------------------------------------------------------------------------------------ 113 | template 114 | AI_FORCE_INLINE aiColor4t operator + (const aiColor4t& v1, const aiColor4t& v2) { 115 | return aiColor4t( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a); 116 | } 117 | // ------------------------------------------------------------------------------------------------ 118 | template 119 | AI_FORCE_INLINE aiColor4t operator - (const aiColor4t& v1, const aiColor4t& v2) { 120 | return aiColor4t( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a); 121 | } 122 | // ------------------------------------------------------------------------------------------------ 123 | template 124 | AI_FORCE_INLINE aiColor4t operator * (const aiColor4t& v1, const aiColor4t& v2) { 125 | return aiColor4t( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a); 126 | } 127 | // ------------------------------------------------------------------------------------------------ 128 | template 129 | AI_FORCE_INLINE aiColor4t operator / (const aiColor4t& v1, const aiColor4t& v2) { 130 | return aiColor4t( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a); 131 | } 132 | // ------------------------------------------------------------------------------------------------ 133 | template 134 | AI_FORCE_INLINE aiColor4t operator * ( TReal f, const aiColor4t& v) { 135 | return aiColor4t( f*v.r, f*v.g, f*v.b, f*v.a); 136 | } 137 | // ------------------------------------------------------------------------------------------------ 138 | template 139 | AI_FORCE_INLINE aiColor4t operator * ( const aiColor4t& v, TReal f) { 140 | return aiColor4t( f*v.r, f*v.g, f*v.b, f*v.a); 141 | } 142 | // ------------------------------------------------------------------------------------------------ 143 | template 144 | AI_FORCE_INLINE aiColor4t operator / ( const aiColor4t& v, TReal f) { 145 | return v * (1/f); 146 | } 147 | // ------------------------------------------------------------------------------------------------ 148 | template 149 | AI_FORCE_INLINE aiColor4t operator / ( TReal f,const aiColor4t& v) { 150 | return aiColor4t(f,f,f,f)/v; 151 | } 152 | // ------------------------------------------------------------------------------------------------ 153 | template 154 | AI_FORCE_INLINE aiColor4t operator + ( const aiColor4t& v, TReal f) { 155 | return aiColor4t( f+v.r, f+v.g, f+v.b, f+v.a); 156 | } 157 | // ------------------------------------------------------------------------------------------------ 158 | template 159 | AI_FORCE_INLINE aiColor4t operator - ( const aiColor4t& v, TReal f) { 160 | return aiColor4t( v.r-f, v.g-f, v.b-f, v.a-f); 161 | } 162 | // ------------------------------------------------------------------------------------------------ 163 | template 164 | AI_FORCE_INLINE aiColor4t operator + ( TReal f, const aiColor4t& v) { 165 | return aiColor4t( f+v.r, f+v.g, f+v.b, f+v.a); 166 | } 167 | // ------------------------------------------------------------------------------------------------ 168 | template 169 | AI_FORCE_INLINE aiColor4t operator - ( TReal f, const aiColor4t& v) { 170 | return aiColor4t( f-v.r, f-v.g, f-v.b, f-v.a); 171 | } 172 | 173 | // ------------------------------------------------------------------------------------------------ 174 | template 175 | inline bool aiColor4t :: IsBlack() const { 176 | // The alpha component doesn't care here. black is black. 177 | static const TReal epsilon = 10e-3f; 178 | return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon; 179 | } 180 | 181 | #endif // __cplusplus 182 | #endif // AI_VECTOR3D_INL_INC 183 | -------------------------------------------------------------------------------- /external/assimp/assimp/importerdesc.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file importerdesc.h 43 | * @brief #aiImporterFlags, aiImporterDesc implementation. 44 | */ 45 | #ifndef INCLUDED_AI_IMPORTER_DESC_H 46 | #define INCLUDED_AI_IMPORTER_DESC_H 47 | 48 | 49 | /** Mixed set of flags for #aiImporterDesc, indicating some features 50 | * common to many importers*/ 51 | enum aiImporterFlags 52 | { 53 | /** Indicates that there is a textual encoding of the 54 | * file format; and that it is supported.*/ 55 | aiImporterFlags_SupportTextFlavour = 0x1, 56 | 57 | /** Indicates that there is a binary encoding of the 58 | * file format; and that it is supported.*/ 59 | aiImporterFlags_SupportBinaryFlavour = 0x2, 60 | 61 | /** Indicates that there is a compressed encoding of the 62 | * file format; and that it is supported.*/ 63 | aiImporterFlags_SupportCompressedFlavour = 0x4, 64 | 65 | /** Indicates that the importer reads only a very particular 66 | * subset of the file format. This happens commonly for 67 | * declarative or procedural formats which cannot easily 68 | * be mapped to #aiScene */ 69 | aiImporterFlags_LimitedSupport = 0x8, 70 | 71 | /** Indicates that the importer is highly experimental and 72 | * should be used with care. This only happens for trunk 73 | * (i.e. SVN) versions, experimental code is not included 74 | * in releases. */ 75 | aiImporterFlags_Experimental = 0x10 76 | }; 77 | 78 | 79 | /** Meta information about a particular importer. Importers need to fill 80 | * this structure, but they can freely decide how talkative they are. 81 | * A common use case for loader meta info is a user interface 82 | * in which the user can choose between various import/export file 83 | * formats. Building such an UI by hand means a lot of maintenance 84 | * as importers/exporters are added to Assimp, so it might be useful 85 | * to have a common mechanism to query some rough importer 86 | * characteristics. */ 87 | struct aiImporterDesc 88 | { 89 | /** Full name of the importer (i.e. Blender3D importer)*/ 90 | const char* mName; 91 | 92 | /** Original author (left blank if unknown or whole assimp team) */ 93 | const char* mAuthor; 94 | 95 | /** Current maintainer, left blank if the author maintains */ 96 | const char* mMaintainer; 97 | 98 | /** Implementation comments, i.e. unimplemented features*/ 99 | const char* mComments; 100 | 101 | /** These flags indicate some characteristics common to many 102 | importers. */ 103 | unsigned int mFlags; 104 | 105 | /** Minimum format version that can be loaded im major.minor format, 106 | both are set to 0 if there is either no version scheme 107 | or if the loader doesn't care. */ 108 | unsigned int mMinMajor; 109 | unsigned int mMinMinor; 110 | 111 | /** Maximum format version that can be loaded im major.minor format, 112 | both are set to 0 if there is either no version scheme 113 | or if the loader doesn't care. Loaders that expect to be 114 | forward-compatible to potential future format versions should 115 | indicate zero, otherwise they should specify the current 116 | maximum version.*/ 117 | unsigned int mMaxMajor; 118 | unsigned int mMaxMinor; 119 | 120 | /** List of file extensions this importer can handle. 121 | List entries are separated by space characters. 122 | All entries are lower case without a leading dot (i.e. 123 | "xml dae" would be a valid value. Note that multiple 124 | importers may respond to the same file extension - 125 | assimp calls all importers in the order in which they 126 | are registered and each importer gets the opportunity 127 | to load the file until one importer "claims" the file. Apart 128 | from file extension checks, importers typically use 129 | other methods to quickly reject files (i.e. magic 130 | words) so this does not mean that common or generic 131 | file extensions such as XML would be tediously slow. */ 132 | const char* mFileExtensions; 133 | }; 134 | 135 | /** \brief Returns the Importer description for a given extension. 136 | 137 | Will return a NULL-pointer if no assigned importer desc. was found for the given extension 138 | \param extension [in] The extension to look for 139 | \return A pointer showing to the ImporterDesc, \see aiImporterDesc. 140 | */ 141 | ASSIMP_API const C_STRUCT aiImporterDesc* aiGetImporterDesc( const char *extension ); 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /external/assimp/assimp/matrix3x3.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/external/assimp/assimp/matrix3x3.h -------------------------------------------------------------------------------- /external/assimp/assimp/matrix3x3.inl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/external/assimp/assimp/matrix3x3.inl -------------------------------------------------------------------------------- /external/assimp/assimp/matrix4x4.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/external/assimp/assimp/matrix4x4.h -------------------------------------------------------------------------------- /external/assimp/assimp/matrix4x4.inl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SaschaWillems/VulkanDungeonCrawler/2e0b6c9e40ed4e900f31ae6518b1279ea35535a8/external/assimp/assimp/matrix4x4.inl -------------------------------------------------------------------------------- /external/assimp/assimp/metadata.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file metadata.h 43 | * @brief Defines the data structures for holding node meta information. 44 | */ 45 | #ifndef __AI_METADATA_H_INC__ 46 | #define __AI_METADATA_H_INC__ 47 | 48 | #include 49 | 50 | #if defined(_MSC_VER) && (_MSC_VER <= 1500) 51 | #include "Compiler/pstdint.h" 52 | #else 53 | #include 54 | #include 55 | #endif 56 | 57 | 58 | 59 | // ------------------------------------------------------------------------------- 60 | /** 61 | * Enum used to distinguish data types 62 | */ 63 | // ------------------------------------------------------------------------------- 64 | typedef enum aiMetadataType 65 | { 66 | AI_BOOL = 0, 67 | AI_INT = 1, 68 | AI_UINT64 = 2, 69 | AI_FLOAT = 3, 70 | AI_AISTRING = 4, 71 | AI_AIVECTOR3D = 5, 72 | 73 | #ifndef SWIG 74 | FORCE_32BIT = INT_MAX 75 | #endif 76 | } aiMetadataType; 77 | 78 | 79 | 80 | // ------------------------------------------------------------------------------- 81 | /** 82 | * Metadata entry 83 | * 84 | * The type field uniquely identifies the underlying type of the data field 85 | */ 86 | // ------------------------------------------------------------------------------- 87 | struct aiMetadataEntry 88 | { 89 | aiMetadataType mType; 90 | void* mData; 91 | }; 92 | 93 | 94 | 95 | #ifdef __cplusplus 96 | 97 | #include 98 | 99 | 100 | 101 | // ------------------------------------------------------------------------------- 102 | /** 103 | * Helper functions to get the aiType enum entry for a type 104 | */ 105 | // ------------------------------------------------------------------------------- 106 | inline aiMetadataType GetAiType( bool ) { return AI_BOOL; } 107 | inline aiMetadataType GetAiType( int ) { return AI_INT; } 108 | inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; } 109 | inline aiMetadataType GetAiType( float ) { return AI_FLOAT; } 110 | inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; } 111 | inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; } 112 | 113 | 114 | 115 | #endif 116 | 117 | 118 | 119 | // ------------------------------------------------------------------------------- 120 | /** 121 | * Container for holding metadata. 122 | * 123 | * Metadata is a key-value store using string keys and values. 124 | */ 125 | // ------------------------------------------------------------------------------- 126 | struct aiMetadata 127 | { 128 | /** Length of the mKeys and mValues arrays, respectively */ 129 | unsigned int mNumProperties; 130 | 131 | /** Arrays of keys, may not be NULL. Entries in this array may not be NULL as well. */ 132 | C_STRUCT aiString* mKeys; 133 | 134 | /** Arrays of values, may not be NULL. Entries in this array may be NULL if the 135 | * corresponding property key has no assigned value. */ 136 | C_STRUCT aiMetadataEntry* mValues; 137 | 138 | #ifdef __cplusplus 139 | 140 | /** Constructor */ 141 | aiMetadata() 142 | // set all members to zero by default 143 | : mNumProperties(0) 144 | , mKeys(NULL) 145 | , mValues(NULL) 146 | {} 147 | 148 | 149 | /** Destructor */ 150 | ~aiMetadata() 151 | { 152 | delete[] mKeys; 153 | mKeys = NULL; 154 | if (mValues) 155 | { 156 | // Delete each metadata entry 157 | for (unsigned i=0; i(data); 164 | break; 165 | case AI_INT: 166 | delete static_cast(data); 167 | break; 168 | case AI_UINT64: 169 | delete static_cast(data); 170 | break; 171 | case AI_FLOAT: 172 | delete static_cast(data); 173 | break; 174 | case AI_AISTRING: 175 | delete static_cast(data); 176 | break; 177 | case AI_AIVECTOR3D: 178 | delete static_cast(data); 179 | break; 180 | default: 181 | assert(false); 182 | break; 183 | } 184 | } 185 | 186 | // Delete the metadata array 187 | delete [] mValues; 188 | mValues = NULL; 189 | } 190 | } 191 | 192 | 193 | 194 | template 195 | inline void Set( unsigned index, const std::string& key, const T& value ) 196 | { 197 | // In range assertion 198 | assert(index < mNumProperties); 199 | 200 | // Set metadata key 201 | mKeys[index] = key; 202 | 203 | // Set metadata type 204 | mValues[index].mType = GetAiType(value); 205 | // Copy the given value to the dynamic storage 206 | mValues[index].mData = new T(value); 207 | } 208 | 209 | template 210 | inline bool Get( unsigned index, T& value ) 211 | { 212 | // In range assertion 213 | assert(index < mNumProperties); 214 | 215 | // Return false if the output data type does 216 | // not match the found value's data type 217 | if ( GetAiType( value ) != mValues[ index ].mType ) { 218 | return false; 219 | } 220 | 221 | // Otherwise, output the found value and 222 | // return true 223 | value = *static_cast(mValues[index].mData); 224 | return true; 225 | } 226 | 227 | template 228 | inline bool Get( const aiString& key, T& value ) 229 | { 230 | // Search for the given key 231 | for (unsigned i=0; i 238 | inline bool Get( const std::string& key, T& value ) { 239 | return Get(aiString(key), value); 240 | } 241 | 242 | #endif // __cplusplus 243 | 244 | }; 245 | 246 | #endif // __AI_METADATA_H_INC__ 247 | 248 | 249 | -------------------------------------------------------------------------------- /external/assimp/assimp/port/AndroidJNI/AndroidJNIIOSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2012, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file Android implementation of IOSystem using the standard C file functions. 42 | * Aimed to ease the acces to android assets */ 43 | 44 | #if __ANDROID__ and __ANDROID_API__ > 9 and defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) 45 | #ifndef AI_ANDROIDJNIIOSYSTEM_H_INC 46 | #define AI_ANDROIDJNIIOSYSTEM_H_INC 47 | 48 | #include "../code/DefaultIOSystem.h" 49 | #include 50 | #include 51 | #include 52 | 53 | namespace Assimp { 54 | 55 | // --------------------------------------------------------------------------- 56 | /** Android extension to DefaultIOSystem using the standard C file functions */ 57 | class AndroidJNIIOSystem : public DefaultIOSystem 58 | { 59 | public: 60 | 61 | /** Initialize android activity data */ 62 | std::string mApkWorkspacePath; 63 | AAssetManager* mApkAssetManager; 64 | 65 | /** Constructor. */ 66 | AndroidJNIIOSystem(ANativeActivity* activity); 67 | 68 | /** Destructor. */ 69 | ~AndroidJNIIOSystem(); 70 | 71 | // ------------------------------------------------------------------- 72 | /** Tests for the existence of a file at the given path. */ 73 | bool Exists( const char* pFile) const; 74 | 75 | // ------------------------------------------------------------------- 76 | /** Opens a file at the given path, with given mode */ 77 | IOStream* Open( const char* strFile, const char* strMode); 78 | 79 | // ------------------------------------------------------------------------------------------------ 80 | // Inits Android extractor 81 | void AndroidActivityInit(ANativeActivity* activity); 82 | 83 | // ------------------------------------------------------------------------------------------------ 84 | // Extracts android asset 85 | bool AndroidExtractAsset(std::string name); 86 | 87 | }; 88 | 89 | } //!ns Assimp 90 | 91 | #endif //AI_ANDROIDJNIIOSYSTEM_H_INC 92 | #endif //__ANDROID__ and __ANDROID_API__ > 9 and defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) 93 | -------------------------------------------------------------------------------- /external/assimp/assimp/quaternion.h: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2015, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file quaternion.h 42 | * @brief Quaternion structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_QUATERNION_H_INC 45 | #define AI_QUATERNION_H_INC 46 | 47 | #ifdef __cplusplus 48 | 49 | template class aiVector3t; 50 | template class aiMatrix3x3t; 51 | 52 | // --------------------------------------------------------------------------- 53 | /** Represents a quaternion in a 4D vector. */ 54 | template 55 | class aiQuaterniont 56 | { 57 | public: 58 | aiQuaterniont() : w(1.0), x(), y(), z() {} 59 | aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz) 60 | : w(pw), x(px), y(py), z(pz) {} 61 | 62 | /** Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. */ 63 | explicit aiQuaterniont( const aiMatrix3x3t& pRotMatrix); 64 | 65 | /** Construct from euler angles */ 66 | aiQuaterniont( TReal rotx, TReal roty, TReal rotz); 67 | 68 | /** Construct from an axis-angle pair */ 69 | aiQuaterniont( aiVector3t axis, TReal angle); 70 | 71 | /** Construct from a normalized quaternion stored in a vec3 */ 72 | explicit aiQuaterniont( aiVector3t normalized); 73 | 74 | /** Returns a matrix representation of the quaternion */ 75 | aiMatrix3x3t GetMatrix() const; 76 | 77 | public: 78 | 79 | bool operator== (const aiQuaterniont& o) const; 80 | bool operator!= (const aiQuaterniont& o) const; 81 | 82 | bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const; 83 | 84 | public: 85 | 86 | /** Normalize the quaternion */ 87 | aiQuaterniont& Normalize(); 88 | 89 | /** Compute quaternion conjugate */ 90 | aiQuaterniont& Conjugate (); 91 | 92 | /** Rotate a point by this quaternion */ 93 | aiVector3t Rotate (const aiVector3t& in); 94 | 95 | /** Multiply two quaternions */ 96 | aiQuaterniont operator* (const aiQuaterniont& two) const; 97 | 98 | public: 99 | 100 | /** Performs a spherical interpolation between two quaternions and writes the result into the third. 101 | * @param pOut Target object to received the interpolated rotation. 102 | * @param pStart Start rotation of the interpolation at factor == 0. 103 | * @param pEnd End rotation, factor == 1. 104 | * @param pFactor Interpolation factor between 0 and 1. Values outside of this range yield undefined results. 105 | */ 106 | static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart, 107 | const aiQuaterniont& pEnd, TReal pFactor); 108 | 109 | public: 110 | 111 | //! w,x,y,z components of the quaternion 112 | TReal w, x, y, z; 113 | } ; 114 | 115 | typedef aiQuaterniont aiQuaternion; 116 | 117 | #else 118 | 119 | struct aiQuaternion { 120 | float w, x, y, z; 121 | }; 122 | 123 | #endif 124 | 125 | 126 | #endif // AI_QUATERNION_H_INC 127 | -------------------------------------------------------------------------------- /external/assimp/assimp/texture.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file texture.h 43 | * @brief Defines texture helper structures for the library 44 | * 45 | * Used for file formats which embed their textures into the model file. 46 | * Supported are both normal textures, which are stored as uncompressed 47 | * pixels, and "compressed" textures, which are stored in a file format 48 | * such as PNG or TGA. 49 | */ 50 | 51 | #ifndef AI_TEXTURE_H_INC 52 | #define AI_TEXTURE_H_INC 53 | 54 | #include "types.h" 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | 61 | // -------------------------------------------------------------------------------- 62 | /** @def AI_MAKE_EMBEDDED_TEXNAME 63 | * Used to build the reserved path name used by the material system to 64 | * reference textures that are embedded into their corresponding 65 | * model files. The parameter specifies the index of the texture 66 | * (zero-based, in the aiScene::mTextures array) 67 | */ 68 | #if (!defined AI_MAKE_EMBEDDED_TEXNAME) 69 | # define AI_MAKE_EMBEDDED_TEXNAME(_n_) "*" # _n_ 70 | #endif 71 | 72 | 73 | #include "./Compiler/pushpack1.h" 74 | 75 | // -------------------------------------------------------------------------------- 76 | /** @brief Helper structure to represent a texel in a ARGB8888 format 77 | * 78 | * Used by aiTexture. 79 | */ 80 | struct aiTexel 81 | { 82 | unsigned char b,g,r,a; 83 | 84 | #ifdef __cplusplus 85 | //! Comparison operator 86 | bool operator== (const aiTexel& other) const 87 | { 88 | return b == other.b && r == other.r && 89 | g == other.g && a == other.a; 90 | } 91 | 92 | //! Inverse comparison operator 93 | bool operator!= (const aiTexel& other) const 94 | { 95 | return b != other.b || r != other.r || 96 | g != other.g || a != other.a; 97 | } 98 | 99 | //! Conversion to a floating-point 4d color 100 | operator aiColor4D() const 101 | { 102 | return aiColor4D(r/255.f,g/255.f,b/255.f,a/255.f); 103 | } 104 | #endif // __cplusplus 105 | 106 | } PACK_STRUCT; 107 | 108 | #include "./Compiler/poppack1.h" 109 | 110 | // -------------------------------------------------------------------------------- 111 | /** Helper structure to describe an embedded texture 112 | * 113 | * Normally textures are contained in external files but some file formats embed 114 | * them directly in the model file. There are two types of embedded textures: 115 | * 1. Uncompressed textures. The color data is given in an uncompressed format. 116 | * 2. Compressed textures stored in a file format like png or jpg. The raw file 117 | * bytes are given so the application must utilize an image decoder (e.g. DevIL) to 118 | * get access to the actual color data. 119 | * 120 | * Embedded textures are referenced from materials using strings like "*0", "*1", etc. 121 | * as the texture paths (a single asterisk character followed by the 122 | * zero-based index of the texture in the aiScene::mTextures array). 123 | */ 124 | struct aiTexture 125 | { 126 | /** Width of the texture, in pixels 127 | * 128 | * If mHeight is zero the texture is compressed in a format 129 | * like JPEG. In this case mWidth specifies the size of the 130 | * memory area pcData is pointing to, in bytes. 131 | */ 132 | unsigned int mWidth; 133 | 134 | /** Height of the texture, in pixels 135 | * 136 | * If this value is zero, pcData points to an compressed texture 137 | * in any format (e.g. JPEG). 138 | */ 139 | unsigned int mHeight; 140 | 141 | /** A hint from the loader to make it easier for applications 142 | * to determine the type of embedded compressed textures. 143 | * 144 | * If mHeight != 0 this member is undefined. Otherwise it 145 | * is set set to '\\0\\0\\0\\0' if the loader has no additional 146 | * information about the texture file format used OR the 147 | * file extension of the format without a trailing dot. If there 148 | * are multiple file extensions for a format, the shortest 149 | * extension is chosen (JPEG maps to 'jpg', not to 'jpeg'). 150 | * E.g. 'dds\\0', 'pcx\\0', 'jpg\\0'. All characters are lower-case. 151 | * The fourth character will always be '\\0'. 152 | */ 153 | char achFormatHint[4]; 154 | 155 | /** Data of the texture. 156 | * 157 | * Points to an array of mWidth * mHeight aiTexel's. 158 | * The format of the texture data is always ARGB8888 to 159 | * make the implementation for user of the library as easy 160 | * as possible. If mHeight = 0 this is a pointer to a memory 161 | * buffer of size mWidth containing the compressed texture 162 | * data. Good luck, have fun! 163 | */ 164 | C_STRUCT aiTexel* pcData; 165 | 166 | #ifdef __cplusplus 167 | 168 | //! For compressed textures (mHeight == 0): compare the 169 | //! format hint against a given string. 170 | //! @param s Input string. 3 characters are maximally processed. 171 | //! Example values: "jpg", "png" 172 | //! @return true if the given string matches the format hint 173 | bool CheckFormat(const char* s) const 174 | { 175 | return (0 == ::strncmp(achFormatHint,s,3)); 176 | } 177 | 178 | // Construction 179 | aiTexture () 180 | : mWidth (0) 181 | , mHeight (0) 182 | , pcData (NULL) 183 | { 184 | achFormatHint[0] = achFormatHint[1] = 0; 185 | achFormatHint[2] = achFormatHint[3] = 0; 186 | } 187 | 188 | // Destruction 189 | ~aiTexture () 190 | { 191 | delete[] pcData; 192 | } 193 | #endif 194 | }; 195 | 196 | 197 | #ifdef __cplusplus 198 | } 199 | #endif 200 | 201 | #endif // AI_TEXTURE_H_INC 202 | -------------------------------------------------------------------------------- /external/assimp/assimp/vector2.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | /** @file vector2.h 42 | * @brief 2D vector structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_VECTOR2D_H_INC 45 | #define AI_VECTOR2D_H_INC 46 | 47 | #ifdef __cplusplus 48 | # include 49 | #else 50 | # include 51 | #endif 52 | 53 | #include "./Compiler/pushpack1.h" 54 | 55 | // ---------------------------------------------------------------------------------- 56 | /** Represents a two-dimensional vector. 57 | */ 58 | 59 | #ifdef __cplusplus 60 | template 61 | class aiVector2t 62 | { 63 | public: 64 | 65 | aiVector2t () : x(), y() {} 66 | aiVector2t (TReal _x, TReal _y) : x(_x), y(_y) {} 67 | explicit aiVector2t (TReal _xyz) : x(_xyz), y(_xyz) {} 68 | aiVector2t (const aiVector2t& o) : x(o.x), y(o.y) {} 69 | 70 | public: 71 | 72 | void Set( TReal pX, TReal pY); 73 | TReal SquareLength() const ; 74 | TReal Length() const ; 75 | aiVector2t& Normalize(); 76 | 77 | public: 78 | 79 | const aiVector2t& operator += (const aiVector2t& o); 80 | const aiVector2t& operator -= (const aiVector2t& o); 81 | const aiVector2t& operator *= (TReal f); 82 | const aiVector2t& operator /= (TReal f); 83 | 84 | TReal operator[](unsigned int i) const; 85 | TReal& operator[](unsigned int i); 86 | 87 | bool operator== (const aiVector2t& other) const; 88 | bool operator!= (const aiVector2t& other) const; 89 | 90 | bool Equal(const aiVector2t& other, TReal epsilon = 1e-6) const; 91 | 92 | aiVector2t& operator= (TReal f); 93 | const aiVector2t SymMul(const aiVector2t& o); 94 | 95 | template 96 | operator aiVector2t () const; 97 | 98 | TReal x, y; 99 | } PACK_STRUCT; 100 | 101 | typedef aiVector2t aiVector2D; 102 | 103 | #else 104 | 105 | struct aiVector2D { 106 | float x,y; 107 | }; 108 | 109 | #endif // __cplusplus 110 | 111 | #include "./Compiler/poppack1.h" 112 | 113 | #endif // AI_VECTOR2D_H_INC 114 | -------------------------------------------------------------------------------- /external/assimp/assimp/vector2.inl: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file vector2.inl 43 | * @brief Inline implementation of aiVector2t operators 44 | */ 45 | #ifndef AI_VECTOR2D_INL_INC 46 | #define AI_VECTOR2D_INL_INC 47 | 48 | #ifdef __cplusplus 49 | #include "vector2.h" 50 | 51 | #include 52 | 53 | // ------------------------------------------------------------------------------------------------ 54 | template 55 | template 56 | aiVector2t::operator aiVector2t () const { 57 | return aiVector2t(static_cast(x),static_cast(y)); 58 | } 59 | // ------------------------------------------------------------------------------------------------ 60 | template 61 | void aiVector2t::Set( TReal pX, TReal pY) { 62 | x = pX; y = pY; 63 | } 64 | 65 | // ------------------------------------------------------------------------------------------------ 66 | template 67 | TReal aiVector2t::SquareLength() const { 68 | return x*x + y*y; 69 | } 70 | 71 | // ------------------------------------------------------------------------------------------------ 72 | template 73 | TReal aiVector2t::Length() const { 74 | return std::sqrt( SquareLength()); 75 | } 76 | 77 | // ------------------------------------------------------------------------------------------------ 78 | template 79 | aiVector2t& aiVector2t::Normalize() { 80 | *this /= Length(); 81 | return *this; 82 | } 83 | 84 | // ------------------------------------------------------------------------------------------------ 85 | template 86 | const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { 87 | x += o.x; y += o.y; 88 | return *this; 89 | } 90 | 91 | // ------------------------------------------------------------------------------------------------ 92 | template 93 | const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { 94 | x -= o.x; y -= o.y; 95 | return *this; 96 | } 97 | 98 | // ------------------------------------------------------------------------------------------------ 99 | template 100 | const aiVector2t& aiVector2t::operator *= (TReal f) { 101 | x *= f; y *= f; 102 | return *this; 103 | } 104 | 105 | // ------------------------------------------------------------------------------------------------ 106 | template 107 | const aiVector2t& aiVector2t::operator /= (TReal f) { 108 | x /= f; y /= f; 109 | return *this; 110 | } 111 | 112 | // ------------------------------------------------------------------------------------------------ 113 | template 114 | TReal aiVector2t::operator[](unsigned int i) const { 115 | return *(&x + i); 116 | } 117 | 118 | // ------------------------------------------------------------------------------------------------ 119 | template 120 | TReal& aiVector2t::operator[](unsigned int i) { 121 | return *(&x + i); 122 | } 123 | 124 | // ------------------------------------------------------------------------------------------------ 125 | template 126 | bool aiVector2t::operator== (const aiVector2t& other) const { 127 | return x == other.x && y == other.y; 128 | } 129 | 130 | // ------------------------------------------------------------------------------------------------ 131 | template 132 | bool aiVector2t::operator!= (const aiVector2t& other) const { 133 | return x != other.x || y != other.y; 134 | } 135 | 136 | // --------------------------------------------------------------------------- 137 | template 138 | bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { 139 | return 140 | std::abs(x - other.x) <= epsilon && 141 | std::abs(y - other.y) <= epsilon; 142 | } 143 | 144 | // ------------------------------------------------------------------------------------------------ 145 | template 146 | aiVector2t& aiVector2t::operator= (TReal f) { 147 | x = y = f; 148 | return *this; 149 | } 150 | 151 | // ------------------------------------------------------------------------------------------------ 152 | template 153 | const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { 154 | return aiVector2t(x*o.x,y*o.y); 155 | } 156 | 157 | 158 | // ------------------------------------------------------------------------------------------------ 159 | // symmetric addition 160 | template 161 | inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) 162 | { 163 | return aiVector2t( v1.x + v2.x, v1.y + v2.y); 164 | } 165 | 166 | // ------------------------------------------------------------------------------------------------ 167 | // symmetric subtraction 168 | template 169 | inline aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) 170 | { 171 | return aiVector2t( v1.x - v2.x, v1.y - v2.y); 172 | } 173 | 174 | // ------------------------------------------------------------------------------------------------ 175 | // scalar product 176 | template 177 | inline TReal operator * (const aiVector2t& v1, const aiVector2t& v2) 178 | { 179 | return v1.x*v2.x + v1.y*v2.y; 180 | } 181 | 182 | // ------------------------------------------------------------------------------------------------ 183 | // scalar multiplication 184 | template 185 | inline aiVector2t operator * ( TReal f, const aiVector2t& v) 186 | { 187 | return aiVector2t( f*v.x, f*v.y); 188 | } 189 | 190 | // ------------------------------------------------------------------------------------------------ 191 | // and the other way around 192 | template 193 | inline aiVector2t operator * ( const aiVector2t& v, TReal f) 194 | { 195 | return aiVector2t( f*v.x, f*v.y); 196 | } 197 | 198 | // ------------------------------------------------------------------------------------------------ 199 | // scalar division 200 | template 201 | inline aiVector2t operator / ( const aiVector2t& v, TReal f) 202 | { 203 | 204 | return v * (1/f); 205 | } 206 | 207 | // ------------------------------------------------------------------------------------------------ 208 | // vector division 209 | template 210 | inline aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) 211 | { 212 | return aiVector2t(v.x / v2.x,v.y / v2.y); 213 | } 214 | 215 | // ------------------------------------------------------------------------------------------------ 216 | // vector negation 217 | template 218 | inline aiVector2t operator - ( const aiVector2t& v) 219 | { 220 | return aiVector2t( -v.x, -v.y); 221 | } 222 | 223 | #endif 224 | #endif 225 | -------------------------------------------------------------------------------- /external/assimp/assimp/vector3.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | /** @file vector3.h 42 | * @brief 3D vector structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_VECTOR3D_H_INC 45 | #define AI_VECTOR3D_H_INC 46 | 47 | #ifdef __cplusplus 48 | # include 49 | #else 50 | # include 51 | #endif 52 | 53 | #include "./Compiler/pushpack1.h" 54 | 55 | #ifdef __cplusplus 56 | 57 | template class aiMatrix3x3t; 58 | template class aiMatrix4x4t; 59 | 60 | // --------------------------------------------------------------------------- 61 | /** Represents a three-dimensional vector. */ 62 | template 63 | class aiVector3t 64 | { 65 | public: 66 | 67 | aiVector3t () : x(), y(), z() {} 68 | aiVector3t (TReal _x, TReal _y, TReal _z) : x(_x), y(_y), z(_z) {} 69 | explicit aiVector3t (TReal _xyz) : x(_xyz), y(_xyz), z(_xyz) {} 70 | aiVector3t (const aiVector3t& o) : x(o.x), y(o.y), z(o.z) {} 71 | 72 | public: 73 | 74 | // combined operators 75 | const aiVector3t& operator += (const aiVector3t& o); 76 | const aiVector3t& operator -= (const aiVector3t& o); 77 | const aiVector3t& operator *= (TReal f); 78 | const aiVector3t& operator /= (TReal f); 79 | 80 | // transform vector by matrix 81 | aiVector3t& operator *= (const aiMatrix3x3t& mat); 82 | aiVector3t& operator *= (const aiMatrix4x4t& mat); 83 | 84 | // access a single element 85 | TReal operator[](unsigned int i) const; 86 | TReal& operator[](unsigned int i); 87 | 88 | // comparison 89 | bool operator== (const aiVector3t& other) const; 90 | bool operator!= (const aiVector3t& other) const; 91 | bool operator < (const aiVector3t& other) const; 92 | 93 | bool Equal(const aiVector3t& other, TReal epsilon = 1e-6) const; 94 | 95 | template 96 | operator aiVector3t () const; 97 | 98 | public: 99 | 100 | /** @brief Set the components of a vector 101 | * @param pX X component 102 | * @param pY Y component 103 | * @param pZ Z component */ 104 | void Set( TReal pX, TReal pY, TReal pZ); 105 | 106 | /** @brief Get the squared length of the vector 107 | * @return Square length */ 108 | TReal SquareLength() const; 109 | 110 | 111 | /** @brief Get the length of the vector 112 | * @return length */ 113 | TReal Length() const; 114 | 115 | 116 | /** @brief Normalize the vector */ 117 | aiVector3t& Normalize(); 118 | 119 | 120 | /** @brief Componentwise multiplication of two vectors 121 | * 122 | * Note that vec*vec yields the dot product. 123 | * @param o Second factor */ 124 | const aiVector3t SymMul(const aiVector3t& o); 125 | 126 | TReal x, y, z; 127 | } PACK_STRUCT; 128 | 129 | 130 | typedef aiVector3t aiVector3D; 131 | 132 | #else 133 | 134 | struct aiVector3D { 135 | 136 | float x,y,z; 137 | } PACK_STRUCT; 138 | 139 | #endif // __cplusplus 140 | 141 | #include "./Compiler/poppack1.h" 142 | 143 | #ifdef __cplusplus 144 | 145 | 146 | 147 | #endif // __cplusplus 148 | 149 | #endif // AI_VECTOR3D_H_INC 150 | -------------------------------------------------------------------------------- /external/assimp/assimp/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2015, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file version.h 43 | * @brief Functions to query the version of the Assimp runtime, check 44 | * compile flags, ... 45 | */ 46 | #ifndef INCLUDED_AI_VERSION_H 47 | #define INCLUDED_AI_VERSION_H 48 | 49 | #include "defs.h" 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | // --------------------------------------------------------------------------- 56 | /** @brief Returns a string with legal copyright and licensing information 57 | * about Assimp. The string may include multiple lines. 58 | * @return Pointer to static string. 59 | */ 60 | ASSIMP_API const char* aiGetLegalString (void); 61 | 62 | // --------------------------------------------------------------------------- 63 | /** @brief Returns the current minor version number of Assimp. 64 | * @return Minor version of the Assimp runtime the application was 65 | * linked/built against 66 | */ 67 | ASSIMP_API unsigned int aiGetVersionMinor (void); 68 | 69 | // --------------------------------------------------------------------------- 70 | /** @brief Returns the current major version number of Assimp. 71 | * @return Major version of the Assimp runtime the application was 72 | * linked/built against 73 | */ 74 | ASSIMP_API unsigned int aiGetVersionMajor (void); 75 | 76 | // --------------------------------------------------------------------------- 77 | /** @brief Returns the repository revision of the Assimp runtime. 78 | * @return SVN Repository revision number of the Assimp runtime the 79 | * application was linked/built against. 80 | */ 81 | ASSIMP_API unsigned int aiGetVersionRevision (void); 82 | 83 | //! Assimp was compiled as a shared object (Windows: DLL) 84 | #define ASSIMP_CFLAGS_SHARED 0x1 85 | //! Assimp was compiled against STLport 86 | #define ASSIMP_CFLAGS_STLPORT 0x2 87 | //! Assimp was compiled as a debug build 88 | #define ASSIMP_CFLAGS_DEBUG 0x4 89 | 90 | //! Assimp was compiled with ASSIMP_BUILD_BOOST_WORKAROUND defined 91 | #define ASSIMP_CFLAGS_NOBOOST 0x8 92 | //! Assimp was compiled with ASSIMP_BUILD_SINGLETHREADED defined 93 | #define ASSIMP_CFLAGS_SINGLETHREADED 0x10 94 | 95 | // --------------------------------------------------------------------------- 96 | /** @brief Returns assimp's compile flags 97 | * @return Any bitwise combination of the ASSIMP_CFLAGS_xxx constants. 98 | */ 99 | ASSIMP_API unsigned int aiGetCompileFlags (void); 100 | 101 | #ifdef __cplusplus 102 | } // end extern "C" 103 | #endif 104 | 105 | #endif // !! #ifndef INCLUDED_AI_VERSION_H 106 | -------------------------------------------------------------------------------- /external/imgui/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Omar Cornut and ImGui contributors 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 | -------------------------------------------------------------------------------- /external/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // USER IMPLEMENTATION 3 | // This file contains compile-time options for ImGui. 4 | // Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO(). 5 | //----------------------------------------------------------------------------- 6 | 7 | #pragma once 8 | 9 | //---- Define assertion handler. Defaults to calling assert(). 10 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 11 | 12 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. 13 | //#define IMGUI_API __declspec( dllexport ) 14 | //#define IMGUI_API __declspec( dllimport ) 15 | 16 | //---- Include imgui_user.h at the end of imgui.h 17 | //#define IMGUI_INCLUDE_IMGUI_USER_H 18 | 19 | //---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions) 20 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS 21 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS 22 | 23 | //---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty) 24 | //#define IMGUI_DISABLE_TEST_WINDOWS 25 | 26 | //---- Don't define obsolete functions names 27 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 28 | 29 | //---- Pack colors to BGRA instead of RGBA (remove need to post process vertex buffer in back ends) 30 | //#define IMGUI_USE_BGRA_PACKED_COLOR 31 | 32 | //---- Implement STB libraries in a namespace to avoid conflicts 33 | //#define IMGUI_STB_NAMESPACE ImGuiStb 34 | 35 | //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. 36 | /* 37 | #define IM_VEC2_CLASS_EXTRA \ 38 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 39 | operator MyVec2() const { return MyVec2(x,y); } 40 | 41 | #define IM_VEC4_CLASS_EXTRA \ 42 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 43 | operator MyVec4() const { return MyVec4(x,y,z,w); } 44 | */ 45 | 46 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 47 | //---- e.g. create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers. 48 | /* 49 | namespace ImGui 50 | { 51 | void Value(const char* prefix, const MyMatrix44& v, const char* float_format = NULL); 52 | } 53 | */ 54 | 55 | -------------------------------------------------------------------------------- /external/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2017 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif // __cplusplus 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | // On Windows, Vulkan commands use the stdcall convention 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 55 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 56 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 57 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 58 | // calling convention, i.e. float parameters are passed in registers. This 59 | // is true even if the rest of the application passes floats on the stack, 60 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | // On other platforms, use the default calling convention 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif // !defined(VK_NO_STDINT_H) 87 | 88 | #ifdef __cplusplus 89 | } // extern "C" 90 | #endif // __cplusplus 91 | 92 | // Platform-specific headers required by platform window system extensions. 93 | // These are enabled prior to #including "vulkan.h". The same enable then 94 | // controls inclusion of the extension interfaces in vulkan.h. 95 | 96 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 97 | #include 98 | #endif 99 | 100 | #ifdef VK_USE_PLATFORM_MIR_KHR 101 | #include 102 | #endif 103 | 104 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 105 | #include 106 | #endif 107 | 108 | #ifdef VK_USE_PLATFORM_WIN32_KHR 109 | #include 110 | #endif 111 | 112 | #ifdef VK_USE_PLATFORM_XLIB_KHR 113 | #include 114 | #endif 115 | 116 | #ifdef VK_USE_PLATFORM_XCB_KHR 117 | #include 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /external/vulkan/vk_sdk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_sdk_platform.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2016 The Khronos Group Inc. 6 | * Copyright (c) 2015-2016 Valve Corporation 7 | * Copyright (c) 2015-2016 LunarG, Inc. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef VK_SDK_PLATFORM_H 23 | #define VK_SDK_PLATFORM_H 24 | 25 | #if defined(_WIN32) 26 | #define NOMINMAX 27 | #ifndef __cplusplus 28 | #undef inline 29 | #define inline __inline 30 | #endif // __cplusplus 31 | 32 | #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) 33 | // C99: 34 | // Microsoft didn't implement C99 in Visual Studio; but started adding it with 35 | // VS2013. However, VS2013 still didn't have snprintf(). The following is a 36 | // work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the 37 | // "CMakeLists.txt" file). 38 | // NOTE: This is fixed in Visual Studio 2015. 39 | #define snprintf _snprintf 40 | #endif 41 | 42 | #define strdup _strdup 43 | 44 | #endif // _WIN32 45 | 46 | #endif // VK_SDK_PLATFORM_H 47 | -------------------------------------------------------------------------------- /source/Player.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Player class 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include "Player.h" 10 | 11 | Player::Player() 12 | { 13 | freeLookDelta = glm::vec2(0.0f); 14 | freeLookRotation = glm::vec3(0.0f); 15 | } 16 | 17 | 18 | Player::~Player() 19 | { 20 | } 21 | 22 | void Player::setPerspective(float fov, float aspect, float znear, float zfar) 23 | { 24 | this->fov = fov; 25 | this->znear = znear; 26 | this->zfar = zfar; 27 | matrices.projection = glm::perspective(glm::radians(fov), aspect, znear, zfar); 28 | } 29 | 30 | void Player::setPosition(glm::vec3 position) 31 | { 32 | this->position = position; 33 | this->targetPosition = position; 34 | updateViewMatrix(); 35 | } 36 | 37 | void Player::setRotation(glm::vec3 rotation) 38 | { 39 | this->rotation = rotation; 40 | this->targetRotation = rotation.y; 41 | this->freeLookDelta = glm::vec2(0.0f); 42 | this->freeLookRotation = glm::vec3(0.0f); 43 | updateViewMatrix(); 44 | } 45 | 46 | void Player::setDungeon(dungeongenerator::Dungeon *dungeon) 47 | { 48 | this->dungeon = dungeon; 49 | } 50 | 51 | bool Player::move(glm::vec3 dirVec, bool animate) { 52 | glm::vec3 movementVector = dirVec; 53 | movementVector = glm::rotate(movementVector, glm::radians(rotation.y), glm::vec3(0.0, 1.0f, 0.0f)); 54 | dungeongenerator::Cell *targetCell = dungeon->getCell(round(position.x + movementVector.x), round(position.z - movementVector.z)); 55 | if (targetCell->type == dungeongenerator::Cell::cellTypeEmpty) { 56 | // TODO : Blocking animation 57 | return false; 58 | } 59 | if (!animate) { 60 | position.x += movementVector.x; 61 | position.z -= movementVector.z; 62 | targetPosition = position; 63 | updateViewMatrix(); 64 | } 65 | else { 66 | dungeongenerator::Cell *targetCell = dungeon->getCell(round(position.x + movementVector.x), round(position.z - movementVector.z)); 67 | double distance = glm::distance(position, targetPosition); 68 | if (distance == 0.0f) { 69 | targetPosition.x = position.x + movementVector.x; 70 | targetPosition.z = position.z - movementVector.z; 71 | return true; 72 | } 73 | } 74 | 75 | return true; 76 | // TODO: Return false if blocked 77 | } 78 | 79 | void Player::rotate(float dir, bool animate) { 80 | if (!animate) { 81 | rotation.y += dir; 82 | if (rotation.y < 0) { 83 | rotation.y += 360; 84 | } 85 | if (rotation.y >= 360) { 86 | rotation.y -= 360; 87 | } 88 | updateViewMatrix(); 89 | } 90 | else { 91 | if (rotationDir == 0.0f) { 92 | rotationDir = (dir < 0) ? -1.0f : 1.0f; 93 | targetRotation = rotation.y + dir; 94 | animRotation = abs(dir); 95 | } 96 | } 97 | } 98 | 99 | bool Player::updateFreeLook(float timeFactor) { 100 | float freeLookSpeed = 65.0f; 101 | float freeLookRebound = 0.25f; 102 | bool viewChange = false; 103 | glm::vec3 freeLookLimits = glm::vec3(12.5f, 15.0f, 0.0f); 104 | if (freeLook) { 105 | freeLookRotation.y += freeLookDelta.x * timeFactor * freeLookSpeed; 106 | freeLookRotation.x += freeLookDelta.y * timeFactor * freeLookSpeed; 107 | freeLookRotation.x = glm::clamp(freeLookRotation.x, -freeLookLimits.x, freeLookLimits.x); 108 | freeLookRotation.y = glm::clamp(freeLookRotation.y, -freeLookLimits.y, freeLookLimits.y); 109 | viewChange = true; 110 | } 111 | else { 112 | if (freeLookRotation.x > 0.0f) { 113 | freeLookRotation.x -= timeFactor * freeLookSpeed * freeLookRebound; 114 | if (freeLookRotation.x < 0.0f) { 115 | freeLookRotation.x = 0.0; 116 | } 117 | viewChange = true; 118 | } 119 | if (freeLookRotation.x < 0.0f) { 120 | freeLookRotation.x += timeFactor * freeLookSpeed * freeLookRebound; 121 | if (freeLookRotation.x > 0.0f) { 122 | freeLookRotation.x = 0.0; 123 | } 124 | viewChange = true; 125 | } 126 | if (freeLookRotation.y > 0.0f) { 127 | freeLookRotation.y -= timeFactor * freeLookSpeed * freeLookRebound; 128 | if (freeLookRotation.y < 0.0f) { 129 | freeLookRotation.y = 0.0; 130 | } 131 | viewChange = true; 132 | } 133 | if (freeLookRotation.y < 0.0f) { 134 | freeLookRotation.y += timeFactor * freeLookSpeed * freeLookRebound; 135 | if (freeLookRotation.y > 0.0f) { 136 | freeLookRotation.y = 0.0; 137 | } 138 | viewChange = true; 139 | } 140 | } 141 | return viewChange; 142 | } 143 | 144 | bool Player::updateMovement(float timeFactor) { 145 | glm::vec3 distVec = glm::normalize(position - targetPosition); 146 | double distance = glm::distance(position, targetPosition); 147 | if (distance > 0.0f) { 148 | position -= glm::normalize(distVec) * timeFactor * movementSpeed; 149 | if (distance <= timeFactor) { 150 | position = targetPosition; 151 | }; 152 | return true; 153 | }; 154 | return false; 155 | } 156 | 157 | bool Player::updateRotation(float timeFactor) { 158 | if (rotationDir != 0.0f) { 159 | float rotationFactor = rotationDir * timeFactor * rotationSpeed * 100.0f; 160 | rotation.y += rotationFactor; 161 | animRotation -= abs(rotationFactor); 162 | if (animRotation <= 0.0f) { 163 | rotation.y = targetRotation; 164 | rotationDir = 0.0f; 165 | } 166 | return true; 167 | } 168 | return false; 169 | } 170 | 171 | void Player::updateViewMatrix() { 172 | glm::mat4 rotM = glm::mat4(1.0f); 173 | glm::mat4 transM; 174 | rotM = glm::rotate(rotM, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); 175 | rotM = glm::rotate(rotM, glm::radians(freeLookRotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); 176 | rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)); 177 | rotM = glm::rotate(rotM, glm::radians(freeLookRotation.y), glm::vec3(0.0f, 1.0f, 0.0f)); 178 | rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); 179 | transM = glm::translate(glm::mat4(1.0f), position * glm::vec3(-1.0f, 1.0f, -1.0f)); 180 | matrices.view = rotM * transM; 181 | } 182 | 183 | bool Player::update(float timeFactor) { 184 | bool viewChange = false; 185 | viewChange |= updateFreeLook(timeFactor); 186 | viewChange |= updateMovement(timeFactor); 187 | viewChange |= updateRotation(timeFactor); 188 | if (viewChange) { 189 | updateViewMatrix(); 190 | } 191 | return viewChange; 192 | } 193 | 194 | void Player::setFreeLookDelta(glm::vec2 delta) { 195 | freeLookDelta = delta; 196 | } 197 | -------------------------------------------------------------------------------- /source/Player.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Player class 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include "generator\Dungeon.h" 17 | 18 | class Player 19 | { 20 | private: 21 | glm::vec2 freeLookDelta; 22 | dungeongenerator::Dungeon *dungeon; 23 | float rotationDir; 24 | float animRotation; 25 | float targetRotation; 26 | bool updateFreeLook(float timeFactor); 27 | bool updateMovement(float timeFactor); 28 | bool updateRotation(float timeFactor); 29 | void updateViewMatrix(); 30 | public: 31 | struct { 32 | glm::mat4 projection; 33 | glm::mat4 view; 34 | } matrices; 35 | 36 | float fov, znear, zfar; 37 | float rotationSpeed = 1.75f; 38 | float movementSpeed = 2.0f; 39 | 40 | glm::vec3 position; 41 | glm::vec3 rotation; 42 | glm::vec3 movementVector; 43 | glm::vec3 targetPosition; 44 | glm::vec3 freeLookRotation; 45 | bool freeLook; 46 | Player(); 47 | ~Player(); 48 | 49 | void setPerspective(float fov, float aspect, float znear, float zfar); 50 | void setPosition(glm::vec3 position); 51 | void setRotation(glm::vec3 rotation); 52 | 53 | void setDungeon(dungeongenerator::Dungeon *dungeon); 54 | bool move(glm::vec3 dirVec, bool animate); 55 | void rotate(float dir, bool animate); 56 | bool update(float timeFactor); 57 | void setFreeLookDelta(glm::vec2 delta); 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /source/generator/BspPartition.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include "BspPartition.h" 10 | #include 11 | #include 12 | 13 | namespace dungeongenerator { 14 | 15 | BspPartition::BspPartition(BspPartition* parent, int left, int top, int right, int bottom, int splitIn, int depth) 16 | { 17 | this->parent = parent; 18 | this->left = left; 19 | this->right = right; 20 | this->top = top; 21 | this->bottom = bottom; 22 | this->splitIn = splitIn; 23 | this->depth = depth; 24 | 25 | this->centerX = round(left + (float)(right - left) / 2.0f); 26 | this->centerY = round(top + (float)(bottom - top) / 2.0f); 27 | 28 | // Don't split if any of the dimensions is below certain threshold 29 | if ((depth > 0) && ((right - left <= 8) || (bottom - top <= 8))) { 30 | return; 31 | } 32 | 33 | // Randomly stop splitting 34 | if (splitIn == BspPartitionSplitVertical) { 35 | if ((right - left < 4) || (bottom - top < 4)) { 36 | if ((rand() % 100 < 25 /*this.dungeon.splitStop*/) && (depth > 0)) { 37 | return; 38 | } 39 | } 40 | } 41 | 42 | // Split 43 | int splitRangeX = round((float)(right - left) / ((depth == 0) ? 8 : 4)); 44 | int splitRangeY = round((float)(bottom - top) / ((depth == 0) ? 8 : 4)); 45 | 46 | int splitX = round(left + ((right - left) / 2) + round(rand() % splitRangeX) - round(rand() % splitRangeX)); 47 | int splitY = round(top + ((bottom - top) / 2) + round(rand() % splitRangeY) - round(rand() % splitRangeY)); 48 | 49 | // Add four new child partitions 50 | children.push_back(new BspPartition(this, left, top, splitX, splitY, rand() % 2, depth + 1)); 51 | children.push_back(new BspPartition(this, splitX, top, right, splitY, rand() % 2, depth + 1)); 52 | children.push_back(new BspPartition(this, left, splitY, splitX, bottom, rand() % 2, depth + 1)); 53 | children.push_back(new BspPartition(this, splitX, splitY, right, bottom, rand() % 2, depth + 1)); 54 | 55 | } 56 | 57 | 58 | BspPartition::~BspPartition() 59 | { 60 | } 61 | 62 | void BspPartition::split(bool origin, int maxDivision, int minDivision) 63 | { 64 | 65 | // Don't split if any of the dimensions is below certain threshold 66 | if ( (right - left <= maxDivision) || (bottom - top <= maxDivision) ) { 67 | return; 68 | } 69 | 70 | // Randomly stop splitting 71 | if (splitIn == BspPartitionSplitVertical) { 72 | if ((right - left < minDivision) || (bottom - top < minDivision)) { 73 | if ((rand() % 100 < 25 /*this.dungeon.splitStop*/) && (!origin)) { 74 | return; 75 | } 76 | } 77 | } 78 | 79 | // Split 80 | int splitRangeX = round((float)(right - left) / ((origin) ? 8 : 4)); 81 | int splitRangeY = round((float)(bottom - top) / ((origin) ? 8 : 4)); 82 | 83 | int splitX = round(left + ((right - left) / 2) + round(rand() % splitRangeX) - round(rand() % splitRangeX)); 84 | int splitY = round(top + ((bottom - top) / 2) + round(rand() % splitRangeY) - round(rand() % splitRangeY)); 85 | 86 | // Add four new child partitions 87 | 88 | BspPartition child0 = BspPartition(this, left, top, splitX, splitY, rand() % 2, depth + 1); 89 | BspPartition child1 = BspPartition(this, splitX, top, right, splitY, rand() % 2, depth + 1); 90 | BspPartition child2 = BspPartition(this, left, splitY, splitX, bottom, rand() % 2, depth + 1); 91 | BspPartition child3 = BspPartition(this, splitX, splitY, right, bottom, rand() % 2, depth + 1); 92 | 93 | child0.split(false, 12, 24); 94 | child1.split(false, 12, 24); 95 | child2.split(false, 12, 24); 96 | child3.split(false, 12, 24); 97 | 98 | children.push_back(&child0); 99 | children.push_back(&child1); 100 | children.push_back(&child2); 101 | children.push_back(&child3); 102 | 103 | //for (auto child : children) { 104 | // child.split(false, 16, 32); 105 | //} 106 | } 107 | 108 | void BspPartition::connect() 109 | { 110 | std::vector connectionList; 111 | 112 | // Add child nodes with rooms to connection target list 113 | if (!children.empty()) { 114 | for (auto child : children) { 115 | if (child->hasRoom) { 116 | connectionList.push_back(child); 117 | } 118 | } 119 | } 120 | 121 | // Add this node (and if set it's parent) to the connection list 122 | connectionList.push_back(this); 123 | if (parent != NULL) { 124 | connectionList.push_back(parent); 125 | } 126 | fprintf(stdout, "%d\n", connectionList.size()); 127 | 128 | if (connectionList.size() == 0) { 129 | return; 130 | } 131 | 132 | // Randomize connection list 133 | // TODO : Not the pretiest code... 134 | bool skip = false; 135 | int index = 0; 136 | std::vector randomList; 137 | 138 | //do { 139 | // index = rand() % connectionList.size(); 140 | // fprintf(stdout, "%d - %d / %d\n", index, randomList.size(), connectionList.size()); 141 | // if (std::find(randomList.begin(), randomList.end(), connectionList[index]) == randomList.end()) { 142 | // randomList.push_back(connectionList[index]); 143 | // } 144 | //} 145 | //while (randomList.size() != connectionList.size()); 146 | 147 | for (int i = 0; i < connectionList.size(); i++) { 148 | randomList.push_back(connectionList[i]); 149 | } 150 | 151 | for (auto partition : randomList) { 152 | 153 | } 154 | 155 | 156 | //if (randomList.length > 0) { 157 | // for (var i = 0; i < randomList.length - 1; i++) { 158 | // srcX = connectionList[randomList[i]].centerX; 159 | // srcY = connectionList[randomList[i]].centerY; 160 | // dstX = connectionList[randomList[i + 1]].centerX; 161 | // dstY = connectionList[randomList[i + 1]].centerY; 162 | // this.createCorridor(srcX, srcY, dstX, dstY); 163 | // } 164 | //} 165 | 166 | } 167 | 168 | } 169 | -------------------------------------------------------------------------------- /source/generator/BspPartition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace dungeongenerator { 14 | 15 | class BspPartition 16 | { 17 | public: 18 | BspPartition *parent; 19 | int left; 20 | int right; 21 | int top; 22 | int bottom; 23 | int centerX; 24 | int centerY; 25 | int splitIn; 26 | int depth; 27 | bool hasRoom = false; 28 | static const int BspPartitionSplitVertical = 0; 29 | static const int BspPartitionSplitHorizontal = 0; 30 | std::vector children; 31 | BspPartition(BspPartition *parent, int left, int top, int right, int bottom, int splitIn, int depth); 32 | ~BspPartition(); 33 | void placeRoom(); 34 | void split(bool origin, int maxDivision, int minDivision); 35 | void createCorridor(int originX, int originY, int destX, int destY); 36 | void connect(); 37 | }; 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /source/generator/Cell.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include "Cell.h" 10 | #include 11 | 12 | namespace dungeongenerator { 13 | 14 | Cell::Cell(int posX, int posY) 15 | { 16 | x = posX; 17 | y = posY; 18 | type = cellTypeEmpty; 19 | walls = { false, false, false, false }; 20 | doors = { false, false, false, false }; 21 | modelMatrix = glm::mat4(); 22 | modelMatrix = glm::translate(modelMatrix, glm::vec3((float)x, 0, (float)y)); 23 | } 24 | 25 | Cell::~Cell() 26 | { 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /source/generator/Cell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include "vulkan/vulkan.h" 13 | #include 14 | 15 | namespace dungeongenerator { 16 | 17 | class Cell 18 | { 19 | public: 20 | static const int cellTypeEmpty = 0; 21 | static const int cellTypeCorridor = 1; 22 | static const int cellTypeRoom = 2; 23 | static const int dirNorth = 0; 24 | static const int dirSouth = 1; 25 | static const int dirWest= 2; 26 | static const int dirEast = 3; 27 | int x; 28 | int y; 29 | int type; 30 | bool hasDoor = false; 31 | VkCommandBuffer commandBuffer = VK_NULL_HANDLE; 32 | bool uncovered = false; 33 | glm::mat4 modelMatrix; 34 | std::vector walls; 35 | std::vector doors; 36 | Cell(int posX, int posY); 37 | ~Cell(); 38 | }; 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /source/generator/Dungeon.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include "Dungeon.h" 10 | #include "BspPartition.h" 11 | #include 12 | 13 | namespace dungeongenerator { 14 | 15 | Dungeon::Dungeon(int w, int h) 16 | { 17 | width = w; 18 | height = h; 19 | 20 | cells.resize(width); 21 | for (int x = 0; x < width; ++x) { 22 | cells[x].resize(height); 23 | for (int y = 0; y < height; ++y) { 24 | cells[x][y] = new Cell(x, y); 25 | } 26 | } 27 | 28 | } 29 | 30 | 31 | Dungeon::~Dungeon() 32 | { 33 | for (int x = 0; x < width; ++x) { 34 | cells[x].resize(height); 35 | for (int y = 0; y < height; ++y) { 36 | delete(cells[x][y]); 37 | } 38 | } 39 | } 40 | 41 | Cell* Dungeon::getCell(int x, int y) { 42 | return cells[x][y]; 43 | } 44 | 45 | void generateCells(Dungeon* dungeon, BspPartition* bspPartition) { 46 | // TODO: Constant for max. room size (to avoid huge rooms) 47 | if ((bspPartition->children.size() == 0) && (rand() % 100) < 75 /*dungeonRoomFrequency*/) { 48 | bspPartition->hasRoom = true; 49 | for (int x = bspPartition->left + 2; x <= bspPartition->right - 2; x++) { 50 | for (int y = bspPartition->top + 2; y <= bspPartition->bottom - 2; y++) { 51 | if ((x >= dungeon->width - 1) || (y >= dungeon->height - 1)) { 52 | break; 53 | } 54 | dungeon->cells[x][y]->type = Cell::cellTypeRoom; 55 | //this.roomDimLeft = this.left + 2; 56 | //this.roomDimTop = this.top + 2; 57 | //this.roomDimRight = this.right - 2; 58 | //this.roomDimBottom = this.bottom - 2; 59 | } 60 | } 61 | 62 | 63 | } 64 | else { 65 | for (auto& child : bspPartition->children) { 66 | generateCells(dungeon, child); 67 | } 68 | } 69 | 70 | } 71 | 72 | void Dungeon::getPartitions(BspPartition *bspPartition) 73 | { 74 | if (bspPartition->children.empty()) { 75 | partitionList.push_back(bspPartition); 76 | } else { 77 | for (auto child : bspPartition->children) { 78 | getPartitions(child); 79 | } 80 | } 81 | } 82 | 83 | void generateCorridor(Dungeon* dungeon, int startX, int startY, int destX, int destY) { 84 | 85 | int curPosX = startX; 86 | int curPosY = startY; 87 | 88 | do { 89 | 90 | if (curPosX < destX) { 91 | curPosX++; 92 | } 93 | else { 94 | if (curPosX > destX) { 95 | curPosX--; 96 | } 97 | else { 98 | if (curPosY < destY) { 99 | curPosY++; 100 | } 101 | else { 102 | if (curPosY > destY) { 103 | curPosY--; 104 | } 105 | } 106 | } 107 | } 108 | 109 | //if (!dungeon->pointInRoom(curPosX, curPosY)) { 110 | // dungeon->cell[curPosX][curPosY].isCorridor = true; 111 | //} 112 | 113 | if (dungeon->cells[curPosX][curPosY]->type != Cell::cellTypeRoom) { 114 | dungeon->cells[curPosX][curPosY]->type = Cell::cellTypeCorridor; 115 | } 116 | 117 | } while ((curPosX != destX) || (curPosY != destY)); 118 | 119 | } 120 | 121 | void connectPartition(Dungeon* dungeon, BspPartition* partition) { 122 | std::vector connectionList; 123 | 124 | // Add child nodes with rooms to connection target list 125 | if (!partition->children.empty()) { 126 | for (auto child : partition->children) { 127 | if (child->hasRoom) { 128 | connectionList.push_back(child); 129 | } 130 | } 131 | } 132 | 133 | // Add this node (and if set it's parent) to the connection list 134 | connectionList.push_back(partition); 135 | if (partition->parent != NULL) { 136 | connectionList.push_back(partition->parent); 137 | } 138 | 139 | if (connectionList.size() == 0) { 140 | return; 141 | } 142 | 143 | for (int i = 0; i < connectionList.size() - 1; i++) { 144 | int startX = connectionList[i]->centerX; 145 | int startY = connectionList[i]->centerY; 146 | int destX = connectionList[i + 1]->centerX; 147 | int destY = connectionList[i + 1]->centerY; 148 | generateCorridor(dungeon, startX, startY, destX, destY); 149 | } 150 | 151 | if (partition->parent != NULL) { 152 | connectPartition(dungeon, partition->parent); 153 | } 154 | } 155 | 156 | void generateCorridors(Dungeon* dungeon) { 157 | for (auto partition : dungeon->partitionList) { 158 | if ((partition->hasRoom) && (partition->children.empty())) { 159 | connectPartition(dungeon, partition); 160 | } 161 | } 162 | } 163 | 164 | void Dungeon::generateRooms() { 165 | dungeongenerator::BspPartition rootPartition(NULL, 0, 0, width, height, BspPartition::BspPartitionSplitHorizontal, 0); 166 | //rootPartition.split(true, 15, 32); 167 | 168 | generateCells(this, &rootPartition); 169 | 170 | partitionList.clear(); 171 | getPartitions(&rootPartition); 172 | 173 | generateCorridors(this); 174 | 175 | } 176 | 177 | BspPartition* Dungeon::getRandomRoom() { 178 | BspPartition* room = NULL; 179 | do { 180 | int roomIndex = rand() % partitionList.size(); 181 | if ((partitionList[roomIndex]->hasRoom) && (partitionList[roomIndex]->children.empty())) { 182 | room = partitionList[roomIndex]; 183 | } 184 | } while (room == NULL); 185 | 186 | return room; 187 | } 188 | 189 | void Dungeon::generateWalls() { 190 | for (int x = 0; x < width; ++x) { 191 | for (int y = 0; y < height; ++y) { 192 | if (cells[x][y]->type != Cell::cellTypeEmpty) { 193 | Cell *curCell = cells[x][y]; 194 | // To the west 195 | if (x == 0) { 196 | curCell->walls[Cell::dirWest] = true; 197 | } 198 | else { 199 | if (cells[x - 1][y]->type == Cell::cellTypeEmpty) { 200 | curCell->walls[Cell::dirWest] = true; 201 | } 202 | } 203 | 204 | // To the east 205 | if (x == width - 1) { 206 | curCell->walls[Cell::dirEast] = true; 207 | } 208 | else { 209 | if (cells[x + 1][y]->type == Cell::cellTypeEmpty) { 210 | curCell->walls[Cell::dirEast] = true; 211 | } 212 | } 213 | 214 | // To the north 215 | if (y == 0) { 216 | curCell->walls[Cell::dirNorth] = true; 217 | } 218 | else { 219 | if (cells[x][y - 1]->type == Cell::cellTypeEmpty) { 220 | curCell->walls[Cell::dirNorth] = true; 221 | } 222 | } 223 | 224 | // To the south 225 | if (y == height - 1) { 226 | curCell->walls[Cell::dirSouth] = true; 227 | } 228 | else { 229 | if (cells[x][y + 1]->type == Cell::cellTypeEmpty) { 230 | curCell->walls[Cell::dirSouth] = true; 231 | } 232 | } 233 | } 234 | } 235 | } 236 | } 237 | 238 | void Dungeon::generateDoors() { 239 | for (int x = 1; x < width-1; ++x) { 240 | for (int y = 1; y < height-1; ++y) { 241 | Cell *curCell = cells[x][y]; 242 | // TODO : Code doesnt' take corridors alongside 243 | if (curCell->type == Cell::cellTypeCorridor) { 244 | 245 | // Check if cell has at least two opposite walls to each other (east and west or south and north) 246 | // Then check against neighbors. If neighbor cell has less than two walls, a corridor usually ends into a room and a door needs to be placed 247 | 248 | if ((curCell->walls[Cell::dirWest]) && (curCell->walls[Cell::dirEast])) { 249 | if ((cells[x][y - 1]->type != Cell::cellTypeEmpty) && (cells[x][y - 1]->type != Cell::cellTypeCorridor)) 250 | curCell->doors[Cell::dirNorth] = true; 251 | if ((cells[x][y + 1]->type != Cell::cellTypeEmpty) && (cells[x][y + 1]->type != Cell::cellTypeCorridor)) 252 | curCell->doors[Cell::dirSouth] = true; 253 | } 254 | 255 | if ((curCell->walls[Cell::dirNorth]) && (curCell->walls[Cell::dirSouth])) { 256 | if ((cells[x - 1][y]->type != Cell::cellTypeEmpty) && (cells[x - 1][y]->type != Cell::cellTypeCorridor)) 257 | curCell->doors[Cell::dirWest] = true; 258 | if ((cells[x + 1][y]->type != Cell::cellTypeEmpty) && (cells[x + 1][y]->type != Cell::cellTypeCorridor)) 259 | curCell->doors[Cell::dirEast] = true; 260 | } 261 | 262 | } 263 | for (auto d : curCell->doors) { 264 | if (d) { 265 | curCell->hasDoor = true; 266 | } 267 | } 268 | } 269 | } 270 | } 271 | 272 | } 273 | -------------------------------------------------------------------------------- /source/generator/Dungeon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include "BspPartition.h" 13 | #include "Cell.h" 14 | 15 | namespace dungeongenerator { 16 | 17 | class Dungeon 18 | { 19 | private: 20 | void getPartitions(BspPartition *bspPartition); 21 | public: 22 | int width; 23 | int height; 24 | std::vector partitionList; 25 | std::vector< std::vector > cells; 26 | Dungeon(int w, int h); 27 | ~Dungeon(); 28 | Cell* getCell(int x, int y); 29 | void generateRooms(); 30 | void generateWalls(); 31 | void generateDoors(); 32 | BspPartition* getRandomRoom(); 33 | }; 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /source/generator/Room.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include "Room.h" 10 | 11 | 12 | Room::Room(int posX, int posY) 13 | { 14 | } 15 | 16 | 17 | Room::~Room() 18 | { 19 | } 20 | 21 | void Room::SetSize(int left, int top, int right, int bottom) 22 | { 23 | size.left = left; 24 | size.top = top; 25 | size.right = right; 26 | size.bottom = bottom; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /source/generator/Room.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Random dungeon generator 3 | * 4 | * Copyright (C) 2017 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #pragma once 10 | 11 | template 12 | struct rect 13 | { 14 | rect() : left(), top(), right(), bottom() {} 15 | rect(T left, T top, T right, T bottom) : 16 | left(left), top(top), right(right), bottom(bottom) {} 17 | template 18 | rect(Point p, T width, T height) : 19 | left(p.x), right(p.y), right(p.x + width), bottom(p.y + height) {} 20 | 21 | T left; 22 | T top; 23 | T right; 24 | T bottom; 25 | }; 26 | 27 | class Room 28 | { 29 | public: 30 | int x; 31 | int y; 32 | rect size; 33 | Room(int posX, int posY); 34 | ~Room(); 35 | void SetSize(int left, int top, int right, int bottom); 36 | }; 37 | 38 | --------------------------------------------------------------------------------