├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── build.bat ├── build.sh ├── docs ├── GDC2006_Catto_Erin_PhysicsTutorial.pdf └── HowDoPhysicsEnginesWork.pdf ├── extern ├── glad │ ├── CMakeLists.txt │ ├── include │ │ ├── KHR │ │ │ └── khrplatform.h │ │ └── glad │ │ │ └── glad.h │ └── src │ │ └── glad.c ├── glfw │ ├── CMakeLists.txt │ ├── include │ │ └── GLFW │ │ │ ├── glfw3.h │ │ │ └── glfw3native.h │ └── src │ │ ├── cocoa_init.m │ │ ├── cocoa_joystick.h │ │ ├── cocoa_joystick.m │ │ ├── cocoa_monitor.m │ │ ├── cocoa_platform.h │ │ ├── cocoa_time.c │ │ ├── cocoa_window.m │ │ ├── context.c │ │ ├── egl_context.c │ │ ├── egl_context.h │ │ ├── glfw_config.h │ │ ├── glx_context.c │ │ ├── glx_context.h │ │ ├── init.c │ │ ├── input.c │ │ ├── internal.h │ │ ├── linux_joystick.c │ │ ├── linux_joystick.h │ │ ├── mappings.h │ │ ├── mappings.h.in │ │ ├── monitor.c │ │ ├── nsgl_context.h │ │ ├── nsgl_context.m │ │ ├── null_init.c │ │ ├── null_joystick.c │ │ ├── null_joystick.h │ │ ├── null_monitor.c │ │ ├── null_platform.h │ │ ├── null_window.c │ │ ├── osmesa_context.c │ │ ├── osmesa_context.h │ │ ├── posix_thread.c │ │ ├── posix_thread.h │ │ ├── posix_time.c │ │ ├── posix_time.h │ │ ├── vulkan.c │ │ ├── wgl_context.c │ │ ├── wgl_context.h │ │ ├── win32_init.c │ │ ├── win32_joystick.c │ │ ├── win32_joystick.h │ │ ├── win32_monitor.c │ │ ├── win32_platform.h │ │ ├── win32_thread.c │ │ ├── win32_time.c │ │ ├── win32_window.c │ │ ├── window.c │ │ ├── wl_init.c │ │ ├── wl_monitor.c │ │ ├── wl_platform.h │ │ ├── wl_window.c │ │ ├── x11_init.c │ │ ├── x11_monitor.c │ │ ├── x11_platform.h │ │ ├── x11_window.c │ │ ├── xkb_unicode.c │ │ └── xkb_unicode.h └── imgui │ ├── CMakeLists.txt │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_internal.h │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h ├── include └── box2d-lite │ ├── Arbiter.h │ ├── Body.h │ ├── Joint.h │ ├── MathUtils.h │ └── World.h ├── samples ├── CMakeLists.txt ├── imgui_impl_glfw.cpp ├── imgui_impl_glfw.h ├── imgui_impl_opengl2.cpp ├── imgui_impl_opengl2.h └── main.cpp └── src ├── Arbiter.cpp ├── Body.cpp ├── CMakeLists.txt ├── Collide.cpp ├── Joint.cpp └── World.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | *.dll filter=lfs diff=lfs merge=lfs -text 2 | *.lib filter=lfs diff=lfs merge=lfs -text 3 | *.pptx filter=lfs diff=lfs merge=lfs -text 4 | *.pdf filter=lfs diff=lfs merge=lfs -text 5 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | 14 | github: [erincatto] 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: clang 3 | 4 | branches: 5 | only: 6 | - master 7 | 8 | addons: 9 | apt: 10 | packages: 11 | - libxrandr-dev 12 | - libxinerama-dev 13 | - libxcursor-dev 14 | - libxi-dev 15 | 16 | matrix: 17 | include: 18 | - os: linux 19 | env: 20 | - os: osx 21 | env: 22 | 23 | script: 24 | - mkdir build 25 | - cd build 26 | - cmake .. 27 | - cmake --build . 28 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project(box2d-lite LANGUAGES CXX) 4 | 5 | add_subdirectory(src) 6 | 7 | option(BOX2D_BUILD_SAMPLES "Build the box2d-lite sample program" ON) 8 | 9 | if (BOX2D_BUILD_SAMPLES) 10 | 11 | add_subdirectory(extern/glad) 12 | add_subdirectory(extern/glfw) 13 | add_subdirectory(extern/imgui) 14 | add_subdirectory(samples) 15 | 16 | # default startup project for Visual Studio 17 | if (MSVC) 18 | set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT samples) 19 | endif() 20 | 21 | endif() 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Erin Catto 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 | # Box2D-Lite 2 | Box2D-Lite is a small 2D physics engine. It was developed for the [2006 GDC Physics Tutorial](docs/GDC2006_Catto_Erin_PhysicsTutorial.pdf). This is the original version of the larger [Box2D](https://box2d.org) library. The Lite version is more suitable for learning about game physics. 3 | 4 | # Building 5 | - Install [CMake](https://cmake.org/) 6 | - Ensure CMake is in the user `PATH` 7 | - Visual Studio 2017: run `build.bat` 8 | - Otherwise: run `build.sh` from a bash shell 9 | - Results are in the build sub-folder 10 | 11 | # Build Status 12 | [![Build Status](https://travis-ci.org/erincatto/box2d-lite.svg?branch=master)](https://travis-ci.org/erincatto/box2d-lite) 13 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | rem Use this batch file to build box2d-lite and samples for Visual Studio 2017 2 | rmdir /s /q build 3 | mkdir build 4 | cd build 5 | cmake .. 6 | cmake --build . 7 | start box2d-lite.sln 8 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Use this to build box2d-lite and samples on any system with a bash shell 4 | rm -rf build 5 | mkdir build 6 | cd build 7 | cmake .. 8 | cmake --build . 9 | -------------------------------------------------------------------------------- /docs/GDC2006_Catto_Erin_PhysicsTutorial.pdf: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:38b3565e1924b3754e75035e2c7a27541f256007b8f5467bf6cc4b4969c24bcc 3 | size 1388156 4 | -------------------------------------------------------------------------------- /docs/HowDoPhysicsEnginesWork.pdf: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8ad28eeff971343652f8603201d6086d580995edd318087957f4143227935f69 3 | size 460905 4 | -------------------------------------------------------------------------------- /extern/glad/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(glad C) 2 | 3 | set(GLAD_SOURCE_FILES 4 | src/glad.c) 5 | 6 | set(GLAD_HEADER_FILES 7 | include/glad/glad.h 8 | include/KHR/khrplatform.h) 9 | 10 | add_library(glad STATIC ${GLAD_SOURCE_FILES} ${GLAD_HEADER_FILES}) 11 | target_include_directories(glad PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) 12 | -------------------------------------------------------------------------------- /extern/glad/include/KHR/khrplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __khrplatform_h_ 2 | #define __khrplatform_h_ 3 | 4 | /* 5 | ** Copyright (c) 2008-2018 The Khronos Group Inc. 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person obtaining a 8 | ** copy of this software and/or associated documentation files (the 9 | ** "Materials"), to deal in the Materials without restriction, including 10 | ** without limitation the rights to use, copy, modify, merge, publish, 11 | ** distribute, sublicense, and/or sell copies of the Materials, and to 12 | ** permit persons to whom the Materials are furnished to do so, subject to 13 | ** the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included 16 | ** in all copies or substantial portions of the Materials. 17 | ** 18 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 25 | */ 26 | 27 | /* Khronos platform-specific types and definitions. 28 | * 29 | * The master copy of khrplatform.h is maintained in the Khronos EGL 30 | * Registry repository at https://github.com/KhronosGroup/EGL-Registry 31 | * The last semantic modification to khrplatform.h was at commit ID: 32 | * 67a3e0864c2d75ea5287b9f3d2eb74a745936692 33 | * 34 | * Adopters may modify this file to suit their platform. Adopters are 35 | * encouraged to submit platform specific modifications to the Khronos 36 | * group so that they can be included in future versions of this file. 37 | * Please submit changes by filing pull requests or issues on 38 | * the EGL Registry repository linked above. 39 | * 40 | * 41 | * See the Implementer's Guidelines for information about where this file 42 | * should be located on your system and for more details of its use: 43 | * http://www.khronos.org/registry/implementers_guide.pdf 44 | * 45 | * This file should be included as 46 | * #include 47 | * by Khronos client API header files that use its types and defines. 48 | * 49 | * The types in khrplatform.h should only be used to define API-specific types. 50 | * 51 | * Types defined in khrplatform.h: 52 | * khronos_int8_t signed 8 bit 53 | * khronos_uint8_t unsigned 8 bit 54 | * khronos_int16_t signed 16 bit 55 | * khronos_uint16_t unsigned 16 bit 56 | * khronos_int32_t signed 32 bit 57 | * khronos_uint32_t unsigned 32 bit 58 | * khronos_int64_t signed 64 bit 59 | * khronos_uint64_t unsigned 64 bit 60 | * khronos_intptr_t signed same number of bits as a pointer 61 | * khronos_uintptr_t unsigned same number of bits as a pointer 62 | * khronos_ssize_t signed size 63 | * khronos_usize_t unsigned size 64 | * khronos_float_t signed 32 bit floating point 65 | * khronos_time_ns_t unsigned 64 bit time in nanoseconds 66 | * khronos_utime_nanoseconds_t unsigned time interval or absolute time in 67 | * nanoseconds 68 | * khronos_stime_nanoseconds_t signed time interval in nanoseconds 69 | * khronos_boolean_enum_t enumerated boolean type. This should 70 | * only be used as a base type when a client API's boolean type is 71 | * an enum. Client APIs which use an integer or other type for 72 | * booleans cannot use this as the base type for their boolean. 73 | * 74 | * Tokens defined in khrplatform.h: 75 | * 76 | * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. 77 | * 78 | * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. 79 | * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. 80 | * 81 | * Calling convention macros defined in this file: 82 | * KHRONOS_APICALL 83 | * KHRONOS_APIENTRY 84 | * KHRONOS_APIATTRIBUTES 85 | * 86 | * These may be used in function prototypes as: 87 | * 88 | * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( 89 | * int arg1, 90 | * int arg2) KHRONOS_APIATTRIBUTES; 91 | */ 92 | 93 | #if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) 94 | # define KHRONOS_STATIC 1 95 | #endif 96 | 97 | /*------------------------------------------------------------------------- 98 | * Definition of KHRONOS_APICALL 99 | *------------------------------------------------------------------------- 100 | * This precedes the return type of the function in the function prototype. 101 | */ 102 | #if defined(KHRONOS_STATIC) 103 | /* If the preprocessor constant KHRONOS_STATIC is defined, make the 104 | * header compatible with static linking. */ 105 | # define KHRONOS_APICALL 106 | #elif defined(_WIN32) 107 | # define KHRONOS_APICALL __declspec(dllimport) 108 | #elif defined (__SYMBIAN32__) 109 | # define KHRONOS_APICALL IMPORT_C 110 | #elif defined(__ANDROID__) 111 | # define KHRONOS_APICALL __attribute__((visibility("default"))) 112 | #else 113 | # define KHRONOS_APICALL 114 | #endif 115 | 116 | /*------------------------------------------------------------------------- 117 | * Definition of KHRONOS_APIENTRY 118 | *------------------------------------------------------------------------- 119 | * This follows the return type of the function and precedes the function 120 | * name in the function prototype. 121 | */ 122 | #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(KHRONOS_STATIC) 123 | /* Win32 but not WinCE */ 124 | # define KHRONOS_APIENTRY __stdcall 125 | #else 126 | # define KHRONOS_APIENTRY 127 | #endif 128 | 129 | /*------------------------------------------------------------------------- 130 | * Definition of KHRONOS_APIATTRIBUTES 131 | *------------------------------------------------------------------------- 132 | * This follows the closing parenthesis of the function prototype arguments. 133 | */ 134 | #if defined (__ARMCC_2__) 135 | #define KHRONOS_APIATTRIBUTES __softfp 136 | #else 137 | #define KHRONOS_APIATTRIBUTES 138 | #endif 139 | 140 | /*------------------------------------------------------------------------- 141 | * basic type definitions 142 | *-----------------------------------------------------------------------*/ 143 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) 144 | 145 | 146 | /* 147 | * Using 148 | */ 149 | #include 150 | typedef int32_t khronos_int32_t; 151 | typedef uint32_t khronos_uint32_t; 152 | typedef int64_t khronos_int64_t; 153 | typedef uint64_t khronos_uint64_t; 154 | #define KHRONOS_SUPPORT_INT64 1 155 | #define KHRONOS_SUPPORT_FLOAT 1 156 | 157 | #elif defined(__VMS ) || defined(__sgi) 158 | 159 | /* 160 | * Using 161 | */ 162 | #include 163 | typedef int32_t khronos_int32_t; 164 | typedef uint32_t khronos_uint32_t; 165 | typedef int64_t khronos_int64_t; 166 | typedef uint64_t khronos_uint64_t; 167 | #define KHRONOS_SUPPORT_INT64 1 168 | #define KHRONOS_SUPPORT_FLOAT 1 169 | 170 | #elif defined(_WIN32) && !defined(__SCITECH_SNAP__) 171 | 172 | /* 173 | * Win32 174 | */ 175 | typedef __int32 khronos_int32_t; 176 | typedef unsigned __int32 khronos_uint32_t; 177 | typedef __int64 khronos_int64_t; 178 | typedef unsigned __int64 khronos_uint64_t; 179 | #define KHRONOS_SUPPORT_INT64 1 180 | #define KHRONOS_SUPPORT_FLOAT 1 181 | 182 | #elif defined(__sun__) || defined(__digital__) 183 | 184 | /* 185 | * Sun or Digital 186 | */ 187 | typedef int khronos_int32_t; 188 | typedef unsigned int khronos_uint32_t; 189 | #if defined(__arch64__) || defined(_LP64) 190 | typedef long int khronos_int64_t; 191 | typedef unsigned long int khronos_uint64_t; 192 | #else 193 | typedef long long int khronos_int64_t; 194 | typedef unsigned long long int khronos_uint64_t; 195 | #endif /* __arch64__ */ 196 | #define KHRONOS_SUPPORT_INT64 1 197 | #define KHRONOS_SUPPORT_FLOAT 1 198 | 199 | #elif 0 200 | 201 | /* 202 | * Hypothetical platform with no float or int64 support 203 | */ 204 | typedef int khronos_int32_t; 205 | typedef unsigned int khronos_uint32_t; 206 | #define KHRONOS_SUPPORT_INT64 0 207 | #define KHRONOS_SUPPORT_FLOAT 0 208 | 209 | #else 210 | 211 | /* 212 | * Generic fallback 213 | */ 214 | #include 215 | typedef int32_t khronos_int32_t; 216 | typedef uint32_t khronos_uint32_t; 217 | typedef int64_t khronos_int64_t; 218 | typedef uint64_t khronos_uint64_t; 219 | #define KHRONOS_SUPPORT_INT64 1 220 | #define KHRONOS_SUPPORT_FLOAT 1 221 | 222 | #endif 223 | 224 | 225 | /* 226 | * Types that are (so far) the same on all platforms 227 | */ 228 | typedef signed char khronos_int8_t; 229 | typedef unsigned char khronos_uint8_t; 230 | typedef signed short int khronos_int16_t; 231 | typedef unsigned short int khronos_uint16_t; 232 | 233 | /* 234 | * Types that differ between LLP64 and LP64 architectures - in LLP64, 235 | * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears 236 | * to be the only LLP64 architecture in current use. 237 | */ 238 | #ifdef _WIN64 239 | typedef signed long long int khronos_intptr_t; 240 | typedef unsigned long long int khronos_uintptr_t; 241 | typedef signed long long int khronos_ssize_t; 242 | typedef unsigned long long int khronos_usize_t; 243 | #else 244 | typedef signed long int khronos_intptr_t; 245 | typedef unsigned long int khronos_uintptr_t; 246 | typedef signed long int khronos_ssize_t; 247 | typedef unsigned long int khronos_usize_t; 248 | #endif 249 | 250 | #if KHRONOS_SUPPORT_FLOAT 251 | /* 252 | * Float type 253 | */ 254 | typedef float khronos_float_t; 255 | #endif 256 | 257 | #if KHRONOS_SUPPORT_INT64 258 | /* Time types 259 | * 260 | * These types can be used to represent a time interval in nanoseconds or 261 | * an absolute Unadjusted System Time. Unadjusted System Time is the number 262 | * of nanoseconds since some arbitrary system event (e.g. since the last 263 | * time the system booted). The Unadjusted System Time is an unsigned 264 | * 64 bit value that wraps back to 0 every 584 years. Time intervals 265 | * may be either signed or unsigned. 266 | */ 267 | typedef khronos_uint64_t khronos_utime_nanoseconds_t; 268 | typedef khronos_int64_t khronos_stime_nanoseconds_t; 269 | #endif 270 | 271 | /* 272 | * Dummy value used to pad enum types to 32 bits. 273 | */ 274 | #ifndef KHRONOS_MAX_ENUM 275 | #define KHRONOS_MAX_ENUM 0x7FFFFFFF 276 | #endif 277 | 278 | /* 279 | * Enumerated boolean type 280 | * 281 | * Values other than zero should be considered to be true. Therefore 282 | * comparisons should not be made against KHRONOS_TRUE. 283 | */ 284 | typedef enum { 285 | KHRONOS_FALSE = 0, 286 | KHRONOS_TRUE = 1, 287 | KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM 288 | } khronos_boolean_enum_t; 289 | 290 | #endif /* __khrplatform_h_ */ 291 | -------------------------------------------------------------------------------- /extern/glfw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(glfw C) 2 | 3 | find_package(Threads REQUIRED) 4 | 5 | # Establish target libraries and include directories 6 | if (APPLE) 7 | 8 | list(APPEND glfw_LIBRARIES 9 | "-framework Cocoa" 10 | "-framework IOKit" 11 | "-framework CoreFoundation" 12 | "-framework CoreVideo") 13 | 14 | elseif (UNIX) 15 | find_library(RT_LIBRARY rt) 16 | if (RT_LIBRARY) 17 | list(APPEND glfw_LIBRARIES "${RT_LIBRARY}") 18 | endif() 19 | 20 | find_library(MATH_LIBRARY m) 21 | if (MATH_LIBRARY) 22 | list(APPEND glfw_LIBRARIES "${MATH_LIBRARY}") 23 | endif() 24 | 25 | if (CMAKE_DL_LIBS) 26 | list(APPEND glfw_LIBRARIES "${CMAKE_DL_LIBS}") 27 | endif() 28 | 29 | find_package(X11 REQUIRED) 30 | 31 | # Set up library and include paths 32 | list(APPEND glfw_INCLUDE_DIRS "${X11_X11_INCLUDE_PATH}") 33 | list(APPEND glfw_LIBRARIES "${X11_X11_LIB}" "${CMAKE_THREAD_LIBS_INIT}") 34 | 35 | # Check for XRandR (modern resolution switching and gamma control) 36 | if (NOT X11_Xrandr_FOUND) 37 | message(FATAL_ERROR "The RandR headers were not found") 38 | endif() 39 | 40 | # Check for Xinerama (legacy multi-monitor support) 41 | if (NOT X11_Xinerama_FOUND) 42 | message(FATAL_ERROR "The Xinerama headers were not found") 43 | endif() 44 | 45 | # Check for Xkb (X keyboard extension) 46 | if (NOT X11_Xkb_FOUND) 47 | message(FATAL_ERROR "The X keyboard extension headers were not found") 48 | endif() 49 | 50 | # Check for Xcursor (cursor creation from RGBA images) 51 | if (NOT X11_Xcursor_FOUND) 52 | message(FATAL_ERROR "The Xcursor headers were not found") 53 | endif() 54 | 55 | list(APPEND glfw_INCLUDE_DIRS "${X11_Xrandr_INCLUDE_PATH}" 56 | "${X11_Xinerama_INCLUDE_PATH}" 57 | "${X11_Xkb_INCLUDE_PATH}" 58 | "${X11_Xcursor_INCLUDE_PATH}") 59 | endif() 60 | 61 | set(common_HEADERS src/internal.h src/mappings.h 62 | include/GLFW/glfw3.h 63 | include/GLFW/glfw3native.h) 64 | set(common_SOURCES src/context.c src/init.c src/input.c src/monitor.c src/vulkan.c src/window.c) 65 | 66 | if (APPLE) 67 | set(glfw_HEADERS ${common_HEADERS} src/cocoa_platform.h src/cocoa_joystick.h 68 | src/posix_thread.h src/nsgl_context.h src/egl_context.h src/osmesa_context.h) 69 | set(glfw_SOURCES ${common_SOURCES} src/cocoa_init.m src/cocoa_joystick.m 70 | src/cocoa_monitor.m src/cocoa_window.m src/cocoa_time.c src/posix_thread.c 71 | src/nsgl_context.m src/egl_context.c src/osmesa_context.c) 72 | set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) 73 | elseif (WIN32) 74 | set(glfw_HEADERS ${common_HEADERS} src/win32_platform.h src/win32_joystick.h 75 | src/wgl_context.h src/egl_context.h src/osmesa_context.h) 76 | set(glfw_SOURCES ${common_SOURCES} src/win32_init.c src/win32_joystick.c 77 | src/win32_monitor.c src/win32_time.c src/win32_thread.c src/win32_window.c 78 | src/wgl_context.c src/egl_context.c src/osmesa_context.c) 79 | elseif (UNIX) 80 | set(glfw_HEADERS ${common_HEADERS} src/x11_platform.h src/xkb_unicode.h src/posix_time.h 81 | src/posix_thread.h src/glx_context.h src/egl_context.h src/osmesa_context.h) 82 | set(glfw_SOURCES ${common_SOURCES} src/x11_init.c src/x11_monitor.c src/x11_window.c 83 | src/xkb_unicode.c src/posix_time.c src/posix_thread.c src/glx_context.c 84 | src/egl_context.c src/osmesa_context.c) 85 | set(glfw_HEADERS ${glfw_HEADERS} src/linux_joystick.h) 86 | set(glfw_SOURCES ${glfw_SOURCES} src/linux_joystick.c) 87 | endif() 88 | 89 | add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) 90 | target_include_directories(glfw PUBLIC include) 91 | target_include_directories(glfw PRIVATE ${glfw_INCLUDE_DIRS}) 92 | target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES}) 93 | -------------------------------------------------------------------------------- /extern/glfw/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns 33 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE 34 | 35 | #define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X" 36 | 37 | // Cocoa-specific per-joystick data 38 | // 39 | typedef struct _GLFWjoystickNS 40 | { 41 | IOHIDDeviceRef device; 42 | CFMutableArrayRef axes; 43 | CFMutableArrayRef buttons; 44 | CFMutableArrayRef hats; 45 | } _GLFWjoystickNS; 46 | 47 | 48 | void _glfwInitJoysticksNS(void); 49 | void _glfwTerminateJoysticksNS(void); 50 | 51 | -------------------------------------------------------------------------------- /extern/glfw/src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #if defined(__OBJC__) 32 | #import 33 | #else 34 | typedef void* id; 35 | #endif 36 | 37 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 38 | 39 | typedef struct VkMacOSSurfaceCreateInfoMVK 40 | { 41 | VkStructureType sType; 42 | const void* pNext; 43 | VkMacOSSurfaceCreateFlagsMVK flags; 44 | const void* pView; 45 | } VkMacOSSurfaceCreateInfoMVK; 46 | 47 | typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*); 48 | 49 | #include "posix_thread.h" 50 | #include "cocoa_joystick.h" 51 | #include "nsgl_context.h" 52 | #include "egl_context.h" 53 | #include "osmesa_context.h" 54 | 55 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 56 | #define _glfw_dlclose(handle) dlclose(handle) 57 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 58 | 59 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->ns.view) 60 | #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY 61 | 62 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns 63 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns 64 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerNS ns 65 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns 66 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns 67 | 68 | // HIToolbox.framework pointer typedefs 69 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData 70 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); 71 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource 72 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); 73 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty 74 | typedef UInt8 (*PFN_LMGetKbdType)(void); 75 | #define LMGetKbdType _glfw.ns.tis.GetKbdType 76 | 77 | 78 | // Cocoa-specific per-window data 79 | // 80 | typedef struct _GLFWwindowNS 81 | { 82 | id object; 83 | id delegate; 84 | id view; 85 | id layer; 86 | 87 | GLFWbool maximized; 88 | 89 | // Cached window properties to filter out duplicate events 90 | int width, height; 91 | int fbWidth, fbHeight; 92 | float xscale, yscale; 93 | 94 | // The total sum of the distances the cursor has been warped 95 | // since the last cursor motion event was processed 96 | // This is kept to counteract Cocoa doing the same internally 97 | double cursorWarpDeltaX, cursorWarpDeltaY; 98 | 99 | } _GLFWwindowNS; 100 | 101 | // Cocoa-specific global data 102 | // 103 | typedef struct _GLFWlibraryNS 104 | { 105 | CGEventSourceRef eventSource; 106 | id delegate; 107 | id autoreleasePool; 108 | GLFWbool cursorHidden; 109 | TISInputSourceRef inputSource; 110 | IOHIDManagerRef hidManager; 111 | id unicodeData; 112 | id helper; 113 | id keyUpMonitor; 114 | id nibObjects; 115 | 116 | char keyName[64]; 117 | short int keycodes[256]; 118 | short int scancodes[GLFW_KEY_LAST + 1]; 119 | char* clipboardString; 120 | CGPoint cascadePoint; 121 | // Where to place the cursor when re-enabled 122 | double restoreCursorPosX, restoreCursorPosY; 123 | // The window whose disabled cursor mode is active 124 | _GLFWwindow* disabledCursorWindow; 125 | 126 | struct { 127 | CFBundleRef bundle; 128 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; 129 | PFN_TISGetInputSourceProperty GetInputSourceProperty; 130 | PFN_LMGetKbdType GetKbdType; 131 | CFStringRef kPropertyUnicodeKeyLayoutData; 132 | } tis; 133 | 134 | } _GLFWlibraryNS; 135 | 136 | // Cocoa-specific per-monitor data 137 | // 138 | typedef struct _GLFWmonitorNS 139 | { 140 | CGDirectDisplayID displayID; 141 | CGDisplayModeRef previousMode; 142 | uint32_t unitNumber; 143 | id screen; 144 | 145 | } _GLFWmonitorNS; 146 | 147 | // Cocoa-specific per-cursor data 148 | // 149 | typedef struct _GLFWcursorNS 150 | { 151 | id object; 152 | 153 | } _GLFWcursorNS; 154 | 155 | // Cocoa-specific global timer data 156 | // 157 | typedef struct _GLFWtimerNS 158 | { 159 | uint64_t frequency; 160 | 161 | } _GLFWtimerNS; 162 | 163 | 164 | void _glfwInitTimerNS(void); 165 | 166 | void _glfwPollMonitorsNS(void); 167 | void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); 168 | void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); 169 | 170 | -------------------------------------------------------------------------------- /extern/glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #include 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW internal API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | // Initialise timer 37 | // 38 | void _glfwInitTimerNS(void) 39 | { 40 | mach_timebase_info_data_t info; 41 | mach_timebase_info(&info); 42 | 43 | _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; 44 | } 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | ////// GLFW platform API ////// 49 | ////////////////////////////////////////////////////////////////////////// 50 | 51 | uint64_t _glfwPlatformGetTimerValue(void) 52 | { 53 | return mach_absolute_time(); 54 | } 55 | 56 | uint64_t _glfwPlatformGetTimerFrequency(void) 57 | { 58 | return _glfw.timer.ns.frequency; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /extern/glfw/src/egl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 EGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #if defined(_GLFW_USE_EGLPLATFORM_H) 29 | #include 30 | #elif defined(_GLFW_WIN32) 31 | #define EGLAPIENTRY __stdcall 32 | typedef HDC EGLNativeDisplayType; 33 | typedef HWND EGLNativeWindowType; 34 | #elif defined(_GLFW_COCOA) 35 | #define EGLAPIENTRY 36 | typedef void* EGLNativeDisplayType; 37 | typedef id EGLNativeWindowType; 38 | #elif defined(_GLFW_X11) 39 | #define EGLAPIENTRY 40 | typedef Display* EGLNativeDisplayType; 41 | typedef Window EGLNativeWindowType; 42 | #elif defined(_GLFW_WAYLAND) 43 | #define EGLAPIENTRY 44 | typedef struct wl_display* EGLNativeDisplayType; 45 | typedef struct wl_egl_window* EGLNativeWindowType; 46 | #else 47 | #error "No supported EGL platform selected" 48 | #endif 49 | 50 | #define EGL_SUCCESS 0x3000 51 | #define EGL_NOT_INITIALIZED 0x3001 52 | #define EGL_BAD_ACCESS 0x3002 53 | #define EGL_BAD_ALLOC 0x3003 54 | #define EGL_BAD_ATTRIBUTE 0x3004 55 | #define EGL_BAD_CONFIG 0x3005 56 | #define EGL_BAD_CONTEXT 0x3006 57 | #define EGL_BAD_CURRENT_SURFACE 0x3007 58 | #define EGL_BAD_DISPLAY 0x3008 59 | #define EGL_BAD_MATCH 0x3009 60 | #define EGL_BAD_NATIVE_PIXMAP 0x300a 61 | #define EGL_BAD_NATIVE_WINDOW 0x300b 62 | #define EGL_BAD_PARAMETER 0x300c 63 | #define EGL_BAD_SURFACE 0x300d 64 | #define EGL_CONTEXT_LOST 0x300e 65 | #define EGL_COLOR_BUFFER_TYPE 0x303f 66 | #define EGL_RGB_BUFFER 0x308e 67 | #define EGL_SURFACE_TYPE 0x3033 68 | #define EGL_WINDOW_BIT 0x0004 69 | #define EGL_RENDERABLE_TYPE 0x3040 70 | #define EGL_OPENGL_ES_BIT 0x0001 71 | #define EGL_OPENGL_ES2_BIT 0x0004 72 | #define EGL_OPENGL_BIT 0x0008 73 | #define EGL_ALPHA_SIZE 0x3021 74 | #define EGL_BLUE_SIZE 0x3022 75 | #define EGL_GREEN_SIZE 0x3023 76 | #define EGL_RED_SIZE 0x3024 77 | #define EGL_DEPTH_SIZE 0x3025 78 | #define EGL_STENCIL_SIZE 0x3026 79 | #define EGL_SAMPLES 0x3031 80 | #define EGL_OPENGL_ES_API 0x30a0 81 | #define EGL_OPENGL_API 0x30a2 82 | #define EGL_NONE 0x3038 83 | #define EGL_EXTENSIONS 0x3055 84 | #define EGL_CONTEXT_CLIENT_VERSION 0x3098 85 | #define EGL_NATIVE_VISUAL_ID 0x302e 86 | #define EGL_NO_SURFACE ((EGLSurface) 0) 87 | #define EGL_NO_DISPLAY ((EGLDisplay) 0) 88 | #define EGL_NO_CONTEXT ((EGLContext) 0) 89 | #define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType) 0) 90 | 91 | #define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002 92 | #define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001 93 | #define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002 94 | #define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001 95 | #define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31bd 96 | #define EGL_NO_RESET_NOTIFICATION_KHR 0x31be 97 | #define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31bf 98 | #define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004 99 | #define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098 100 | #define EGL_CONTEXT_MINOR_VERSION_KHR 0x30fb 101 | #define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30fd 102 | #define EGL_CONTEXT_FLAGS_KHR 0x30fc 103 | #define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31b3 104 | #define EGL_GL_COLORSPACE_KHR 0x309d 105 | #define EGL_GL_COLORSPACE_SRGB_KHR 0x3089 106 | #define EGL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x2097 107 | #define EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR 0 108 | #define EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR 0x2098 109 | 110 | typedef int EGLint; 111 | typedef unsigned int EGLBoolean; 112 | typedef unsigned int EGLenum; 113 | typedef void* EGLConfig; 114 | typedef void* EGLContext; 115 | typedef void* EGLDisplay; 116 | typedef void* EGLSurface; 117 | 118 | // EGL function pointer typedefs 119 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglGetConfigAttrib)(EGLDisplay,EGLConfig,EGLint,EGLint*); 120 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglGetConfigs)(EGLDisplay,EGLConfig*,EGLint,EGLint*); 121 | typedef EGLDisplay (EGLAPIENTRY * PFN_eglGetDisplay)(EGLNativeDisplayType); 122 | typedef EGLint (EGLAPIENTRY * PFN_eglGetError)(void); 123 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglInitialize)(EGLDisplay,EGLint*,EGLint*); 124 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglTerminate)(EGLDisplay); 125 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglBindAPI)(EGLenum); 126 | typedef EGLContext (EGLAPIENTRY * PFN_eglCreateContext)(EGLDisplay,EGLConfig,EGLContext,const EGLint*); 127 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglDestroySurface)(EGLDisplay,EGLSurface); 128 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglDestroyContext)(EGLDisplay,EGLContext); 129 | typedef EGLSurface (EGLAPIENTRY * PFN_eglCreateWindowSurface)(EGLDisplay,EGLConfig,EGLNativeWindowType,const EGLint*); 130 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglMakeCurrent)(EGLDisplay,EGLSurface,EGLSurface,EGLContext); 131 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapBuffers)(EGLDisplay,EGLSurface); 132 | typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapInterval)(EGLDisplay,EGLint); 133 | typedef const char* (EGLAPIENTRY * PFN_eglQueryString)(EGLDisplay,EGLint); 134 | typedef GLFWglproc (EGLAPIENTRY * PFN_eglGetProcAddress)(const char*); 135 | #define eglGetConfigAttrib _glfw.egl.GetConfigAttrib 136 | #define eglGetConfigs _glfw.egl.GetConfigs 137 | #define eglGetDisplay _glfw.egl.GetDisplay 138 | #define eglGetError _glfw.egl.GetError 139 | #define eglInitialize _glfw.egl.Initialize 140 | #define eglTerminate _glfw.egl.Terminate 141 | #define eglBindAPI _glfw.egl.BindAPI 142 | #define eglCreateContext _glfw.egl.CreateContext 143 | #define eglDestroySurface _glfw.egl.DestroySurface 144 | #define eglDestroyContext _glfw.egl.DestroyContext 145 | #define eglCreateWindowSurface _glfw.egl.CreateWindowSurface 146 | #define eglMakeCurrent _glfw.egl.MakeCurrent 147 | #define eglSwapBuffers _glfw.egl.SwapBuffers 148 | #define eglSwapInterval _glfw.egl.SwapInterval 149 | #define eglQueryString _glfw.egl.QueryString 150 | #define eglGetProcAddress _glfw.egl.GetProcAddress 151 | 152 | #define _GLFW_EGL_CONTEXT_STATE _GLFWcontextEGL egl 153 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE _GLFWlibraryEGL egl 154 | 155 | 156 | // EGL-specific per-context data 157 | // 158 | typedef struct _GLFWcontextEGL 159 | { 160 | EGLConfig config; 161 | EGLContext handle; 162 | EGLSurface surface; 163 | 164 | void* client; 165 | 166 | } _GLFWcontextEGL; 167 | 168 | // EGL-specific global data 169 | // 170 | typedef struct _GLFWlibraryEGL 171 | { 172 | EGLDisplay display; 173 | EGLint major, minor; 174 | GLFWbool prefix; 175 | 176 | GLFWbool KHR_create_context; 177 | GLFWbool KHR_create_context_no_error; 178 | GLFWbool KHR_gl_colorspace; 179 | GLFWbool KHR_get_all_proc_addresses; 180 | GLFWbool KHR_context_flush_control; 181 | 182 | void* handle; 183 | 184 | PFN_eglGetConfigAttrib GetConfigAttrib; 185 | PFN_eglGetConfigs GetConfigs; 186 | PFN_eglGetDisplay GetDisplay; 187 | PFN_eglGetError GetError; 188 | PFN_eglInitialize Initialize; 189 | PFN_eglTerminate Terminate; 190 | PFN_eglBindAPI BindAPI; 191 | PFN_eglCreateContext CreateContext; 192 | PFN_eglDestroySurface DestroySurface; 193 | PFN_eglDestroyContext DestroyContext; 194 | PFN_eglCreateWindowSurface CreateWindowSurface; 195 | PFN_eglMakeCurrent MakeCurrent; 196 | PFN_eglSwapBuffers SwapBuffers; 197 | PFN_eglSwapInterval SwapInterval; 198 | PFN_eglQueryString QueryString; 199 | PFN_eglGetProcAddress GetProcAddress; 200 | 201 | } _GLFWlibraryEGL; 202 | 203 | 204 | GLFWbool _glfwInitEGL(void); 205 | void _glfwTerminateEGL(void); 206 | GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, 207 | const _GLFWctxconfig* ctxconfig, 208 | const _GLFWfbconfig* fbconfig); 209 | #if defined(_GLFW_X11) 210 | GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig, 211 | const _GLFWctxconfig* ctxconfig, 212 | const _GLFWfbconfig* fbconfig, 213 | Visual** visual, int* depth); 214 | #endif /*_GLFW_X11*/ 215 | 216 | -------------------------------------------------------------------------------- /extern/glfw/src/glfw_config.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As glfw_config.h.in, this file is used by CMake to produce the 27 | // glfw_config.h configuration header file. If you are adding a feature 28 | // requiring conditional compilation, this is where to add the macro. 29 | //======================================================================== 30 | // As glfw_config.h, this file defines compile-time option macros for a 31 | // specific platform and development environment. If you are using the 32 | // GLFW CMake files, modify glfw_config.h.in instead of this file. If you 33 | // are using your own build system, make this file define the appropriate 34 | // macros in whatever way is suitable. 35 | //======================================================================== 36 | 37 | // MODIFIED_ERIN 38 | #ifdef _WIN32 39 | #define _GLFW_WIN32 40 | #define _CRT_SECURE_NO_WARNINGS 41 | #elif __APPLE__ 42 | #define _GLFW_COCOA 43 | #else 44 | #define _GLFW_X11 45 | #endif -------------------------------------------------------------------------------- /extern/glfw/src/glx_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 GLX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLX_VENDOR 1 29 | #define GLX_RGBA_BIT 0x00000001 30 | #define GLX_WINDOW_BIT 0x00000001 31 | #define GLX_DRAWABLE_TYPE 0x8010 32 | #define GLX_RENDER_TYPE 0x8011 33 | #define GLX_RGBA_TYPE 0x8014 34 | #define GLX_DOUBLEBUFFER 5 35 | #define GLX_STEREO 6 36 | #define GLX_AUX_BUFFERS 7 37 | #define GLX_RED_SIZE 8 38 | #define GLX_GREEN_SIZE 9 39 | #define GLX_BLUE_SIZE 10 40 | #define GLX_ALPHA_SIZE 11 41 | #define GLX_DEPTH_SIZE 12 42 | #define GLX_STENCIL_SIZE 13 43 | #define GLX_ACCUM_RED_SIZE 14 44 | #define GLX_ACCUM_GREEN_SIZE 15 45 | #define GLX_ACCUM_BLUE_SIZE 16 46 | #define GLX_ACCUM_ALPHA_SIZE 17 47 | #define GLX_SAMPLES 0x186a1 48 | #define GLX_VISUAL_ID 0x800b 49 | 50 | #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20b2 51 | #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 52 | #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 53 | #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 54 | #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 55 | #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 56 | #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 57 | #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 58 | #define GLX_CONTEXT_FLAGS_ARB 0x2094 59 | #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 60 | #define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 61 | #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 62 | #define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 63 | #define GLX_NO_RESET_NOTIFICATION_ARB 0x8261 64 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 65 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 66 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 67 | #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3 68 | 69 | typedef XID GLXWindow; 70 | typedef XID GLXDrawable; 71 | typedef struct __GLXFBConfig* GLXFBConfig; 72 | typedef struct __GLXcontext* GLXContext; 73 | typedef void (*__GLXextproc)(void); 74 | 75 | typedef int (*PFNGLXGETFBCONFIGATTRIBPROC)(Display*,GLXFBConfig,int,int*); 76 | typedef const char* (*PFNGLXGETCLIENTSTRINGPROC)(Display*,int); 77 | typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display*,int*,int*); 78 | typedef Bool (*PFNGLXQUERYVERSIONPROC)(Display*,int*,int*); 79 | typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display*,GLXContext); 80 | typedef Bool (*PFNGLXMAKECURRENTPROC)(Display*,GLXDrawable,GLXContext); 81 | typedef void (*PFNGLXSWAPBUFFERSPROC)(Display*,GLXDrawable); 82 | typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int); 83 | typedef GLXFBConfig* (*PFNGLXGETFBCONFIGSPROC)(Display*,int,int*); 84 | typedef GLXContext (*PFNGLXCREATENEWCONTEXTPROC)(Display*,GLXFBConfig,int,GLXContext,Bool); 85 | typedef __GLXextproc (* PFNGLXGETPROCADDRESSPROC)(const GLubyte *procName); 86 | typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int); 87 | typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); 88 | typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*); 89 | typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); 90 | 91 | typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); 92 | typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int); 93 | typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); 94 | 95 | // libGL.so function pointer typedefs 96 | #define glXGetFBConfigs _glfw.glx.GetFBConfigs 97 | #define glXGetFBConfigAttrib _glfw.glx.GetFBConfigAttrib 98 | #define glXGetClientString _glfw.glx.GetClientString 99 | #define glXQueryExtension _glfw.glx.QueryExtension 100 | #define glXQueryVersion _glfw.glx.QueryVersion 101 | #define glXDestroyContext _glfw.glx.DestroyContext 102 | #define glXMakeCurrent _glfw.glx.MakeCurrent 103 | #define glXSwapBuffers _glfw.glx.SwapBuffers 104 | #define glXQueryExtensionsString _glfw.glx.QueryExtensionsString 105 | #define glXCreateNewContext _glfw.glx.CreateNewContext 106 | #define glXGetVisualFromFBConfig _glfw.glx.GetVisualFromFBConfig 107 | #define glXCreateWindow _glfw.glx.CreateWindow 108 | #define glXDestroyWindow _glfw.glx.DestroyWindow 109 | 110 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx 111 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryGLX glx 112 | 113 | 114 | // GLX-specific per-context data 115 | // 116 | typedef struct _GLFWcontextGLX 117 | { 118 | GLXContext handle; 119 | GLXWindow window; 120 | 121 | } _GLFWcontextGLX; 122 | 123 | // GLX-specific global data 124 | // 125 | typedef struct _GLFWlibraryGLX 126 | { 127 | int major, minor; 128 | int eventBase; 129 | int errorBase; 130 | 131 | // dlopen handle for libGL.so.1 132 | void* handle; 133 | 134 | // GLX 1.3 functions 135 | PFNGLXGETFBCONFIGSPROC GetFBConfigs; 136 | PFNGLXGETFBCONFIGATTRIBPROC GetFBConfigAttrib; 137 | PFNGLXGETCLIENTSTRINGPROC GetClientString; 138 | PFNGLXQUERYEXTENSIONPROC QueryExtension; 139 | PFNGLXQUERYVERSIONPROC QueryVersion; 140 | PFNGLXDESTROYCONTEXTPROC DestroyContext; 141 | PFNGLXMAKECURRENTPROC MakeCurrent; 142 | PFNGLXSWAPBUFFERSPROC SwapBuffers; 143 | PFNGLXQUERYEXTENSIONSSTRINGPROC QueryExtensionsString; 144 | PFNGLXCREATENEWCONTEXTPROC CreateNewContext; 145 | PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig; 146 | PFNGLXCREATEWINDOWPROC CreateWindow; 147 | PFNGLXDESTROYWINDOWPROC DestroyWindow; 148 | 149 | // GLX 1.4 and extension functions 150 | PFNGLXGETPROCADDRESSPROC GetProcAddress; 151 | PFNGLXGETPROCADDRESSPROC GetProcAddressARB; 152 | PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; 153 | PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; 154 | PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; 155 | PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 156 | GLFWbool SGI_swap_control; 157 | GLFWbool EXT_swap_control; 158 | GLFWbool MESA_swap_control; 159 | GLFWbool ARB_multisample; 160 | GLFWbool ARB_framebuffer_sRGB; 161 | GLFWbool EXT_framebuffer_sRGB; 162 | GLFWbool ARB_create_context; 163 | GLFWbool ARB_create_context_profile; 164 | GLFWbool ARB_create_context_robustness; 165 | GLFWbool EXT_create_context_es2_profile; 166 | GLFWbool ARB_create_context_no_error; 167 | GLFWbool ARB_context_flush_control; 168 | 169 | } _GLFWlibraryGLX; 170 | 171 | GLFWbool _glfwInitGLX(void); 172 | void _glfwTerminateGLX(void); 173 | GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, 174 | const _GLFWctxconfig* ctxconfig, 175 | const _GLFWfbconfig* fbconfig); 176 | void _glfwDestroyContextGLX(_GLFWwindow* window); 177 | GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig, 178 | const _GLFWctxconfig* ctxconfig, 179 | const _GLFWfbconfig* fbconfig, 180 | Visual** visual, int* depth); 181 | 182 | -------------------------------------------------------------------------------- /extern/glfw/src/init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | #include "mappings.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | // The global variables below comprise all mutable global data in GLFW 39 | // 40 | // Any other global variable is a bug 41 | 42 | // Global state shared between compilation units of GLFW 43 | // 44 | _GLFWlibrary _glfw = { GLFW_FALSE }; 45 | 46 | // These are outside of _glfw so they can be used before initialization and 47 | // after termination 48 | // 49 | static _GLFWerror _glfwMainThreadError; 50 | static GLFWerrorfun _glfwErrorCallback; 51 | static _GLFWinitconfig _glfwInitHints = 52 | { 53 | GLFW_TRUE, // hat buttons 54 | { 55 | GLFW_TRUE, // macOS menu bar 56 | GLFW_TRUE // macOS bundle chdir 57 | } 58 | }; 59 | 60 | // Terminate the library 61 | // 62 | static void terminate(void) 63 | { 64 | int i; 65 | 66 | memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); 67 | 68 | while (_glfw.windowListHead) 69 | glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); 70 | 71 | while (_glfw.cursorListHead) 72 | glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); 73 | 74 | for (i = 0; i < _glfw.monitorCount; i++) 75 | { 76 | _GLFWmonitor* monitor = _glfw.monitors[i]; 77 | if (monitor->originalRamp.size) 78 | _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); 79 | _glfwFreeMonitor(monitor); 80 | } 81 | 82 | free(_glfw.monitors); 83 | _glfw.monitors = NULL; 84 | _glfw.monitorCount = 0; 85 | 86 | free(_glfw.mappings); 87 | _glfw.mappings = NULL; 88 | _glfw.mappingCount = 0; 89 | 90 | _glfwTerminateVulkan(); 91 | _glfwPlatformTerminate(); 92 | 93 | _glfw.initialized = GLFW_FALSE; 94 | 95 | while (_glfw.errorListHead) 96 | { 97 | _GLFWerror* error = _glfw.errorListHead; 98 | _glfw.errorListHead = error->next; 99 | free(error); 100 | } 101 | 102 | _glfwPlatformDestroyTls(&_glfw.contextSlot); 103 | _glfwPlatformDestroyTls(&_glfw.errorSlot); 104 | _glfwPlatformDestroyMutex(&_glfw.errorLock); 105 | 106 | memset(&_glfw, 0, sizeof(_glfw)); 107 | } 108 | 109 | 110 | ////////////////////////////////////////////////////////////////////////// 111 | ////// GLFW internal API ////// 112 | ////////////////////////////////////////////////////////////////////////// 113 | 114 | char* _glfw_strdup(const char* source) 115 | { 116 | const size_t length = strlen(source); 117 | char* result = calloc(length + 1, 1); 118 | strcpy(result, source); 119 | return result; 120 | } 121 | 122 | float _glfw_fminf(float a, float b) 123 | { 124 | if (a != a) 125 | return b; 126 | else if (b != b) 127 | return a; 128 | else if (a < b) 129 | return a; 130 | else 131 | return b; 132 | } 133 | 134 | float _glfw_fmaxf(float a, float b) 135 | { 136 | if (a != a) 137 | return b; 138 | else if (b != b) 139 | return a; 140 | else if (a > b) 141 | return a; 142 | else 143 | return b; 144 | } 145 | 146 | 147 | ////////////////////////////////////////////////////////////////////////// 148 | ////// GLFW event API ////// 149 | ////////////////////////////////////////////////////////////////////////// 150 | 151 | // Notifies shared code of an error 152 | // 153 | void _glfwInputError(int code, const char* format, ...) 154 | { 155 | _GLFWerror* error; 156 | char description[_GLFW_MESSAGE_SIZE]; 157 | 158 | if (format) 159 | { 160 | va_list vl; 161 | 162 | va_start(vl, format); 163 | vsnprintf(description, sizeof(description), format, vl); 164 | va_end(vl); 165 | 166 | description[sizeof(description) - 1] = '\0'; 167 | } 168 | else 169 | { 170 | if (code == GLFW_NOT_INITIALIZED) 171 | strcpy(description, "The GLFW library is not initialized"); 172 | else if (code == GLFW_NO_CURRENT_CONTEXT) 173 | strcpy(description, "There is no current context"); 174 | else if (code == GLFW_INVALID_ENUM) 175 | strcpy(description, "Invalid argument for enum parameter"); 176 | else if (code == GLFW_INVALID_VALUE) 177 | strcpy(description, "Invalid value for parameter"); 178 | else if (code == GLFW_OUT_OF_MEMORY) 179 | strcpy(description, "Out of memory"); 180 | else if (code == GLFW_API_UNAVAILABLE) 181 | strcpy(description, "The requested API is unavailable"); 182 | else if (code == GLFW_VERSION_UNAVAILABLE) 183 | strcpy(description, "The requested API version is unavailable"); 184 | else if (code == GLFW_PLATFORM_ERROR) 185 | strcpy(description, "A platform-specific error occurred"); 186 | else if (code == GLFW_FORMAT_UNAVAILABLE) 187 | strcpy(description, "The requested format is unavailable"); 188 | else if (code == GLFW_NO_WINDOW_CONTEXT) 189 | strcpy(description, "The specified window has no context"); 190 | else 191 | strcpy(description, "ERROR: UNKNOWN GLFW ERROR"); 192 | } 193 | 194 | if (_glfw.initialized) 195 | { 196 | error = _glfwPlatformGetTls(&_glfw.errorSlot); 197 | if (!error) 198 | { 199 | error = calloc(1, sizeof(_GLFWerror)); 200 | _glfwPlatformSetTls(&_glfw.errorSlot, error); 201 | _glfwPlatformLockMutex(&_glfw.errorLock); 202 | error->next = _glfw.errorListHead; 203 | _glfw.errorListHead = error; 204 | _glfwPlatformUnlockMutex(&_glfw.errorLock); 205 | } 206 | } 207 | else 208 | error = &_glfwMainThreadError; 209 | 210 | error->code = code; 211 | strcpy(error->description, description); 212 | 213 | if (_glfwErrorCallback) 214 | _glfwErrorCallback(code, description); 215 | } 216 | 217 | 218 | ////////////////////////////////////////////////////////////////////////// 219 | ////// GLFW public API ////// 220 | ////////////////////////////////////////////////////////////////////////// 221 | 222 | GLFWAPI int glfwInit(void) 223 | { 224 | if (_glfw.initialized) 225 | return GLFW_TRUE; 226 | 227 | memset(&_glfw, 0, sizeof(_glfw)); 228 | _glfw.hints.init = _glfwInitHints; 229 | 230 | if (!_glfwPlatformInit()) 231 | { 232 | terminate(); 233 | return GLFW_FALSE; 234 | } 235 | 236 | if (!_glfwPlatformCreateMutex(&_glfw.errorLock) || 237 | !_glfwPlatformCreateTls(&_glfw.errorSlot) || 238 | !_glfwPlatformCreateTls(&_glfw.contextSlot)) 239 | { 240 | terminate(); 241 | return GLFW_FALSE; 242 | } 243 | 244 | _glfwPlatformSetTls(&_glfw.errorSlot, &_glfwMainThreadError); 245 | 246 | _glfw.initialized = GLFW_TRUE; 247 | _glfw.timer.offset = _glfwPlatformGetTimerValue(); 248 | 249 | glfwDefaultWindowHints(); 250 | 251 | { 252 | int i; 253 | 254 | for (i = 0; _glfwDefaultMappings[i]; i++) 255 | { 256 | if (!glfwUpdateGamepadMappings(_glfwDefaultMappings[i])) 257 | { 258 | terminate(); 259 | return GLFW_FALSE; 260 | } 261 | } 262 | } 263 | 264 | return GLFW_TRUE; 265 | } 266 | 267 | GLFWAPI void glfwTerminate(void) 268 | { 269 | if (!_glfw.initialized) 270 | return; 271 | 272 | terminate(); 273 | } 274 | 275 | GLFWAPI void glfwInitHint(int hint, int value) 276 | { 277 | switch (hint) 278 | { 279 | case GLFW_JOYSTICK_HAT_BUTTONS: 280 | _glfwInitHints.hatButtons = value; 281 | return; 282 | case GLFW_COCOA_CHDIR_RESOURCES: 283 | _glfwInitHints.ns.chdir = value; 284 | return; 285 | case GLFW_COCOA_MENUBAR: 286 | _glfwInitHints.ns.menubar = value; 287 | return; 288 | } 289 | 290 | _glfwInputError(GLFW_INVALID_ENUM, 291 | "Invalid init hint 0x%08X", hint); 292 | } 293 | 294 | GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) 295 | { 296 | if (major != NULL) 297 | *major = GLFW_VERSION_MAJOR; 298 | if (minor != NULL) 299 | *minor = GLFW_VERSION_MINOR; 300 | if (rev != NULL) 301 | *rev = GLFW_VERSION_REVISION; 302 | } 303 | 304 | GLFWAPI const char* glfwGetVersionString(void) 305 | { 306 | return _glfwPlatformGetVersionString(); 307 | } 308 | 309 | GLFWAPI int glfwGetError(const char** description) 310 | { 311 | _GLFWerror* error; 312 | int code = GLFW_NO_ERROR; 313 | 314 | if (description) 315 | *description = NULL; 316 | 317 | if (_glfw.initialized) 318 | error = _glfwPlatformGetTls(&_glfw.errorSlot); 319 | else 320 | error = &_glfwMainThreadError; 321 | 322 | if (error) 323 | { 324 | code = error->code; 325 | error->code = GLFW_NO_ERROR; 326 | if (description && code) 327 | *description = error->description; 328 | } 329 | 330 | return code; 331 | } 332 | 333 | GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 334 | { 335 | _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); 336 | return cbfun; 337 | } 338 | 339 | -------------------------------------------------------------------------------- /extern/glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs 32 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs 33 | 34 | #define _GLFW_PLATFORM_MAPPING_NAME "Linux" 35 | 36 | // Linux-specific joystick data 37 | // 38 | typedef struct _GLFWjoystickLinux 39 | { 40 | int fd; 41 | char path[PATH_MAX]; 42 | int keyMap[KEY_CNT - BTN_MISC]; 43 | int absMap[ABS_CNT]; 44 | struct input_absinfo absInfo[ABS_CNT]; 45 | int hats[4][2]; 46 | } _GLFWjoystickLinux; 47 | 48 | // Linux-specific joystick API data 49 | // 50 | typedef struct _GLFWlibraryLinux 51 | { 52 | int inotify; 53 | int watch; 54 | regex_t regex; 55 | GLFWbool dropped; 56 | } _GLFWlibraryLinux; 57 | 58 | 59 | GLFWbool _glfwInitJoysticksLinux(void); 60 | void _glfwTerminateJoysticksLinux(void); 61 | void _glfwDetectJoystickConnectionLinux(void); 62 | 63 | -------------------------------------------------------------------------------- /extern/glfw/src/mappings.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As mappings.h.in, this file is used by CMake to produce the mappings.h 27 | // header file. If you are adding a GLFW specific gamepad mapping, this is 28 | // where to put it. 29 | //======================================================================== 30 | // As mappings.h, this provides all pre-defined gamepad mappings, including 31 | // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad 32 | // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. 33 | // This file can be re-generated from mappings.h.in and the upstream 34 | // gamecontrollerdb.txt with the GenerateMappings.cmake script. 35 | //======================================================================== 36 | 37 | // All gamepad mappings not labeled GLFW are copied from the 38 | // SDL_GameControllerDB project under the following license: 39 | // 40 | // Simple DirectMedia Layer 41 | // Copyright (C) 1997-2013 Sam Lantinga 42 | // 43 | // This software is provided 'as-is', without any express or implied warranty. 44 | // In no event will the authors be held liable for any damages arising from the 45 | // use of this software. 46 | // 47 | // Permission is granted to anyone to use this software for any purpose, 48 | // including commercial applications, and to alter it and redistribute it 49 | // freely, subject to the following restrictions: 50 | // 51 | // 1. The origin of this software must not be misrepresented; you must not 52 | // claim that you wrote the original software. If you use this software 53 | // in a product, an acknowledgment in the product documentation would 54 | // be appreciated but is not required. 55 | // 56 | // 2. Altered source versions must be plainly marked as such, and must not be 57 | // misrepresented as being the original software. 58 | // 59 | // 3. This notice may not be removed or altered from any source distribution. 60 | 61 | const char* _glfwDefaultMappings[] = 62 | { 63 | @GLFW_GAMEPAD_MAPPINGS@ 64 | "78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 65 | "78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 66 | "78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 67 | "78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 68 | "78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 69 | "78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 70 | "78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 71 | NULL 72 | }; 73 | 74 | -------------------------------------------------------------------------------- /extern/glfw/src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 28 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 29 | 30 | 31 | // NSGL-specific per-context data 32 | // 33 | typedef struct _GLFWcontextNSGL 34 | { 35 | id pixelFormat; 36 | id object; 37 | 38 | } _GLFWcontextNSGL; 39 | 40 | // NSGL-specific global data 41 | // 42 | typedef struct _GLFWlibraryNSGL 43 | { 44 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 45 | CFBundleRef framework; 46 | 47 | } _GLFWlibraryNSGL; 48 | 49 | 50 | GLFWbool _glfwInitNSGL(void); 51 | void _glfwTerminateNSGL(void); 52 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 53 | const _GLFWctxconfig* ctxconfig, 54 | const _GLFWfbconfig* fbconfig); 55 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 56 | 57 | -------------------------------------------------------------------------------- /extern/glfw/src/nsgl_context.m: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 30 | #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval 31 | #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity 32 | #endif 33 | 34 | static void makeContextCurrentNSGL(_GLFWwindow* window) 35 | { 36 | if (window) 37 | [window->context.nsgl.object makeCurrentContext]; 38 | else 39 | [NSOpenGLContext clearCurrentContext]; 40 | 41 | _glfwPlatformSetTls(&_glfw.contextSlot, window); 42 | } 43 | 44 | static void swapBuffersNSGL(_GLFWwindow* window) 45 | { 46 | // ARP appears to be unnecessary, but this is future-proof 47 | [window->context.nsgl.object flushBuffer]; 48 | } 49 | 50 | static void swapIntervalNSGL(int interval) 51 | { 52 | _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); 53 | 54 | GLint sync = interval; 55 | [window->context.nsgl.object setValues:&sync 56 | forParameter:NSOpenGLContextParameterSwapInterval]; 57 | } 58 | 59 | static int extensionSupportedNSGL(const char* extension) 60 | { 61 | // There are no NSGL extensions 62 | return GLFW_FALSE; 63 | } 64 | 65 | static GLFWglproc getProcAddressNSGL(const char* procname) 66 | { 67 | CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault, 68 | procname, 69 | kCFStringEncodingASCII); 70 | 71 | GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfw.nsgl.framework, 72 | symbolName); 73 | 74 | CFRelease(symbolName); 75 | 76 | return symbol; 77 | } 78 | 79 | // Destroy the OpenGL context 80 | // 81 | static void destroyContextNSGL(_GLFWwindow* window) 82 | { 83 | [window->context.nsgl.pixelFormat release]; 84 | window->context.nsgl.pixelFormat = nil; 85 | 86 | [window->context.nsgl.object release]; 87 | window->context.nsgl.object = nil; 88 | } 89 | 90 | 91 | ////////////////////////////////////////////////////////////////////////// 92 | ////// GLFW internal API ////// 93 | ////////////////////////////////////////////////////////////////////////// 94 | 95 | // Initialize OpenGL support 96 | // 97 | GLFWbool _glfwInitNSGL(void) 98 | { 99 | if (_glfw.nsgl.framework) 100 | return GLFW_TRUE; 101 | 102 | _glfw.nsgl.framework = 103 | CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); 104 | if (_glfw.nsgl.framework == NULL) 105 | { 106 | _glfwInputError(GLFW_API_UNAVAILABLE, 107 | "NSGL: Failed to locate OpenGL framework"); 108 | return GLFW_FALSE; 109 | } 110 | 111 | return GLFW_TRUE; 112 | } 113 | 114 | // Terminate OpenGL support 115 | // 116 | void _glfwTerminateNSGL(void) 117 | { 118 | } 119 | 120 | // Create the OpenGL context 121 | // 122 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 123 | const _GLFWctxconfig* ctxconfig, 124 | const _GLFWfbconfig* fbconfig) 125 | { 126 | if (ctxconfig->client == GLFW_OPENGL_ES_API) 127 | { 128 | _glfwInputError(GLFW_API_UNAVAILABLE, 129 | "NSGL: OpenGL ES is not available on macOS"); 130 | return GLFW_FALSE; 131 | } 132 | 133 | if (ctxconfig->major > 2) 134 | { 135 | if (ctxconfig->major == 3 && ctxconfig->minor < 2) 136 | { 137 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 138 | "NSGL: The targeted version of macOS does not support OpenGL 3.0 or 3.1 but may support 3.2 and above"); 139 | return GLFW_FALSE; 140 | } 141 | 142 | if (!ctxconfig->forward || ctxconfig->profile != GLFW_OPENGL_CORE_PROFILE) 143 | { 144 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 145 | "NSGL: The targeted version of macOS only supports forward-compatible core profile contexts for OpenGL 3.2 and above"); 146 | return GLFW_FALSE; 147 | } 148 | } 149 | 150 | // Context robustness modes (GL_KHR_robustness) are not yet supported by 151 | // macOS but are not a hard constraint, so ignore and continue 152 | 153 | // Context release behaviors (GL_KHR_context_flush_control) are not yet 154 | // supported by macOS but are not a hard constraint, so ignore and continue 155 | 156 | // Debug contexts (GL_KHR_debug) are not yet supported by macOS but are not 157 | // a hard constraint, so ignore and continue 158 | 159 | // No-error contexts (GL_KHR_no_error) are not yet supported by macOS but 160 | // are not a hard constraint, so ignore and continue 161 | 162 | #define addAttrib(a) \ 163 | { \ 164 | assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ 165 | attribs[index++] = a; \ 166 | } 167 | #define setAttrib(a, v) { addAttrib(a); addAttrib(v); } 168 | 169 | NSOpenGLPixelFormatAttribute attribs[40]; 170 | int index = 0; 171 | 172 | addAttrib(NSOpenGLPFAAccelerated); 173 | addAttrib(NSOpenGLPFAClosestPolicy); 174 | 175 | if (ctxconfig->nsgl.offline) 176 | { 177 | addAttrib(NSOpenGLPFAAllowOfflineRenderers); 178 | // NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in 179 | // Info.plist for unbundled applications 180 | // HACK: This assumes that NSOpenGLPixelFormat will remain 181 | // a straightforward wrapper of its CGL counterpart 182 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 183 | addAttrib(kCGLPFASupportsAutomaticGraphicsSwitching); 184 | #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ 185 | } 186 | 187 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 188 | if (ctxconfig->major >= 4) 189 | { 190 | setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core); 191 | } 192 | else 193 | #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ 194 | if (ctxconfig->major >= 3) 195 | { 196 | setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); 197 | } 198 | 199 | if (ctxconfig->major <= 2) 200 | { 201 | if (fbconfig->auxBuffers != GLFW_DONT_CARE) 202 | setAttrib(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); 203 | 204 | if (fbconfig->accumRedBits != GLFW_DONT_CARE && 205 | fbconfig->accumGreenBits != GLFW_DONT_CARE && 206 | fbconfig->accumBlueBits != GLFW_DONT_CARE && 207 | fbconfig->accumAlphaBits != GLFW_DONT_CARE) 208 | { 209 | const int accumBits = fbconfig->accumRedBits + 210 | fbconfig->accumGreenBits + 211 | fbconfig->accumBlueBits + 212 | fbconfig->accumAlphaBits; 213 | 214 | setAttrib(NSOpenGLPFAAccumSize, accumBits); 215 | } 216 | } 217 | 218 | if (fbconfig->redBits != GLFW_DONT_CARE && 219 | fbconfig->greenBits != GLFW_DONT_CARE && 220 | fbconfig->blueBits != GLFW_DONT_CARE) 221 | { 222 | int colorBits = fbconfig->redBits + 223 | fbconfig->greenBits + 224 | fbconfig->blueBits; 225 | 226 | // macOS needs non-zero color size, so set reasonable values 227 | if (colorBits == 0) 228 | colorBits = 24; 229 | else if (colorBits < 15) 230 | colorBits = 15; 231 | 232 | setAttrib(NSOpenGLPFAColorSize, colorBits); 233 | } 234 | 235 | if (fbconfig->alphaBits != GLFW_DONT_CARE) 236 | setAttrib(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); 237 | 238 | if (fbconfig->depthBits != GLFW_DONT_CARE) 239 | setAttrib(NSOpenGLPFADepthSize, fbconfig->depthBits); 240 | 241 | if (fbconfig->stencilBits != GLFW_DONT_CARE) 242 | setAttrib(NSOpenGLPFAStencilSize, fbconfig->stencilBits); 243 | 244 | if (fbconfig->stereo) 245 | { 246 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 247 | _glfwInputError(GLFW_FORMAT_UNAVAILABLE, 248 | "NSGL: Stereo rendering is deprecated"); 249 | return GLFW_FALSE; 250 | #else 251 | addAttrib(NSOpenGLPFAStereo); 252 | #endif 253 | } 254 | 255 | if (fbconfig->doublebuffer) 256 | addAttrib(NSOpenGLPFADoubleBuffer); 257 | 258 | if (fbconfig->samples != GLFW_DONT_CARE) 259 | { 260 | if (fbconfig->samples == 0) 261 | { 262 | setAttrib(NSOpenGLPFASampleBuffers, 0); 263 | } 264 | else 265 | { 266 | setAttrib(NSOpenGLPFASampleBuffers, 1); 267 | setAttrib(NSOpenGLPFASamples, fbconfig->samples); 268 | } 269 | } 270 | 271 | // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB 272 | // framebuffer, so there's no need (and no way) to request it 273 | 274 | addAttrib(0); 275 | 276 | #undef addAttrib 277 | #undef setAttrib 278 | 279 | window->context.nsgl.pixelFormat = 280 | [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; 281 | if (window->context.nsgl.pixelFormat == nil) 282 | { 283 | _glfwInputError(GLFW_FORMAT_UNAVAILABLE, 284 | "NSGL: Failed to find a suitable pixel format"); 285 | return GLFW_FALSE; 286 | } 287 | 288 | NSOpenGLContext* share = NULL; 289 | 290 | if (ctxconfig->share) 291 | share = ctxconfig->share->context.nsgl.object; 292 | 293 | window->context.nsgl.object = 294 | [[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat 295 | shareContext:share]; 296 | if (window->context.nsgl.object == nil) 297 | { 298 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 299 | "NSGL: Failed to create OpenGL context"); 300 | return GLFW_FALSE; 301 | } 302 | 303 | if (fbconfig->transparent) 304 | { 305 | GLint opaque = 0; 306 | [window->context.nsgl.object setValues:&opaque 307 | forParameter:NSOpenGLContextParameterSurfaceOpacity]; 308 | } 309 | 310 | [window->context.nsgl.object setView:window->ns.view]; 311 | 312 | window->context.makeCurrent = makeContextCurrentNSGL; 313 | window->context.swapBuffers = swapBuffersNSGL; 314 | window->context.swapInterval = swapIntervalNSGL; 315 | window->context.extensionSupported = extensionSupportedNSGL; 316 | window->context.getProcAddress = getProcAddressNSGL; 317 | window->context.destroy = destroyContextNSGL; 318 | 319 | return GLFW_TRUE; 320 | } 321 | 322 | 323 | ////////////////////////////////////////////////////////////////////////// 324 | ////// GLFW native API ////// 325 | ////////////////////////////////////////////////////////////////////////// 326 | 327 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) 328 | { 329 | _GLFWwindow* window = (_GLFWwindow*) handle; 330 | _GLFW_REQUIRE_INIT_OR_RETURN(nil); 331 | 332 | if (window->context.client == GLFW_NO_API) 333 | { 334 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 335 | return NULL; 336 | } 337 | 338 | return window->context.nsgl.object; 339 | } 340 | 341 | -------------------------------------------------------------------------------- /extern/glfw/src/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW platform API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | int _glfwPlatformInit(void) 36 | { 37 | _glfwInitTimerPOSIX(); 38 | return GLFW_TRUE; 39 | } 40 | 41 | void _glfwPlatformTerminate(void) 42 | { 43 | _glfwTerminateOSMesa(); 44 | } 45 | 46 | const char* _glfwPlatformGetVersionString(void) 47 | { 48 | return _GLFW_VERSION_NUMBER " null OSMesa"; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /extern/glfw/src/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | 30 | ////////////////////////////////////////////////////////////////////////// 31 | ////// GLFW platform API ////// 32 | ////////////////////////////////////////////////////////////////////////// 33 | 34 | int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) 35 | { 36 | return GLFW_FALSE; 37 | } 38 | 39 | void _glfwPlatformUpdateGamepadGUID(char* guid) 40 | { 41 | } 42 | 43 | -------------------------------------------------------------------------------- /extern/glfw/src/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_JOYSTICK_STATE int nulljs 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE int nulljs 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "" 31 | 32 | -------------------------------------------------------------------------------- /extern/glfw/src/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW platform API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) 36 | { 37 | } 38 | 39 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 40 | { 41 | } 42 | 43 | void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, 44 | float* xscale, float* yscale) 45 | { 46 | if (xscale) 47 | *xscale = 1.f; 48 | if (yscale) 49 | *yscale = 1.f; 50 | } 51 | 52 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 53 | { 54 | return NULL; 55 | } 56 | 57 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 58 | { 59 | } 60 | 61 | GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 62 | { 63 | return GLFW_FALSE; 64 | } 65 | 66 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 67 | { 68 | } 69 | 70 | -------------------------------------------------------------------------------- /extern/glfw/src/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNull null 31 | 32 | #define _GLFW_PLATFORM_CONTEXT_STATE 33 | #define _GLFW_PLATFORM_MONITOR_STATE 34 | #define _GLFW_PLATFORM_CURSOR_STATE 35 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE 37 | #define _GLFW_EGL_CONTEXT_STATE 38 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE 39 | 40 | #include "osmesa_context.h" 41 | #include "posix_time.h" 42 | #include "posix_thread.h" 43 | #include "null_joystick.h" 44 | 45 | #if defined(_GLFW_WIN32) 46 | #define _glfw_dlopen(name) LoadLibraryA(name) 47 | #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle) 48 | #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name) 49 | #else 50 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 51 | #define _glfw_dlclose(handle) dlclose(handle) 52 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 53 | #endif 54 | 55 | // Null-specific per-window data 56 | // 57 | typedef struct _GLFWwindowNull 58 | { 59 | int width; 60 | int height; 61 | } _GLFWwindowNull; 62 | 63 | -------------------------------------------------------------------------------- /extern/glfw/src/null_window.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | static int createNativeWindow(_GLFWwindow* window, 32 | const _GLFWwndconfig* wndconfig) 33 | { 34 | window->null.width = wndconfig->width; 35 | window->null.height = wndconfig->height; 36 | 37 | return GLFW_TRUE; 38 | } 39 | 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | ////// GLFW platform API ////// 43 | ////////////////////////////////////////////////////////////////////////// 44 | 45 | int _glfwPlatformCreateWindow(_GLFWwindow* window, 46 | const _GLFWwndconfig* wndconfig, 47 | const _GLFWctxconfig* ctxconfig, 48 | const _GLFWfbconfig* fbconfig) 49 | { 50 | if (!createNativeWindow(window, wndconfig)) 51 | return GLFW_FALSE; 52 | 53 | if (ctxconfig->client != GLFW_NO_API) 54 | { 55 | if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API || 56 | ctxconfig->source == GLFW_OSMESA_CONTEXT_API) 57 | { 58 | if (!_glfwInitOSMesa()) 59 | return GLFW_FALSE; 60 | if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) 61 | return GLFW_FALSE; 62 | } 63 | else 64 | { 65 | _glfwInputError(GLFW_API_UNAVAILABLE, "Null: EGL not available"); 66 | return GLFW_FALSE; 67 | } 68 | } 69 | 70 | return GLFW_TRUE; 71 | } 72 | 73 | void _glfwPlatformDestroyWindow(_GLFWwindow* window) 74 | { 75 | if (window->context.destroy) 76 | window->context.destroy(window); 77 | } 78 | 79 | void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) 80 | { 81 | } 82 | 83 | void _glfwPlatformSetWindowIcon(_GLFWwindow* window, int count, 84 | const GLFWimage* images) 85 | { 86 | } 87 | 88 | void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, 89 | _GLFWmonitor* monitor, 90 | int xpos, int ypos, 91 | int width, int height, 92 | int refreshRate) 93 | { 94 | } 95 | 96 | void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos) 97 | { 98 | } 99 | 100 | void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos) 101 | { 102 | } 103 | 104 | void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) 105 | { 106 | if (width) 107 | *width = window->null.width; 108 | if (height) 109 | *height = window->null.height; 110 | } 111 | 112 | void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) 113 | { 114 | window->null.width = width; 115 | window->null.height = height; 116 | } 117 | 118 | void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, 119 | int minwidth, int minheight, 120 | int maxwidth, int maxheight) 121 | { 122 | } 123 | 124 | void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int n, int d) 125 | { 126 | } 127 | 128 | void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height) 129 | { 130 | if (width) 131 | *width = window->null.width; 132 | if (height) 133 | *height = window->null.height; 134 | } 135 | 136 | void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, 137 | int* left, int* top, 138 | int* right, int* bottom) 139 | { 140 | } 141 | 142 | void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, 143 | float* xscale, float* yscale) 144 | { 145 | if (xscale) 146 | *xscale = 1.f; 147 | if (yscale) 148 | *yscale = 1.f; 149 | } 150 | 151 | void _glfwPlatformIconifyWindow(_GLFWwindow* window) 152 | { 153 | } 154 | 155 | void _glfwPlatformRestoreWindow(_GLFWwindow* window) 156 | { 157 | } 158 | 159 | void _glfwPlatformMaximizeWindow(_GLFWwindow* window) 160 | { 161 | } 162 | 163 | int _glfwPlatformWindowMaximized(_GLFWwindow* window) 164 | { 165 | return GLFW_FALSE; 166 | } 167 | 168 | int _glfwPlatformWindowHovered(_GLFWwindow* window) 169 | { 170 | return GLFW_FALSE; 171 | } 172 | 173 | int _glfwPlatformFramebufferTransparent(_GLFWwindow* window) 174 | { 175 | return GLFW_FALSE; 176 | } 177 | 178 | void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) 179 | { 180 | } 181 | 182 | void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled) 183 | { 184 | } 185 | 186 | void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) 187 | { 188 | } 189 | 190 | float _glfwPlatformGetWindowOpacity(_GLFWwindow* window) 191 | { 192 | return 1.f; 193 | } 194 | 195 | void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity) 196 | { 197 | } 198 | 199 | void _glfwPlatformShowWindow(_GLFWwindow* window) 200 | { 201 | } 202 | 203 | 204 | void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) 205 | { 206 | } 207 | 208 | void _glfwPlatformUnhideWindow(_GLFWwindow* window) 209 | { 210 | } 211 | 212 | void _glfwPlatformHideWindow(_GLFWwindow* window) 213 | { 214 | } 215 | 216 | void _glfwPlatformFocusWindow(_GLFWwindow* window) 217 | { 218 | } 219 | 220 | int _glfwPlatformWindowFocused(_GLFWwindow* window) 221 | { 222 | return GLFW_FALSE; 223 | } 224 | 225 | int _glfwPlatformWindowIconified(_GLFWwindow* window) 226 | { 227 | return GLFW_FALSE; 228 | } 229 | 230 | int _glfwPlatformWindowVisible(_GLFWwindow* window) 231 | { 232 | return GLFW_FALSE; 233 | } 234 | 235 | void _glfwPlatformPollEvents(void) 236 | { 237 | } 238 | 239 | void _glfwPlatformWaitEvents(void) 240 | { 241 | } 242 | 243 | void _glfwPlatformWaitEventsTimeout(double timeout) 244 | { 245 | } 246 | 247 | void _glfwPlatformPostEmptyEvent(void) 248 | { 249 | } 250 | 251 | void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) 252 | { 253 | } 254 | 255 | void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) 256 | { 257 | } 258 | 259 | void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) 260 | { 261 | } 262 | 263 | int _glfwPlatformCreateCursor(_GLFWcursor* cursor, 264 | const GLFWimage* image, 265 | int xhot, int yhot) 266 | { 267 | return GLFW_TRUE; 268 | } 269 | 270 | int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) 271 | { 272 | return GLFW_TRUE; 273 | } 274 | 275 | void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) 276 | { 277 | } 278 | 279 | void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) 280 | { 281 | } 282 | 283 | void _glfwPlatformSetClipboardString(const char* string) 284 | { 285 | } 286 | 287 | const char* _glfwPlatformGetClipboardString(void) 288 | { 289 | return NULL; 290 | } 291 | 292 | const char* _glfwPlatformGetScancodeName(int scancode) 293 | { 294 | return ""; 295 | } 296 | 297 | int _glfwPlatformGetKeyScancode(int key) 298 | { 299 | return -1; 300 | } 301 | 302 | void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) 303 | { 304 | } 305 | 306 | int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, 307 | VkPhysicalDevice device, 308 | uint32_t queuefamily) 309 | { 310 | return GLFW_FALSE; 311 | } 312 | 313 | VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, 314 | _GLFWwindow* window, 315 | const VkAllocationCallbacks* allocator, 316 | VkSurfaceKHR* surface) 317 | { 318 | // This seems like the most appropriate error to return here 319 | return VK_ERROR_INITIALIZATION_FAILED; 320 | } 321 | 322 | -------------------------------------------------------------------------------- /extern/glfw/src/osmesa_context.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "internal.h" 33 | 34 | 35 | static void makeContextCurrentOSMesa(_GLFWwindow* window) 36 | { 37 | if (window) 38 | { 39 | int width, height; 40 | _glfwPlatformGetFramebufferSize(window, &width, &height); 41 | 42 | // Check to see if we need to allocate a new buffer 43 | if ((window->context.osmesa.buffer == NULL) || 44 | (width != window->context.osmesa.width) || 45 | (height != window->context.osmesa.height)) 46 | { 47 | free(window->context.osmesa.buffer); 48 | 49 | // Allocate the new buffer (width * height * 8-bit RGBA) 50 | window->context.osmesa.buffer = calloc(4, width * height); 51 | window->context.osmesa.width = width; 52 | window->context.osmesa.height = height; 53 | } 54 | 55 | if (!OSMesaMakeCurrent(window->context.osmesa.handle, 56 | window->context.osmesa.buffer, 57 | GL_UNSIGNED_BYTE, 58 | width, height)) 59 | { 60 | _glfwInputError(GLFW_PLATFORM_ERROR, 61 | "OSMesa: Failed to make context current"); 62 | return; 63 | } 64 | } 65 | 66 | _glfwPlatformSetTls(&_glfw.contextSlot, window); 67 | } 68 | 69 | static GLFWglproc getProcAddressOSMesa(const char* procname) 70 | { 71 | return (GLFWglproc) OSMesaGetProcAddress(procname); 72 | } 73 | 74 | static void destroyContextOSMesa(_GLFWwindow* window) 75 | { 76 | if (window->context.osmesa.handle) 77 | { 78 | OSMesaDestroyContext(window->context.osmesa.handle); 79 | window->context.osmesa.handle = NULL; 80 | } 81 | 82 | if (window->context.osmesa.buffer) 83 | { 84 | free(window->context.osmesa.buffer); 85 | window->context.osmesa.width = 0; 86 | window->context.osmesa.height = 0; 87 | } 88 | } 89 | 90 | static void swapBuffersOSMesa(_GLFWwindow* window) 91 | { 92 | // No double buffering on OSMesa 93 | } 94 | 95 | static void swapIntervalOSMesa(int interval) 96 | { 97 | // No swap interval on OSMesa 98 | } 99 | 100 | static int extensionSupportedOSMesa(const char* extension) 101 | { 102 | // OSMesa does not have extensions 103 | return GLFW_FALSE; 104 | } 105 | 106 | 107 | ////////////////////////////////////////////////////////////////////////// 108 | ////// GLFW internal API ////// 109 | ////////////////////////////////////////////////////////////////////////// 110 | 111 | GLFWbool _glfwInitOSMesa(void) 112 | { 113 | int i; 114 | const char* sonames[] = 115 | { 116 | #if defined(_GLFW_OSMESA_LIBRARY) 117 | _GLFW_OSMESA_LIBRARY, 118 | #elif defined(_WIN32) 119 | "libOSMesa.dll", 120 | "OSMesa.dll", 121 | #elif defined(__APPLE__) 122 | "libOSMesa.8.dylib", 123 | #elif defined(__CYGWIN__) 124 | "libOSMesa-8.so", 125 | #else 126 | "libOSMesa.so.8", 127 | "libOSMesa.so.6", 128 | #endif 129 | NULL 130 | }; 131 | 132 | if (_glfw.osmesa.handle) 133 | return GLFW_TRUE; 134 | 135 | for (i = 0; sonames[i]; i++) 136 | { 137 | _glfw.osmesa.handle = _glfw_dlopen(sonames[i]); 138 | if (_glfw.osmesa.handle) 139 | break; 140 | } 141 | 142 | if (!_glfw.osmesa.handle) 143 | { 144 | _glfwInputError(GLFW_API_UNAVAILABLE, "OSMesa: Library not found"); 145 | return GLFW_FALSE; 146 | } 147 | 148 | _glfw.osmesa.CreateContextExt = (PFN_OSMesaCreateContextExt) 149 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextExt"); 150 | _glfw.osmesa.CreateContextAttribs = (PFN_OSMesaCreateContextAttribs) 151 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextAttribs"); 152 | _glfw.osmesa.DestroyContext = (PFN_OSMesaDestroyContext) 153 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaDestroyContext"); 154 | _glfw.osmesa.MakeCurrent = (PFN_OSMesaMakeCurrent) 155 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaMakeCurrent"); 156 | _glfw.osmesa.GetColorBuffer = (PFN_OSMesaGetColorBuffer) 157 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetColorBuffer"); 158 | _glfw.osmesa.GetDepthBuffer = (PFN_OSMesaGetDepthBuffer) 159 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetDepthBuffer"); 160 | _glfw.osmesa.GetProcAddress = (PFN_OSMesaGetProcAddress) 161 | _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetProcAddress"); 162 | 163 | if (!_glfw.osmesa.CreateContextExt || 164 | !_glfw.osmesa.DestroyContext || 165 | !_glfw.osmesa.MakeCurrent || 166 | !_glfw.osmesa.GetColorBuffer || 167 | !_glfw.osmesa.GetDepthBuffer || 168 | !_glfw.osmesa.GetProcAddress) 169 | { 170 | _glfwInputError(GLFW_PLATFORM_ERROR, 171 | "OSMesa: Failed to load required entry points"); 172 | 173 | _glfwTerminateOSMesa(); 174 | return GLFW_FALSE; 175 | } 176 | 177 | return GLFW_TRUE; 178 | } 179 | 180 | void _glfwTerminateOSMesa(void) 181 | { 182 | if (_glfw.osmesa.handle) 183 | { 184 | _glfw_dlclose(_glfw.osmesa.handle); 185 | _glfw.osmesa.handle = NULL; 186 | } 187 | } 188 | 189 | #define setAttrib(a, v) \ 190 | { \ 191 | assert((size_t) (index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ 192 | attribs[index++] = a; \ 193 | attribs[index++] = v; \ 194 | } 195 | 196 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 197 | const _GLFWctxconfig* ctxconfig, 198 | const _GLFWfbconfig* fbconfig) 199 | { 200 | OSMesaContext share = NULL; 201 | const int accumBits = fbconfig->accumRedBits + 202 | fbconfig->accumGreenBits + 203 | fbconfig->accumBlueBits + 204 | fbconfig->accumAlphaBits; 205 | 206 | if (ctxconfig->client == GLFW_OPENGL_ES_API) 207 | { 208 | _glfwInputError(GLFW_API_UNAVAILABLE, 209 | "OSMesa: OpenGL ES is not available on OSMesa"); 210 | return GLFW_FALSE; 211 | } 212 | 213 | if (ctxconfig->share) 214 | share = ctxconfig->share->context.osmesa.handle; 215 | 216 | if (OSMesaCreateContextAttribs) 217 | { 218 | int index = 0, attribs[40]; 219 | 220 | setAttrib(OSMESA_FORMAT, OSMESA_RGBA); 221 | setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); 222 | setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); 223 | setAttrib(OSMESA_ACCUM_BITS, accumBits); 224 | 225 | if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) 226 | { 227 | setAttrib(OSMESA_PROFILE, OSMESA_CORE_PROFILE); 228 | } 229 | else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) 230 | { 231 | setAttrib(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); 232 | } 233 | 234 | if (ctxconfig->major != 1 || ctxconfig->minor != 0) 235 | { 236 | setAttrib(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); 237 | setAttrib(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); 238 | } 239 | 240 | if (ctxconfig->forward) 241 | { 242 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 243 | "OSMesa: Forward-compatible contexts not supported"); 244 | return GLFW_FALSE; 245 | } 246 | 247 | setAttrib(0, 0); 248 | 249 | window->context.osmesa.handle = 250 | OSMesaCreateContextAttribs(attribs, share); 251 | } 252 | else 253 | { 254 | if (ctxconfig->profile) 255 | { 256 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 257 | "OSMesa: OpenGL profiles unavailable"); 258 | return GLFW_FALSE; 259 | } 260 | 261 | window->context.osmesa.handle = 262 | OSMesaCreateContextExt(OSMESA_RGBA, 263 | fbconfig->depthBits, 264 | fbconfig->stencilBits, 265 | accumBits, 266 | share); 267 | } 268 | 269 | if (window->context.osmesa.handle == NULL) 270 | { 271 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 272 | "OSMesa: Failed to create context"); 273 | return GLFW_FALSE; 274 | } 275 | 276 | window->context.makeCurrent = makeContextCurrentOSMesa; 277 | window->context.swapBuffers = swapBuffersOSMesa; 278 | window->context.swapInterval = swapIntervalOSMesa; 279 | window->context.extensionSupported = extensionSupportedOSMesa; 280 | window->context.getProcAddress = getProcAddressOSMesa; 281 | window->context.destroy = destroyContextOSMesa; 282 | 283 | return GLFW_TRUE; 284 | } 285 | 286 | #undef setAttrib 287 | 288 | 289 | ////////////////////////////////////////////////////////////////////////// 290 | ////// GLFW native API ////// 291 | ////////////////////////////////////////////////////////////////////////// 292 | 293 | GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* handle, int* width, 294 | int* height, int* format, void** buffer) 295 | { 296 | void* mesaBuffer; 297 | GLint mesaWidth, mesaHeight, mesaFormat; 298 | _GLFWwindow* window = (_GLFWwindow*) handle; 299 | assert(window != NULL); 300 | 301 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 302 | 303 | if (!OSMesaGetColorBuffer(window->context.osmesa.handle, 304 | &mesaWidth, &mesaHeight, 305 | &mesaFormat, &mesaBuffer)) 306 | { 307 | _glfwInputError(GLFW_PLATFORM_ERROR, 308 | "OSMesa: Failed to retrieve color buffer"); 309 | return GLFW_FALSE; 310 | } 311 | 312 | if (width) 313 | *width = mesaWidth; 314 | if (height) 315 | *height = mesaHeight; 316 | if (format) 317 | *format = mesaFormat; 318 | if (buffer) 319 | *buffer = mesaBuffer; 320 | 321 | return GLFW_TRUE; 322 | } 323 | 324 | GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* handle, 325 | int* width, int* height, 326 | int* bytesPerValue, 327 | void** buffer) 328 | { 329 | void* mesaBuffer; 330 | GLint mesaWidth, mesaHeight, mesaBytes; 331 | _GLFWwindow* window = (_GLFWwindow*) handle; 332 | assert(window != NULL); 333 | 334 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 335 | 336 | if (!OSMesaGetDepthBuffer(window->context.osmesa.handle, 337 | &mesaWidth, &mesaHeight, 338 | &mesaBytes, &mesaBuffer)) 339 | { 340 | _glfwInputError(GLFW_PLATFORM_ERROR, 341 | "OSMesa: Failed to retrieve depth buffer"); 342 | return GLFW_FALSE; 343 | } 344 | 345 | if (width) 346 | *width = mesaWidth; 347 | if (height) 348 | *height = mesaHeight; 349 | if (bytesPerValue) 350 | *bytesPerValue = mesaBytes; 351 | if (buffer) 352 | *buffer = mesaBuffer; 353 | 354 | return GLFW_TRUE; 355 | } 356 | 357 | GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* handle) 358 | { 359 | _GLFWwindow* window = (_GLFWwindow*) handle; 360 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 361 | 362 | if (window->context.client == GLFW_NO_API) 363 | { 364 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 365 | return NULL; 366 | } 367 | 368 | return window->context.osmesa.handle; 369 | } 370 | 371 | -------------------------------------------------------------------------------- /extern/glfw/src/osmesa_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define OSMESA_RGBA 0x1908 29 | #define OSMESA_FORMAT 0x22 30 | #define OSMESA_DEPTH_BITS 0x30 31 | #define OSMESA_STENCIL_BITS 0x31 32 | #define OSMESA_ACCUM_BITS 0x32 33 | #define OSMESA_PROFILE 0x33 34 | #define OSMESA_CORE_PROFILE 0x34 35 | #define OSMESA_COMPAT_PROFILE 0x35 36 | #define OSMESA_CONTEXT_MAJOR_VERSION 0x36 37 | #define OSMESA_CONTEXT_MINOR_VERSION 0x37 38 | 39 | typedef void* OSMesaContext; 40 | typedef void (*OSMESAproc)(void); 41 | 42 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextExt)(GLenum,GLint,GLint,GLint,OSMesaContext); 43 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextAttribs)(const int*,OSMesaContext); 44 | typedef void (GLAPIENTRY * PFN_OSMesaDestroyContext)(OSMesaContext); 45 | typedef int (GLAPIENTRY * PFN_OSMesaMakeCurrent)(OSMesaContext,void*,int,int,int); 46 | typedef int (GLAPIENTRY * PFN_OSMesaGetColorBuffer)(OSMesaContext,int*,int*,int*,void**); 47 | typedef int (GLAPIENTRY * PFN_OSMesaGetDepthBuffer)(OSMesaContext,int*,int*,int*,void**); 48 | typedef GLFWglproc (GLAPIENTRY * PFN_OSMesaGetProcAddress)(const char*); 49 | #define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt 50 | #define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs 51 | #define OSMesaDestroyContext _glfw.osmesa.DestroyContext 52 | #define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent 53 | #define OSMesaGetColorBuffer _glfw.osmesa.GetColorBuffer 54 | #define OSMesaGetDepthBuffer _glfw.osmesa.GetDepthBuffer 55 | #define OSMesaGetProcAddress _glfw.osmesa.GetProcAddress 56 | 57 | #define _GLFW_OSMESA_CONTEXT_STATE _GLFWcontextOSMesa osmesa 58 | #define _GLFW_OSMESA_LIBRARY_CONTEXT_STATE _GLFWlibraryOSMesa osmesa 59 | 60 | 61 | // OSMesa-specific per-context data 62 | // 63 | typedef struct _GLFWcontextOSMesa 64 | { 65 | OSMesaContext handle; 66 | int width; 67 | int height; 68 | void* buffer; 69 | 70 | } _GLFWcontextOSMesa; 71 | 72 | // OSMesa-specific global data 73 | // 74 | typedef struct _GLFWlibraryOSMesa 75 | { 76 | void* handle; 77 | 78 | PFN_OSMesaCreateContextExt CreateContextExt; 79 | PFN_OSMesaCreateContextAttribs CreateContextAttribs; 80 | PFN_OSMesaDestroyContext DestroyContext; 81 | PFN_OSMesaMakeCurrent MakeCurrent; 82 | PFN_OSMesaGetColorBuffer GetColorBuffer; 83 | PFN_OSMesaGetDepthBuffer GetDepthBuffer; 84 | PFN_OSMesaGetProcAddress GetProcAddress; 85 | 86 | } _GLFWlibraryOSMesa; 87 | 88 | 89 | GLFWbool _glfwInitOSMesa(void); 90 | void _glfwTerminateOSMesa(void); 91 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 92 | const _GLFWctxconfig* ctxconfig, 93 | const _GLFWfbconfig* fbconfig); 94 | 95 | -------------------------------------------------------------------------------- /extern/glfw/src/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW platform API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 39 | { 40 | assert(tls->posix.allocated == GLFW_FALSE); 41 | 42 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 43 | { 44 | _glfwInputError(GLFW_PLATFORM_ERROR, 45 | "POSIX: Failed to create context TLS"); 46 | return GLFW_FALSE; 47 | } 48 | 49 | tls->posix.allocated = GLFW_TRUE; 50 | return GLFW_TRUE; 51 | } 52 | 53 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 54 | { 55 | if (tls->posix.allocated) 56 | pthread_key_delete(tls->posix.key); 57 | memset(tls, 0, sizeof(_GLFWtls)); 58 | } 59 | 60 | void* _glfwPlatformGetTls(_GLFWtls* tls) 61 | { 62 | assert(tls->posix.allocated == GLFW_TRUE); 63 | return pthread_getspecific(tls->posix.key); 64 | } 65 | 66 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 67 | { 68 | assert(tls->posix.allocated == GLFW_TRUE); 69 | pthread_setspecific(tls->posix.key, value); 70 | } 71 | 72 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 73 | { 74 | assert(mutex->posix.allocated == GLFW_FALSE); 75 | 76 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 77 | { 78 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 79 | return GLFW_FALSE; 80 | } 81 | 82 | return mutex->posix.allocated = GLFW_TRUE; 83 | } 84 | 85 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 86 | { 87 | if (mutex->posix.allocated) 88 | pthread_mutex_destroy(&mutex->posix.handle); 89 | memset(mutex, 0, sizeof(_GLFWmutex)); 90 | } 91 | 92 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 93 | { 94 | assert(mutex->posix.allocated == GLFW_TRUE); 95 | pthread_mutex_lock(&mutex->posix.handle); 96 | } 97 | 98 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 99 | { 100 | assert(mutex->posix.allocated == GLFW_TRUE); 101 | pthread_mutex_unlock(&mutex->posix.handle); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /extern/glfw/src/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define _GLFW_PLATFORM_TLS_STATE _GLFWtlsPOSIX posix 31 | #define _GLFW_PLATFORM_MUTEX_STATE _GLFWmutexPOSIX posix 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | 41 | } _GLFWtlsPOSIX; 42 | 43 | // POSIX-specific mutex data 44 | // 45 | typedef struct _GLFWmutexPOSIX 46 | { 47 | GLFWbool allocated; 48 | pthread_mutex_t handle; 49 | 50 | } _GLFWmutexPOSIX; 51 | 52 | -------------------------------------------------------------------------------- /extern/glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimerPOSIX(void) 41 | { 42 | #if defined(CLOCK_MONOTONIC) 43 | struct timespec ts; 44 | 45 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 46 | { 47 | _glfw.timer.posix.monotonic = GLFW_TRUE; 48 | _glfw.timer.posix.frequency = 1000000000; 49 | } 50 | else 51 | #endif 52 | { 53 | _glfw.timer.posix.monotonic = GLFW_FALSE; 54 | _glfw.timer.posix.frequency = 1000000; 55 | } 56 | } 57 | 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | ////// GLFW platform API ////// 61 | ////////////////////////////////////////////////////////////////////////// 62 | 63 | uint64_t _glfwPlatformGetTimerValue(void) 64 | { 65 | #if defined(CLOCK_MONOTONIC) 66 | if (_glfw.timer.posix.monotonic) 67 | { 68 | struct timespec ts; 69 | clock_gettime(CLOCK_MONOTONIC, &ts); 70 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 71 | } 72 | else 73 | #endif 74 | { 75 | struct timeval tv; 76 | gettimeofday(&tv, NULL); 77 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 78 | } 79 | } 80 | 81 | uint64_t _glfwPlatformGetTimerFrequency(void) 82 | { 83 | return _glfw.timer.posix.frequency; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /extern/glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix 29 | 30 | #include 31 | 32 | 33 | // POSIX-specific global timer data 34 | // 35 | typedef struct _GLFWtimerPOSIX 36 | { 37 | GLFWbool monotonic; 38 | uint64_t frequency; 39 | 40 | } _GLFWtimerPOSIX; 41 | 42 | 43 | void _glfwInitTimerPOSIX(void); 44 | 45 | -------------------------------------------------------------------------------- /extern/glfw/src/vulkan.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define _GLFW_FIND_LOADER 1 35 | #define _GLFW_REQUIRE_LOADER 2 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW internal API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | GLFWbool _glfwInitVulkan(int mode) 43 | { 44 | VkResult err; 45 | VkExtensionProperties* ep; 46 | uint32_t i, count; 47 | 48 | if (_glfw.vk.available) 49 | return GLFW_TRUE; 50 | 51 | #if !defined(_GLFW_VULKAN_STATIC) 52 | #if defined(_GLFW_VULKAN_LIBRARY) 53 | _glfw.vk.handle = _glfw_dlopen(_GLFW_VULKAN_LIBRARY); 54 | #elif defined(_GLFW_WIN32) 55 | _glfw.vk.handle = _glfw_dlopen("vulkan-1.dll"); 56 | #elif defined(_GLFW_COCOA) 57 | _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib"); 58 | #else 59 | _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1"); 60 | #endif 61 | if (!_glfw.vk.handle) 62 | { 63 | if (mode == _GLFW_REQUIRE_LOADER) 64 | _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found"); 65 | 66 | return GLFW_FALSE; 67 | } 68 | 69 | _glfw.vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) 70 | _glfw_dlsym(_glfw.vk.handle, "vkGetInstanceProcAddr"); 71 | if (!_glfw.vk.GetInstanceProcAddr) 72 | { 73 | _glfwInputError(GLFW_API_UNAVAILABLE, 74 | "Vulkan: Loader does not export vkGetInstanceProcAddr"); 75 | 76 | _glfwTerminateVulkan(); 77 | return GLFW_FALSE; 78 | } 79 | 80 | _glfw.vk.EnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties) 81 | vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties"); 82 | if (!_glfw.vk.EnumerateInstanceExtensionProperties) 83 | { 84 | _glfwInputError(GLFW_API_UNAVAILABLE, 85 | "Vulkan: Failed to retrieve vkEnumerateInstanceExtensionProperties"); 86 | 87 | _glfwTerminateVulkan(); 88 | return GLFW_FALSE; 89 | } 90 | #endif // _GLFW_VULKAN_STATIC 91 | 92 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); 93 | if (err) 94 | { 95 | // NOTE: This happens on systems with a loader but without any Vulkan ICD 96 | if (mode == _GLFW_REQUIRE_LOADER) 97 | { 98 | _glfwInputError(GLFW_API_UNAVAILABLE, 99 | "Vulkan: Failed to query instance extension count: %s", 100 | _glfwGetVulkanResultString(err)); 101 | } 102 | 103 | _glfwTerminateVulkan(); 104 | return GLFW_FALSE; 105 | } 106 | 107 | ep = calloc(count, sizeof(VkExtensionProperties)); 108 | 109 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep); 110 | if (err) 111 | { 112 | _glfwInputError(GLFW_API_UNAVAILABLE, 113 | "Vulkan: Failed to query instance extensions: %s", 114 | _glfwGetVulkanResultString(err)); 115 | 116 | free(ep); 117 | _glfwTerminateVulkan(); 118 | return GLFW_FALSE; 119 | } 120 | 121 | for (i = 0; i < count; i++) 122 | { 123 | if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0) 124 | _glfw.vk.KHR_surface = GLFW_TRUE; 125 | #if defined(_GLFW_WIN32) 126 | else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0) 127 | _glfw.vk.KHR_win32_surface = GLFW_TRUE; 128 | #elif defined(_GLFW_COCOA) 129 | else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0) 130 | _glfw.vk.MVK_macos_surface = GLFW_TRUE; 131 | #elif defined(_GLFW_X11) 132 | else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0) 133 | _glfw.vk.KHR_xlib_surface = GLFW_TRUE; 134 | else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0) 135 | _glfw.vk.KHR_xcb_surface = GLFW_TRUE; 136 | #elif defined(_GLFW_WAYLAND) 137 | else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0) 138 | _glfw.vk.KHR_wayland_surface = GLFW_TRUE; 139 | #endif 140 | } 141 | 142 | free(ep); 143 | 144 | _glfw.vk.available = GLFW_TRUE; 145 | 146 | _glfwPlatformGetRequiredInstanceExtensions(_glfw.vk.extensions); 147 | 148 | return GLFW_TRUE; 149 | } 150 | 151 | void _glfwTerminateVulkan(void) 152 | { 153 | #if !defined(_GLFW_VULKAN_STATIC) 154 | if (_glfw.vk.handle) 155 | _glfw_dlclose(_glfw.vk.handle); 156 | #endif 157 | } 158 | 159 | const char* _glfwGetVulkanResultString(VkResult result) 160 | { 161 | switch (result) 162 | { 163 | case VK_SUCCESS: 164 | return "Success"; 165 | case VK_NOT_READY: 166 | return "A fence or query has not yet completed"; 167 | case VK_TIMEOUT: 168 | return "A wait operation has not completed in the specified time"; 169 | case VK_EVENT_SET: 170 | return "An event is signaled"; 171 | case VK_EVENT_RESET: 172 | return "An event is unsignaled"; 173 | case VK_INCOMPLETE: 174 | return "A return array was too small for the result"; 175 | case VK_ERROR_OUT_OF_HOST_MEMORY: 176 | return "A host memory allocation has failed"; 177 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: 178 | return "A device memory allocation has failed"; 179 | case VK_ERROR_INITIALIZATION_FAILED: 180 | return "Initialization of an object could not be completed for implementation-specific reasons"; 181 | case VK_ERROR_DEVICE_LOST: 182 | return "The logical or physical device has been lost"; 183 | case VK_ERROR_MEMORY_MAP_FAILED: 184 | return "Mapping of a memory object has failed"; 185 | case VK_ERROR_LAYER_NOT_PRESENT: 186 | return "A requested layer is not present or could not be loaded"; 187 | case VK_ERROR_EXTENSION_NOT_PRESENT: 188 | return "A requested extension is not supported"; 189 | case VK_ERROR_FEATURE_NOT_PRESENT: 190 | return "A requested feature is not supported"; 191 | case VK_ERROR_INCOMPATIBLE_DRIVER: 192 | return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible"; 193 | case VK_ERROR_TOO_MANY_OBJECTS: 194 | return "Too many objects of the type have already been created"; 195 | case VK_ERROR_FORMAT_NOT_SUPPORTED: 196 | return "A requested format is not supported on this device"; 197 | case VK_ERROR_SURFACE_LOST_KHR: 198 | return "A surface is no longer available"; 199 | case VK_SUBOPTIMAL_KHR: 200 | return "A swapchain no longer matches the surface properties exactly, but can still be used"; 201 | case VK_ERROR_OUT_OF_DATE_KHR: 202 | return "A surface has changed in such a way that it is no longer compatible with the swapchain"; 203 | case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: 204 | return "The display used by a swapchain does not use the same presentable image layout"; 205 | case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: 206 | return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API"; 207 | case VK_ERROR_VALIDATION_FAILED_EXT: 208 | return "A validation layer found an error"; 209 | default: 210 | return "ERROR: UNKNOWN VULKAN ERROR"; 211 | } 212 | } 213 | 214 | 215 | ////////////////////////////////////////////////////////////////////////// 216 | ////// GLFW public API ////// 217 | ////////////////////////////////////////////////////////////////////////// 218 | 219 | GLFWAPI int glfwVulkanSupported(void) 220 | { 221 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 222 | return _glfwInitVulkan(_GLFW_FIND_LOADER); 223 | } 224 | 225 | GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) 226 | { 227 | assert(count != NULL); 228 | 229 | *count = 0; 230 | 231 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 232 | 233 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 234 | return NULL; 235 | 236 | if (!_glfw.vk.extensions[0]) 237 | return NULL; 238 | 239 | *count = 2; 240 | return (const char**) _glfw.vk.extensions; 241 | } 242 | 243 | GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, 244 | const char* procname) 245 | { 246 | GLFWvkproc proc; 247 | assert(procname != NULL); 248 | 249 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 250 | 251 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 252 | return NULL; 253 | 254 | proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname); 255 | #if defined(_GLFW_VULKAN_STATIC) 256 | if (!proc) 257 | { 258 | if (strcmp(procname, "vkGetInstanceProcAddr") == 0) 259 | return (GLFWvkproc) vkGetInstanceProcAddr; 260 | } 261 | #else 262 | if (!proc) 263 | proc = (GLFWvkproc) _glfw_dlsym(_glfw.vk.handle, procname); 264 | #endif 265 | 266 | return proc; 267 | } 268 | 269 | GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, 270 | VkPhysicalDevice device, 271 | uint32_t queuefamily) 272 | { 273 | assert(instance != VK_NULL_HANDLE); 274 | assert(device != VK_NULL_HANDLE); 275 | 276 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 277 | 278 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 279 | return GLFW_FALSE; 280 | 281 | if (!_glfw.vk.extensions[0]) 282 | { 283 | _glfwInputError(GLFW_API_UNAVAILABLE, 284 | "Vulkan: Window surface creation extensions not found"); 285 | return GLFW_FALSE; 286 | } 287 | 288 | return _glfwPlatformGetPhysicalDevicePresentationSupport(instance, 289 | device, 290 | queuefamily); 291 | } 292 | 293 | GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, 294 | GLFWwindow* handle, 295 | const VkAllocationCallbacks* allocator, 296 | VkSurfaceKHR* surface) 297 | { 298 | _GLFWwindow* window = (_GLFWwindow*) handle; 299 | assert(instance != VK_NULL_HANDLE); 300 | assert(window != NULL); 301 | assert(surface != NULL); 302 | 303 | *surface = VK_NULL_HANDLE; 304 | 305 | _GLFW_REQUIRE_INIT_OR_RETURN(VK_ERROR_INITIALIZATION_FAILED); 306 | 307 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 308 | return VK_ERROR_INITIALIZATION_FAILED; 309 | 310 | if (!_glfw.vk.extensions[0]) 311 | { 312 | _glfwInputError(GLFW_API_UNAVAILABLE, 313 | "Vulkan: Window surface creation extensions not found"); 314 | return VK_ERROR_EXTENSION_NOT_PRESENT; 315 | } 316 | 317 | if (window->context.client != GLFW_NO_API) 318 | { 319 | _glfwInputError(GLFW_INVALID_VALUE, 320 | "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API"); 321 | return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; 322 | } 323 | 324 | return _glfwPlatformCreateWindowSurface(instance, window, allocator, surface); 325 | } 326 | 327 | -------------------------------------------------------------------------------- /extern/glfw/src/wgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 WGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 29 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 30 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 31 | #define WGL_PIXEL_TYPE_ARB 0x2013 32 | #define WGL_TYPE_RGBA_ARB 0x202b 33 | #define WGL_ACCELERATION_ARB 0x2003 34 | #define WGL_NO_ACCELERATION_ARB 0x2025 35 | #define WGL_RED_BITS_ARB 0x2015 36 | #define WGL_RED_SHIFT_ARB 0x2016 37 | #define WGL_GREEN_BITS_ARB 0x2017 38 | #define WGL_GREEN_SHIFT_ARB 0x2018 39 | #define WGL_BLUE_BITS_ARB 0x2019 40 | #define WGL_BLUE_SHIFT_ARB 0x201a 41 | #define WGL_ALPHA_BITS_ARB 0x201b 42 | #define WGL_ALPHA_SHIFT_ARB 0x201c 43 | #define WGL_ACCUM_BITS_ARB 0x201d 44 | #define WGL_ACCUM_RED_BITS_ARB 0x201e 45 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201f 46 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 47 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 48 | #define WGL_DEPTH_BITS_ARB 0x2022 49 | #define WGL_STENCIL_BITS_ARB 0x2023 50 | #define WGL_AUX_BUFFERS_ARB 0x2024 51 | #define WGL_STEREO_ARB 0x2012 52 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 53 | #define WGL_SAMPLES_ARB 0x2042 54 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9 55 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 56 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 57 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 58 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 59 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 60 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 61 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 62 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 63 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 64 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 65 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 66 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 67 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 68 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 69 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 70 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 71 | #define WGL_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3 72 | #define WGL_COLORSPACE_EXT 0x309d 73 | #define WGL_COLORSPACE_SRGB_EXT 0x3089 74 | 75 | #define ERROR_INVALID_VERSION_ARB 0x2095 76 | #define ERROR_INVALID_PROFILE_ARB 0x2096 77 | #define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 78 | 79 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int); 80 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC,int,int,UINT,const int*,int*); 81 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); 82 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC); 83 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC,HGLRC,const int*); 84 | 85 | typedef HGLRC (WINAPI * PFN_wglCreateContext)(HDC); 86 | typedef BOOL (WINAPI * PFN_wglDeleteContext)(HGLRC); 87 | typedef PROC (WINAPI * PFN_wglGetProcAddress)(LPCSTR); 88 | typedef HDC (WINAPI * PFN_wglGetCurrentDC)(void); 89 | typedef HGLRC (WINAPI * PFN_wglGetCurrentContext)(void); 90 | typedef BOOL (WINAPI * PFN_wglMakeCurrent)(HDC,HGLRC); 91 | typedef BOOL (WINAPI * PFN_wglShareLists)(HGLRC,HGLRC); 92 | 93 | // opengl32.dll function pointer typedefs 94 | #define wglCreateContext _glfw.wgl.CreateContext 95 | #define wglDeleteContext _glfw.wgl.DeleteContext 96 | #define wglGetProcAddress _glfw.wgl.GetProcAddress 97 | #define wglGetCurrentDC _glfw.wgl.GetCurrentDC 98 | #define wglGetCurrentContext _glfw.wgl.GetCurrentContext 99 | #define wglMakeCurrent _glfw.wgl.MakeCurrent 100 | #define wglShareLists _glfw.wgl.ShareLists 101 | 102 | #define _GLFW_RECREATION_NOT_NEEDED 0 103 | #define _GLFW_RECREATION_REQUIRED 1 104 | #define _GLFW_RECREATION_IMPOSSIBLE 2 105 | 106 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 107 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl 108 | 109 | 110 | // WGL-specific per-context data 111 | // 112 | typedef struct _GLFWcontextWGL 113 | { 114 | HDC dc; 115 | HGLRC handle; 116 | int interval; 117 | 118 | } _GLFWcontextWGL; 119 | 120 | // WGL-specific global data 121 | // 122 | typedef struct _GLFWlibraryWGL 123 | { 124 | HINSTANCE instance; 125 | PFN_wglCreateContext CreateContext; 126 | PFN_wglDeleteContext DeleteContext; 127 | PFN_wglGetProcAddress GetProcAddress; 128 | PFN_wglGetCurrentDC GetCurrentDC; 129 | PFN_wglGetCurrentContext GetCurrentContext; 130 | PFN_wglMakeCurrent MakeCurrent; 131 | PFN_wglShareLists ShareLists; 132 | 133 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 134 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 135 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 136 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 137 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 138 | GLFWbool EXT_swap_control; 139 | GLFWbool EXT_colorspace; 140 | GLFWbool ARB_multisample; 141 | GLFWbool ARB_framebuffer_sRGB; 142 | GLFWbool EXT_framebuffer_sRGB; 143 | GLFWbool ARB_pixel_format; 144 | GLFWbool ARB_create_context; 145 | GLFWbool ARB_create_context_profile; 146 | GLFWbool EXT_create_context_es2_profile; 147 | GLFWbool ARB_create_context_robustness; 148 | GLFWbool ARB_create_context_no_error; 149 | GLFWbool ARB_context_flush_control; 150 | 151 | } _GLFWlibraryWGL; 152 | 153 | 154 | GLFWbool _glfwInitWGL(void); 155 | void _glfwTerminateWGL(void); 156 | GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, 157 | const _GLFWctxconfig* ctxconfig, 158 | const _GLFWfbconfig* fbconfig); 159 | 160 | -------------------------------------------------------------------------------- /extern/glfw/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE int dummy 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "Windows" 31 | 32 | // Joystick element (axis, button or slider) 33 | // 34 | typedef struct _GLFWjoyobjectWin32 35 | { 36 | int offset; 37 | int type; 38 | } _GLFWjoyobjectWin32; 39 | 40 | // Win32-specific per-joystick data 41 | // 42 | typedef struct _GLFWjoystickWin32 43 | { 44 | _GLFWjoyobjectWin32* objects; 45 | int objectCount; 46 | IDirectInputDevice8W* device; 47 | DWORD index; 48 | GUID guid; 49 | } _GLFWjoystickWin32; 50 | 51 | 52 | void _glfwInitJoysticksWin32(void); 53 | void _glfwTerminateJoysticksWin32(void); 54 | void _glfwDetectJoystickConnectionWin32(void); 55 | void _glfwDetectJoystickDisconnectionWin32(void); 56 | 57 | -------------------------------------------------------------------------------- /extern/glfw/src/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 38 | { 39 | assert(tls->win32.allocated == GLFW_FALSE); 40 | 41 | tls->win32.index = TlsAlloc(); 42 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 43 | { 44 | _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, 45 | "Win32: Failed to allocate TLS index"); 46 | return GLFW_FALSE; 47 | } 48 | 49 | tls->win32.allocated = GLFW_TRUE; 50 | return GLFW_TRUE; 51 | } 52 | 53 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 54 | { 55 | if (tls->win32.allocated) 56 | TlsFree(tls->win32.index); 57 | memset(tls, 0, sizeof(_GLFWtls)); 58 | } 59 | 60 | void* _glfwPlatformGetTls(_GLFWtls* tls) 61 | { 62 | assert(tls->win32.allocated == GLFW_TRUE); 63 | return TlsGetValue(tls->win32.index); 64 | } 65 | 66 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 67 | { 68 | assert(tls->win32.allocated == GLFW_TRUE); 69 | TlsSetValue(tls->win32.index, value); 70 | } 71 | 72 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 73 | { 74 | assert(mutex->win32.allocated == GLFW_FALSE); 75 | InitializeCriticalSection(&mutex->win32.section); 76 | return mutex->win32.allocated = GLFW_TRUE; 77 | } 78 | 79 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 80 | { 81 | if (mutex->win32.allocated) 82 | DeleteCriticalSection(&mutex->win32.section); 83 | memset(mutex, 0, sizeof(_GLFWmutex)); 84 | } 85 | 86 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 87 | { 88 | assert(mutex->win32.allocated == GLFW_TRUE); 89 | EnterCriticalSection(&mutex->win32.section); 90 | } 91 | 92 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 93 | { 94 | assert(mutex->win32.allocated == GLFW_TRUE); 95 | LeaveCriticalSection(&mutex->win32.section); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /extern/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW internal API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | // Initialise timer 36 | // 37 | void _glfwInitTimerWin32(void) 38 | { 39 | uint64_t frequency; 40 | 41 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 42 | { 43 | _glfw.timer.win32.hasPC = GLFW_TRUE; 44 | _glfw.timer.win32.frequency = frequency; 45 | } 46 | else 47 | { 48 | _glfw.timer.win32.hasPC = GLFW_FALSE; 49 | _glfw.timer.win32.frequency = 1000; 50 | } 51 | } 52 | 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | ////// GLFW platform API ////// 56 | ////////////////////////////////////////////////////////////////////////// 57 | 58 | uint64_t _glfwPlatformGetTimerValue(void) 59 | { 60 | if (_glfw.timer.win32.hasPC) 61 | { 62 | uint64_t value; 63 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 64 | return value; 65 | } 66 | else 67 | return (uint64_t) timeGetTime(); 68 | } 69 | 70 | uint64_t _glfwPlatformGetTimerFrequency(void) 71 | { 72 | return _glfw.timer.win32.frequency; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /extern/glfw/src/wl_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Wayland - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | static void outputHandleGeometry(void* data, 36 | struct wl_output* output, 37 | int32_t x, 38 | int32_t y, 39 | int32_t physicalWidth, 40 | int32_t physicalHeight, 41 | int32_t subpixel, 42 | const char* make, 43 | const char* model, 44 | int32_t transform) 45 | { 46 | struct _GLFWmonitor *monitor = data; 47 | char name[1024]; 48 | 49 | monitor->wl.x = x; 50 | monitor->wl.y = y; 51 | monitor->widthMM = physicalWidth; 52 | monitor->heightMM = physicalHeight; 53 | 54 | snprintf(name, sizeof(name), "%s %s", make, model); 55 | monitor->name = _glfw_strdup(name); 56 | } 57 | 58 | static void outputHandleMode(void* data, 59 | struct wl_output* output, 60 | uint32_t flags, 61 | int32_t width, 62 | int32_t height, 63 | int32_t refresh) 64 | { 65 | struct _GLFWmonitor *monitor = data; 66 | GLFWvidmode mode; 67 | 68 | mode.width = width; 69 | mode.height = height; 70 | mode.redBits = 8; 71 | mode.greenBits = 8; 72 | mode.blueBits = 8; 73 | mode.refreshRate = refresh / 1000; 74 | 75 | monitor->modeCount++; 76 | monitor->modes = 77 | realloc(monitor->modes, monitor->modeCount * sizeof(GLFWvidmode)); 78 | monitor->modes[monitor->modeCount - 1] = mode; 79 | 80 | if (flags & WL_OUTPUT_MODE_CURRENT) 81 | monitor->wl.currentMode = monitor->modeCount - 1; 82 | } 83 | 84 | static void outputHandleDone(void* data, struct wl_output* output) 85 | { 86 | struct _GLFWmonitor *monitor = data; 87 | 88 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); 89 | } 90 | 91 | static void outputHandleScale(void* data, 92 | struct wl_output* output, 93 | int32_t factor) 94 | { 95 | struct _GLFWmonitor *monitor = data; 96 | 97 | monitor->wl.scale = factor; 98 | } 99 | 100 | static const struct wl_output_listener outputListener = { 101 | outputHandleGeometry, 102 | outputHandleMode, 103 | outputHandleDone, 104 | outputHandleScale, 105 | }; 106 | 107 | 108 | ////////////////////////////////////////////////////////////////////////// 109 | ////// GLFW internal API ////// 110 | ////////////////////////////////////////////////////////////////////////// 111 | 112 | void _glfwAddOutputWayland(uint32_t name, uint32_t version) 113 | { 114 | _GLFWmonitor *monitor; 115 | struct wl_output *output; 116 | 117 | if (version < 2) 118 | { 119 | _glfwInputError(GLFW_PLATFORM_ERROR, 120 | "Wayland: Unsupported output interface version"); 121 | return; 122 | } 123 | 124 | // The actual name of this output will be set in the geometry handler. 125 | monitor = _glfwAllocMonitor(NULL, 0, 0); 126 | 127 | output = wl_registry_bind(_glfw.wl.registry, 128 | name, 129 | &wl_output_interface, 130 | 2); 131 | if (!output) 132 | { 133 | _glfwFreeMonitor(monitor); 134 | return; 135 | } 136 | 137 | monitor->wl.scale = 1; 138 | monitor->wl.output = output; 139 | monitor->wl.name = name; 140 | 141 | wl_output_add_listener(output, &outputListener, monitor); 142 | } 143 | 144 | 145 | ////////////////////////////////////////////////////////////////////////// 146 | ////// GLFW platform API ////// 147 | ////////////////////////////////////////////////////////////////////////// 148 | 149 | void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) 150 | { 151 | if (monitor->wl.output) 152 | wl_output_destroy(monitor->wl.output); 153 | } 154 | 155 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 156 | { 157 | if (xpos) 158 | *xpos = monitor->wl.x; 159 | if (ypos) 160 | *ypos = monitor->wl.y; 161 | } 162 | 163 | void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, 164 | float* xscale, float* yscale) 165 | { 166 | if (xscale) 167 | *xscale = (float) monitor->wl.scale; 168 | if (yscale) 169 | *yscale = (float) monitor->wl.scale; 170 | } 171 | 172 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 173 | { 174 | *found = monitor->modeCount; 175 | return monitor->modes; 176 | } 177 | 178 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 179 | { 180 | *mode = monitor->modes[monitor->wl.currentMode]; 181 | } 182 | 183 | GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 184 | { 185 | _glfwInputError(GLFW_PLATFORM_ERROR, 186 | "Wayland: Gamma ramp access it not available"); 187 | return GLFW_FALSE; 188 | } 189 | 190 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, 191 | const GLFWgammaramp* ramp) 192 | { 193 | _glfwInputError(GLFW_PLATFORM_ERROR, 194 | "Wayland: Gamma ramp access is not available"); 195 | } 196 | 197 | 198 | ////////////////////////////////////////////////////////////////////////// 199 | ////// GLFW native API ////// 200 | ////////////////////////////////////////////////////////////////////////// 201 | 202 | GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle) 203 | { 204 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 205 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 206 | return monitor->wl.output; 207 | } 208 | 209 | -------------------------------------------------------------------------------- /extern/glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | long _glfwKeySym2Unicode(unsigned int keysym); 28 | 29 | -------------------------------------------------------------------------------- /extern/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(imgui CXX) 2 | 3 | # dear imgui 4 | set(IMGUI_SOURCE_FILES 5 | imgui.cpp 6 | imgui_draw.cpp 7 | imgui_widgets.cpp) 8 | 9 | set(IMGUI_HEADER_FILES 10 | imconfig.h 11 | imgui.h 12 | imgui_internal.h 13 | imstb_rectpack.h 14 | imstb_textedit.h 15 | imstb_truetype.h) 16 | 17 | add_library(imgui STATIC ${IMGUI_SOURCE_FILES} ${IMGUI_HEADER_FILES}) 18 | target_include_directories(imgui PUBLIC ..) 19 | -------------------------------------------------------------------------------- /extern/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h) 7 | // B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h" 8 | // If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include 9 | // the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures. 10 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 11 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | //---- Define assertion handler. Defaults to calling assert(). 17 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 18 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 19 | 20 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. 21 | //#define IMGUI_API __declspec( dllexport ) 22 | //#define IMGUI_API __declspec( dllimport ) 23 | 24 | //---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 25 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 26 | 27 | //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) 28 | //---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. 29 | //#define IMGUI_DISABLE_DEMO_WINDOWS 30 | 31 | //---- Don't implement some functions to reduce linkage requirements. 32 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. 33 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. 34 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function. 35 | //#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf. 36 | //#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h. 37 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 38 | 39 | //---- Include imgui_user.h at the end of imgui.h as a convenience 40 | //#define IMGUI_INCLUDE_IMGUI_USER_H 41 | 42 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 43 | //#define IMGUI_USE_BGRA_PACKED_COLOR 44 | 45 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 46 | // By default the embedded implementations are declared static and not available outside of imgui cpp files. 47 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 48 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 49 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 50 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 51 | 52 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 53 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 54 | /* 55 | #define IM_VEC2_CLASS_EXTRA \ 56 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 57 | operator MyVec2() const { return MyVec2(x,y); } 58 | 59 | #define IM_VEC4_CLASS_EXTRA \ 60 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 61 | operator MyVec4() const { return MyVec4(x,y,z,w); } 62 | */ 63 | 64 | //---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it. 65 | //#define ImDrawIdx unsigned int 66 | 67 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 68 | /* 69 | namespace ImGui 70 | { 71 | void MyFunction(const char* name, const MyMatrix44& v); 72 | } 73 | */ 74 | -------------------------------------------------------------------------------- /include/box2d-lite/Arbiter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #ifndef ARBITER_H 13 | #define ARBITER_H 14 | 15 | #include "MathUtils.h" 16 | 17 | struct Body; 18 | 19 | union FeaturePair 20 | { 21 | struct Edges 22 | { 23 | char inEdge1; 24 | char outEdge1; 25 | char inEdge2; 26 | char outEdge2; 27 | } e; 28 | int value; 29 | }; 30 | 31 | struct Contact 32 | { 33 | Contact() : Pn(0.0f), Pt(0.0f), Pnb(0.0f) {} 34 | 35 | Vec2 position; 36 | Vec2 normal; 37 | Vec2 r1, r2; 38 | float separation; 39 | float Pn; // accumulated normal impulse 40 | float Pt; // accumulated tangent impulse 41 | float Pnb; // accumulated normal impulse for position bias 42 | float massNormal, massTangent; 43 | float bias; 44 | FeaturePair feature; 45 | }; 46 | 47 | struct ArbiterKey 48 | { 49 | ArbiterKey(Body* b1, Body* b2) 50 | { 51 | if (b1 < b2) 52 | { 53 | body1 = b1; body2 = b2; 54 | } 55 | else 56 | { 57 | body1 = b2; body2 = b1; 58 | } 59 | } 60 | 61 | Body* body1; 62 | Body* body2; 63 | }; 64 | 65 | struct Arbiter 66 | { 67 | enum {MAX_POINTS = 2}; 68 | 69 | Arbiter(Body* b1, Body* b2); 70 | 71 | void Update(Contact* contacts, int numContacts); 72 | 73 | void PreStep(float inv_dt); 74 | void ApplyImpulse(); 75 | 76 | Contact contacts[MAX_POINTS]; 77 | int numContacts; 78 | 79 | Body* body1; 80 | Body* body2; 81 | 82 | // Combined friction 83 | float friction; 84 | }; 85 | 86 | // This is used by std::set 87 | inline bool operator < (const ArbiterKey& a1, const ArbiterKey& a2) 88 | { 89 | if (a1.body1 < a2.body1) 90 | return true; 91 | 92 | if (a1.body1 == a2.body1 && a1.body2 < a2.body2) 93 | return true; 94 | 95 | return false; 96 | } 97 | 98 | int Collide(Contact* contacts, Body* body1, Body* body2); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /include/box2d-lite/Body.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #ifndef BODY_H 13 | #define BODY_H 14 | 15 | #include "MathUtils.h" 16 | 17 | struct Body 18 | { 19 | Body(); 20 | void Set(const Vec2& w, float m); 21 | 22 | void AddForce(const Vec2& f) 23 | { 24 | force += f; 25 | } 26 | 27 | Vec2 position; 28 | float rotation; 29 | 30 | Vec2 velocity; 31 | float angularVelocity; 32 | 33 | Vec2 force; 34 | float torque; 35 | 36 | Vec2 width; 37 | 38 | float friction; 39 | float mass, invMass; 40 | float I, invI; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/box2d-lite/Joint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #ifndef JOINT_H 13 | #define JOINT_H 14 | 15 | #include "MathUtils.h" 16 | 17 | struct Body; 18 | 19 | struct Joint 20 | { 21 | Joint() : 22 | body1(0), body2(0), 23 | P(0.0f, 0.0f), 24 | biasFactor(0.2f), softness(0.0f) 25 | {} 26 | 27 | void Set(Body* body1, Body* body2, const Vec2& anchor); 28 | 29 | void PreStep(float inv_dt); 30 | void ApplyImpulse(); 31 | 32 | Mat22 M; 33 | Vec2 localAnchor1, localAnchor2; 34 | Vec2 r1, r2; 35 | Vec2 bias; 36 | Vec2 P; // accumulated impulse 37 | Body* body1; 38 | Body* body2; 39 | float biasFactor; 40 | float softness; 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /include/box2d-lite/MathUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #ifndef MATHUTILS_H 13 | #define MATHUTILS_H 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | const float k_pi = 3.14159265358979323846264f; 21 | 22 | struct Vec2 23 | { 24 | Vec2() {} 25 | Vec2(float x, float y) : x(x), y(y) {} 26 | 27 | void Set(float x_, float y_) { x = x_; y = y_; } 28 | 29 | Vec2 operator -() { return Vec2(-x, -y); } 30 | 31 | void operator += (const Vec2& v) 32 | { 33 | x += v.x; y += v.y; 34 | } 35 | 36 | void operator -= (const Vec2& v) 37 | { 38 | x -= v.x; y -= v.y; 39 | } 40 | 41 | void operator *= (float a) 42 | { 43 | x *= a; y *= a; 44 | } 45 | 46 | float Length() const 47 | { 48 | return sqrtf(x * x + y * y); 49 | } 50 | 51 | float x, y; 52 | }; 53 | 54 | struct Mat22 55 | { 56 | Mat22() {} 57 | Mat22(float angle) 58 | { 59 | float c = cosf(angle), s = sinf(angle); 60 | col1.x = c; col2.x = -s; 61 | col1.y = s; col2.y = c; 62 | } 63 | 64 | Mat22(const Vec2& col1, const Vec2& col2) : col1(col1), col2(col2) {} 65 | 66 | Mat22 Transpose() const 67 | { 68 | return Mat22(Vec2(col1.x, col2.x), Vec2(col1.y, col2.y)); 69 | } 70 | 71 | Mat22 Invert() const 72 | { 73 | float a = col1.x, b = col2.x, c = col1.y, d = col2.y; 74 | Mat22 B; 75 | float det = a * d - b * c; 76 | assert(det != 0.0f); 77 | det = 1.0f / det; 78 | B.col1.x = det * d; B.col2.x = -det * b; 79 | B.col1.y = -det * c; B.col2.y = det * a; 80 | return B; 81 | } 82 | 83 | Vec2 col1, col2; 84 | }; 85 | 86 | inline float Dot(const Vec2& a, const Vec2& b) 87 | { 88 | return a.x * b.x + a.y * b.y; 89 | } 90 | 91 | inline float Cross(const Vec2& a, const Vec2& b) 92 | { 93 | return a.x * b.y - a.y * b.x; 94 | } 95 | 96 | inline Vec2 Cross(const Vec2& a, float s) 97 | { 98 | return Vec2(s * a.y, -s * a.x); 99 | } 100 | 101 | inline Vec2 Cross(float s, const Vec2& a) 102 | { 103 | return Vec2(-s * a.y, s * a.x); 104 | } 105 | 106 | inline Vec2 operator * (const Mat22& A, const Vec2& v) 107 | { 108 | return Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y); 109 | } 110 | 111 | inline Vec2 operator + (const Vec2& a, const Vec2& b) 112 | { 113 | return Vec2(a.x + b.x, a.y + b.y); 114 | } 115 | 116 | inline Vec2 operator - (const Vec2& a, const Vec2& b) 117 | { 118 | return Vec2(a.x - b.x, a.y - b.y); 119 | } 120 | 121 | inline Vec2 operator * (float s, const Vec2& v) 122 | { 123 | return Vec2(s * v.x, s * v.y); 124 | } 125 | 126 | inline Mat22 operator + (const Mat22& A, const Mat22& B) 127 | { 128 | return Mat22(A.col1 + B.col1, A.col2 + B.col2); 129 | } 130 | 131 | inline Mat22 operator * (const Mat22& A, const Mat22& B) 132 | { 133 | return Mat22(A * B.col1, A * B.col2); 134 | } 135 | 136 | inline float Abs(float a) 137 | { 138 | return a > 0.0f ? a : -a; 139 | } 140 | 141 | inline Vec2 Abs(const Vec2& a) 142 | { 143 | return Vec2(fabsf(a.x), fabsf(a.y)); 144 | } 145 | 146 | inline Mat22 Abs(const Mat22& A) 147 | { 148 | return Mat22(Abs(A.col1), Abs(A.col2)); 149 | } 150 | 151 | inline float Sign(float x) 152 | { 153 | return x < 0.0f ? -1.0f : 1.0f; 154 | } 155 | 156 | inline float Min(float a, float b) 157 | { 158 | return a < b ? a : b; 159 | } 160 | 161 | inline float Max(float a, float b) 162 | { 163 | return a > b ? a : b; 164 | } 165 | 166 | inline float Clamp(float a, float low, float high) 167 | { 168 | return Max(low, Min(a, high)); 169 | } 170 | 171 | template inline void Swap(T& a, T& b) 172 | { 173 | T tmp = a; 174 | a = b; 175 | b = tmp; 176 | } 177 | 178 | // Random number in range [-1,1] 179 | inline float Random() 180 | { 181 | float r = (float)rand(); 182 | r /= RAND_MAX; 183 | r = 2.0f * r - 1.0f; 184 | return r; 185 | } 186 | 187 | inline float Random(float lo, float hi) 188 | { 189 | float r = (float)rand(); 190 | r /= RAND_MAX; 191 | r = (hi - lo) * r + lo; 192 | return r; 193 | } 194 | 195 | #endif 196 | 197 | -------------------------------------------------------------------------------- /include/box2d-lite/World.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #ifndef WORLD_H 13 | #define WORLD_H 14 | 15 | #include 16 | #include 17 | #include "MathUtils.h" 18 | #include "Arbiter.h" 19 | 20 | struct Body; 21 | struct Joint; 22 | 23 | struct World 24 | { 25 | World(Vec2 gravity, int iterations) : gravity(gravity), iterations(iterations) {} 26 | 27 | void Add(Body* body); 28 | void Add(Joint* joint); 29 | void Clear(); 30 | 31 | void Step(float dt); 32 | 33 | void BroadPhase(); 34 | 35 | std::vector bodies; 36 | std::vector joints; 37 | std::map arbiters; 38 | Vec2 gravity; 39 | int iterations; 40 | static bool accumulateImpulses; 41 | static bool warmStarting; 42 | static bool positionCorrection; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(samples LANGUAGES CXX) 2 | 3 | set (SAMPLE_SOURCE_FILES 4 | imgui_impl_glfw.cpp 5 | imgui_impl_opengl2.cpp 6 | main.cpp) 7 | 8 | set (SAMPLE_HEADER_FILES 9 | imgui_impl_glfw.h 10 | imgui_impl_opengl2.h) 11 | 12 | add_executable(samples ${SAMPLE_SOURCE_FILES} ${SAMPLE_HEADER_FILES}) 13 | target_include_directories(samples PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 14 | target_link_libraries(samples PUBLIC box2d-lite glfw imgui glad ${OPENGL_LIBRARIES}) 15 | -------------------------------------------------------------------------------- /samples/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 8 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. 9 | // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). 10 | 11 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 12 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 13 | // https://github.com/ocornut/imgui 14 | 15 | // About GLSL version: 16 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 17 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 18 | 19 | #pragma once 20 | 21 | struct GLFWwindow; 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 24 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 25 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 27 | 28 | // InitXXX function with 'install_callbacks=true': install GLFW callbacks. They will call user's previously installed callbacks, if any. 29 | // InitXXX function with 'install_callbacks=false': do not install GLFW callbacks. You will need to call them yourself from your own GLFW callbacks. 30 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 31 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 32 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 33 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 34 | -------------------------------------------------------------------------------- /samples/imgui_impl_opengl2.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for OpenGL2 (legacy OpenGL, fixed pipeline) 2 | // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 6 | 7 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 8 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 9 | // https://github.com/ocornut/imgui 10 | 11 | // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** 12 | // **Prefer using the code in imgui_impl_opengl3.cpp** 13 | // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. 14 | // If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more 15 | // complicated, will require your code to reset every single OpenGL attributes to their initial state, and might 16 | // confuse your GPU driver. 17 | // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. 18 | 19 | // CHANGELOG 20 | // (minor and older changes stripped away, please see git history for details) 21 | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. 22 | // 2018-08-03: OpenGL: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications. 23 | // 2018-06-08: Misc: Extracted imgui_impl_opengl2.cpp/.h away from the old combined GLFW/SDL+OpenGL2 examples. 24 | // 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. 25 | // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplGlfwGL2_RenderDrawData() in the .h file so you can call it yourself. 26 | // 2017-09-01: OpenGL: Save and restore current polygon mode. 27 | // 2016-09-10: OpenGL: Uploading font texture as RGBA32 to increase compatibility with users shaders (not ideal). 28 | // 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle. 29 | 30 | #include "imgui/imgui.h" 31 | #include "imgui_impl_opengl2.h" 32 | #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier 33 | #include // intptr_t 34 | #else 35 | #include // intptr_t 36 | #endif 37 | 38 | // Include OpenGL header (without an OpenGL loader) requires a bit of fiddling 39 | #if defined(_WIN32) && !defined(APIENTRY) 40 | #define APIENTRY __stdcall // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms. Additionally, the Windows OpenGL header needs APIENTRY. 41 | #endif 42 | #if defined(_WIN32) && !defined(WINGDIAPI) 43 | #define WINGDIAPI __declspec(dllimport) // Some Windows OpenGL headers need this 44 | #endif 45 | 46 | #if defined(__APPLE__) 47 | // #include 48 | #include "glad/glad.h" 49 | #else 50 | // #include 51 | #include "glad/glad.h" 52 | #endif 53 | 54 | // OpenGL Data 55 | static GLuint g_FontTexture = 0; 56 | 57 | // Functions 58 | bool ImGui_ImplOpenGL2_Init() 59 | { 60 | ImGuiIO& io = ImGui::GetIO(); 61 | io.BackendRendererName = "imgui_impl_opengl2"; 62 | return true; 63 | } 64 | 65 | void ImGui_ImplOpenGL2_Shutdown() 66 | { 67 | ImGui_ImplOpenGL2_DestroyDeviceObjects(); 68 | } 69 | 70 | void ImGui_ImplOpenGL2_NewFrame() 71 | { 72 | if (!g_FontTexture) 73 | ImGui_ImplOpenGL2_CreateDeviceObjects(); 74 | } 75 | 76 | // OpenGL2 Render function. 77 | // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop) 78 | // Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so. 79 | void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data) 80 | { 81 | // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) 82 | ImGuiIO& io = ImGui::GetIO(); 83 | int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x); 84 | int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y); 85 | if (fb_width == 0 || fb_height == 0) 86 | return; 87 | draw_data->ScaleClipRects(io.DisplayFramebufferScale); 88 | 89 | // We are using the OpenGL fixed pipeline to make the example code simpler to read! 90 | // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill. 91 | GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); 92 | GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); 93 | GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); 94 | GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); 95 | glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); 96 | glEnable(GL_BLEND); 97 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 98 | glDisable(GL_CULL_FACE); 99 | glDisable(GL_DEPTH_TEST); 100 | glDisable(GL_LIGHTING); 101 | glDisable(GL_COLOR_MATERIAL); 102 | glEnable(GL_SCISSOR_TEST); 103 | glEnableClientState(GL_VERTEX_ARRAY); 104 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); 105 | glEnableClientState(GL_COLOR_ARRAY); 106 | glEnable(GL_TEXTURE_2D); 107 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 108 | //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound 109 | 110 | // Setup viewport, orthographic projection matrix 111 | // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps. 112 | glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); 113 | glMatrixMode(GL_PROJECTION); 114 | glPushMatrix(); 115 | glLoadIdentity(); 116 | glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f); 117 | glMatrixMode(GL_MODELVIEW); 118 | glPushMatrix(); 119 | glLoadIdentity(); 120 | 121 | // Render command lists 122 | ImVec2 pos = draw_data->DisplayPos; 123 | for (int n = 0; n < draw_data->CmdListsCount; n++) 124 | { 125 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 126 | const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; 127 | const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; 128 | glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos))); 129 | glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv))); 130 | glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col))); 131 | 132 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) 133 | { 134 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; 135 | if (pcmd->UserCallback) 136 | { 137 | // User callback (registered via ImDrawList::AddCallback) 138 | pcmd->UserCallback(cmd_list, pcmd); 139 | } 140 | else 141 | { 142 | ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y); 143 | if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) 144 | { 145 | // Apply scissor/clipping rectangle 146 | glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y)); 147 | 148 | // Bind texture, Draw 149 | glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); 150 | glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer); 151 | } 152 | } 153 | idx_buffer += pcmd->ElemCount; 154 | } 155 | } 156 | 157 | // Restore modified state 158 | glDisableClientState(GL_COLOR_ARRAY); 159 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); 160 | glDisableClientState(GL_VERTEX_ARRAY); 161 | glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture); 162 | glMatrixMode(GL_MODELVIEW); 163 | glPopMatrix(); 164 | glMatrixMode(GL_PROJECTION); 165 | glPopMatrix(); 166 | glPopAttrib(); 167 | glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); 168 | glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); 169 | glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); 170 | } 171 | 172 | bool ImGui_ImplOpenGL2_CreateFontsTexture() 173 | { 174 | // Build texture atlas 175 | ImGuiIO& io = ImGui::GetIO(); 176 | unsigned char* pixels; 177 | int width, height; 178 | io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. 179 | 180 | // Upload texture to graphics system 181 | GLint last_texture; 182 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); 183 | glGenTextures(1, &g_FontTexture); 184 | glBindTexture(GL_TEXTURE_2D, g_FontTexture); 185 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 186 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 187 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 188 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 189 | 190 | // Store our identifier 191 | io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture; 192 | 193 | // Restore state 194 | glBindTexture(GL_TEXTURE_2D, last_texture); 195 | 196 | return true; 197 | } 198 | 199 | void ImGui_ImplOpenGL2_DestroyFontsTexture() 200 | { 201 | if (g_FontTexture) 202 | { 203 | ImGuiIO& io = ImGui::GetIO(); 204 | glDeleteTextures(1, &g_FontTexture); 205 | io.Fonts->TexID = 0; 206 | g_FontTexture = 0; 207 | } 208 | } 209 | 210 | bool ImGui_ImplOpenGL2_CreateDeviceObjects() 211 | { 212 | return ImGui_ImplOpenGL2_CreateFontsTexture(); 213 | } 214 | 215 | void ImGui_ImplOpenGL2_DestroyDeviceObjects() 216 | { 217 | ImGui_ImplOpenGL2_DestroyFontsTexture(); 218 | } 219 | -------------------------------------------------------------------------------- /samples/imgui_impl_opengl2.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for OpenGL2 (legacy OpenGL, fixed pipeline) 2 | // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 6 | 7 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 8 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 9 | // https://github.com/ocornut/imgui 10 | 11 | // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** 12 | // **Prefer using the code in imgui_impl_opengl3.cpp** 13 | // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. 14 | // If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more 15 | // complicated, will require your code to reset every single OpenGL attributes to their initial state, and might 16 | // confuse your GPU driver. 17 | // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. 18 | 19 | #pragma once 20 | 21 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init(); 22 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown(); 23 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame(); 24 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data); 25 | 26 | // Called by Init/NewFrame/Shutdown 27 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateFontsTexture(); 28 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyFontsTexture(); 29 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects(); 30 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects(); 31 | -------------------------------------------------------------------------------- /src/Arbiter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #include "box2d-lite/Arbiter.h" 13 | #include "box2d-lite/Body.h" 14 | #include "box2d-lite/World.h" 15 | 16 | Arbiter::Arbiter(Body* b1, Body* b2) 17 | { 18 | if (b1 < b2) 19 | { 20 | body1 = b1; 21 | body2 = b2; 22 | } 23 | else 24 | { 25 | body1 = b2; 26 | body2 = b1; 27 | } 28 | 29 | numContacts = Collide(contacts, body1, body2); 30 | 31 | friction = sqrtf(body1->friction * body2->friction); 32 | } 33 | 34 | void Arbiter::Update(Contact* newContacts, int numNewContacts) 35 | { 36 | Contact mergedContacts[2]; 37 | 38 | for (int i = 0; i < numNewContacts; ++i) 39 | { 40 | Contact* cNew = newContacts + i; 41 | int k = -1; 42 | for (int j = 0; j < numContacts; ++j) 43 | { 44 | Contact* cOld = contacts + j; 45 | if (cNew->feature.value == cOld->feature.value) 46 | { 47 | k = j; 48 | break; 49 | } 50 | } 51 | 52 | if (k > -1) 53 | { 54 | Contact* c = mergedContacts + i; 55 | Contact* cOld = contacts + k; 56 | *c = *cNew; 57 | if (World::warmStarting) 58 | { 59 | c->Pn = cOld->Pn; 60 | c->Pt = cOld->Pt; 61 | c->Pnb = cOld->Pnb; 62 | } 63 | else 64 | { 65 | c->Pn = 0.0f; 66 | c->Pt = 0.0f; 67 | c->Pnb = 0.0f; 68 | } 69 | } 70 | else 71 | { 72 | mergedContacts[i] = newContacts[i]; 73 | } 74 | } 75 | 76 | for (int i = 0; i < numNewContacts; ++i) 77 | contacts[i] = mergedContacts[i]; 78 | 79 | numContacts = numNewContacts; 80 | } 81 | 82 | 83 | void Arbiter::PreStep(float inv_dt) 84 | { 85 | const float k_allowedPenetration = 0.01f; 86 | float k_biasFactor = World::positionCorrection ? 0.2f : 0.0f; 87 | 88 | for (int i = 0; i < numContacts; ++i) 89 | { 90 | Contact* c = contacts + i; 91 | 92 | Vec2 r1 = c->position - body1->position; 93 | Vec2 r2 = c->position - body2->position; 94 | 95 | // Precompute normal mass, tangent mass, and bias. 96 | float rn1 = Dot(r1, c->normal); 97 | float rn2 = Dot(r2, c->normal); 98 | float kNormal = body1->invMass + body2->invMass; 99 | kNormal += body1->invI * (Dot(r1, r1) - rn1 * rn1) + body2->invI * (Dot(r2, r2) - rn2 * rn2); 100 | c->massNormal = 1.0f / kNormal; 101 | 102 | Vec2 tangent = Cross(c->normal, 1.0f); 103 | float rt1 = Dot(r1, tangent); 104 | float rt2 = Dot(r2, tangent); 105 | float kTangent = body1->invMass + body2->invMass; 106 | kTangent += body1->invI * (Dot(r1, r1) - rt1 * rt1) + body2->invI * (Dot(r2, r2) - rt2 * rt2); 107 | c->massTangent = 1.0f / kTangent; 108 | 109 | c->bias = -k_biasFactor * inv_dt * Min(0.0f, c->separation + k_allowedPenetration); 110 | 111 | if (World::accumulateImpulses) 112 | { 113 | // Apply normal + friction impulse 114 | Vec2 P = c->Pn * c->normal + c->Pt * tangent; 115 | 116 | body1->velocity -= body1->invMass * P; 117 | body1->angularVelocity -= body1->invI * Cross(r1, P); 118 | 119 | body2->velocity += body2->invMass * P; 120 | body2->angularVelocity += body2->invI * Cross(r2, P); 121 | } 122 | } 123 | } 124 | 125 | void Arbiter::ApplyImpulse() 126 | { 127 | Body* b1 = body1; 128 | Body* b2 = body2; 129 | 130 | for (int i = 0; i < numContacts; ++i) 131 | { 132 | Contact* c = contacts + i; 133 | c->r1 = c->position - b1->position; 134 | c->r2 = c->position - b2->position; 135 | 136 | // Relative velocity at contact 137 | Vec2 dv = b2->velocity + Cross(b2->angularVelocity, c->r2) - b1->velocity - Cross(b1->angularVelocity, c->r1); 138 | 139 | // Compute normal impulse 140 | float vn = Dot(dv, c->normal); 141 | 142 | float dPn = c->massNormal * (-vn + c->bias); 143 | 144 | if (World::accumulateImpulses) 145 | { 146 | // Clamp the accumulated impulse 147 | float Pn0 = c->Pn; 148 | c->Pn = Max(Pn0 + dPn, 0.0f); 149 | dPn = c->Pn - Pn0; 150 | } 151 | else 152 | { 153 | dPn = Max(dPn, 0.0f); 154 | } 155 | 156 | // Apply contact impulse 157 | Vec2 Pn = dPn * c->normal; 158 | 159 | b1->velocity -= b1->invMass * Pn; 160 | b1->angularVelocity -= b1->invI * Cross(c->r1, Pn); 161 | 162 | b2->velocity += b2->invMass * Pn; 163 | b2->angularVelocity += b2->invI * Cross(c->r2, Pn); 164 | 165 | // Relative velocity at contact 166 | dv = b2->velocity + Cross(b2->angularVelocity, c->r2) - b1->velocity - Cross(b1->angularVelocity, c->r1); 167 | 168 | Vec2 tangent = Cross(c->normal, 1.0f); 169 | float vt = Dot(dv, tangent); 170 | float dPt = c->massTangent * (-vt); 171 | 172 | if (World::accumulateImpulses) 173 | { 174 | // Compute friction impulse 175 | float maxPt = friction * c->Pn; 176 | 177 | // Clamp friction 178 | float oldTangentImpulse = c->Pt; 179 | c->Pt = Clamp(oldTangentImpulse + dPt, -maxPt, maxPt); 180 | dPt = c->Pt - oldTangentImpulse; 181 | } 182 | else 183 | { 184 | float maxPt = friction * dPn; 185 | dPt = Clamp(dPt, -maxPt, maxPt); 186 | } 187 | 188 | // Apply contact impulse 189 | Vec2 Pt = dPt * tangent; 190 | 191 | b1->velocity -= b1->invMass * Pt; 192 | b1->angularVelocity -= b1->invI * Cross(c->r1, Pt); 193 | 194 | b2->velocity += b2->invMass * Pt; 195 | b2->angularVelocity += b2->invI * Cross(c->r2, Pt); 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /src/Body.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #include "box2d-lite/Body.h" 13 | 14 | Body::Body() 15 | { 16 | position.Set(0.0f, 0.0f); 17 | rotation = 0.0f; 18 | velocity.Set(0.0f, 0.0f); 19 | angularVelocity = 0.0f; 20 | force.Set(0.0f, 0.0f); 21 | torque = 0.0f; 22 | friction = 0.2f; 23 | 24 | width.Set(1.0f, 1.0f); 25 | mass = FLT_MAX; 26 | invMass = 0.0f; 27 | I = FLT_MAX; 28 | invI = 0.0f; 29 | } 30 | 31 | void Body::Set(const Vec2& w, float m) 32 | { 33 | position.Set(0.0f, 0.0f); 34 | rotation = 0.0f; 35 | velocity.Set(0.0f, 0.0f); 36 | angularVelocity = 0.0f; 37 | force.Set(0.0f, 0.0f); 38 | torque = 0.0f; 39 | friction = 0.2f; 40 | 41 | width = w; 42 | mass = m; 43 | 44 | if (mass < FLT_MAX) 45 | { 46 | invMass = 1.0f / mass; 47 | I = mass * (width.x * width.x + width.y * width.y) / 12.0f; 48 | invI = 1.0f / I; 49 | } 50 | else 51 | { 52 | invMass = 0.0f; 53 | I = FLT_MAX; 54 | invI = 0.0f; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(BOX2D_SOURCE_FILES 2 | Arbiter.cpp 3 | Body.cpp 4 | Collide.cpp 5 | Joint.cpp 6 | World.cpp) 7 | 8 | set(BOX2D_HEADER_FILES 9 | ../include/box2d-lite/Arbiter.h 10 | ../include/box2d-lite/Body.h 11 | ../include/box2d-lite/Joint.h 12 | ../include/box2d-lite/MathUtils.h 13 | ../include/box2d-lite/World.h) 14 | 15 | add_library(box2d-lite STATIC ${BOX2D_SOURCE_FILES} ${BOX2D_HEADER_FILES}) 16 | target_include_directories(box2d-lite PUBLIC ../include) -------------------------------------------------------------------------------- /src/Collide.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #include "box2d-lite/Arbiter.h" 13 | #include "box2d-lite/Body.h" 14 | 15 | // Box vertex and edge numbering: 16 | // 17 | // ^ y 18 | // | 19 | // e1 20 | // v2 ------ v1 21 | // | | 22 | // e2 | | e4 --> x 23 | // | | 24 | // v3 ------ v4 25 | // e3 26 | 27 | enum Axis 28 | { 29 | FACE_A_X, 30 | FACE_A_Y, 31 | FACE_B_X, 32 | FACE_B_Y 33 | }; 34 | 35 | enum EdgeNumbers 36 | { 37 | NO_EDGE = 0, 38 | EDGE1, 39 | EDGE2, 40 | EDGE3, 41 | EDGE4 42 | }; 43 | 44 | struct ClipVertex 45 | { 46 | ClipVertex() { fp.value = 0; } 47 | Vec2 v; 48 | FeaturePair fp; 49 | }; 50 | 51 | void Flip(FeaturePair& fp) 52 | { 53 | Swap(fp.e.inEdge1, fp.e.inEdge2); 54 | Swap(fp.e.outEdge1, fp.e.outEdge2); 55 | } 56 | 57 | int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2], 58 | const Vec2& normal, float offset, char clipEdge) 59 | { 60 | // Start with no output points 61 | int numOut = 0; 62 | 63 | // Calculate the distance of end points to the line 64 | float distance0 = Dot(normal, vIn[0].v) - offset; 65 | float distance1 = Dot(normal, vIn[1].v) - offset; 66 | 67 | // If the points are behind the plane 68 | if (distance0 <= 0.0f) vOut[numOut++] = vIn[0]; 69 | if (distance1 <= 0.0f) vOut[numOut++] = vIn[1]; 70 | 71 | // If the points are on different sides of the plane 72 | if (distance0 * distance1 < 0.0f) 73 | { 74 | // Find intersection point of edge and plane 75 | float interp = distance0 / (distance0 - distance1); 76 | vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v); 77 | if (distance0 > 0.0f) 78 | { 79 | vOut[numOut].fp = vIn[0].fp; 80 | vOut[numOut].fp.e.inEdge1 = clipEdge; 81 | vOut[numOut].fp.e.inEdge2 = NO_EDGE; 82 | } 83 | else 84 | { 85 | vOut[numOut].fp = vIn[1].fp; 86 | vOut[numOut].fp.e.outEdge1 = clipEdge; 87 | vOut[numOut].fp.e.outEdge2 = NO_EDGE; 88 | } 89 | ++numOut; 90 | } 91 | 92 | return numOut; 93 | } 94 | 95 | static void ComputeIncidentEdge(ClipVertex c[2], const Vec2& h, const Vec2& pos, 96 | const Mat22& Rot, const Vec2& normal) 97 | { 98 | // The normal is from the reference box. Convert it 99 | // to the incident boxe's frame and flip sign. 100 | Mat22 RotT = Rot.Transpose(); 101 | Vec2 n = -(RotT * normal); 102 | Vec2 nAbs = Abs(n); 103 | 104 | if (nAbs.x > nAbs.y) 105 | { 106 | if (Sign(n.x) > 0.0f) 107 | { 108 | c[0].v.Set(h.x, -h.y); 109 | c[0].fp.e.inEdge2 = EDGE3; 110 | c[0].fp.e.outEdge2 = EDGE4; 111 | 112 | c[1].v.Set(h.x, h.y); 113 | c[1].fp.e.inEdge2 = EDGE4; 114 | c[1].fp.e.outEdge2 = EDGE1; 115 | } 116 | else 117 | { 118 | c[0].v.Set(-h.x, h.y); 119 | c[0].fp.e.inEdge2 = EDGE1; 120 | c[0].fp.e.outEdge2 = EDGE2; 121 | 122 | c[1].v.Set(-h.x, -h.y); 123 | c[1].fp.e.inEdge2 = EDGE2; 124 | c[1].fp.e.outEdge2 = EDGE3; 125 | } 126 | } 127 | else 128 | { 129 | if (Sign(n.y) > 0.0f) 130 | { 131 | c[0].v.Set(h.x, h.y); 132 | c[0].fp.e.inEdge2 = EDGE4; 133 | c[0].fp.e.outEdge2 = EDGE1; 134 | 135 | c[1].v.Set(-h.x, h.y); 136 | c[1].fp.e.inEdge2 = EDGE1; 137 | c[1].fp.e.outEdge2 = EDGE2; 138 | } 139 | else 140 | { 141 | c[0].v.Set(-h.x, -h.y); 142 | c[0].fp.e.inEdge2 = EDGE2; 143 | c[0].fp.e.outEdge2 = EDGE3; 144 | 145 | c[1].v.Set(h.x, -h.y); 146 | c[1].fp.e.inEdge2 = EDGE3; 147 | c[1].fp.e.outEdge2 = EDGE4; 148 | } 149 | } 150 | 151 | c[0].v = pos + Rot * c[0].v; 152 | c[1].v = pos + Rot * c[1].v; 153 | } 154 | 155 | // The normal points from A to B 156 | int Collide(Contact* contacts, Body* bodyA, Body* bodyB) 157 | { 158 | // Setup 159 | Vec2 hA = 0.5f * bodyA->width; 160 | Vec2 hB = 0.5f * bodyB->width; 161 | 162 | Vec2 posA = bodyA->position; 163 | Vec2 posB = bodyB->position; 164 | 165 | Mat22 RotA(bodyA->rotation), RotB(bodyB->rotation); 166 | 167 | Mat22 RotAT = RotA.Transpose(); 168 | Mat22 RotBT = RotB.Transpose(); 169 | 170 | Vec2 dp = posB - posA; 171 | Vec2 dA = RotAT * dp; 172 | Vec2 dB = RotBT * dp; 173 | 174 | Mat22 C = RotAT * RotB; 175 | Mat22 absC = Abs(C); 176 | Mat22 absCT = absC.Transpose(); 177 | 178 | // Box A faces 179 | Vec2 faceA = Abs(dA) - hA - absC * hB; 180 | if (faceA.x > 0.0f || faceA.y > 0.0f) 181 | return 0; 182 | 183 | // Box B faces 184 | Vec2 faceB = Abs(dB) - absCT * hA - hB; 185 | if (faceB.x > 0.0f || faceB.y > 0.0f) 186 | return 0; 187 | 188 | // Find best axis 189 | Axis axis; 190 | float separation; 191 | Vec2 normal; 192 | 193 | // Box A faces 194 | axis = FACE_A_X; 195 | separation = faceA.x; 196 | normal = dA.x > 0.0f ? RotA.col1 : -RotA.col1; 197 | 198 | const float relativeTol = 0.95f; 199 | const float absoluteTol = 0.01f; 200 | 201 | if (faceA.y > relativeTol * separation + absoluteTol * hA.y) 202 | { 203 | axis = FACE_A_Y; 204 | separation = faceA.y; 205 | normal = dA.y > 0.0f ? RotA.col2 : -RotA.col2; 206 | } 207 | 208 | // Box B faces 209 | if (faceB.x > relativeTol * separation + absoluteTol * hB.x) 210 | { 211 | axis = FACE_B_X; 212 | separation = faceB.x; 213 | normal = dB.x > 0.0f ? RotB.col1 : -RotB.col1; 214 | } 215 | 216 | if (faceB.y > relativeTol * separation + absoluteTol * hB.y) 217 | { 218 | axis = FACE_B_Y; 219 | separation = faceB.y; 220 | normal = dB.y > 0.0f ? RotB.col2 : -RotB.col2; 221 | } 222 | 223 | // Setup clipping plane data based on the separating axis 224 | Vec2 frontNormal, sideNormal; 225 | ClipVertex incidentEdge[2]; 226 | float front, negSide, posSide; 227 | char negEdge, posEdge; 228 | 229 | // Compute the clipping lines and the line segment to be clipped. 230 | switch (axis) 231 | { 232 | case FACE_A_X: 233 | { 234 | frontNormal = normal; 235 | front = Dot(posA, frontNormal) + hA.x; 236 | sideNormal = RotA.col2; 237 | float side = Dot(posA, sideNormal); 238 | negSide = -side + hA.y; 239 | posSide = side + hA.y; 240 | negEdge = EDGE3; 241 | posEdge = EDGE1; 242 | ComputeIncidentEdge(incidentEdge, hB, posB, RotB, frontNormal); 243 | } 244 | break; 245 | 246 | case FACE_A_Y: 247 | { 248 | frontNormal = normal; 249 | front = Dot(posA, frontNormal) + hA.y; 250 | sideNormal = RotA.col1; 251 | float side = Dot(posA, sideNormal); 252 | negSide = -side + hA.x; 253 | posSide = side + hA.x; 254 | negEdge = EDGE2; 255 | posEdge = EDGE4; 256 | ComputeIncidentEdge(incidentEdge, hB, posB, RotB, frontNormal); 257 | } 258 | break; 259 | 260 | case FACE_B_X: 261 | { 262 | frontNormal = -normal; 263 | front = Dot(posB, frontNormal) + hB.x; 264 | sideNormal = RotB.col2; 265 | float side = Dot(posB, sideNormal); 266 | negSide = -side + hB.y; 267 | posSide = side + hB.y; 268 | negEdge = EDGE3; 269 | posEdge = EDGE1; 270 | ComputeIncidentEdge(incidentEdge, hA, posA, RotA, frontNormal); 271 | } 272 | break; 273 | 274 | case FACE_B_Y: 275 | { 276 | frontNormal = -normal; 277 | front = Dot(posB, frontNormal) + hB.y; 278 | sideNormal = RotB.col1; 279 | float side = Dot(posB, sideNormal); 280 | negSide = -side + hB.x; 281 | posSide = side + hB.x; 282 | negEdge = EDGE2; 283 | posEdge = EDGE4; 284 | ComputeIncidentEdge(incidentEdge, hA, posA, RotA, frontNormal); 285 | } 286 | break; 287 | } 288 | 289 | // clip other face with 5 box planes (1 face plane, 4 edge planes) 290 | 291 | ClipVertex clipPoints1[2]; 292 | ClipVertex clipPoints2[2]; 293 | int np; 294 | 295 | // Clip to box side 1 296 | np = ClipSegmentToLine(clipPoints1, incidentEdge, -sideNormal, negSide, negEdge); 297 | 298 | if (np < 2) 299 | return 0; 300 | 301 | // Clip to negative box side 1 302 | np = ClipSegmentToLine(clipPoints2, clipPoints1, sideNormal, posSide, posEdge); 303 | 304 | if (np < 2) 305 | return 0; 306 | 307 | // Now clipPoints2 contains the clipping points. 308 | // Due to roundoff, it is possible that clipping removes all points. 309 | 310 | int numContacts = 0; 311 | for (int i = 0; i < 2; ++i) 312 | { 313 | float separation = Dot(frontNormal, clipPoints2[i].v) - front; 314 | 315 | if (separation <= 0) 316 | { 317 | contacts[numContacts].separation = separation; 318 | contacts[numContacts].normal = normal; 319 | // slide contact point onto reference face (easy to cull) 320 | contacts[numContacts].position = clipPoints2[i].v - separation * frontNormal; 321 | contacts[numContacts].feature = clipPoints2[i].fp; 322 | if (axis == FACE_B_X || axis == FACE_B_Y) 323 | Flip(contacts[numContacts].feature); 324 | ++numContacts; 325 | } 326 | } 327 | 328 | return numContacts; 329 | } -------------------------------------------------------------------------------- /src/Joint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #include "box2d-lite/Joint.h" 13 | #include "box2d-lite/Body.h" 14 | #include "box2d-lite/World.h" 15 | 16 | void Joint::Set(Body* b1, Body* b2, const Vec2& anchor) 17 | { 18 | body1 = b1; 19 | body2 = b2; 20 | 21 | Mat22 Rot1(body1->rotation); 22 | Mat22 Rot2(body2->rotation); 23 | Mat22 Rot1T = Rot1.Transpose(); 24 | Mat22 Rot2T = Rot2.Transpose(); 25 | 26 | localAnchor1 = Rot1T * (anchor - body1->position); 27 | localAnchor2 = Rot2T * (anchor - body2->position); 28 | 29 | P.Set(0.0f, 0.0f); 30 | 31 | softness = 0.0f; 32 | biasFactor = 0.2f; 33 | } 34 | 35 | void Joint::PreStep(float inv_dt) 36 | { 37 | // Pre-compute anchors, mass matrix, and bias. 38 | Mat22 Rot1(body1->rotation); 39 | Mat22 Rot2(body2->rotation); 40 | 41 | r1 = Rot1 * localAnchor1; 42 | r2 = Rot2 * localAnchor2; 43 | 44 | // deltaV = deltaV0 + K * impulse 45 | // invM = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] 46 | // = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y] 47 | // [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x] 48 | Mat22 K1; 49 | K1.col1.x = body1->invMass + body2->invMass; K1.col2.x = 0.0f; 50 | K1.col1.y = 0.0f; K1.col2.y = body1->invMass + body2->invMass; 51 | 52 | Mat22 K2; 53 | K2.col1.x = body1->invI * r1.y * r1.y; K2.col2.x = -body1->invI * r1.x * r1.y; 54 | K2.col1.y = -body1->invI * r1.x * r1.y; K2.col2.y = body1->invI * r1.x * r1.x; 55 | 56 | Mat22 K3; 57 | K3.col1.x = body2->invI * r2.y * r2.y; K3.col2.x = -body2->invI * r2.x * r2.y; 58 | K3.col1.y = -body2->invI * r2.x * r2.y; K3.col2.y = body2->invI * r2.x * r2.x; 59 | 60 | Mat22 K = K1 + K2 + K3; 61 | K.col1.x += softness; 62 | K.col2.y += softness; 63 | 64 | M = K.Invert(); 65 | 66 | Vec2 p1 = body1->position + r1; 67 | Vec2 p2 = body2->position + r2; 68 | Vec2 dp = p2 - p1; 69 | 70 | if (World::positionCorrection) 71 | { 72 | bias = -biasFactor * inv_dt * dp; 73 | } 74 | else 75 | { 76 | bias.Set(0.0f, 0.0f); 77 | } 78 | 79 | if (World::warmStarting) 80 | { 81 | // Apply accumulated impulse. 82 | body1->velocity -= body1->invMass * P; 83 | body1->angularVelocity -= body1->invI * Cross(r1, P); 84 | 85 | body2->velocity += body2->invMass * P; 86 | body2->angularVelocity += body2->invI * Cross(r2, P); 87 | } 88 | else 89 | { 90 | P.Set(0.0f, 0.0f); 91 | } 92 | } 93 | 94 | void Joint::ApplyImpulse() 95 | { 96 | Vec2 dv = body2->velocity + Cross(body2->angularVelocity, r2) - body1->velocity - Cross(body1->angularVelocity, r1); 97 | 98 | Vec2 impulse; 99 | 100 | impulse = M * (bias - dv - softness * P); 101 | 102 | body1->velocity -= body1->invMass * impulse; 103 | body1->angularVelocity -= body1->invI * Cross(r1, impulse); 104 | 105 | body2->velocity += body2->invMass * impulse; 106 | body2->angularVelocity += body2->invI * Cross(r2, impulse); 107 | 108 | P += impulse; 109 | } 110 | -------------------------------------------------------------------------------- /src/World.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 3 | * 4 | * Permission to use, copy, modify, distribute and sell this software 5 | * and its documentation for any purpose is hereby granted without fee, 6 | * provided that the above copyright notice appear in all copies. 7 | * Erin Catto makes no representations about the suitability 8 | * of this software for any purpose. 9 | * It is provided "as is" without express or implied warranty. 10 | */ 11 | 12 | #include "box2d-lite/World.h" 13 | #include "box2d-lite/Body.h" 14 | #include "box2d-lite/Joint.h" 15 | 16 | using std::vector; 17 | using std::map; 18 | using std::pair; 19 | 20 | typedef map::iterator ArbIter; 21 | typedef pair ArbPair; 22 | 23 | bool World::accumulateImpulses = true; 24 | bool World::warmStarting = true; 25 | bool World::positionCorrection = true; 26 | 27 | void World::Add(Body* body) 28 | { 29 | bodies.push_back(body); 30 | } 31 | 32 | void World::Add(Joint* joint) 33 | { 34 | joints.push_back(joint); 35 | } 36 | 37 | void World::Clear() 38 | { 39 | bodies.clear(); 40 | joints.clear(); 41 | arbiters.clear(); 42 | } 43 | 44 | void World::BroadPhase() 45 | { 46 | // O(n^2) broad-phase 47 | for (int i = 0; i < (int)bodies.size(); ++i) 48 | { 49 | Body* bi = bodies[i]; 50 | 51 | for (int j = i + 1; j < (int)bodies.size(); ++j) 52 | { 53 | Body* bj = bodies[j]; 54 | 55 | if (bi->invMass == 0.0f && bj->invMass == 0.0f) 56 | continue; 57 | 58 | Arbiter newArb(bi, bj); 59 | ArbiterKey key(bi, bj); 60 | 61 | if (newArb.numContacts > 0) 62 | { 63 | ArbIter iter = arbiters.find(key); 64 | if (iter == arbiters.end()) 65 | { 66 | arbiters.insert(ArbPair(key, newArb)); 67 | } 68 | else 69 | { 70 | iter->second.Update(newArb.contacts, newArb.numContacts); 71 | } 72 | } 73 | else 74 | { 75 | arbiters.erase(key); 76 | } 77 | } 78 | } 79 | } 80 | 81 | void World::Step(float dt) 82 | { 83 | float inv_dt = dt > 0.0f ? 1.0f / dt : 0.0f; 84 | 85 | // Determine overlapping bodies and update contact points. 86 | BroadPhase(); 87 | 88 | // Integrate forces. 89 | for (int i = 0; i < (int)bodies.size(); ++i) 90 | { 91 | Body* b = bodies[i]; 92 | 93 | if (b->invMass == 0.0f) 94 | continue; 95 | 96 | b->velocity += dt * (gravity + b->invMass * b->force); 97 | b->angularVelocity += dt * b->invI * b->torque; 98 | } 99 | 100 | // Perform pre-steps. 101 | for (ArbIter arb = arbiters.begin(); arb != arbiters.end(); ++arb) 102 | { 103 | arb->second.PreStep(inv_dt); 104 | } 105 | 106 | for (int i = 0; i < (int)joints.size(); ++i) 107 | { 108 | joints[i]->PreStep(inv_dt); 109 | } 110 | 111 | // Perform iterations 112 | for (int i = 0; i < iterations; ++i) 113 | { 114 | for (ArbIter arb = arbiters.begin(); arb != arbiters.end(); ++arb) 115 | { 116 | arb->second.ApplyImpulse(); 117 | } 118 | 119 | for (int j = 0; j < (int)joints.size(); ++j) 120 | { 121 | joints[j]->ApplyImpulse(); 122 | } 123 | } 124 | 125 | // Integrate Velocities 126 | for (int i = 0; i < (int)bodies.size(); ++i) 127 | { 128 | Body* b = bodies[i]; 129 | 130 | b->position += dt * b->velocity; 131 | b->rotation += dt * b->angularVelocity; 132 | 133 | b->force.Set(0.0f, 0.0f); 134 | b->torque = 0.0f; 135 | } 136 | } 137 | --------------------------------------------------------------------------------