├── LICENSE ├── MANIFEST.in ├── README.md ├── examples ├── humanoid.xml ├── slider.xml ├── test_pymujoco.py └── test_slider.py ├── glfw3static.lib ├── mujoco210.dll ├── mujoco210.lib ├── python ├── include │ ├── glfw3.h │ ├── mjdata.h │ ├── mjmodel.h │ ├── mjrender.h │ ├── mjui.h │ ├── mjvisualize.h │ ├── mjxmacro.h │ ├── mujoco.h │ ├── uitools.c │ └── uitools.h ├── pymujoco.cc ├── pymujoco.inl ├── pymujoco_includes.h ├── pymujoco_renderer.cpp └── pymujoco_renderer.h ├── setup.py └── third_party ├── glew_win32 ├── GL │ ├── freeglut.h │ ├── freeglut_ext.h │ ├── freeglut_std.h │ ├── glew.h │ ├── glext.h │ ├── glut.h │ ├── glxew.h │ ├── glxext.h │ ├── wglew.h │ └── wglext.h ├── glew32s.lib └── glew64s.lib ├── glfw ├── .mailmap ├── CMake │ ├── GenerateMappings.cmake │ ├── Info.plist.in │ ├── cmake_uninstall.cmake.in │ ├── glfw3.pc.in │ ├── glfw3Config.cmake.in │ ├── i686-w64-mingw32-clang.cmake │ ├── i686-w64-mingw32.cmake │ ├── modules │ │ ├── FindEpollShim.cmake │ │ └── FindOSMesa.cmake │ ├── x86_64-w64-mingw32-clang.cmake │ └── x86_64-w64-mingw32.cmake ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── deps │ ├── getopt.c │ ├── getopt.h │ ├── glad │ │ ├── gl.h │ │ ├── gles2.h │ │ └── vulkan.h │ ├── linmath.h │ ├── mingw │ │ ├── _mingw_dxhelper.h │ │ ├── dinput.h │ │ └── xinput.h │ ├── nuklear.h │ ├── nuklear_glfw_gl2.h │ ├── stb_image_write.h │ ├── tinycthread.c │ ├── tinycthread.h │ └── vs2008 │ │ └── stdint.h ├── docs │ ├── CMakeLists.txt │ ├── CODEOWNERS │ ├── CONTRIBUTING.md │ ├── Doxyfile.in │ ├── DoxygenLayout.xml │ ├── SUPPORT.md │ ├── build.dox │ ├── compat.dox │ ├── compile.dox │ ├── context.dox │ ├── extra.css │ ├── extra.css.map │ ├── extra.scss │ ├── footer.html │ ├── header.html │ ├── input.dox │ ├── internal.dox │ ├── intro.dox │ ├── main.dox │ ├── monitor.dox │ ├── moving.dox │ ├── news.dox │ ├── quick.dox │ ├── spaces.svg │ ├── vulkan.dox │ └── window.dox ├── examples │ ├── CMakeLists.txt │ ├── boing.c │ ├── gears.c │ ├── glfw.icns │ ├── glfw.ico │ ├── glfw.rc │ ├── heightmap.c │ ├── offscreen.c │ ├── particles.c │ ├── sharing.c │ ├── splitview.c │ ├── triangle-opengl.c │ ├── triangle-opengles.c │ ├── wave.c │ └── windows.c ├── include │ └── GLFW │ │ ├── glfw3.h │ │ └── glfw3native.h ├── src │ ├── CMakeLists.txt │ ├── cocoa_init.m │ ├── cocoa_joystick.h │ ├── cocoa_joystick.m │ ├── cocoa_monitor.m │ ├── cocoa_platform.h │ ├── cocoa_time.c │ ├── cocoa_time.h │ ├── cocoa_window.m │ ├── context.c │ ├── egl_context.c │ ├── glfw.rc.in │ ├── glx_context.c │ ├── init.c │ ├── input.c │ ├── internal.h │ ├── linux_joystick.c │ ├── linux_joystick.h │ ├── mappings.h │ ├── mappings.h.in │ ├── monitor.c │ ├── nsgl_context.m │ ├── null_init.c │ ├── null_joystick.c │ ├── null_joystick.h │ ├── null_monitor.c │ ├── null_platform.h │ ├── null_window.c │ ├── osmesa_context.c │ ├── platform.c │ ├── platform.h │ ├── posix_module.c │ ├── posix_thread.c │ ├── posix_thread.h │ ├── posix_time.c │ ├── posix_time.h │ ├── vulkan.c │ ├── wgl_context.c │ ├── win32_init.c │ ├── win32_joystick.c │ ├── win32_joystick.h │ ├── win32_module.c │ ├── win32_monitor.c │ ├── win32_platform.h │ ├── win32_thread.c │ ├── win32_thread.h │ ├── win32_time.c │ ├── win32_time.h │ ├── win32_window.c │ ├── window.c │ ├── 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 └── tests │ ├── CMakeLists.txt │ ├── allocator.c │ ├── clipboard.c │ ├── cursor.c │ ├── empty.c │ ├── events.c │ ├── gamma.c │ ├── glfwinfo.c │ ├── icon.c │ ├── iconify.c │ ├── inputlag.c │ ├── joysticks.c │ ├── monitors.c │ ├── msaa.c │ ├── reopen.c │ ├── tearing.c │ ├── threads.c │ ├── timeout.c │ ├── title.c │ ├── triangle-vulkan.c │ └── window.c └── pybind11 └── include └── pybind11 ├── attr.h ├── buffer_info.h ├── cast.h ├── chrono.h ├── common.h ├── complex.h ├── detail ├── class.h ├── common.h ├── descr.h ├── init.h ├── internals.h └── typeid.h ├── eigen.h ├── embed.h ├── eval.h ├── functional.h ├── iostream.h ├── numpy.h ├── operators.h ├── options.h ├── pybind11.h ├── pytypes.h ├── stl.h └── stl_bind.h /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include MANIFEST.in *.txt 2 | include *.* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pymujoco [![Software License](https://img.shields.io/hexpm/l/plug.svg)](https://www.apache.org/licenses/LICENSE-2.0) 2 | 3 | `pymujoco`-python bindings for [MuJoCo](http://mujoco.org/) simulator generated using pybind11. 4 | 5 | There is also a preliminary [colab](https://colab.research.google.com/drive/1jJfwcBDRcY3oXLawX2HLDFTDOIyHNdKQ?usp=sharing) that allows headless rendering using EGL (cannot restart the EGL context at the moment). 6 | 7 | ## Usage 8 | 9 | ``` 10 | from pymujoco import * 11 | r = mjv_create_renderer() 12 | 13 | #help(p) 14 | m = mj_loadXML("humanoid.xml") 15 | #print(m.qpos0) 16 | #print(m.nq) 17 | #print(m.nv) 18 | d = mj_makeData(m) 19 | 20 | exit_requested=False 21 | while not exit_requested: 22 | mj_step(m,d) 23 | 24 | print(d.qpos) 25 | exit_requested = r.render(m,d) 26 | 27 | names = ''.join([row.tostring().decode('UTF-8') for row in m.names]).split('\x00') 28 | print("names=",names) 29 | mj_printModel(m, "humanoid2.txt") 30 | mj_deleteData(d) 31 | mj_deleteModel(m) 32 | 33 | mjv_delete_renderer(r) 34 | ``` 35 | -------------------------------------------------------------------------------- /examples/slider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /examples/test_pymujoco.py: -------------------------------------------------------------------------------- 1 | from pymujoco import * 2 | r = mjv_create_renderer() 3 | import numpy as np 4 | np.set_printoptions(suppress=True, precision=3) 5 | #help(p) 6 | m = mj_loadXML("humanoid.xml") 7 | #print(m.qpos0) 8 | #print(m.nq) 9 | #print(m.nv) 10 | d = mj_makeData(m) 11 | 12 | exit_requested=False 13 | while not exit_requested: 14 | mj_step(m,d) 15 | 16 | #print(d.qpos) 17 | print("number of contacts:",d.ncon) 18 | for c in range(int(d.ncon[0])): 19 | ct = d.get_contact(c) 20 | print("contact[",c,"].dist=",ct.dist) 21 | print("contact[",c,"].pos=",ct.pos) 22 | 23 | exit_requested = r.render(m,d) 24 | 25 | names = ''.join([row.tostring().decode('UTF-8') for row in m.names]).split('\x00') 26 | print("names=",names) 27 | mj_printModel(m, "humanoid2.txt") 28 | mj_deleteData(d) 29 | mj_deleteModel(m) 30 | 31 | mjv_delete_renderer(r) -------------------------------------------------------------------------------- /examples/test_slider.py: -------------------------------------------------------------------------------- 1 | from pymujoco import * 2 | r = mjv_create_renderer() 3 | 4 | #help(p) 5 | m = mj_loadXML("slider.xml") 6 | #print(m.qpos0) 7 | #print(m.nq) 8 | #print(m.nv) 9 | d = mj_makeData(m) 10 | 11 | exit_requested=False 12 | while not exit_requested: 13 | mj_step(m,d) 14 | 15 | print(d.qpos) 16 | exit_requested = r.render(m,d) 17 | 18 | names = ''.join([row.tostring().decode('UTF-8') for row in m.names]).split('\x00') 19 | print("names=",names) 20 | mj_printModel(m, "slider.txt") 21 | mj_deleteData(d) 22 | mj_deleteModel(m) 23 | 24 | mjv_delete_renderer(r) -------------------------------------------------------------------------------- /glfw3static.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/glfw3static.lib -------------------------------------------------------------------------------- /mujoco210.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/mujoco210.dll -------------------------------------------------------------------------------- /mujoco210.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/mujoco210.lib -------------------------------------------------------------------------------- /python/include/uitools.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MUJOCO_UITOOLS_H_ 16 | #define MUJOCO_UITOOLS_H_ 17 | 18 | 19 | #include "mujoco.h" 20 | #include "glfw3.h" 21 | 22 | 23 | // this is a C-API 24 | #if defined(__cplusplus) 25 | extern "C" 26 | { 27 | #endif 28 | 29 | 30 | // User-supplied callback function types. 31 | typedef void (*uiEventFn)(mjuiState* state); 32 | typedef void (*uiLayoutFn)(mjuiState* state); 33 | 34 | // Container for GLFW window pointer. 35 | struct _uiUserPointer 36 | { 37 | mjuiState* state; 38 | uiEventFn uiEvent; 39 | uiLayoutFn uiLayout; 40 | double buffer2window; 41 | }; 42 | typedef struct _uiUserPointer uiUserPointer; 43 | 44 | // Set internal and user-supplied UI callbacks in GLFW window. 45 | void uiSetCallback(GLFWwindow* wnd, mjuiState* state, 46 | uiEventFn uiEvent, uiLayoutFn uiLayout); 47 | 48 | // Clear UI callbacks in GLFW window. 49 | void uiClearCallback(GLFWwindow* wnd); 50 | 51 | // Compute suitable font scale. 52 | int uiFontScale(GLFWwindow* wnd); 53 | 54 | // Modify UI structure. 55 | void uiModify(GLFWwindow* wnd, mjUI* ui, mjuiState* state, mjrContext* con); 56 | 57 | 58 | #if defined(__cplusplus) 59 | } 60 | #endif 61 | 62 | #endif // MUJOCO_UITOOLS_H_ 63 | -------------------------------------------------------------------------------- /python/pymujoco_includes.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "mujoco.h" 8 | 9 | 10 | #ifdef _WIN32 11 | #undef min 12 | #undef max 13 | #endif 14 | -------------------------------------------------------------------------------- /python/pymujoco_renderer.h: -------------------------------------------------------------------------------- 1 | #ifndef PY_MUJOCO_RENDERER_H 2 | #define PY_MUJOCO_RENDERER_H 3 | 4 | struct _mjModel; 5 | typedef struct _mjModel mjModel; 6 | struct _mjData; 7 | typedef struct _mjData mjData; 8 | 9 | void py_mjv_init(); 10 | void py_mjv_exit(); 11 | bool py_mjv_render(mjModel* model, mjData* data); 12 | 13 | #endif //PY_MUJOCO_RENDERER_H -------------------------------------------------------------------------------- /third_party/glew_win32/GL/freeglut.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_H__ 2 | #define __FREEGLUT_H__ 3 | 4 | /* 5 | * freeglut.h 6 | * 7 | * The freeglut library include file 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 10 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 12 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | */ 16 | 17 | #include "freeglut_std.h" 18 | #include "freeglut_ext.h" 19 | 20 | /*** END OF FILE ***/ 21 | 22 | #endif /* __FREEGLUT_H__ */ 23 | -------------------------------------------------------------------------------- /third_party/glew_win32/GL/glut.h: -------------------------------------------------------------------------------- 1 | #ifndef __GLUT_H__ 2 | #define __GLUT_H__ 3 | 4 | #define FREEGLUT_STATIC 1 5 | /* 6 | * glut.h 7 | * 8 | * The freeglut library include file 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 11 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 13 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 14 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | */ 17 | 18 | #include "freeglut_std.h" 19 | 20 | /*** END OF FILE ***/ 21 | 22 | #endif /* __GLUT_H__ */ 23 | -------------------------------------------------------------------------------- /third_party/glew_win32/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/third_party/glew_win32/glew32s.lib -------------------------------------------------------------------------------- /third_party/glew_win32/glew64s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/third_party/glew_win32/glew64s.lib -------------------------------------------------------------------------------- /third_party/glfw/.mailmap: -------------------------------------------------------------------------------- 1 | Camilla Löwy 2 | Camilla Löwy 3 | Camilla Löwy 4 | 5 | Emmanuel Gil Peyrot 6 | 7 | Marcus Geelnard 8 | Marcus Geelnard 9 | Marcus Geelnard 10 | 11 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/GenerateMappings.cmake: -------------------------------------------------------------------------------- 1 | # Usage: 2 | # cmake -P GenerateMappings.cmake 3 | 4 | set(source_url "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt") 5 | set(source_path "${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt") 6 | set(template_path "${CMAKE_ARGV3}") 7 | set(target_path "${CMAKE_ARGV4}") 8 | 9 | if (NOT EXISTS "${template_path}") 10 | message(FATAL_ERROR "Failed to find template file ${template_path}") 11 | endif() 12 | 13 | file(DOWNLOAD "${source_url}" "${source_path}" 14 | STATUS download_status 15 | TLS_VERIFY on) 16 | 17 | list(GET download_status 0 status_code) 18 | list(GET download_status 1 status_message) 19 | 20 | if (status_code) 21 | message(FATAL_ERROR "Failed to download ${source_url}: ${status_message}") 22 | endif() 23 | 24 | file(STRINGS "${source_path}" lines) 25 | foreach(line ${lines}) 26 | if (line MATCHES "^[0-9a-fA-F]") 27 | if (line MATCHES "platform:Windows") 28 | if (GLFW_WIN32_MAPPINGS) 29 | string(APPEND GLFW_WIN32_MAPPINGS "\n") 30 | endif() 31 | string(APPEND GLFW_WIN32_MAPPINGS "\"${line}\",") 32 | elseif (line MATCHES "platform:Mac OS X") 33 | if (GLFW_COCOA_MAPPINGS) 34 | string(APPEND GLFW_COCOA_MAPPINGS "\n") 35 | endif() 36 | string(APPEND GLFW_COCOA_MAPPINGS "\"${line}\",") 37 | elseif (line MATCHES "platform:Linux") 38 | if (GLFW_LINUX_MAPPINGS) 39 | string(APPEND GLFW_LINUX_MAPPINGS "\n") 40 | endif() 41 | string(APPEND GLFW_LINUX_MAPPINGS "\"${line}\",") 42 | endif() 43 | endif() 44 | endforeach() 45 | 46 | configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX) 47 | file(REMOVE "${source_path}") 48 | 49 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 9 | CFBundleGetInfoString 10 | ${MACOSX_BUNDLE_INFO_STRING} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | ${MACOSX_BUNDLE_LONG_VERSION_STRING} 19 | CFBundleName 20 | ${MACOSX_BUNDLE_BUNDLE_NAME} 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 29 | CSResourcesFileMapped 30 | 31 | LSRequiresCarbon 32 | 33 | NSHumanReadableCopyright 34 | ${MACOSX_BUNDLE_COPYRIGHT} 35 | NSHighResolutionCapable 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | if (NOT EXISTS "@GLFW_BINARY_DIR@/install_manifest.txt") 3 | message(FATAL_ERROR "Cannot find install manifest: \"@GLFW_BINARY_DIR@/install_manifest.txt\"") 4 | endif() 5 | 6 | file(READ "@GLFW_BINARY_DIR@/install_manifest.txt" files) 7 | string(REGEX REPLACE "\n" ";" files "${files}") 8 | 9 | foreach (file ${files}) 10 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | if (EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval) 15 | if (NOT "${rm_retval}" STREQUAL 0) 16 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 17 | endif() 18 | elseif (IS_SYMLINK "$ENV{DESTDIR}${file}") 19 | EXEC_PROGRAM("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 20 | OUTPUT_VARIABLE rm_out 21 | RETURN_VALUE rm_retval) 22 | if (NOT "${rm_retval}" STREQUAL 0) 23 | message(FATAL_ERROR "Problem when removing symlink \"$ENV{DESTDIR}${file}\"") 24 | endif() 25 | else() 26 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 27 | endif() 28 | endforeach() 29 | 30 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 4 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 5 | 6 | Name: GLFW 7 | Description: A multi-platform library for OpenGL, window and input 8 | Version: @GLFW_VERSION@ 9 | URL: https://www.glfw.org/ 10 | Requires.private: @GLFW_PKG_CONFIG_REQUIRES_PRIVATE@ 11 | Libs: -L${libdir} -l@GLFW_LIB_NAME@ 12 | Libs.private: @GLFW_PKG_CONFIG_LIBS_PRIVATE@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | find_dependency(Threads) 3 | include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") 4 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/i686-w64-mingw32-clang.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 32-bit MinGW-w64 Clang 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-w64-mingw32-clang") 5 | SET(CMAKE_CXX_COMPILER "i686-w64-mingw32-clang++") 6 | SET(CMAKE_RC_COMPILER "i686-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "i686-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/i686-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 32-bit MinGW-w64 GCC 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-w64-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "i686-w64-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "i686-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "i686-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/modules/FindEpollShim.cmake: -------------------------------------------------------------------------------- 1 | # Find EpollShim 2 | # Once done, this will define 3 | # 4 | # EPOLLSHIM_FOUND - System has EpollShim 5 | # EPOLLSHIM_INCLUDE_DIRS - The EpollShim include directories 6 | # EPOLLSHIM_LIBRARIES - The libraries needed to use EpollShim 7 | 8 | find_path(EPOLLSHIM_INCLUDE_DIRS NAMES sys/epoll.h sys/timerfd.h HINTS /usr/local/include/libepoll-shim) 9 | find_library(EPOLLSHIM_LIBRARIES NAMES epoll-shim libepoll-shim HINTS /usr/local/lib) 10 | 11 | if (EPOLLSHIM_INCLUDE_DIRS AND EPOLLSHIM_LIBRARIES) 12 | set(EPOLLSHIM_FOUND TRUE) 13 | endif (EPOLLSHIM_INCLUDE_DIRS AND EPOLLSHIM_LIBRARIES) 14 | 15 | include(FindPackageHandleStandardArgs) 16 | find_package_handle_standard_args(EpollShim DEFAULT_MSG EPOLLSHIM_LIBRARIES EPOLLSHIM_INCLUDE_DIRS) 17 | mark_as_advanced(EPOLLSHIM_INCLUDE_DIRS EPOLLSHIM_LIBRARIES) 18 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/modules/FindOSMesa.cmake: -------------------------------------------------------------------------------- 1 | # Try to find OSMesa on a Unix system 2 | # 3 | # This will define: 4 | # 5 | # OSMESA_LIBRARIES - Link these to use OSMesa 6 | # OSMESA_INCLUDE_DIR - Include directory for OSMesa 7 | # 8 | # Copyright (c) 2014 Brandon Schaefer 9 | 10 | if (NOT WIN32) 11 | 12 | find_package (PkgConfig) 13 | pkg_check_modules (PKG_OSMESA QUIET osmesa) 14 | 15 | set (OSMESA_INCLUDE_DIR ${PKG_OSMESA_INCLUDE_DIRS}) 16 | set (OSMESA_LIBRARIES ${PKG_OSMESA_LIBRARIES}) 17 | 18 | endif () 19 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/x86_64-w64-mingw32-clang.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 64-bit MinGW-w64 Clang 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-clang") 5 | SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-clang++") 6 | SET(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /third_party/glfw/CMake/x86_64-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross-compiling with 64-bit MinGW-w64 GCC 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /third_party/glfw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4...3.20 FATAL_ERROR) 2 | 3 | project(GLFW VERSION 3.4.0 LANGUAGES C) 4 | 5 | set(CMAKE_LEGACY_CYGWIN_WIN32 OFF) 6 | 7 | if (POLICY CMP0054) 8 | cmake_policy(SET CMP0054 NEW) 9 | endif() 10 | 11 | if (POLICY CMP0069) 12 | cmake_policy(SET CMP0069 NEW) 13 | endif() 14 | 15 | if (POLICY CMP0077) 16 | cmake_policy(SET CMP0077 NEW) 17 | endif() 18 | 19 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 20 | 21 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) 22 | set(GLFW_STANDALONE TRUE) 23 | endif() 24 | 25 | option(BUILD_SHARED_LIBS "Build shared libraries" OFF) 26 | option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE}) 27 | option(GLFW_BUILD_TESTS "Build the GLFW test programs" ${GLFW_STANDALONE}) 28 | option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON) 29 | option(GLFW_INSTALL "Generate installation target" ON) 30 | option(GLFW_VULKAN_STATIC "Assume the Vulkan loader is linked with the application" OFF) 31 | 32 | include(GNUInstallDirs) 33 | include(CMakeDependentOption) 34 | 35 | if (GLFW_USE_OSMESA) 36 | message(FATAL_ERROR "GLFW_USE_OSMESA has been removed; set the GLFW_PLATFORM init hint") 37 | endif() 38 | 39 | cmake_dependent_option(GLFW_BUILD_WIN32 "Build support for Win32" ON "WIN32" OFF) 40 | cmake_dependent_option(GLFW_BUILD_COCOA "Build support for Cocoa" ON "APPLE" OFF) 41 | cmake_dependent_option(GLFW_BUILD_X11 "Build support for X11" ON "UNIX;NOT APPLE" OFF) 42 | cmake_dependent_option(GLFW_BUILD_WAYLAND "Build support for Wayland" 43 | "${GLFW_USE_WAYLAND}" "UNIX;NOT APPLE" OFF) 44 | 45 | cmake_dependent_option(GLFW_USE_HYBRID_HPG "Force use of high-performance GPU on hybrid systems" OFF 46 | "WIN32" OFF) 47 | cmake_dependent_option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" ON 48 | "MSVC" OFF) 49 | 50 | set(GLFW_LIBRARY_TYPE "${GLFW_LIBRARY_TYPE}" CACHE STRING 51 | "Library type override for GLFW (SHARED, STATIC, OBJECT, or empty to follow BUILD_SHARED_LIBS)") 52 | 53 | if (GLFW_LIBRARY_TYPE) 54 | if (GLFW_LIBRARY_TYPE STREQUAL "SHARED") 55 | set(GLFW_BUILD_SHARED_LIBRARY TRUE) 56 | else() 57 | set(GLFW_BUILD_SHARED_LIBRARY FALSE) 58 | endif() 59 | else() 60 | set(GLFW_BUILD_SHARED_LIBRARY ${BUILD_SHARED_LIBS}) 61 | endif() 62 | 63 | list(APPEND CMAKE_MODULE_PATH "${GLFW_SOURCE_DIR}/CMake/modules") 64 | 65 | find_package(Threads REQUIRED) 66 | 67 | if (GLFW_BUILD_DOCS) 68 | set(DOXYGEN_SKIP_DOT TRUE) 69 | find_package(Doxygen) 70 | endif() 71 | 72 | #-------------------------------------------------------------------- 73 | # Report backend selection 74 | #-------------------------------------------------------------------- 75 | if (GLFW_BUILD_WIN32) 76 | message(STATUS "Including Win32 support") 77 | endif() 78 | if (GLFW_BUILD_COCOA) 79 | message(STATUS "Including Cocoa support") 80 | endif() 81 | if (GLFW_BUILD_WAYLAND) 82 | message(STATUS "Including Wayland support") 83 | endif() 84 | if (GLFW_BUILD_X11) 85 | message(STATUS "Including X11 support") 86 | endif() 87 | 88 | #-------------------------------------------------------------------- 89 | # Apply Microsoft C runtime library option 90 | # This is here because it also applies to tests and examples 91 | #-------------------------------------------------------------------- 92 | if (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL) 93 | if (CMAKE_VERSION VERSION_LESS 3.15) 94 | foreach (flag CMAKE_C_FLAGS 95 | CMAKE_C_FLAGS_DEBUG 96 | CMAKE_C_FLAGS_RELEASE 97 | CMAKE_C_FLAGS_MINSIZEREL 98 | CMAKE_C_FLAGS_RELWITHDEBINFO) 99 | 100 | if (flag MATCHES "/MD") 101 | string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") 102 | endif() 103 | if (flag MATCHES "/MDd") 104 | string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") 105 | endif() 106 | 107 | endforeach() 108 | else() 109 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 110 | endif() 111 | endif() 112 | 113 | #-------------------------------------------------------------------- 114 | # Create generated files 115 | #-------------------------------------------------------------------- 116 | include(CMakePackageConfigHelpers) 117 | 118 | set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3") 119 | 120 | configure_package_config_file(CMake/glfw3Config.cmake.in 121 | src/glfw3Config.cmake 122 | INSTALL_DESTINATION "${GLFW_CONFIG_PATH}" 123 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) 124 | 125 | write_basic_package_version_file(src/glfw3ConfigVersion.cmake 126 | VERSION ${GLFW_VERSION} 127 | COMPATIBILITY SameMajorVersion) 128 | 129 | #-------------------------------------------------------------------- 130 | # Add subdirectories 131 | #-------------------------------------------------------------------- 132 | add_subdirectory(src) 133 | 134 | if (GLFW_BUILD_EXAMPLES) 135 | add_subdirectory(examples) 136 | endif() 137 | 138 | if (GLFW_BUILD_TESTS) 139 | add_subdirectory(tests) 140 | endif() 141 | 142 | if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS) 143 | add_subdirectory(docs) 144 | endif() 145 | 146 | #-------------------------------------------------------------------- 147 | # Install files other than the library 148 | # The library is installed by src/CMakeLists.txt 149 | #-------------------------------------------------------------------- 150 | if (GLFW_INSTALL) 151 | install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 152 | FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) 153 | 154 | install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" 155 | "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" 156 | DESTINATION "${GLFW_CONFIG_PATH}") 157 | 158 | install(EXPORT glfwTargets FILE glfw3Targets.cmake 159 | EXPORT_LINK_INTERFACE_LIBRARIES 160 | DESTINATION "${GLFW_CONFIG_PATH}") 161 | install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" 162 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 163 | 164 | if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS) 165 | install(DIRECTORY "${GLFW_BINARY_DIR}/docs/html" 166 | DESTINATION "${CMAKE_INSTALL_DOCDIR}") 167 | endif() 168 | 169 | # Only generate this target if no higher-level project already has 170 | if (NOT TARGET uninstall) 171 | configure_file(CMake/cmake_uninstall.cmake.in 172 | cmake_uninstall.cmake IMMEDIATE @ONLY) 173 | 174 | add_custom_target(uninstall 175 | "${CMAKE_COMMAND}" -P 176 | "${GLFW_BINARY_DIR}/cmake_uninstall.cmake") 177 | set_target_properties(uninstall PROPERTIES FOLDER "GLFW3") 178 | endif() 179 | endif() 180 | 181 | -------------------------------------------------------------------------------- /third_party/glfw/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | 3 | Copyright (c) 2006-2019 Camilla Löwy 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would 16 | be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not 19 | be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | 24 | -------------------------------------------------------------------------------- /third_party/glfw/deps/getopt.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Kim Gräsman 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright notice, 9 | * this list of conditions and the following disclaimer in the documentation 10 | * and/or other materials provided with the distribution. 11 | * * Neither the name of Kim Gräsman nor the names of contributors may be used 12 | * to endorse or promote products derived from this software without specific 13 | * prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL KIM GRÄSMAN BE LIABLE FOR ANY DIRECT, 19 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef INCLUDED_GETOPT_PORT_H 28 | #define INCLUDED_GETOPT_PORT_H 29 | 30 | #if defined(__cplusplus) 31 | extern "C" { 32 | #endif 33 | 34 | extern const int no_argument; 35 | extern const int required_argument; 36 | extern const int optional_argument; 37 | 38 | extern char* optarg; 39 | extern int optind, opterr, optopt; 40 | 41 | struct option { 42 | const char* name; 43 | int has_arg; 44 | int* flag; 45 | int val; 46 | }; 47 | 48 | int getopt(int argc, char* const argv[], const char* optstring); 49 | 50 | int getopt_long(int argc, char* const argv[], 51 | const char* optstring, const struct option* longopts, int* longindex); 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif // INCLUDED_GETOPT_PORT_H 58 | -------------------------------------------------------------------------------- /third_party/glfw/deps/mingw/_mingw_dxhelper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS) 8 | #define NONAMELESSUNION 1 9 | #endif 10 | #if defined(NONAMELESSSTRUCT) && \ 11 | !defined(NONAMELESSUNION) 12 | #define NONAMELESSUNION 1 13 | #endif 14 | #if defined(NONAMELESSUNION) && \ 15 | !defined(NONAMELESSSTRUCT) 16 | #define NONAMELESSSTRUCT 1 17 | #endif 18 | #if !defined(__GNU_EXTENSION) 19 | #if defined(__GNUC__) || defined(__GNUG__) 20 | #define __GNU_EXTENSION __extension__ 21 | #else 22 | #define __GNU_EXTENSION 23 | #endif 24 | #endif /* __extension__ */ 25 | 26 | #ifndef __ANONYMOUS_DEFINED 27 | #define __ANONYMOUS_DEFINED 28 | #if defined(__GNUC__) || defined(__GNUG__) 29 | #define _ANONYMOUS_UNION __extension__ 30 | #define _ANONYMOUS_STRUCT __extension__ 31 | #else 32 | #define _ANONYMOUS_UNION 33 | #define _ANONYMOUS_STRUCT 34 | #endif 35 | #ifndef NONAMELESSUNION 36 | #define _UNION_NAME(x) 37 | #define _STRUCT_NAME(x) 38 | #else /* NONAMELESSUNION */ 39 | #define _UNION_NAME(x) x 40 | #define _STRUCT_NAME(x) x 41 | #endif 42 | #endif /* __ANONYMOUS_DEFINED */ 43 | 44 | #ifndef DUMMYUNIONNAME 45 | # ifdef NONAMELESSUNION 46 | # define DUMMYUNIONNAME u 47 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 48 | # define DUMMYUNIONNAME2 u2 49 | # define DUMMYUNIONNAME3 u3 50 | # define DUMMYUNIONNAME4 u4 51 | # define DUMMYUNIONNAME5 u5 52 | # define DUMMYUNIONNAME6 u6 53 | # define DUMMYUNIONNAME7 u7 54 | # define DUMMYUNIONNAME8 u8 55 | # define DUMMYUNIONNAME9 u9 56 | # else /* NONAMELESSUNION */ 57 | # define DUMMYUNIONNAME 58 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 59 | # define DUMMYUNIONNAME2 60 | # define DUMMYUNIONNAME3 61 | # define DUMMYUNIONNAME4 62 | # define DUMMYUNIONNAME5 63 | # define DUMMYUNIONNAME6 64 | # define DUMMYUNIONNAME7 65 | # define DUMMYUNIONNAME8 66 | # define DUMMYUNIONNAME9 67 | # endif 68 | #endif /* DUMMYUNIONNAME */ 69 | 70 | #if !defined(DUMMYUNIONNAME1) /* MinGW does not define this one */ 71 | # ifdef NONAMELESSUNION 72 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 73 | # else 74 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 75 | # endif 76 | #endif /* DUMMYUNIONNAME1 */ 77 | 78 | #ifndef DUMMYSTRUCTNAME 79 | # ifdef NONAMELESSUNION 80 | # define DUMMYSTRUCTNAME s 81 | # define DUMMYSTRUCTNAME1 s1 /* Wine uses this variant */ 82 | # define DUMMYSTRUCTNAME2 s2 83 | # define DUMMYSTRUCTNAME3 s3 84 | # define DUMMYSTRUCTNAME4 s4 85 | # define DUMMYSTRUCTNAME5 s5 86 | # else 87 | # define DUMMYSTRUCTNAME 88 | # define DUMMYSTRUCTNAME1 /* Wine uses this variant */ 89 | # define DUMMYSTRUCTNAME2 90 | # define DUMMYSTRUCTNAME3 91 | # define DUMMYSTRUCTNAME4 92 | # define DUMMYSTRUCTNAME5 93 | # endif 94 | #endif /* DUMMYSTRUCTNAME */ 95 | 96 | /* These are for compatibility with the Wine source tree */ 97 | 98 | #ifndef WINELIB_NAME_AW 99 | # ifdef __MINGW_NAME_AW 100 | # define WINELIB_NAME_AW __MINGW_NAME_AW 101 | # else 102 | # ifdef UNICODE 103 | # define WINELIB_NAME_AW(func) func##W 104 | # else 105 | # define WINELIB_NAME_AW(func) func##A 106 | # endif 107 | # endif 108 | #endif /* WINELIB_NAME_AW */ 109 | 110 | #ifndef DECL_WINELIB_TYPE_AW 111 | # ifdef __MINGW_TYPEDEF_AW 112 | # define DECL_WINELIB_TYPE_AW __MINGW_TYPEDEF_AW 113 | # else 114 | # define DECL_WINELIB_TYPE_AW(type) typedef WINELIB_NAME_AW(type) type; 115 | # endif 116 | #endif /* DECL_WINELIB_TYPE_AW */ 117 | 118 | -------------------------------------------------------------------------------- /third_party/glfw/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # NOTE: The order of this list determines the order of items in the Guides 3 | # (i.e. Pages) list in the generated documentation 4 | set(source_files 5 | main.dox 6 | news.dox 7 | quick.dox 8 | moving.dox 9 | compile.dox 10 | build.dox 11 | intro.dox 12 | context.dox 13 | monitor.dox 14 | window.dox 15 | input.dox 16 | vulkan.dox 17 | compat.dox 18 | internal.dox) 19 | 20 | set(extra_files DoxygenLayout.xml header.html footer.html extra.css spaces.svg) 21 | 22 | set(header_paths 23 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 24 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") 25 | 26 | # Format the source list into a Doxyfile INPUT value that Doxygen can parse 27 | foreach(path IN LISTS header_paths) 28 | string(APPEND GLFW_DOXYGEN_INPUT " \\\n\"${path}\"") 29 | endforeach() 30 | foreach(file IN LISTS source_files) 31 | string(APPEND GLFW_DOXYGEN_INPUT " \\\n\"${CMAKE_CURRENT_SOURCE_DIR}/${file}\"") 32 | endforeach() 33 | 34 | configure_file(Doxyfile.in Doxyfile @ONLY) 35 | 36 | add_custom_command(OUTPUT "html/index.html" 37 | COMMAND "${DOXYGEN_EXECUTABLE}" 38 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" 39 | MAIN_DEPENDENCY Doxyfile 40 | DEPENDS ${header_paths} ${source_files} ${extra_files} 41 | COMMENT "Generating HTML documentation" 42 | VERBATIM) 43 | 44 | add_custom_target(docs ALL SOURCES "html/index.html") 45 | set_target_properties(docs PROPERTIES FOLDER "GLFW3") 46 | 47 | -------------------------------------------------------------------------------- /third_party/glfw/docs/CODEOWNERS: -------------------------------------------------------------------------------- 1 | 2 | * @elmindreda 3 | 4 | src/wl_* @linkmauve 5 | 6 | docs/*.css @glfw/webdev 7 | docs/*.scss @glfw/webdev 8 | docs/*.html @glfw/webdev 9 | docs/*.xml @glfw/webdev 10 | 11 | -------------------------------------------------------------------------------- /third_party/glfw/docs/DoxygenLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /third_party/glfw/docs/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support resources 2 | 3 | See the [latest documentation](https://www.glfw.org/docs/latest/) for tutorials, 4 | guides and the API reference. 5 | 6 | If you have questions about using GLFW, we have a 7 | [forum](https://discourse.glfw.org/), and the `#glfw` IRC channel on 8 | [Libera.Chat](https://libera.chat/). 9 | 10 | Bugs are reported to our [issue tracker](https://github.com/glfw/glfw/issues). 11 | Please check the [contribution 12 | guide](https://github.com/glfw/glfw/blob/master/docs/CONTRIBUTING.md) for 13 | information on what to include when reporting a bug. 14 | 15 | -------------------------------------------------------------------------------- /third_party/glfw/docs/extra.css: -------------------------------------------------------------------------------- 1 | .sm-dox,.sm-dox a,.sm-dox a:focus,.sm-dox a:active,.sm-dox a:hover,.sm-dox a.highlighted,.sm-dox ul a:hover{background:none;text-shadow:none}.sm-dox a span.sub-arrow{border-color:#f2f2f2 transparent transparent transparent}.sm-dox a span.sub-arrow:active,.sm-dox a span.sub-arrow:focus,.sm-dox a span.sub-arrow:hover,.sm-dox a:hover span.sub-arrow{border-color:#f60 transparent transparent transparent}.sm-dox ul a span.sub-arrow:active,.sm-dox ul a span.sub-arrow:focus,.sm-dox ul a span.sub-arrow:hover,.sm-dox ul a:hover span.sub-arrow{border-color:transparent transparent transparent #f60}.sm-dox ul a:hover{background:#666;text-shadow:none}.sm-dox ul.sm-nowrap a{color:#4d4d4d;text-shadow:none}#main-nav,#main-menu,#main-menu a,#main-menu a:visited,#main-menu a:hover,#main-menu li,.memdoc,dl.reflist dd,div.toc li,.ah,span.lineno,span.lineno a,span.lineno a:hover,.note code,.pre code,.post code,.invariant code,.warning code,.attention code,.deprecated code,.bug code,.todo code,.test code,.doxtable code,.markdownTable code{background:none}#titlearea,.footer,.contents,div.header,.memdoc,table.doxtable td,table.doxtable th,table.markdownTable td,table.markdownTable th,hr,.memSeparator{border:none}#main-menu a,#main-menu a:visited,#main-menu a:hover,#main-menu li,.reflist dt a.el,.levels span,.directory .levels span{text-shadow:none}.memdoc,dl.reflist dd{box-shadow:none}div.headertitle,.note code,.pre code,.post code,.invariant code,.warning code,.attention code,.deprecated code,.bug code,.todo code,.test code,table.doxtable code,table.markdownTable code{padding:0}#nav-path,.directory .levels,span.lineno{display:none}html,#titlearea,.footer,tr.even,.directory tr.even,.doxtable tr:nth-child(even),tr.markdownTableBody:nth-child(even),.mdescLeft,.mdescRight,.memItemLeft,.memItemRight,code,.markdownTableRowEven{background:#f2f2f2}body{color:#4d4d4d}h1,h2,h2.groupheader,h3,div.toc h3,h4,h5,h6,strong,em{color:#1a1a1a;border-bottom:none}h1{padding-top:.5em;font-size:180%}h2{padding-top:.5em;margin-bottom:0;font-size:140%}h3{padding-top:.5em;margin-bottom:0;font-size:110%}.glfwheader{font-size:16px;min-height:64px;max-width:920px;padding:0 32px;margin:0 auto;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start;align-items:center;align-content:stretch}#glfwhome{line-height:64px;padding-right:48px;color:#666;font-size:2.5em;background:url("https://www.glfw.org/css/arrow.png") no-repeat right}.glfwnavbar{list-style-type:none;margin:0 0 0 auto;float:right}#glfwhome,.glfwnavbar li{float:left}.glfwnavbar a,.glfwnavbar a:visited{line-height:64px;margin-left:2em;display:block;color:#666}.glfwnavbar{padding-left:0}#glfwhome,.glfwnavbar a,.glfwnavbar a:visited{transition:.35s ease}#titlearea,.footer{color:#666}address.footer{text-align:center;padding:2em;margin-top:3em}#top{background:#666}#main-nav{max-width:960px;margin:0 auto;font-size:13px}#main-menu{max-width:920px;margin:0 auto;font-size:13px}.memtitle{display:none}.memproto,.memname{font-weight:bold;text-shadow:none}#main-menu{min-height:36px;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start;align-items:center;align-content:stretch}#main-menu a,#main-menu a:visited,#main-menu a:hover,#main-menu li{color:#f2f2f2}#main-menu li ul.sm-nowrap li a{color:#4d4d4d}#main-menu li ul.sm-nowrap li a:hover{color:#f60}#main-menu>li:last-child{margin:0 0 0 auto}.contents{min-height:590px}div.contents,div.header{max-width:920px;margin:0 auto;padding:0 32px;background:#fff none}table.doxtable th,table.markdownTable th,dl.reflist dt{background:linear-gradient(to bottom, #ffa733 0%, #ff6600 100%);box-shadow:inset 0 0 32px #f60;text-shadow:0 -1px 1px #b34700;text-align:left;color:#fff}dl.reflist dt a.el{color:#f60;padding:.2em;border-radius:4px;background-color:#ffe0cc}div.toc{float:none;width:auto}div.toc h3{font-size:1.17em}div.toc ul{padding-left:1.5em}div.toc li{font-size:1em;padding-left:0;list-style-type:disc}div.toc,.memproto,div.qindex,div.ah{background:linear-gradient(to bottom, #f2f2f2 0%, #e6e6e6 100%);box-shadow:inset 0 0 32px #e6e6e6;text-shadow:0 1px 1px #fff;color:#1a1a1a;border:2px solid #e6e6e6;border-radius:4px}.paramname{color:#803300}dl.reflist dt{border:2px solid #f60;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom:none}dl.reflist dd{border:2px solid #f60;border-bottom-right-radius:4px;border-bottom-left-radius:4px;border-top:none}table.doxtable,table.markdownTable{border-collapse:inherit;border-spacing:0;border:2px solid #f60;border-radius:4px}a,a:hover,a:visited,a:visited:hover,.contents a:visited,.el,a.el:visited,#glfwhome:hover,#main-menu a:hover,span.lineno a:hover{color:#f60;text-decoration:none}div.directory{border-collapse:inherit;border-spacing:0;border:2px solid #f60;border-radius:4px}hr,.memSeparator{height:2px;background:linear-gradient(to right, #f2f2f2 0%, #d9d9d9 50%, #f2f2f2 100%)}dl.note,dl.pre,dl.post,dl.invariant{background:linear-gradient(to bottom, #ddfad1 0%, #cbf7ba 100%);box-shadow:inset 0 0 32px #baf5a3;color:#1e5309;border:2px solid #afe699}dl.warning,dl.attention{background:linear-gradient(to bottom, #fae8d1 0%, #f7ddba 100%);box-shadow:inset 0 0 32px #f5d1a3;color:#533309;border:2px solid #e6c499}dl.deprecated,dl.bug{background:linear-gradient(to bottom, #fad1e3 0%, #f7bad6 100%);box-shadow:inset 0 0 32px #f5a3c8;color:#53092a;border:2px solid #e699bb}dl.todo,dl.test{background:linear-gradient(to bottom, #d1ecfa 0%, #bae3f7 100%);box-shadow:inset 0 0 32px #a3daf5;color:#093a53;border:2px solid #99cce6}dl.note,dl.pre,dl.post,dl.invariant,dl.warning,dl.attention,dl.deprecated,dl.bug,dl.todo,dl.test{border-radius:4px;padding:1em;text-shadow:0 1px 1px #fff;margin:1em 0}.note a,.pre a,.post a,.invariant a,.warning a,.attention a,.deprecated a,.bug a,.todo a,.test a,.note a:visited,.pre a:visited,.post a:visited,.invariant a:visited,.warning a:visited,.attention a:visited,.deprecated a:visited,.bug a:visited,.todo a:visited,.test a:visited{color:inherit}div.line{line-height:inherit}div.fragment,pre.fragment{background:#f2f2f2;border-radius:4px;border:none;padding:1em;overflow:auto;border-left:4px solid #ccc;margin:1em 0}.lineno a,.lineno a:visited,.line,pre.fragment{color:#4d4d4d}span.preprocessor,span.comment{color:#007899}a.code,a.code:visited{color:#e64500}span.keyword,span.keywordtype,span.keywordflow{color:#404040;font-weight:bold}span.stringliteral{color:#360099}code{padding:.1em;border-radius:4px}/*# sourceMappingURL=extra.css.map */ 2 | -------------------------------------------------------------------------------- /third_party/glfw/docs/extra.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sourceRoot":"","sources":["extra.scss"],"names":[],"mappings":"AA8EA,4GACI,gBACA,iBAGJ,yBACC,yDAGD,6HACC,sDAGD,yIACC,sDAGD,mBACI,WA9EuB,KA+EvB,iBAGJ,uBACC,MAzFoB,QA0FjB,iBAGJ,6UACC,gBAGD,mJACC,YAGD,yHACC,iBAGD,sBACC,gBAGD,4LACC,UAGD,yCACC,aAGD,kMACC,WAnHgC,QAsHjC,KACC,MA1HoB,QA6HrB,sDACC,MA/Ge,QAgHf,mBAGD,GACE,iBACA,eAGF,GACE,iBACA,gBACA,eAGF,GACE,iBACA,gBACA,eAGF,YACC,eACA,gBACA,gBACA,eACA,cAEA,aACA,mBACA,eACA,2BACA,mBACA,sBAGD,UACC,iBACA,mBACA,MA/J0B,KAgK1B,gBACA,qEAGD,YACC,qBACA,kBACA,YAGD,yBACC,WAGD,oCACC,iBACA,gBACA,cACA,MAlL0B,KAqL3B,YACC,eAGD,8CACC,qBAGD,mBACC,MA9L0B,KAiM3B,eACC,kBACA,YACA,eAGD,KACC,WAxM0B,KA2M3B,UACC,gBACA,cACA,eAGD,WACC,gBACA,cACA,eAGD,UACI,aAGJ,mBACI,iBACA,iBAGJ,WACC,gBACA,aACA,mBACA,eACA,2BACA,mBACA,sBAGD,mEACC,MA9OgC,QAiPjC,gCACC,MArPoB,QAwPrB,sCACC,MAjOoB,KAoOrB,yBACC,kBAGD,UACC,iBAGD,wBACC,gBACA,cACA,eACA,qBAGD,uDACC,gEACA,+BACA,+BACA,gBACA,MArPgB,KAwPjB,mBACC,MA5PoB,KA6PpB,aACA,kBACA,yBAGD,QACC,WACA,WAGD,WACC,iBAGD,WACC,mBAGD,WACC,cACA,eACA,qBAGD,oCACC,gEACA,kCACA,2BACA,MAlSe,QAmSf,yBACA,kBAGD,WACC,MA3QuB,QA8QxB,cACC,sBACA,2BACA,4BACA,mBAGD,cACC,sBACA,+BACA,8BACA,gBAGD,mCACC,wBACA,iBACA,sBACA,kBAGD,gIACC,MAxToB,KAyTpB,qBAGD,cACC,wBACA,iBACA,sBACA,kBAGD,iBACC,WACA,4EAGD,oCApSC,gEACA,kCACA,cACA,yBAqSD,wBAxSC,gEACA,kCACA,cACA,yBAySD,qBA5SC,gEACA,kCACA,cACA,yBA6SD,gBAhTC,gEACA,kCACA,cACA,yBAiTD,iGACC,kBACA,YACA,2BACA,aAGD,kRACC,cAGD,SACC,oBAGD,0BACC,mBACA,kBACA,YACA,YACA,cACA,2BACA,aAGD,+CACC,MA1YoB,QA6YrB,+BACC,cAGD,sBACC,cAGD,+CACC,cACA,iBAGD,mBACC,cAGD,KACC,aACA","file":"extra.css"} -------------------------------------------------------------------------------- /third_party/glfw/docs/footer.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /third_party/glfw/docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 |
25 | GLFW 26 | 31 |
32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /third_party/glfw/docs/internal.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @page internals_guide Internal structure 4 | 5 | @tableofcontents 6 | 7 | There are several interfaces inside GLFW. Each interface has its own area of 8 | responsibility and its own naming conventions. 9 | 10 | 11 | @section internals_public Public interface 12 | 13 | The most well-known is the public interface, described in the glfw3.h header 14 | file. This is implemented in source files shared by all platforms and these 15 | files contain no platform-specific code. This code usually ends up calling the 16 | platform and internal interfaces to do the actual work. 17 | 18 | The public interface uses the OpenGL naming conventions except with GLFW and 19 | glfw instead of GL and gl. For struct members, where OpenGL sets no precedent, 20 | it use headless camel case. 21 | 22 | Examples: `glfwCreateWindow`, `GLFWwindow`, `GLFW_RED_BITS` 23 | 24 | 25 | @section internals_native Native interface 26 | 27 | The [native interface](@ref native) is a small set of publicly available 28 | but platform-specific functions, described in the glfw3native.h header file and 29 | used to gain access to the underlying window, context and (on some platforms) 30 | display handles used by the platform interface. 31 | 32 | The function names of the native interface are similar to those of the public 33 | interface, but embeds the name of the interface that the returned handle is 34 | from. 35 | 36 | Examples: `glfwGetX11Window`, `glfwGetWGLContext` 37 | 38 | 39 | @section internals_internal Internal interface 40 | 41 | The internal interface consists of utility functions used by all other 42 | interfaces. It is shared code implemented in the same shared source files as 43 | the public and event interfaces. The internal interface is described in the 44 | internal.h header file. 45 | 46 | The internal interface is in charge of GLFW's global data, which it stores in 47 | a `_GLFWlibrary` struct named `_glfw`. 48 | 49 | The internal interface uses the same style as the public interface, except all 50 | global names have a leading underscore. 51 | 52 | Examples: `_glfwIsValidContextConfig`, `_GLFWwindow`, `_glfw.monitorCount` 53 | 54 | 55 | @section internals_platform Platform interface 56 | 57 | The platform interface implements all platform-specific operations as a service 58 | to the public interface. This includes event processing. The platform 59 | interface is never directly called by application code and never directly calls 60 | application-provided callbacks. It is also prohibited from modifying the 61 | platform-independent part of the internal structs. Instead, it calls the event 62 | interface when events interesting to GLFW are received. 63 | 64 | The platform interface mostly mirrors those parts of the public interface that needs to 65 | perform platform-specific operations on some or all platforms. 66 | 67 | The window system bits of the platform API is called through the `_GLFWplatform` struct of 68 | function pointers, to allow runtime selection of platform. This includes the window and 69 | context creation, input and event processing, monitor and Vulkan surface creation parts of 70 | GLFW. This is located in the global `_glfw` struct. 71 | 72 | Examples: `_glfw.platform.createWindow` 73 | 74 | The timer, threading and module loading bits of the platform API are plain functions with 75 | a `_glfwPlatform` prefix, as these things are independent of what window system is being 76 | used. 77 | 78 | Examples: `_glfwPlatformGetTimerValue` 79 | 80 | The platform interface also defines structs that contain platform-specific 81 | global and per-object state. Their names mirror those of the internal 82 | interface, except that an interface-specific suffix is added. 83 | 84 | Examples: `_GLFWwindowX11`, `_GLFWcontextWGL` 85 | 86 | These structs are incorporated as members into the internal interface structs 87 | using special macros that name them after the specific interface used. This 88 | prevents shared code from accidentally using these members. 89 | 90 | Examples: `window->win32.handle`, `_glfw.x11.display` 91 | 92 | 93 | @section internals_event Event interface 94 | 95 | The event interface is implemented in the same shared source files as the public 96 | interface and is responsible for delivering the events it receives to the 97 | application, either via callbacks, via window state changes or both. 98 | 99 | The function names of the event interface use a `_glfwInput` prefix and the 100 | ObjectEvent pattern. 101 | 102 | Examples: `_glfwInputWindowFocus`, `_glfwInputCursorPos` 103 | 104 | 105 | @section internals_static Static functions 106 | 107 | Static functions may be used by any interface and have no prefixes or suffixes. 108 | These use headless camel case. 109 | 110 | Examples: `isValidElementForJoystick` 111 | 112 | 113 | @section internals_config Configuration macros 114 | 115 | GLFW uses a number of configuration macros to select at compile time which 116 | interfaces and code paths to use. They are defined in the GLFW CMake target. 117 | 118 | Configuration macros the same style as tokens in the public interface, except 119 | with a leading underscore. 120 | 121 | Examples: `_GLFW_WIN32`, `_GLFW_BUILD_DLL` 122 | 123 | */ 124 | -------------------------------------------------------------------------------- /third_party/glfw/docs/main.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | @mainpage notitle 4 | 5 | @section main_intro Introduction 6 | 7 | GLFW is a free, Open Source, multi-platform library for OpenGL, OpenGL ES and 8 | Vulkan application development. It provides a simple, platform-independent API 9 | for creating windows, contexts and surfaces, reading input, handling events, etc. 10 | 11 | @ref news_34 list new features, caveats and deprecations. 12 | 13 | @ref quick_guide is a guide for users new to GLFW. It takes you through how to 14 | write a small but complete program. 15 | 16 | There are guides for each section of the API: 17 | 18 | - @ref intro_guide – initialization, error handling and high-level design 19 | - @ref window_guide – creating and working with windows and framebuffers 20 | - @ref context_guide – working with OpenGL and OpenGL ES contexts 21 | - @ref vulkan_guide - working with Vulkan objects and extensions 22 | - @ref monitor_guide – enumerating and working with monitors and video modes 23 | - @ref input_guide – receiving events, polling and processing input 24 | 25 | Once you have written a program, see @ref compile_guide and @ref build_guide. 26 | 27 | The [reference documentation](modules.html) provides more detailed information 28 | about specific functions. 29 | 30 | @ref moving_guide explains what has changed and how to update existing code to 31 | use the new API. 32 | 33 | There is a section on @ref guarantees_limitations for pointer lifetimes, 34 | reentrancy, thread safety, event order and backward and forward compatibility. 35 | 36 | The [FAQ](https://www.glfw.org/faq.html) answers many common questions about the 37 | design, implementation and use of GLFW. 38 | 39 | Finally, @ref compat_guide explains what APIs, standards and protocols GLFW uses 40 | and what happens when they are not present on a given machine. 41 | 42 | This documentation was generated with Doxygen. The sources for it are available 43 | in both the [source distribution](https://www.glfw.org/download.html) and 44 | [GitHub repository](https://github.com/glfw/glfw). 45 | 46 | */ 47 | -------------------------------------------------------------------------------- /third_party/glfw/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories("${GLFW_SOURCE_DIR}/deps") 5 | 6 | if (MATH_LIBRARY) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | # Workaround for the MS CRT deprecating parts of the standard library 11 | if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 12 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 13 | endif() 14 | 15 | if (WIN32) 16 | set(ICON glfw.rc) 17 | elseif (APPLE) 18 | set(ICON glfw.icns) 19 | endif() 20 | 21 | set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h") 22 | set(GLAD_GLES2 "${GLFW_SOURCE_DIR}/deps/glad/gles2.h") 23 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 24 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 25 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 26 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 27 | 28 | add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD_GL}) 29 | add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD_GL}) 30 | add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD_GL}) 31 | add_executable(offscreen offscreen.c ${ICON} ${GLAD_GL}) 32 | add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD_GL}) 33 | add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${ICON} ${GLAD_GL}) 34 | add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD_GL}) 35 | add_executable(triangle-opengl WIN32 MACOSX_BUNDLE triangle-opengl.c ${ICON} ${GLAD_GL}) 36 | add_executable(triangle-opengles WIN32 MACOSX_BUNDLE triangle-opengles.c ${ICON} ${GLAD_GLES2}) 37 | add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD_GL}) 38 | add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${ICON} ${GLAD_GL}) 39 | 40 | target_link_libraries(particles Threads::Threads) 41 | if (RT_LIBRARY) 42 | target_link_libraries(particles "${RT_LIBRARY}") 43 | endif() 44 | 45 | set(GUI_ONLY_BINARIES boing gears heightmap particles sharing splitview 46 | triangle-opengl triangle-opengles wave windows) 47 | set(CONSOLE_BINARIES offscreen) 48 | 49 | set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 50 | C_STANDARD 99 51 | FOLDER "GLFW3/Examples") 52 | 53 | if (GLFW_USE_OSMESA) 54 | find_package(OSMesa REQUIRED) 55 | target_compile_definitions(offscreen PRIVATE USE_NATIVE_OSMESA) 56 | endif() 57 | 58 | if (MSVC) 59 | # Tell MSVC to use main instead of WinMain 60 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 61 | LINK_FLAGS "/ENTRY:mainCRTStartup") 62 | elseif (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 63 | # Tell Clang using MS CRT to use main instead of WinMain 64 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 65 | LINK_FLAGS "-Wl,/entry:mainCRTStartup") 66 | endif() 67 | 68 | if (APPLE) 69 | set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") 70 | set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") 71 | set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") 72 | set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") 73 | set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") 74 | set_target_properties(triangle-opengl PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "OpenGL Triangle") 75 | set_target_properties(triangle-opengles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "OpenGL ES Triangle") 76 | set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView") 77 | set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") 78 | set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") 79 | 80 | set_source_files_properties(glfw.icns PROPERTIES 81 | MACOSX_PACKAGE_LOCATION "Resources") 82 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 83 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 84 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION} 85 | MACOSX_BUNDLE_ICON_FILE glfw.icns 86 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/Info.plist.in") 87 | endif() 88 | 89 | -------------------------------------------------------------------------------- /third_party/glfw/examples/glfw.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/third_party/glfw/examples/glfw.icns -------------------------------------------------------------------------------- /third_party/glfw/examples/glfw.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erwincoumans/pymujoco/33871d4412bb0c5de80555928f1877c670919d8d/third_party/glfw/examples/glfw.ico -------------------------------------------------------------------------------- /third_party/glfw/examples/glfw.rc: -------------------------------------------------------------------------------- 1 | 2 | GLFW_ICON ICON "glfw.ico" 3 | 4 | -------------------------------------------------------------------------------- /third_party/glfw/examples/offscreen.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Offscreen rendering example 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | 26 | #define GLAD_GL_IMPLEMENTATION 27 | #include 28 | #define GLFW_INCLUDE_NONE 29 | #include 30 | 31 | #if USE_NATIVE_OSMESA 32 | #define GLFW_EXPOSE_NATIVE_OSMESA 33 | #include 34 | #endif 35 | 36 | #include "linmath.h" 37 | 38 | #include 39 | #include 40 | 41 | #define STB_IMAGE_WRITE_IMPLEMENTATION 42 | #include 43 | 44 | static const struct 45 | { 46 | float x, y; 47 | float r, g, b; 48 | } vertices[3] = 49 | { 50 | { -0.6f, -0.4f, 1.f, 0.f, 0.f }, 51 | { 0.6f, -0.4f, 0.f, 1.f, 0.f }, 52 | { 0.f, 0.6f, 0.f, 0.f, 1.f } 53 | }; 54 | 55 | static const char* vertex_shader_text = 56 | "#version 110\n" 57 | "uniform mat4 MVP;\n" 58 | "attribute vec3 vCol;\n" 59 | "attribute vec2 vPos;\n" 60 | "varying vec3 color;\n" 61 | "void main()\n" 62 | "{\n" 63 | " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" 64 | " color = vCol;\n" 65 | "}\n"; 66 | 67 | static const char* fragment_shader_text = 68 | "#version 110\n" 69 | "varying vec3 color;\n" 70 | "void main()\n" 71 | "{\n" 72 | " gl_FragColor = vec4(color, 1.0);\n" 73 | "}\n"; 74 | 75 | static void error_callback(int error, const char* description) 76 | { 77 | fprintf(stderr, "Error: %s\n", description); 78 | } 79 | 80 | int main(void) 81 | { 82 | GLFWwindow* window; 83 | GLuint vertex_buffer, vertex_shader, fragment_shader, program; 84 | GLint mvp_location, vpos_location, vcol_location; 85 | float ratio; 86 | int width, height; 87 | mat4x4 mvp; 88 | char* buffer; 89 | 90 | glfwSetErrorCallback(error_callback); 91 | 92 | glfwInitHint(GLFW_COCOA_MENUBAR, GLFW_FALSE); 93 | 94 | if (!glfwInit()) 95 | exit(EXIT_FAILURE); 96 | 97 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 98 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 99 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 100 | 101 | window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); 102 | if (!window) 103 | { 104 | glfwTerminate(); 105 | exit(EXIT_FAILURE); 106 | } 107 | 108 | glfwMakeContextCurrent(window); 109 | gladLoadGL(glfwGetProcAddress); 110 | 111 | // NOTE: OpenGL error checks have been omitted for brevity 112 | 113 | glGenBuffers(1, &vertex_buffer); 114 | glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 115 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 116 | 117 | vertex_shader = glCreateShader(GL_VERTEX_SHADER); 118 | glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); 119 | glCompileShader(vertex_shader); 120 | 121 | fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 122 | glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL); 123 | glCompileShader(fragment_shader); 124 | 125 | program = glCreateProgram(); 126 | glAttachShader(program, vertex_shader); 127 | glAttachShader(program, fragment_shader); 128 | glLinkProgram(program); 129 | 130 | mvp_location = glGetUniformLocation(program, "MVP"); 131 | vpos_location = glGetAttribLocation(program, "vPos"); 132 | vcol_location = glGetAttribLocation(program, "vCol"); 133 | 134 | glEnableVertexAttribArray(vpos_location); 135 | glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, 136 | sizeof(vertices[0]), (void*) 0); 137 | glEnableVertexAttribArray(vcol_location); 138 | glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, 139 | sizeof(vertices[0]), (void*) (sizeof(float) * 2)); 140 | 141 | glfwGetFramebufferSize(window, &width, &height); 142 | ratio = width / (float) height; 143 | 144 | glViewport(0, 0, width, height); 145 | glClear(GL_COLOR_BUFFER_BIT); 146 | 147 | mat4x4_ortho(mvp, -ratio, ratio, -1.f, 1.f, 1.f, -1.f); 148 | 149 | glUseProgram(program); 150 | glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp); 151 | glDrawArrays(GL_TRIANGLES, 0, 3); 152 | glFinish(); 153 | 154 | #if USE_NATIVE_OSMESA 155 | glfwGetOSMesaColorBuffer(window, &width, &height, NULL, (void**) &buffer); 156 | #else 157 | buffer = calloc(4, width * height); 158 | glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); 159 | #endif 160 | 161 | // Write image Y-flipped because OpenGL 162 | stbi_write_png("offscreen.png", 163 | width, height, 4, 164 | buffer + (width * 4 * (height - 1)), 165 | -width * 4); 166 | 167 | #if USE_NATIVE_OSMESA 168 | // Here is where there's nothing 169 | #else 170 | free(buffer); 171 | #endif 172 | 173 | glfwDestroyWindow(window); 174 | 175 | glfwTerminate(); 176 | exit(EXIT_SUCCESS); 177 | } 178 | 179 | -------------------------------------------------------------------------------- /third_party/glfw/examples/triangle-opengl.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // OpenGL triangle example 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | //! [code] 26 | 27 | #define GLAD_GL_IMPLEMENTATION 28 | #include 29 | #define GLFW_INCLUDE_NONE 30 | #include 31 | 32 | #include "linmath.h" 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | typedef struct Vertex 39 | { 40 | vec2 pos; 41 | vec3 col; 42 | } Vertex; 43 | 44 | static const Vertex vertices[3] = 45 | { 46 | { { -0.6f, -0.4f }, { 1.f, 0.f, 0.f } }, 47 | { { 0.6f, -0.4f }, { 0.f, 1.f, 0.f } }, 48 | { { 0.f, 0.6f }, { 0.f, 0.f, 1.f } } 49 | }; 50 | 51 | static const char* vertex_shader_text = 52 | "#version 330\n" 53 | "uniform mat4 MVP;\n" 54 | "in vec3 vCol;\n" 55 | "in vec2 vPos;\n" 56 | "out vec3 color;\n" 57 | "void main()\n" 58 | "{\n" 59 | " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" 60 | " color = vCol;\n" 61 | "}\n"; 62 | 63 | static const char* fragment_shader_text = 64 | "#version 330\n" 65 | "in vec3 color;\n" 66 | "out vec4 fragment;\n" 67 | "void main()\n" 68 | "{\n" 69 | " fragment = vec4(color, 1.0);\n" 70 | "}\n"; 71 | 72 | static void error_callback(int error, const char* description) 73 | { 74 | fprintf(stderr, "Error: %s\n", description); 75 | } 76 | 77 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 78 | { 79 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 80 | glfwSetWindowShouldClose(window, GLFW_TRUE); 81 | } 82 | 83 | int main(void) 84 | { 85 | glfwSetErrorCallback(error_callback); 86 | 87 | if (!glfwInit()) 88 | exit(EXIT_FAILURE); 89 | 90 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 91 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 92 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 93 | 94 | GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL Triangle", NULL, NULL); 95 | if (!window) 96 | { 97 | glfwTerminate(); 98 | exit(EXIT_FAILURE); 99 | } 100 | 101 | glfwSetKeyCallback(window, key_callback); 102 | 103 | glfwMakeContextCurrent(window); 104 | gladLoadGL(glfwGetProcAddress); 105 | glfwSwapInterval(1); 106 | 107 | // NOTE: OpenGL error checks have been omitted for brevity 108 | 109 | GLuint vertex_buffer; 110 | glGenBuffers(1, &vertex_buffer); 111 | glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 112 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 113 | 114 | const GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); 115 | glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); 116 | glCompileShader(vertex_shader); 117 | 118 | const GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 119 | glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL); 120 | glCompileShader(fragment_shader); 121 | 122 | const GLuint program = glCreateProgram(); 123 | glAttachShader(program, vertex_shader); 124 | glAttachShader(program, fragment_shader); 125 | glLinkProgram(program); 126 | 127 | const GLint mvp_location = glGetUniformLocation(program, "MVP"); 128 | const GLint vpos_location = glGetAttribLocation(program, "vPos"); 129 | const GLint vcol_location = glGetAttribLocation(program, "vCol"); 130 | 131 | GLuint vertex_array; 132 | glGenVertexArrays(1, &vertex_array); 133 | glBindVertexArray(vertex_array); 134 | glEnableVertexAttribArray(vpos_location); 135 | glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, 136 | sizeof(Vertex), (void*) offsetof(Vertex, pos)); 137 | glEnableVertexAttribArray(vcol_location); 138 | glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, 139 | sizeof(Vertex), (void*) offsetof(Vertex, col)); 140 | 141 | while (!glfwWindowShouldClose(window)) 142 | { 143 | int width, height; 144 | glfwGetFramebufferSize(window, &width, &height); 145 | const float ratio = width / (float) height; 146 | 147 | glViewport(0, 0, width, height); 148 | glClear(GL_COLOR_BUFFER_BIT); 149 | 150 | mat4x4 m, p, mvp; 151 | mat4x4_identity(m); 152 | mat4x4_rotate_Z(m, m, (float) glfwGetTime()); 153 | mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f); 154 | mat4x4_mul(mvp, p, m); 155 | 156 | glUseProgram(program); 157 | glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) &mvp); 158 | glBindVertexArray(vertex_array); 159 | glDrawArrays(GL_TRIANGLES, 0, 3); 160 | 161 | glfwSwapBuffers(window); 162 | glfwPollEvents(); 163 | } 164 | 165 | glfwDestroyWindow(window); 166 | 167 | glfwTerminate(); 168 | exit(EXIT_SUCCESS); 169 | } 170 | 171 | //! [code] 172 | -------------------------------------------------------------------------------- /third_party/glfw/examples/triangle-opengles.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // OpenGL ES 2.0 triangle example 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | 26 | #define GLAD_GLES2_IMPLEMENTATION 27 | #include 28 | #define GLFW_INCLUDE_NONE 29 | #include 30 | 31 | #include "linmath.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | typedef struct Vertex 38 | { 39 | vec2 pos; 40 | vec3 col; 41 | } Vertex; 42 | 43 | static const Vertex vertices[3] = 44 | { 45 | { { -0.6f, -0.4f }, { 1.f, 0.f, 0.f } }, 46 | { { 0.6f, -0.4f }, { 0.f, 1.f, 0.f } }, 47 | { { 0.f, 0.6f }, { 0.f, 0.f, 1.f } } 48 | }; 49 | 50 | static const char* vertex_shader_text = 51 | "#version 100\n" 52 | "precision mediump float;\n" 53 | "uniform mat4 MVP;\n" 54 | "attribute vec3 vCol;\n" 55 | "attribute vec2 vPos;\n" 56 | "varying vec3 color;\n" 57 | "void main()\n" 58 | "{\n" 59 | " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" 60 | " color = vCol;\n" 61 | "}\n"; 62 | 63 | static const char* fragment_shader_text = 64 | "#version 100\n" 65 | "precision mediump float;\n" 66 | "varying vec3 color;\n" 67 | "void main()\n" 68 | "{\n" 69 | " gl_FragColor = vec4(color, 1.0);\n" 70 | "}\n"; 71 | 72 | static void error_callback(int error, const char* description) 73 | { 74 | fprintf(stderr, "GLFW Error: %s\n", description); 75 | } 76 | 77 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 78 | { 79 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 80 | glfwSetWindowShouldClose(window, GLFW_TRUE); 81 | } 82 | 83 | int main(void) 84 | { 85 | glfwSetErrorCallback(error_callback); 86 | 87 | if (!glfwInit()) 88 | exit(EXIT_FAILURE); 89 | 90 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 91 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 92 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 93 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); 94 | 95 | GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL ES 2.0 Triangle (EGL)", NULL, NULL); 96 | if (!window) 97 | { 98 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API); 99 | window = glfwCreateWindow(640, 480, "OpenGL ES 2.0 Triangle", NULL, NULL); 100 | if (!window) 101 | { 102 | glfwTerminate(); 103 | exit(EXIT_FAILURE); 104 | } 105 | } 106 | 107 | glfwSetKeyCallback(window, key_callback); 108 | 109 | glfwMakeContextCurrent(window); 110 | gladLoadGLES2(glfwGetProcAddress); 111 | glfwSwapInterval(1); 112 | 113 | GLuint vertex_buffer; 114 | glGenBuffers(1, &vertex_buffer); 115 | glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 116 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 117 | 118 | const GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); 119 | glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); 120 | glCompileShader(vertex_shader); 121 | 122 | const GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 123 | glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL); 124 | glCompileShader(fragment_shader); 125 | 126 | const GLuint program = glCreateProgram(); 127 | glAttachShader(program, vertex_shader); 128 | glAttachShader(program, fragment_shader); 129 | glLinkProgram(program); 130 | 131 | const GLint mvp_location = glGetUniformLocation(program, "MVP"); 132 | const GLint vpos_location = glGetAttribLocation(program, "vPos"); 133 | const GLint vcol_location = glGetAttribLocation(program, "vCol"); 134 | 135 | glEnableVertexAttribArray(vpos_location); 136 | glEnableVertexAttribArray(vcol_location); 137 | glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, 138 | sizeof(Vertex), (void*) offsetof(Vertex, pos)); 139 | glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, 140 | sizeof(Vertex), (void*) offsetof(Vertex, col)); 141 | 142 | while (!glfwWindowShouldClose(window)) 143 | { 144 | int width, height; 145 | glfwGetFramebufferSize(window, &width, &height); 146 | const float ratio = width / (float) height; 147 | 148 | glViewport(0, 0, width, height); 149 | glClear(GL_COLOR_BUFFER_BIT); 150 | 151 | mat4x4 m, p, mvp; 152 | mat4x4_identity(m); 153 | mat4x4_rotate_Z(m, m, (float) glfwGetTime()); 154 | mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f); 155 | mat4x4_mul(mvp, p, m); 156 | 157 | glUseProgram(program); 158 | glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) &mvp); 159 | glDrawArrays(GL_TRIANGLES, 0, 3); 160 | 161 | glfwSwapBuffers(window); 162 | glfwPollEvents(); 163 | } 164 | 165 | glfwDestroyWindow(window); 166 | 167 | glfwTerminate(); 168 | exit(EXIT_SUCCESS); 169 | } 170 | 171 | -------------------------------------------------------------------------------- /third_party/glfw/examples/windows.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Simple multi-window example 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | 26 | #define GLAD_GL_IMPLEMENTATION 27 | #include 28 | #define GLFW_INCLUDE_NONE 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | int main(int argc, char** argv) 35 | { 36 | int xpos, ypos, height; 37 | const char* description; 38 | GLFWwindow* windows[4]; 39 | 40 | if (!glfwInit()) 41 | { 42 | glfwGetError(&description); 43 | printf("Error: %s\n", description); 44 | exit(EXIT_FAILURE); 45 | } 46 | 47 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 48 | glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); 49 | 50 | glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height); 51 | 52 | for (int i = 0; i < 4; i++) 53 | { 54 | const int size = height / 5; 55 | const struct 56 | { 57 | float r, g, b; 58 | } colors[] = 59 | { 60 | { 0.95f, 0.32f, 0.11f }, 61 | { 0.50f, 0.80f, 0.16f }, 62 | { 0.f, 0.68f, 0.94f }, 63 | { 0.98f, 0.74f, 0.04f } 64 | }; 65 | 66 | if (i > 0) 67 | glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE); 68 | 69 | windows[i] = glfwCreateWindow(size, size, "Multi-Window Example", NULL, NULL); 70 | if (!windows[i]) 71 | { 72 | glfwGetError(&description); 73 | printf("Error: %s\n", description); 74 | glfwTerminate(); 75 | exit(EXIT_FAILURE); 76 | } 77 | 78 | glfwSetWindowPos(windows[i], 79 | xpos + size * (1 + (i & 1)), 80 | ypos + size * (1 + (i >> 1))); 81 | glfwSetInputMode(windows[i], GLFW_STICKY_KEYS, GLFW_TRUE); 82 | 83 | glfwMakeContextCurrent(windows[i]); 84 | gladLoadGL(glfwGetProcAddress); 85 | glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); 86 | } 87 | 88 | for (int i = 0; i < 4; i++) 89 | glfwShowWindow(windows[i]); 90 | 91 | for (;;) 92 | { 93 | for (int i = 0; i < 4; i++) 94 | { 95 | glfwMakeContextCurrent(windows[i]); 96 | glClear(GL_COLOR_BUFFER_BIT); 97 | glfwSwapBuffers(windows[i]); 98 | 99 | if (glfwWindowShouldClose(windows[i]) || 100 | glfwGetKey(windows[i], GLFW_KEY_ESCAPE)) 101 | { 102 | glfwTerminate(); 103 | exit(EXIT_SUCCESS); 104 | } 105 | } 106 | 107 | glfwWaitEvents(); 108 | } 109 | } 110 | 111 | -------------------------------------------------------------------------------- /third_party/glfw/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GLFW_COCOA_JOYSTICK_STATE _GLFWjoystickNS ns; 32 | #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE 33 | 34 | #define GLFW_BUILD_COCOA_MAPPINGS 35 | 36 | // Cocoa-specific per-joystick data 37 | // 38 | typedef struct _GLFWjoystickNS 39 | { 40 | IOHIDDeviceRef device; 41 | CFMutableArrayRef axes; 42 | CFMutableArrayRef buttons; 43 | CFMutableArrayRef hats; 44 | } _GLFWjoystickNS; 45 | 46 | GLFWbool _glfwInitJoysticksCocoa(void); 47 | void _glfwTerminateJoysticksCocoa(void); 48 | int _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode); 49 | const char* _glfwGetMappingNameCocoa(void); 50 | void _glfwUpdateGamepadGUIDCocoa(char* guid); 51 | 52 | -------------------------------------------------------------------------------- /third_party/glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 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 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW platform API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | void _glfwPlatformInitTimer(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 | uint64_t _glfwPlatformGetTimerValue(void) 47 | { 48 | return mach_absolute_time(); 49 | } 50 | 51 | uint64_t _glfwPlatformGetTimerFrequency(void) 52 | { 53 | return _glfw.timer.ns.frequency; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /third_party/glfw/src/cocoa_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_COCOA_LIBRARY_TIMER_STATE _GLFWtimerNS ns; 28 | 29 | // Cocoa-specific global timer data 30 | // 31 | typedef struct _GLFWtimerNS 32 | { 33 | uint64_t frequency; 34 | } _GLFWtimerNS; 35 | 36 | -------------------------------------------------------------------------------- /third_party/glfw/src/glfw.rc.in: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION @GLFW_VERSION_MAJOR@,@GLFW_VERSION_MINOR@,@GLFW_VERSION_PATCH@,0 6 | PRODUCTVERSION @GLFW_VERSION_MAJOR@,@GLFW_VERSION_MINOR@,@GLFW_VERSION_PATCH@,0 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 | FILEFLAGS 0 9 | FILEOS VOS_NT_WINDOWS32 10 | FILETYPE VFT_DLL 11 | FILESUBTYPE 0 12 | { 13 | BLOCK "StringFileInfo" 14 | { 15 | BLOCK "040904B0" 16 | { 17 | VALUE "CompanyName", "GLFW" 18 | VALUE "FileDescription", "GLFW @GLFW_VERSION@ DLL" 19 | VALUE "FileVersion", "@GLFW_VERSION@" 20 | VALUE "OriginalFilename", "glfw3.dll" 21 | VALUE "ProductName", "GLFW" 22 | VALUE "ProductVersion", "@GLFW_VERSION@" 23 | } 24 | } 25 | BLOCK "VarFileInfo" 26 | { 27 | VALUE "Translation", 0x409, 1200 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /third_party/glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GLFW_LINUX_JOYSTICK_STATE _GLFWjoystickLinux linjs; 32 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs; 33 | 34 | #define GLFW_BUILD_LINUX_MAPPINGS 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 | void _glfwDetectJoystickConnectionLinux(void); 59 | 60 | GLFWbool _glfwInitJoysticksLinux(void); 61 | void _glfwTerminateJoysticksLinux(void); 62 | int _glfwPollJoystickLinux(_GLFWjoystick* js, int mode); 63 | const char* _glfwGetMappingNameLinux(void); 64 | void _glfwUpdateGamepadGUIDLinux(char* guid); 65 | 66 | -------------------------------------------------------------------------------- /third_party/glfw/src/mappings.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2018 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 'update_mappings' CMake target. 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 | #if defined(GLFW_BUILD_WIN32_MAPPINGS) 64 | @GLFW_WIN32_MAPPINGS@ 65 | "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,", 66 | "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,", 67 | "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,", 68 | "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,", 69 | "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,", 70 | "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,", 71 | "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,", 72 | #endif // GLFW_BUILD_WIN32_MAPPINGS 73 | 74 | #if defined(GLFW_BUILD_COCOA_MAPPINGS) 75 | @GLFW_COCOA_MAPPINGS@ 76 | #endif // GLFW_BUILD_COCOA_MAPPINGS 77 | 78 | #if defined(GLFW_BUILD_LINUX_MAPPINGS) 79 | @GLFW_LINUX_MAPPINGS@ 80 | #endif // GLFW_BUILD_LINUX_MAPPINGS 81 | }; 82 | 83 | -------------------------------------------------------------------------------- /third_party/glfw/src/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) 40 | { 41 | const _GLFWplatform null = 42 | { 43 | GLFW_PLATFORM_NULL, 44 | _glfwInitNull, 45 | _glfwTerminateNull, 46 | _glfwGetCursorPosNull, 47 | _glfwSetCursorPosNull, 48 | _glfwSetCursorModeNull, 49 | _glfwSetRawMouseMotionNull, 50 | _glfwRawMouseMotionSupportedNull, 51 | _glfwCreateCursorNull, 52 | _glfwCreateStandardCursorNull, 53 | _glfwDestroyCursorNull, 54 | _glfwSetCursorNull, 55 | _glfwGetScancodeNameNull, 56 | _glfwGetKeyScancodeNull, 57 | _glfwSetClipboardStringNull, 58 | _glfwGetClipboardStringNull, 59 | _glfwInitJoysticksNull, 60 | _glfwTerminateJoysticksNull, 61 | _glfwPollJoystickNull, 62 | _glfwGetMappingNameNull, 63 | _glfwUpdateGamepadGUIDNull, 64 | _glfwFreeMonitorNull, 65 | _glfwGetMonitorPosNull, 66 | _glfwGetMonitorContentScaleNull, 67 | _glfwGetMonitorWorkareaNull, 68 | _glfwGetVideoModesNull, 69 | _glfwGetVideoModeNull, 70 | _glfwGetGammaRampNull, 71 | _glfwSetGammaRampNull, 72 | _glfwCreateWindowNull, 73 | _glfwDestroyWindowNull, 74 | _glfwSetWindowTitleNull, 75 | _glfwSetWindowIconNull, 76 | _glfwGetWindowPosNull, 77 | _glfwSetWindowPosNull, 78 | _glfwGetWindowSizeNull, 79 | _glfwSetWindowSizeNull, 80 | _glfwSetWindowSizeLimitsNull, 81 | _glfwSetWindowAspectRatioNull, 82 | _glfwGetFramebufferSizeNull, 83 | _glfwGetWindowFrameSizeNull, 84 | _glfwGetWindowContentScaleNull, 85 | _glfwIconifyWindowNull, 86 | _glfwRestoreWindowNull, 87 | _glfwMaximizeWindowNull, 88 | _glfwShowWindowNull, 89 | _glfwHideWindowNull, 90 | _glfwRequestWindowAttentionNull, 91 | _glfwFocusWindowNull, 92 | _glfwSetWindowMonitorNull, 93 | _glfwWindowFocusedNull, 94 | _glfwWindowIconifiedNull, 95 | _glfwWindowVisibleNull, 96 | _glfwWindowMaximizedNull, 97 | _glfwWindowHoveredNull, 98 | _glfwFramebufferTransparentNull, 99 | _glfwGetWindowOpacityNull, 100 | _glfwSetWindowResizableNull, 101 | _glfwSetWindowDecoratedNull, 102 | _glfwSetWindowFloatingNull, 103 | _glfwSetWindowOpacityNull, 104 | _glfwSetWindowMousePassthroughNull, 105 | _glfwPollEventsNull, 106 | _glfwWaitEventsNull, 107 | _glfwWaitEventsTimeoutNull, 108 | _glfwPostEmptyEventNull, 109 | _glfwGetEGLPlatformNull, 110 | _glfwGetEGLNativeDisplayNull, 111 | _glfwGetEGLNativeWindowNull, 112 | _glfwGetRequiredInstanceExtensionsNull, 113 | _glfwGetPhysicalDevicePresentationSupportNull, 114 | _glfwCreateWindowSurfaceNull, 115 | }; 116 | 117 | *platform = null; 118 | return GLFW_TRUE; 119 | } 120 | 121 | int _glfwInitNull(void) 122 | { 123 | _glfwPollMonitorsNull(); 124 | return GLFW_TRUE; 125 | } 126 | 127 | void _glfwTerminateNull(void) 128 | { 129 | free(_glfw.null.clipboardString); 130 | _glfwTerminateOSMesa(); 131 | _glfwTerminateEGL(); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /third_party/glfw/src/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | GLFWbool _glfwInitJoysticksNull(void) 37 | { 38 | return GLFW_TRUE; 39 | } 40 | 41 | void _glfwTerminateJoysticksNull(void) 42 | { 43 | } 44 | 45 | int _glfwPollJoystickNull(_GLFWjoystick* js, int mode) 46 | { 47 | return GLFW_FALSE; 48 | } 49 | 50 | const char* _glfwGetMappingNameNull(void) 51 | { 52 | return ""; 53 | } 54 | 55 | void _glfwUpdateGamepadGUIDNull(char* guid) 56 | { 57 | } 58 | 59 | -------------------------------------------------------------------------------- /third_party/glfw/src/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | GLFWbool _glfwInitJoysticksNull(void); 28 | void _glfwTerminateJoysticksNull(void); 29 | int _glfwPollJoystickNull(_GLFWjoystick* js, int mode); 30 | const char* _glfwGetMappingNameNull(void); 31 | void _glfwUpdateGamepadGUIDNull(char* guid); 32 | 33 | -------------------------------------------------------------------------------- /third_party/glfw/src/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | // The the sole (fake) video mode of our (sole) fake monitor 37 | // 38 | static GLFWvidmode getVideoMode(void) 39 | { 40 | GLFWvidmode mode; 41 | mode.width = 1920; 42 | mode.height = 1080; 43 | mode.redBits = 8; 44 | mode.greenBits = 8; 45 | mode.blueBits = 8; 46 | mode.refreshRate = 60; 47 | return mode; 48 | } 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | ////// GLFW internal API ////// 52 | ////////////////////////////////////////////////////////////////////////// 53 | 54 | void _glfwPollMonitorsNull(void) 55 | { 56 | const float dpi = 141.f; 57 | const GLFWvidmode mode = getVideoMode(); 58 | _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0", 59 | (int) (mode.width * 25.4f / dpi), 60 | (int) (mode.height * 25.4f / dpi)); 61 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST); 62 | } 63 | 64 | ////////////////////////////////////////////////////////////////////////// 65 | ////// GLFW platform API ////// 66 | ////////////////////////////////////////////////////////////////////////// 67 | 68 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor) 69 | { 70 | _glfwFreeGammaArrays(&monitor->null.ramp); 71 | } 72 | 73 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos) 74 | { 75 | if (xpos) 76 | *xpos = 0; 77 | if (ypos) 78 | *ypos = 0; 79 | } 80 | 81 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, 82 | float* xscale, float* yscale) 83 | { 84 | if (xscale) 85 | *xscale = 1.f; 86 | if (yscale) 87 | *yscale = 1.f; 88 | } 89 | 90 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, 91 | int* xpos, int* ypos, 92 | int* width, int* height) 93 | { 94 | const GLFWvidmode mode = getVideoMode(); 95 | 96 | if (xpos) 97 | *xpos = 0; 98 | if (ypos) 99 | *ypos = 10; 100 | if (width) 101 | *width = mode.width; 102 | if (height) 103 | *height = mode.height - 10; 104 | } 105 | 106 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found) 107 | { 108 | GLFWvidmode* mode = _glfw_calloc(1, sizeof(GLFWvidmode)); 109 | *mode = getVideoMode(); 110 | *found = 1; 111 | return mode; 112 | } 113 | 114 | void _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode) 115 | { 116 | *mode = getVideoMode(); 117 | } 118 | 119 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 120 | { 121 | if (!monitor->null.ramp.size) 122 | { 123 | unsigned int i; 124 | 125 | _glfwAllocGammaArrays(&monitor->null.ramp, 256); 126 | 127 | for (i = 0; i < monitor->null.ramp.size; i++) 128 | { 129 | const float gamma = 2.2f; 130 | float value; 131 | value = i / (float) (monitor->null.ramp.size - 1); 132 | value = powf(value, 1.f / gamma) * 65535.f + 0.5f; 133 | value = _glfw_fminf(value, 65535.f); 134 | 135 | monitor->null.ramp.red[i] = (unsigned short) value; 136 | monitor->null.ramp.green[i] = (unsigned short) value; 137 | monitor->null.ramp.blue[i] = (unsigned short) value; 138 | } 139 | } 140 | 141 | _glfwAllocGammaArrays(ramp, monitor->null.ramp.size); 142 | memcpy(ramp->red, monitor->null.ramp.red, sizeof(short) * ramp->size); 143 | memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size); 144 | memcpy(ramp->blue, monitor->null.ramp.blue, sizeof(short) * ramp->size); 145 | return GLFW_TRUE; 146 | } 147 | 148 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 149 | { 150 | if (monitor->null.ramp.size != ramp->size) 151 | { 152 | _glfwInputError(GLFW_PLATFORM_ERROR, 153 | "Null: Gamma ramp size must match current ramp size"); 154 | return; 155 | } 156 | 157 | memcpy(monitor->null.ramp.red, ramp->red, sizeof(short) * ramp->size); 158 | memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size); 159 | memcpy(monitor->null.ramp.blue, ramp->blue, sizeof(short) * ramp->size); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /third_party/glfw/src/platform.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW internal API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | static const struct 37 | { 38 | int ID; 39 | GLFWbool (*connect)(int,_GLFWplatform*); 40 | } supportedPlatforms[] = 41 | { 42 | #if defined(_GLFW_WIN32) 43 | { GLFW_PLATFORM_WIN32, _glfwConnectWin32 }, 44 | #endif 45 | #if defined(_GLFW_COCOA) 46 | { GLFW_PLATFORM_COCOA, _glfwConnectCocoa }, 47 | #endif 48 | #if defined(_GLFW_X11) 49 | { GLFW_PLATFORM_X11, _glfwConnectX11 }, 50 | #endif 51 | #if defined(_GLFW_WAYLAND) 52 | { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland }, 53 | #endif 54 | }; 55 | 56 | GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform) 57 | { 58 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 59 | size_t i; 60 | 61 | if (desiredID != GLFW_ANY_PLATFORM && 62 | desiredID != GLFW_PLATFORM_WIN32 && 63 | desiredID != GLFW_PLATFORM_COCOA && 64 | desiredID != GLFW_PLATFORM_WAYLAND && 65 | desiredID != GLFW_PLATFORM_X11 && 66 | desiredID != GLFW_PLATFORM_NULL) 67 | { 68 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", desiredID); 69 | return GLFW_FALSE; 70 | } 71 | 72 | // Only allow the Null platform if specifically requested 73 | if (desiredID == GLFW_PLATFORM_NULL) 74 | return _glfwConnectNull(desiredID, platform); 75 | 76 | // If there is only one platform available for auto-selection, let it emit the error 77 | // on failure as the platform-specific error description may be more helpful 78 | if (desiredID == GLFW_ANY_PLATFORM && count == 1) 79 | return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform); 80 | 81 | for (i = 0; i < count; i++) 82 | { 83 | if (desiredID == GLFW_ANY_PLATFORM || desiredID == supportedPlatforms[i].ID) 84 | { 85 | if (supportedPlatforms[i].connect(desiredID, platform)) 86 | return GLFW_TRUE; 87 | else if (desiredID == supportedPlatforms[i].ID) 88 | return GLFW_FALSE; 89 | } 90 | } 91 | 92 | if (desiredID == GLFW_ANY_PLATFORM) 93 | { 94 | if (count) 95 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform"); 96 | else 97 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform"); 98 | } 99 | else 100 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported"); 101 | 102 | return GLFW_FALSE; 103 | } 104 | 105 | ////////////////////////////////////////////////////////////////////////// 106 | ////// GLFW public API ////// 107 | ////////////////////////////////////////////////////////////////////////// 108 | 109 | GLFWAPI int glfwGetPlatform(void) 110 | { 111 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 112 | return _glfw.platform.platformID; 113 | } 114 | 115 | GLFWAPI int glfwPlatformSupported(int platformID) 116 | { 117 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 118 | size_t i; 119 | 120 | if (platformID != GLFW_PLATFORM_WIN32 && 121 | platformID != GLFW_PLATFORM_COCOA && 122 | platformID != GLFW_PLATFORM_WAYLAND && 123 | platformID != GLFW_PLATFORM_X11 && 124 | platformID != GLFW_PLATFORM_NULL) 125 | { 126 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", platformID); 127 | return GLFW_FALSE; 128 | } 129 | 130 | if (platformID == GLFW_PLATFORM_NULL) 131 | return GLFW_TRUE; 132 | 133 | for (i = 0; i < count; i++) 134 | { 135 | if (platformID == supportedPlatforms[i].ID) 136 | return GLFW_TRUE; 137 | } 138 | 139 | return GLFW_FALSE; 140 | } 141 | 142 | GLFWAPI const char* glfwGetVersionString(void) 143 | { 144 | return _GLFW_VERSION_NUMBER 145 | #if defined(_GLFW_WIN32) 146 | " Win32 WGL" 147 | #endif 148 | #if defined(_GLFW_COCOA) 149 | " Cocoa NSGL" 150 | #endif 151 | #if defined(_GLFW_WAYLAND) 152 | " Wayland" 153 | #endif 154 | #if defined(_GLFW_X11) 155 | " X11 GLX" 156 | #endif 157 | " Null" 158 | " EGL" 159 | " OSMesa" 160 | #if defined(__MINGW64_VERSION_MAJOR) 161 | " MinGW-w64" 162 | #elif defined(__MINGW32__) 163 | " MinGW" 164 | #elif defined(_MSC_VER) 165 | " VisualC" 166 | #endif 167 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 168 | " hybrid-GPU" 169 | #endif 170 | #if defined(_POSIX_MONOTONIC_CLOCK) 171 | " monotonic" 172 | #endif 173 | #if defined(_GLFW_BUILD_DLL) 174 | #if defined(_WIN32) 175 | " DLL" 176 | #elif defined(__APPLE__) 177 | " dynamic" 178 | #else 179 | " shared" 180 | #endif 181 | #endif 182 | ; 183 | } 184 | 185 | -------------------------------------------------------------------------------- /third_party/glfw/src/platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "null_platform.h" 29 | 30 | #if defined(_GLFW_WIN32) 31 | #include "win32_platform.h" 32 | #else 33 | #define GLFW_WIN32_WINDOW_STATE 34 | #define GLFW_WIN32_MONITOR_STATE 35 | #define GLFW_WIN32_CURSOR_STATE 36 | #define GLFW_WIN32_LIBRARY_WINDOW_STATE 37 | #define GLFW_WGL_CONTEXT_STATE 38 | #define GLFW_WGL_LIBRARY_CONTEXT_STATE 39 | #endif 40 | 41 | #if defined(_GLFW_COCOA) 42 | #include "cocoa_platform.h" 43 | #else 44 | #define GLFW_COCOA_WINDOW_STATE 45 | #define GLFW_COCOA_MONITOR_STATE 46 | #define GLFW_COCOA_CURSOR_STATE 47 | #define GLFW_COCOA_LIBRARY_WINDOW_STATE 48 | #define GLFW_NSGL_CONTEXT_STATE 49 | #define GLFW_NSGL_LIBRARY_CONTEXT_STATE 50 | #endif 51 | 52 | #if defined(_GLFW_WAYLAND) 53 | #include "wl_platform.h" 54 | #else 55 | #define GLFW_WAYLAND_WINDOW_STATE 56 | #define GLFW_WAYLAND_MONITOR_STATE 57 | #define GLFW_WAYLAND_CURSOR_STATE 58 | #define GLFW_WAYLAND_LIBRARY_WINDOW_STATE 59 | #endif 60 | 61 | #if defined(_GLFW_X11) 62 | #include "x11_platform.h" 63 | #else 64 | #define GLFW_X11_WINDOW_STATE 65 | #define GLFW_X11_MONITOR_STATE 66 | #define GLFW_X11_CURSOR_STATE 67 | #define GLFW_X11_LIBRARY_WINDOW_STATE 68 | #define GLFW_GLX_CONTEXT_STATE 69 | #define GLFW_GLX_LIBRARY_CONTEXT_STATE 70 | #endif 71 | 72 | #include "null_joystick.h" 73 | 74 | #if defined(_GLFW_WIN32) 75 | #include "win32_joystick.h" 76 | #else 77 | #define GLFW_WIN32_JOYSTICK_STATE 78 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 79 | #endif 80 | 81 | #if defined(_GLFW_COCOA) 82 | #include "cocoa_joystick.h" 83 | #else 84 | #define GLFW_COCOA_JOYSTICK_STATE 85 | #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE 86 | #endif 87 | 88 | #if (defined(_GLFW_X11) || defined(_GLFW_WAYLAND)) && defined(__linux__) 89 | #include "linux_joystick.h" 90 | #else 91 | #define GLFW_LINUX_JOYSTICK_STATE 92 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE 93 | #endif 94 | 95 | #if defined(_WIN32) 96 | #include "win32_thread.h" 97 | #define GLFW_POSIX_TLS_STATE 98 | #define GLFW_POSIX_MUTEX_STATE 99 | #else 100 | #include "posix_thread.h" 101 | #define GLFW_WIN32_TLS_STATE 102 | #define GLFW_WIN32_MUTEX_STATE 103 | #endif 104 | 105 | #if defined(_WIN32) 106 | #include "win32_time.h" 107 | #define GLFW_POSIX_LIBRARY_TIMER_STATE 108 | #define GLFW_COCOA_LIBRARY_TIMER_STATE 109 | #elif defined(__APPLE__) 110 | #include "cocoa_time.h" 111 | #define GLFW_WIN32_LIBRARY_TIMER_STATE 112 | #define GLFW_POSIX_LIBRARY_TIMER_STATE 113 | #else 114 | #include "posix_time.h" 115 | #define GLFW_WIN32_LIBRARY_TIMER_STATE 116 | #define GLFW_COCOA_LIBRARY_TIMER_STATE 117 | #endif 118 | 119 | #define GLFW_PLATFORM_WINDOW_STATE \ 120 | GLFW_WIN32_WINDOW_STATE \ 121 | GLFW_COCOA_WINDOW_STATE \ 122 | GLFW_WAYLAND_WINDOW_STATE \ 123 | GLFW_X11_WINDOW_STATE \ 124 | GLFW_NULL_WINDOW_STATE \ 125 | 126 | #define GLFW_PLATFORM_MONITOR_STATE \ 127 | GLFW_WIN32_MONITOR_STATE \ 128 | GLFW_COCOA_MONITOR_STATE \ 129 | GLFW_WAYLAND_MONITOR_STATE \ 130 | GLFW_X11_MONITOR_STATE \ 131 | GLFW_NULL_MONITOR_STATE \ 132 | 133 | #define GLFW_PLATFORM_CURSOR_STATE \ 134 | GLFW_WIN32_CURSOR_STATE \ 135 | GLFW_COCOA_CURSOR_STATE \ 136 | GLFW_WAYLAND_CURSOR_STATE \ 137 | GLFW_X11_CURSOR_STATE \ 138 | GLFW_NULL_CURSOR_STATE \ 139 | 140 | #define GLFW_PLATFORM_JOYSTICK_STATE \ 141 | GLFW_WIN32_JOYSTICK_STATE \ 142 | GLFW_COCOA_JOYSTICK_STATE \ 143 | GLFW_LINUX_JOYSTICK_STATE 144 | 145 | #define GLFW_PLATFORM_TLS_STATE \ 146 | GLFW_WIN32_TLS_STATE \ 147 | GLFW_POSIX_TLS_STATE \ 148 | 149 | #define GLFW_PLATFORM_MUTEX_STATE \ 150 | GLFW_WIN32_MUTEX_STATE \ 151 | GLFW_POSIX_MUTEX_STATE \ 152 | 153 | #define GLFW_PLATFORM_LIBRARY_WINDOW_STATE \ 154 | GLFW_WIN32_LIBRARY_WINDOW_STATE \ 155 | GLFW_COCOA_LIBRARY_WINDOW_STATE \ 156 | GLFW_WAYLAND_LIBRARY_WINDOW_STATE \ 157 | GLFW_X11_LIBRARY_WINDOW_STATE \ 158 | GLFW_NULL_LIBRARY_WINDOW_STATE \ 159 | 160 | #define GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 161 | GLFW_WIN32_LIBRARY_JOYSTICK_STATE \ 162 | GLFW_COCOA_LIBRARY_JOYSTICK_STATE \ 163 | GLFW_LINUX_LIBRARY_JOYSTICK_STATE 164 | 165 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE \ 166 | GLFW_WIN32_LIBRARY_TIMER_STATE \ 167 | GLFW_COCOA_LIBRARY_TIMER_STATE \ 168 | GLFW_POSIX_LIBRARY_TIMER_STATE \ 169 | 170 | #define GLFW_PLATFORM_CONTEXT_STATE \ 171 | GLFW_WGL_CONTEXT_STATE \ 172 | GLFW_NSGL_CONTEXT_STATE \ 173 | GLFW_GLX_CONTEXT_STATE 174 | 175 | #define GLFW_PLATFORM_LIBRARY_CONTEXT_STATE \ 176 | GLFW_WGL_LIBRARY_CONTEXT_STATE \ 177 | GLFW_NSGL_LIBRARY_CONTEXT_STATE \ 178 | GLFW_GLX_LIBRARY_CONTEXT_STATE 179 | 180 | -------------------------------------------------------------------------------- /third_party/glfw/src/posix_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #include 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void* _glfwPlatformLoadModule(const char* path) 38 | { 39 | return dlopen(path, RTLD_LAZY | RTLD_LOCAL); 40 | } 41 | 42 | void _glfwPlatformFreeModule(void* module) 43 | { 44 | dlclose(module); 45 | } 46 | 47 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 48 | { 49 | return dlsym(module, name); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /third_party/glfw/src/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 41 | { 42 | assert(tls->posix.allocated == GLFW_FALSE); 43 | 44 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, 47 | "POSIX: Failed to create context TLS"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->posix.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->posix.allocated) 58 | pthread_key_delete(tls->posix.key); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->posix.allocated == GLFW_TRUE); 65 | return pthread_getspecific(tls->posix.key); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->posix.allocated == GLFW_TRUE); 71 | pthread_setspecific(tls->posix.key, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->posix.allocated == GLFW_FALSE); 77 | 78 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 79 | { 80 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 81 | return GLFW_FALSE; 82 | } 83 | 84 | return mutex->posix.allocated = GLFW_TRUE; 85 | } 86 | 87 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 88 | { 89 | if (mutex->posix.allocated) 90 | pthread_mutex_destroy(&mutex->posix.handle); 91 | memset(mutex, 0, sizeof(_GLFWmutex)); 92 | } 93 | 94 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->posix.allocated == GLFW_TRUE); 97 | pthread_mutex_lock(&mutex->posix.handle); 98 | } 99 | 100 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 101 | { 102 | assert(mutex->posix.allocated == GLFW_TRUE); 103 | pthread_mutex_unlock(&mutex->posix.handle); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /third_party/glfw/src/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_POSIX_TLS_STATE _GLFWtlsPOSIX posix; 31 | #define GLFW_POSIX_MUTEX_STATE _GLFWmutexPOSIX posix; 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | } _GLFWtlsPOSIX; 41 | 42 | // POSIX-specific mutex data 43 | // 44 | typedef struct _GLFWmutexPOSIX 45 | { 46 | GLFWbool allocated; 47 | pthread_mutex_t handle; 48 | } _GLFWmutexPOSIX; 49 | 50 | -------------------------------------------------------------------------------- /third_party/glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | void _glfwPlatformInitTimer(void) 41 | { 42 | _glfw.timer.posix.clock = CLOCK_REALTIME; 43 | _glfw.timer.posix.frequency = 1000000000; 44 | 45 | #if defined(_POSIX_MONOTONIC_CLOCK) 46 | struct timespec ts; 47 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 48 | _glfw.timer.posix.clock = CLOCK_MONOTONIC; 49 | #endif 50 | } 51 | 52 | uint64_t _glfwPlatformGetTimerValue(void) 53 | { 54 | struct timespec ts; 55 | clock_gettime(_glfw.timer.posix.clock, &ts); 56 | return (uint64_t) ts.tv_sec * _glfw.timer.posix.frequency + (uint64_t) ts.tv_nsec; 57 | } 58 | 59 | uint64_t _glfwPlatformGetTimerFrequency(void) 60 | { 61 | return _glfw.timer.posix.frequency; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /third_party/glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLFW_POSIX_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix; 29 | 30 | #include 31 | #include 32 | 33 | 34 | // POSIX-specific global timer data 35 | // 36 | typedef struct _GLFWtimerPOSIX 37 | { 38 | clockid_t clock; 39 | uint64_t frequency; 40 | } _GLFWtimerPOSIX; 41 | 42 | -------------------------------------------------------------------------------- /third_party/glfw/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_WIN32_JOYSTICK_STATE _GLFWjoystickWin32 win32; 28 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 29 | 30 | #define GLFW_BUILD_WIN32_MAPPINGS 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 | void _glfwDetectJoystickConnectionWin32(void); 52 | void _glfwDetectJoystickDisconnectionWin32(void); 53 | 54 | -------------------------------------------------------------------------------- /third_party/glfw/src/win32_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // Please use C89 style variable declarations in this file because VS 2010 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW platform API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | void* _glfwPlatformLoadModule(const char* path) 36 | { 37 | return LoadLibraryA(path); 38 | } 39 | 40 | void _glfwPlatformFreeModule(void* module) 41 | { 42 | FreeLibrary((HMODULE) module); 43 | } 44 | 45 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 46 | { 47 | return (GLFWproc) GetProcAddress((HMODULE) module, name); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /third_party/glfw/src/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 40 | { 41 | assert(tls->win32.allocated == GLFW_FALSE); 42 | 43 | tls->win32.index = TlsAlloc(); 44 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index"); 47 | return GLFW_FALSE; 48 | } 49 | 50 | tls->win32.allocated = GLFW_TRUE; 51 | return GLFW_TRUE; 52 | } 53 | 54 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 55 | { 56 | if (tls->win32.allocated) 57 | TlsFree(tls->win32.index); 58 | memset(tls, 0, sizeof(_GLFWtls)); 59 | } 60 | 61 | void* _glfwPlatformGetTls(_GLFWtls* tls) 62 | { 63 | assert(tls->win32.allocated == GLFW_TRUE); 64 | return TlsGetValue(tls->win32.index); 65 | } 66 | 67 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 68 | { 69 | assert(tls->win32.allocated == GLFW_TRUE); 70 | TlsSetValue(tls->win32.index, value); 71 | } 72 | 73 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 74 | { 75 | assert(mutex->win32.allocated == GLFW_FALSE); 76 | InitializeCriticalSection(&mutex->win32.section); 77 | return mutex->win32.allocated = GLFW_TRUE; 78 | } 79 | 80 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 81 | { 82 | if (mutex->win32.allocated) 83 | DeleteCriticalSection(&mutex->win32.section); 84 | memset(mutex, 0, sizeof(_GLFWmutex)); 85 | } 86 | 87 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 88 | { 89 | assert(mutex->win32.allocated == GLFW_TRUE); 90 | EnterCriticalSection(&mutex->win32.section); 91 | } 92 | 93 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 94 | { 95 | assert(mutex->win32.allocated == GLFW_TRUE); 96 | LeaveCriticalSection(&mutex->win32.section); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /third_party/glfw/src/win32_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32; 31 | #define GLFW_WIN32_MUTEX_STATE _GLFWmutexWin32 win32; 32 | 33 | // Win32-specific thread local storage data 34 | // 35 | typedef struct _GLFWtlsWin32 36 | { 37 | GLFWbool allocated; 38 | DWORD index; 39 | } _GLFWtlsWin32; 40 | 41 | // Win32-specific mutex data 42 | // 43 | typedef struct _GLFWmutexWin32 44 | { 45 | GLFWbool allocated; 46 | CRITICAL_SECTION section; 47 | } _GLFWmutexWin32; 48 | 49 | -------------------------------------------------------------------------------- /third_party/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void _glfwPlatformInitTimer(void) 38 | { 39 | QueryPerformanceFrequency((LARGE_INTEGER*) &_glfw.timer.win32.frequency); 40 | } 41 | 42 | uint64_t _glfwPlatformGetTimerValue(void) 43 | { 44 | uint64_t value; 45 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 46 | return value; 47 | } 48 | 49 | uint64_t _glfwPlatformGetTimerFrequency(void) 50 | { 51 | return _glfw.timer.win32.frequency; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /third_party/glfw/src/win32_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_WIN32_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32; 31 | 32 | // Win32-specific global timer data 33 | // 34 | typedef struct _GLFWtimerWin32 35 | { 36 | uint64_t frequency; 37 | } _GLFWtimerWin32; 38 | 39 | -------------------------------------------------------------------------------- /third_party/glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | long _glfwKeySym2Unicode(unsigned int keysym); 28 | 29 | -------------------------------------------------------------------------------- /third_party/glfw/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories("${GLFW_SOURCE_DIR}/deps") 5 | 6 | if (MATH_LIBRARY) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | # Workaround for the MS CRT deprecating parts of the standard library 11 | if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 12 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 13 | endif() 14 | 15 | set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h") 16 | set(GLAD_VULKAN "${GLFW_SOURCE_DIR}/deps/glad/vulkan.h") 17 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 18 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 19 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 20 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 21 | 22 | add_executable(allocator allocator.c ${GLAD_GL}) 23 | add_executable(clipboard clipboard.c ${GETOPT} ${GLAD_GL}) 24 | add_executable(events events.c ${GETOPT} ${GLAD_GL}) 25 | add_executable(msaa msaa.c ${GETOPT} ${GLAD_GL}) 26 | add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD_GL} ${GLAD_VULKAN}) 27 | add_executable(iconify iconify.c ${GETOPT} ${GLAD_GL}) 28 | add_executable(monitors monitors.c ${GETOPT} ${GLAD_GL}) 29 | add_executable(reopen reopen.c ${GLAD_GL}) 30 | add_executable(cursor cursor.c ${GLAD_GL}) 31 | 32 | add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD_GL}) 33 | add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD_GL}) 34 | add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD_GL}) 35 | add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD_GL}) 36 | add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD_GL}) 37 | add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GLAD_GL}) 38 | add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD_GL}) 39 | add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD_GL}) 40 | add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD_GL}) 41 | add_executable(triangle-vulkan WIN32 triangle-vulkan.c ${GLAD_VULKAN}) 42 | add_executable(window WIN32 MACOSX_BUNDLE window.c ${GLAD_GL}) 43 | 44 | target_link_libraries(empty Threads::Threads) 45 | target_link_libraries(threads Threads::Threads) 46 | if (RT_LIBRARY) 47 | target_link_libraries(empty "${RT_LIBRARY}") 48 | target_link_libraries(threads "${RT_LIBRARY}") 49 | endif() 50 | 51 | set(GUI_ONLY_BINARIES empty gamma icon inputlag joysticks tearing threads 52 | timeout title triangle-vulkan window) 53 | set(CONSOLE_BINARIES allocator clipboard events msaa glfwinfo iconify monitors 54 | reopen cursor) 55 | 56 | set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 57 | C_STANDARD 99 58 | FOLDER "GLFW3/Tests") 59 | 60 | if (MSVC) 61 | # Tell MSVC to use main instead of WinMain 62 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 63 | LINK_FLAGS "/ENTRY:mainCRTStartup") 64 | elseif (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 65 | # Tell Clang using MS CRT to use main instead of WinMain 66 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 67 | LINK_FLAGS "-Wl,/entry:mainCRTStartup") 68 | endif() 69 | 70 | if (APPLE) 71 | set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") 72 | set_target_properties(gamma PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gamma") 73 | set_target_properties(inputlag PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Input Lag") 74 | set_target_properties(joysticks PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Joysticks") 75 | set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") 76 | set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") 77 | set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout") 78 | set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") 79 | set_target_properties(window PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Window") 80 | 81 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 82 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 83 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION} 84 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/Info.plist.in") 85 | endif() 86 | 87 | -------------------------------------------------------------------------------- /third_party/glfw/tests/allocator.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Custom heap allocator test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | 26 | #define GLAD_GL_IMPLEMENTATION 27 | #include 28 | #define GLFW_INCLUDE_NONE 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #define CALL(x) (function_name = #x, x) 36 | static const char* function_name = NULL; 37 | 38 | struct allocator_stats 39 | { 40 | size_t total; 41 | size_t current; 42 | size_t maximum; 43 | }; 44 | 45 | static void error_callback(int error, const char* description) 46 | { 47 | fprintf(stderr, "Error: %s\n", description); 48 | } 49 | 50 | static void* allocate(size_t size, void* user) 51 | { 52 | struct allocator_stats* stats = user; 53 | assert(size > 0); 54 | 55 | stats->total += size; 56 | stats->current += size; 57 | if (stats->current > stats->maximum) 58 | stats->maximum = stats->current; 59 | 60 | printf("%s: allocate %zu bytes (current %zu maximum %zu total %zu)\n", 61 | function_name, size, stats->current, stats->maximum, stats->total); 62 | 63 | size_t* real_block = malloc(size + sizeof(size_t)); 64 | assert(real_block != NULL); 65 | *real_block = size; 66 | return real_block + 1; 67 | } 68 | 69 | static void deallocate(void* block, void* user) 70 | { 71 | struct allocator_stats* stats = user; 72 | assert(block != NULL); 73 | 74 | size_t* real_block = (size_t*) block - 1; 75 | stats->current -= *real_block; 76 | 77 | printf("%s: deallocate %zu bytes (current %zu maximum %zu total %zu)\n", 78 | function_name, *real_block, stats->current, stats->maximum, stats->total); 79 | 80 | free(real_block); 81 | } 82 | 83 | static void* reallocate(void* block, size_t size, void* user) 84 | { 85 | struct allocator_stats* stats = user; 86 | assert(block != NULL); 87 | assert(size > 0); 88 | 89 | size_t* real_block = (size_t*) block - 1; 90 | stats->total += size; 91 | stats->current += size - *real_block; 92 | if (stats->current > stats->maximum) 93 | stats->maximum = stats->current; 94 | 95 | printf("%s: reallocate %zu bytes to %zu bytes (current %zu maximum %zu total %zu)\n", 96 | function_name, *real_block, size, stats->current, stats->maximum, stats->total); 97 | 98 | real_block = realloc(real_block, size + sizeof(size_t)); 99 | assert(real_block != NULL); 100 | *real_block = size; 101 | return real_block + 1; 102 | } 103 | 104 | int main(void) 105 | { 106 | struct allocator_stats stats = {0}; 107 | const GLFWallocator allocator = 108 | { 109 | .allocate = allocate, 110 | .deallocate = deallocate, 111 | .reallocate = reallocate, 112 | .user = &stats 113 | }; 114 | 115 | glfwSetErrorCallback(error_callback); 116 | glfwInitAllocator(&allocator); 117 | 118 | if (!CALL(glfwInit)()) 119 | exit(EXIT_FAILURE); 120 | 121 | GLFWwindow* window = CALL(glfwCreateWindow)(400, 400, "Custom allocator test", NULL, NULL); 122 | if (!window) 123 | { 124 | glfwTerminate(); 125 | exit(EXIT_FAILURE); 126 | } 127 | 128 | CALL(glfwMakeContextCurrent)(window); 129 | gladLoadGL(glfwGetProcAddress); 130 | CALL(glfwSwapInterval)(1); 131 | 132 | while (!CALL(glfwWindowShouldClose)(window)) 133 | { 134 | glClear(GL_COLOR_BUFFER_BIT); 135 | CALL(glfwSwapBuffers)(window); 136 | CALL(glfwWaitEvents)(); 137 | } 138 | 139 | CALL(glfwTerminate)(); 140 | exit(EXIT_SUCCESS); 141 | } 142 | 143 | -------------------------------------------------------------------------------- /third_party/glfw/tests/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Clipboard test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the clipboard functionality. 27 | // 28 | //======================================================================== 29 | 30 | #define GLAD_GL_IMPLEMENTATION 31 | #include 32 | #define GLFW_INCLUDE_NONE 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | #if defined(__APPLE__) 41 | #define MODIFIER GLFW_MOD_SUPER 42 | #else 43 | #define MODIFIER GLFW_MOD_CONTROL 44 | #endif 45 | 46 | static void usage(void) 47 | { 48 | printf("Usage: clipboard [-h]\n"); 49 | } 50 | 51 | static void error_callback(int error, const char* description) 52 | { 53 | fprintf(stderr, "Error: %s\n", description); 54 | } 55 | 56 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 57 | { 58 | if (action != GLFW_PRESS) 59 | return; 60 | 61 | switch (key) 62 | { 63 | case GLFW_KEY_ESCAPE: 64 | glfwSetWindowShouldClose(window, GLFW_TRUE); 65 | break; 66 | 67 | case GLFW_KEY_V: 68 | if (mods == MODIFIER) 69 | { 70 | const char* string; 71 | 72 | string = glfwGetClipboardString(NULL); 73 | if (string) 74 | printf("Clipboard contains \"%s\"\n", string); 75 | else 76 | printf("Clipboard does not contain a string\n"); 77 | } 78 | break; 79 | 80 | case GLFW_KEY_C: 81 | if (mods == MODIFIER) 82 | { 83 | const char* string = "Hello GLFW World!"; 84 | glfwSetClipboardString(NULL, string); 85 | printf("Setting clipboard to \"%s\"\n", string); 86 | } 87 | break; 88 | } 89 | } 90 | 91 | int main(int argc, char** argv) 92 | { 93 | int ch; 94 | GLFWwindow* window; 95 | 96 | while ((ch = getopt(argc, argv, "h")) != -1) 97 | { 98 | switch (ch) 99 | { 100 | case 'h': 101 | usage(); 102 | exit(EXIT_SUCCESS); 103 | 104 | default: 105 | usage(); 106 | exit(EXIT_FAILURE); 107 | } 108 | } 109 | 110 | glfwSetErrorCallback(error_callback); 111 | 112 | if (!glfwInit()) 113 | { 114 | fprintf(stderr, "Failed to initialize GLFW\n"); 115 | exit(EXIT_FAILURE); 116 | } 117 | 118 | window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL); 119 | if (!window) 120 | { 121 | glfwTerminate(); 122 | 123 | fprintf(stderr, "Failed to open GLFW window\n"); 124 | exit(EXIT_FAILURE); 125 | } 126 | 127 | glfwMakeContextCurrent(window); 128 | gladLoadGL(glfwGetProcAddress); 129 | glfwSwapInterval(1); 130 | 131 | glfwSetKeyCallback(window, key_callback); 132 | 133 | glClearColor(0.5f, 0.5f, 0.5f, 0); 134 | 135 | while (!glfwWindowShouldClose(window)) 136 | { 137 | glClear(GL_COLOR_BUFFER_BIT); 138 | 139 | glfwSwapBuffers(window); 140 | glfwWaitEvents(); 141 | } 142 | 143 | glfwTerminate(); 144 | exit(EXIT_SUCCESS); 145 | } 146 | 147 | -------------------------------------------------------------------------------- /third_party/glfw/tests/empty.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Empty event test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that posting of empty events works 27 | // 28 | //======================================================================== 29 | 30 | #include "tinycthread.h" 31 | 32 | #define GLAD_GL_IMPLEMENTATION 33 | #include 34 | #define GLFW_INCLUDE_NONE 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | static volatile int running = GLFW_TRUE; 42 | 43 | static void error_callback(int error, const char* description) 44 | { 45 | fprintf(stderr, "Error: %s\n", description); 46 | } 47 | 48 | static int thread_main(void* data) 49 | { 50 | struct timespec time; 51 | 52 | while (running) 53 | { 54 | clock_gettime(CLOCK_REALTIME, &time); 55 | time.tv_sec += 1; 56 | thrd_sleep(&time, NULL); 57 | 58 | glfwPostEmptyEvent(); 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 65 | { 66 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 67 | glfwSetWindowShouldClose(window, GLFW_TRUE); 68 | } 69 | 70 | static float nrand(void) 71 | { 72 | return (float) rand() / (float) RAND_MAX; 73 | } 74 | 75 | int main(void) 76 | { 77 | int result; 78 | thrd_t thread; 79 | GLFWwindow* window; 80 | 81 | srand((unsigned int) time(NULL)); 82 | 83 | glfwSetErrorCallback(error_callback); 84 | 85 | if (!glfwInit()) 86 | exit(EXIT_FAILURE); 87 | 88 | window = glfwCreateWindow(640, 480, "Empty Event Test", NULL, NULL); 89 | if (!window) 90 | { 91 | glfwTerminate(); 92 | exit(EXIT_FAILURE); 93 | } 94 | 95 | glfwMakeContextCurrent(window); 96 | gladLoadGL(glfwGetProcAddress); 97 | glfwSetKeyCallback(window, key_callback); 98 | 99 | if (thrd_create(&thread, thread_main, NULL) != thrd_success) 100 | { 101 | fprintf(stderr, "Failed to create secondary thread\n"); 102 | 103 | glfwTerminate(); 104 | exit(EXIT_FAILURE); 105 | } 106 | 107 | while (running) 108 | { 109 | int width, height; 110 | float r = nrand(), g = nrand(), b = nrand(); 111 | float l = (float) sqrt(r * r + g * g + b * b); 112 | 113 | glfwGetFramebufferSize(window, &width, &height); 114 | 115 | glViewport(0, 0, width, height); 116 | glClearColor(r / l, g / l, b / l, 1.f); 117 | glClear(GL_COLOR_BUFFER_BIT); 118 | glfwSwapBuffers(window); 119 | 120 | glfwWaitEvents(); 121 | 122 | if (glfwWindowShouldClose(window)) 123 | running = GLFW_FALSE; 124 | } 125 | 126 | glfwHideWindow(window); 127 | thrd_join(thread, &result); 128 | glfwDestroyWindow(window); 129 | 130 | glfwTerminate(); 131 | exit(EXIT_SUCCESS); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /third_party/glfw/tests/gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Gamma correction test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the gamma correction functionality for 27 | // both full screen and windowed mode windows 28 | // 29 | //======================================================================== 30 | 31 | #define GLAD_GL_IMPLEMENTATION 32 | #include 33 | #define GLFW_INCLUDE_NONE 34 | #include 35 | 36 | #define NK_IMPLEMENTATION 37 | #define NK_INCLUDE_FIXED_TYPES 38 | #define NK_INCLUDE_FONT_BAKING 39 | #define NK_INCLUDE_DEFAULT_FONT 40 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 41 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 42 | #define NK_INCLUDE_STANDARD_VARARGS 43 | #define NK_BUTTON_TRIGGER_ON_RELEASE 44 | #include 45 | 46 | #define NK_GLFW_GL2_IMPLEMENTATION 47 | #include 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | static void error_callback(int error, const char* description) 54 | { 55 | fprintf(stderr, "Error: %s\n", description); 56 | } 57 | 58 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 59 | { 60 | if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) 61 | glfwSetWindowShouldClose(window, GLFW_TRUE); 62 | } 63 | 64 | static void chart_ramp_array(struct nk_context* nk, 65 | struct nk_color color, 66 | int count, unsigned short int* values) 67 | { 68 | if (nk_chart_begin_colored(nk, NK_CHART_LINES, 69 | color, nk_rgb(255, 255, 255), 70 | count, 0, 65535)) 71 | { 72 | int i; 73 | for (i = 0; i < count; i++) 74 | { 75 | char buffer[1024]; 76 | if (nk_chart_push(nk, values[i])) 77 | { 78 | snprintf(buffer, sizeof(buffer), "#%u: %u (%0.5f) ", 79 | i, values[i], values[i] / 65535.f); 80 | nk_tooltip(nk, buffer); 81 | } 82 | } 83 | 84 | nk_chart_end(nk); 85 | } 86 | } 87 | 88 | int main(int argc, char** argv) 89 | { 90 | GLFWmonitor* monitor = NULL; 91 | GLFWwindow* window; 92 | GLFWgammaramp orig_ramp; 93 | struct nk_context* nk; 94 | struct nk_font_atlas* atlas; 95 | float gamma_value = 1.f; 96 | 97 | glfwSetErrorCallback(error_callback); 98 | 99 | if (!glfwInit()) 100 | exit(EXIT_FAILURE); 101 | 102 | monitor = glfwGetPrimaryMonitor(); 103 | 104 | glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); 105 | glfwWindowHint(GLFW_WIN32_KEYBOARD_MENU, GLFW_TRUE); 106 | 107 | window = glfwCreateWindow(800, 400, "Gamma Test", NULL, NULL); 108 | if (!window) 109 | { 110 | glfwTerminate(); 111 | exit(EXIT_FAILURE); 112 | } 113 | 114 | { 115 | const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); 116 | const size_t array_size = ramp->size * sizeof(short); 117 | orig_ramp.size = ramp->size; 118 | orig_ramp.red = malloc(array_size); 119 | orig_ramp.green = malloc(array_size); 120 | orig_ramp.blue = malloc(array_size); 121 | memcpy(orig_ramp.red, ramp->red, array_size); 122 | memcpy(orig_ramp.green, ramp->green, array_size); 123 | memcpy(orig_ramp.blue, ramp->blue, array_size); 124 | } 125 | 126 | glfwMakeContextCurrent(window); 127 | gladLoadGL(glfwGetProcAddress); 128 | glfwSwapInterval(1); 129 | 130 | nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS); 131 | nk_glfw3_font_stash_begin(&atlas); 132 | nk_glfw3_font_stash_end(); 133 | 134 | glfwSetKeyCallback(window, key_callback); 135 | 136 | while (!glfwWindowShouldClose(window)) 137 | { 138 | int width, height; 139 | struct nk_rect area; 140 | 141 | glfwGetWindowSize(window, &width, &height); 142 | area = nk_rect(0.f, 0.f, (float) width, (float) height); 143 | nk_window_set_bounds(nk, "", area); 144 | 145 | glClear(GL_COLOR_BUFFER_BIT); 146 | nk_glfw3_new_frame(); 147 | if (nk_begin(nk, "", area, 0)) 148 | { 149 | const GLFWgammaramp* ramp; 150 | 151 | nk_layout_row_dynamic(nk, 30, 3); 152 | if (nk_slider_float(nk, 0.1f, &gamma_value, 5.f, 0.1f)) 153 | glfwSetGamma(monitor, gamma_value); 154 | nk_labelf(nk, NK_TEXT_LEFT, "%0.1f", gamma_value); 155 | if (nk_button_label(nk, "Revert")) 156 | glfwSetGammaRamp(monitor, &orig_ramp); 157 | 158 | ramp = glfwGetGammaRamp(monitor); 159 | 160 | nk_layout_row_dynamic(nk, height - 60.f, 3); 161 | chart_ramp_array(nk, nk_rgb(255, 0, 0), ramp->size, ramp->red); 162 | chart_ramp_array(nk, nk_rgb(0, 255, 0), ramp->size, ramp->green); 163 | chart_ramp_array(nk, nk_rgb(0, 0, 255), ramp->size, ramp->blue); 164 | } 165 | 166 | nk_end(nk); 167 | nk_glfw3_render(NK_ANTI_ALIASING_ON); 168 | 169 | glfwSwapBuffers(window); 170 | glfwWaitEventsTimeout(1.0); 171 | } 172 | 173 | free(orig_ramp.red); 174 | free(orig_ramp.green); 175 | free(orig_ramp.blue); 176 | 177 | nk_glfw3_shutdown(); 178 | glfwTerminate(); 179 | exit(EXIT_SUCCESS); 180 | } 181 | 182 | -------------------------------------------------------------------------------- /third_party/glfw/tests/icon.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window icon test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the icon feature. 27 | // 28 | //======================================================================== 29 | 30 | #define GLAD_GL_IMPLEMENTATION 31 | #include 32 | #define GLFW_INCLUDE_NONE 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // a simple glfw logo 40 | const char* const logo[] = 41 | { 42 | "................", 43 | "................", 44 | "...0000..0......", 45 | "...0.....0......", 46 | "...0.00..0......", 47 | "...0..0..0......", 48 | "...0000..0000...", 49 | "................", 50 | "................", 51 | "...000..0...0...", 52 | "...0....0...0...", 53 | "...000..0.0.0...", 54 | "...0....0.0.0...", 55 | "...0....00000...", 56 | "................", 57 | "................" 58 | }; 59 | 60 | const unsigned char icon_colors[5][4] = 61 | { 62 | { 0, 0, 0, 255 }, // black 63 | { 255, 0, 0, 255 }, // red 64 | { 0, 255, 0, 255 }, // green 65 | { 0, 0, 255, 255 }, // blue 66 | { 255, 255, 255, 255 } // white 67 | }; 68 | 69 | static int cur_icon_color = 0; 70 | 71 | static void set_icon(GLFWwindow* window, int icon_color) 72 | { 73 | int x, y; 74 | unsigned char pixels[16 * 16 * 4]; 75 | unsigned char* target = pixels; 76 | GLFWimage img = { 16, 16, pixels }; 77 | 78 | for (y = 0; y < img.width; y++) 79 | { 80 | for (x = 0; x < img.height; x++) 81 | { 82 | if (logo[y][x] == '0') 83 | memcpy(target, icon_colors[icon_color], 4); 84 | else 85 | memset(target, 0, 4); 86 | 87 | target += 4; 88 | } 89 | } 90 | 91 | glfwSetWindowIcon(window, 1, &img); 92 | } 93 | 94 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 95 | { 96 | if (action != GLFW_PRESS) 97 | return; 98 | 99 | switch (key) 100 | { 101 | case GLFW_KEY_ESCAPE: 102 | glfwSetWindowShouldClose(window, GLFW_TRUE); 103 | break; 104 | case GLFW_KEY_SPACE: 105 | cur_icon_color = (cur_icon_color + 1) % 5; 106 | set_icon(window, cur_icon_color); 107 | break; 108 | case GLFW_KEY_X: 109 | glfwSetWindowIcon(window, 0, NULL); 110 | break; 111 | } 112 | } 113 | 114 | int main(int argc, char** argv) 115 | { 116 | GLFWwindow* window; 117 | 118 | if (!glfwInit()) 119 | { 120 | fprintf(stderr, "Failed to initialize GLFW\n"); 121 | exit(EXIT_FAILURE); 122 | } 123 | 124 | window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL); 125 | if (!window) 126 | { 127 | glfwTerminate(); 128 | 129 | fprintf(stderr, "Failed to open GLFW window\n"); 130 | exit(EXIT_FAILURE); 131 | } 132 | 133 | glfwMakeContextCurrent(window); 134 | gladLoadGL(glfwGetProcAddress); 135 | 136 | glfwSetKeyCallback(window, key_callback); 137 | set_icon(window, cur_icon_color); 138 | 139 | while (!glfwWindowShouldClose(window)) 140 | { 141 | glClear(GL_COLOR_BUFFER_BIT); 142 | glfwSwapBuffers(window); 143 | glfwWaitEvents(); 144 | } 145 | 146 | glfwDestroyWindow(window); 147 | glfwTerminate(); 148 | exit(EXIT_SUCCESS); 149 | } 150 | 151 | -------------------------------------------------------------------------------- /third_party/glfw/tests/threads.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multi-threading test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify whether the OpenGL context part of 27 | // the GLFW API is able to be used from multiple threads 28 | // 29 | //======================================================================== 30 | 31 | #include "tinycthread.h" 32 | 33 | #define GLAD_GL_IMPLEMENTATION 34 | #include 35 | #define GLFW_INCLUDE_NONE 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | typedef struct 43 | { 44 | GLFWwindow* window; 45 | const char* title; 46 | float r, g, b; 47 | thrd_t id; 48 | } Thread; 49 | 50 | static volatile int running = GLFW_TRUE; 51 | 52 | static void error_callback(int error, const char* description) 53 | { 54 | fprintf(stderr, "Error: %s\n", description); 55 | } 56 | 57 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 58 | { 59 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 60 | glfwSetWindowShouldClose(window, GLFW_TRUE); 61 | } 62 | 63 | static int thread_main(void* data) 64 | { 65 | const Thread* thread = data; 66 | 67 | glfwMakeContextCurrent(thread->window); 68 | glfwSwapInterval(1); 69 | 70 | while (running) 71 | { 72 | const float v = (float) fabs(sin(glfwGetTime() * 2.f)); 73 | glClearColor(thread->r * v, thread->g * v, thread->b * v, 0.f); 74 | 75 | glClear(GL_COLOR_BUFFER_BIT); 76 | glfwSwapBuffers(thread->window); 77 | } 78 | 79 | glfwMakeContextCurrent(NULL); 80 | return 0; 81 | } 82 | 83 | int main(void) 84 | { 85 | int i, result; 86 | Thread threads[] = 87 | { 88 | { NULL, "Red", 1.f, 0.f, 0.f, 0 }, 89 | { NULL, "Green", 0.f, 1.f, 0.f, 0 }, 90 | { NULL, "Blue", 0.f, 0.f, 1.f, 0 } 91 | }; 92 | const int count = sizeof(threads) / sizeof(Thread); 93 | 94 | glfwSetErrorCallback(error_callback); 95 | 96 | if (!glfwInit()) 97 | exit(EXIT_FAILURE); 98 | 99 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 100 | 101 | for (i = 0; i < count; i++) 102 | { 103 | threads[i].window = glfwCreateWindow(200, 200, 104 | threads[i].title, 105 | NULL, NULL); 106 | if (!threads[i].window) 107 | { 108 | glfwTerminate(); 109 | exit(EXIT_FAILURE); 110 | } 111 | 112 | glfwSetKeyCallback(threads[i].window, key_callback); 113 | 114 | glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); 115 | glfwShowWindow(threads[i].window); 116 | } 117 | 118 | glfwMakeContextCurrent(threads[0].window); 119 | gladLoadGL(glfwGetProcAddress); 120 | glfwMakeContextCurrent(NULL); 121 | 122 | for (i = 0; i < count; i++) 123 | { 124 | if (thrd_create(&threads[i].id, thread_main, threads + i) != 125 | thrd_success) 126 | { 127 | fprintf(stderr, "Failed to create secondary thread\n"); 128 | 129 | glfwTerminate(); 130 | exit(EXIT_FAILURE); 131 | } 132 | } 133 | 134 | while (running) 135 | { 136 | glfwWaitEvents(); 137 | 138 | for (i = 0; i < count; i++) 139 | { 140 | if (glfwWindowShouldClose(threads[i].window)) 141 | running = GLFW_FALSE; 142 | } 143 | } 144 | 145 | for (i = 0; i < count; i++) 146 | glfwHideWindow(threads[i].window); 147 | 148 | for (i = 0; i < count; i++) 149 | thrd_join(threads[i].id, &result); 150 | 151 | exit(EXIT_SUCCESS); 152 | } 153 | 154 | -------------------------------------------------------------------------------- /third_party/glfw/tests/timeout.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Event wait timeout test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that waiting for events with timeout works 27 | // 28 | //======================================================================== 29 | 30 | #define GLAD_GL_IMPLEMENTATION 31 | #include 32 | #define GLFW_INCLUDE_NONE 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | static void error_callback(int error, const char* description) 41 | { 42 | fprintf(stderr, "Error: %s\n", description); 43 | } 44 | 45 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 46 | { 47 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 48 | glfwSetWindowShouldClose(window, GLFW_TRUE); 49 | } 50 | 51 | static float nrand(void) 52 | { 53 | return (float) rand() / (float) RAND_MAX; 54 | } 55 | 56 | int main(void) 57 | { 58 | GLFWwindow* window; 59 | 60 | srand((unsigned int) time(NULL)); 61 | 62 | glfwSetErrorCallback(error_callback); 63 | 64 | if (!glfwInit()) 65 | exit(EXIT_FAILURE); 66 | 67 | window = glfwCreateWindow(640, 480, "Event Wait Timeout Test", NULL, NULL); 68 | if (!window) 69 | { 70 | glfwTerminate(); 71 | exit(EXIT_FAILURE); 72 | } 73 | 74 | glfwMakeContextCurrent(window); 75 | gladLoadGL(glfwGetProcAddress); 76 | glfwSetKeyCallback(window, key_callback); 77 | 78 | while (!glfwWindowShouldClose(window)) 79 | { 80 | int width, height; 81 | float r = nrand(), g = nrand(), b = nrand(); 82 | float l = (float) sqrt(r * r + g * g + b * b); 83 | 84 | glfwGetFramebufferSize(window, &width, &height); 85 | 86 | glViewport(0, 0, width, height); 87 | glClearColor(r / l, g / l, b / l, 1.f); 88 | glClear(GL_COLOR_BUFFER_BIT); 89 | glfwSwapBuffers(window); 90 | 91 | glfwWaitEventsTimeout(1.0); 92 | } 93 | 94 | glfwDestroyWindow(window); 95 | 96 | glfwTerminate(); 97 | exit(EXIT_SUCCESS); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /third_party/glfw/tests/title.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // UTF-8 window title test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test sets a UTF-8 window title 27 | // 28 | //======================================================================== 29 | 30 | #define GLAD_GL_IMPLEMENTATION 31 | #include 32 | #define GLFW_INCLUDE_NONE 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | static void error_callback(int error, const char* description) 39 | { 40 | fprintf(stderr, "Error: %s\n", description); 41 | } 42 | 43 | int main(void) 44 | { 45 | GLFWwindow* window; 46 | 47 | glfwSetErrorCallback(error_callback); 48 | 49 | if (!glfwInit()) 50 | exit(EXIT_FAILURE); 51 | 52 | window = glfwCreateWindow(400, 400, "English 日本語 русский язык 官話", NULL, NULL); 53 | if (!window) 54 | { 55 | glfwTerminate(); 56 | exit(EXIT_FAILURE); 57 | } 58 | 59 | glfwMakeContextCurrent(window); 60 | gladLoadGL(glfwGetProcAddress); 61 | glfwSwapInterval(1); 62 | 63 | while (!glfwWindowShouldClose(window)) 64 | { 65 | glClear(GL_COLOR_BUFFER_BIT); 66 | glfwSwapBuffers(window); 67 | glfwWaitEvents(); 68 | } 69 | 70 | glfwTerminate(); 71 | exit(EXIT_SUCCESS); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/buffer_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/buffer_info.h: Python buffer object interface 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | /// Information record describing a Python buffer object 17 | struct buffer_info { 18 | void *ptr = nullptr; // Pointer to the underlying storage 19 | ssize_t itemsize = 0; // Size of individual items in bytes 20 | ssize_t size = 0; // Total number of entries 21 | std::string format; // For homogeneous buffers, this should be set to format_descriptor::format() 22 | ssize_t ndim = 0; // Number of dimensions 23 | std::vector shape; // Shape of the tensor (1 entry per dimension) 24 | std::vector strides; // Number of bytes between adjacent entries (for each per dimension) 25 | bool readonly = false; // flag to indicate if the underlying storage may be written to 26 | 27 | buffer_info() { } 28 | 29 | buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, 30 | detail::any_container shape_in, detail::any_container strides_in, bool readonly=false) 31 | : ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim), 32 | shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) { 33 | if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) 34 | pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length"); 35 | for (size_t i = 0; i < (size_t) ndim; ++i) 36 | size *= shape[i]; 37 | } 38 | 39 | template 40 | buffer_info(T *ptr, detail::any_container shape_in, detail::any_container strides_in, bool readonly=false) 41 | : buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor::format(), static_cast(shape_in->size()), std::move(shape_in), std::move(strides_in), readonly) { } 42 | 43 | buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false) 44 | : buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) { } 45 | 46 | template 47 | buffer_info(T *ptr, ssize_t size, bool readonly=false) 48 | : buffer_info(ptr, sizeof(T), format_descriptor::format(), size, readonly) { } 49 | 50 | template 51 | buffer_info(const T *ptr, ssize_t size, bool readonly=true) 52 | : buffer_info(const_cast(ptr), sizeof(T), format_descriptor::format(), size, readonly) { } 53 | 54 | explicit buffer_info(Py_buffer *view, bool ownview = true) 55 | : buffer_info(view->buf, view->itemsize, view->format, view->ndim, 56 | {view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}, view->readonly) { 57 | this->view = view; 58 | this->ownview = ownview; 59 | } 60 | 61 | buffer_info(const buffer_info &) = delete; 62 | buffer_info& operator=(const buffer_info &) = delete; 63 | 64 | buffer_info(buffer_info &&other) { 65 | (*this) = std::move(other); 66 | } 67 | 68 | buffer_info& operator=(buffer_info &&rhs) { 69 | ptr = rhs.ptr; 70 | itemsize = rhs.itemsize; 71 | size = rhs.size; 72 | format = std::move(rhs.format); 73 | ndim = rhs.ndim; 74 | shape = std::move(rhs.shape); 75 | strides = std::move(rhs.strides); 76 | std::swap(view, rhs.view); 77 | std::swap(ownview, rhs.ownview); 78 | readonly = rhs.readonly; 79 | return *this; 80 | } 81 | 82 | ~buffer_info() { 83 | if (view && ownview) { PyBuffer_Release(view); delete view; } 84 | } 85 | 86 | private: 87 | struct private_ctr_tag { }; 88 | 89 | buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, 90 | detail::any_container &&shape_in, detail::any_container &&strides_in, bool readonly) 91 | : buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) { } 92 | 93 | Py_buffer *view = nullptr; 94 | bool ownview = false; 95 | }; 96 | 97 | NAMESPACE_BEGIN(detail) 98 | 99 | template struct compare_buffer_info { 100 | static bool compare(const buffer_info& b) { 101 | return b.format == format_descriptor::format() && b.itemsize == (ssize_t) sizeof(T); 102 | } 103 | }; 104 | 105 | template struct compare_buffer_info::value>> { 106 | static bool compare(const buffer_info& b) { 107 | return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor::value || 108 | ((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned::value ? "L" : "l")) || 109 | ((sizeof(T) == sizeof(size_t)) && b.format == (std::is_unsigned::value ? "N" : "n"))); 110 | } 111 | }; 112 | 113 | NAMESPACE_END(detail) 114 | NAMESPACE_END(PYBIND11_NAMESPACE) 115 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/common.h: -------------------------------------------------------------------------------- 1 | #include "detail/common.h" 2 | #warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'." 3 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/complex.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/complex.h: Complex number support 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | #include 14 | 15 | /// glibc defines I as a macro which breaks things, e.g., boost template names 16 | #ifdef I 17 | # undef I 18 | #endif 19 | 20 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 21 | 22 | template struct format_descriptor, detail::enable_if_t::value>> { 23 | static constexpr const char c = format_descriptor::c; 24 | static constexpr const char value[3] = { 'Z', c, '\0' }; 25 | static std::string format() { return std::string(value); } 26 | }; 27 | 28 | #ifndef PYBIND11_CPP17 29 | 30 | template constexpr const char format_descriptor< 31 | std::complex, detail::enable_if_t::value>>::value[3]; 32 | 33 | #endif 34 | 35 | NAMESPACE_BEGIN(detail) 36 | 37 | template struct is_fmt_numeric, detail::enable_if_t::value>> { 38 | static constexpr bool value = true; 39 | static constexpr int index = is_fmt_numeric::index + 3; 40 | }; 41 | 42 | template class type_caster> { 43 | public: 44 | bool load(handle src, bool convert) { 45 | if (!src) 46 | return false; 47 | if (!convert && !PyComplex_Check(src.ptr())) 48 | return false; 49 | Py_complex result = PyComplex_AsCComplex(src.ptr()); 50 | if (result.real == -1.0 && PyErr_Occurred()) { 51 | PyErr_Clear(); 52 | return false; 53 | } 54 | value = std::complex((T) result.real, (T) result.imag); 55 | return true; 56 | } 57 | 58 | static handle cast(const std::complex &src, return_value_policy /* policy */, handle /* parent */) { 59 | return PyComplex_FromDoubles((double) src.real(), (double) src.imag()); 60 | } 61 | 62 | PYBIND11_TYPE_CASTER(std::complex, _("complex")); 63 | }; 64 | NAMESPACE_END(detail) 65 | NAMESPACE_END(PYBIND11_NAMESPACE) 66 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/detail/descr.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/detail/descr.h: Helper type for concatenating type signatures at compile time 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "common.h" 13 | 14 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | NAMESPACE_BEGIN(detail) 16 | 17 | #if !defined(_MSC_VER) 18 | # define PYBIND11_DESCR_CONSTEXPR static constexpr 19 | #else 20 | # define PYBIND11_DESCR_CONSTEXPR const 21 | #endif 22 | 23 | /* Concatenate type signatures at compile time */ 24 | template 25 | struct descr { 26 | char text[N + 1]; 27 | 28 | constexpr descr() : text{'\0'} { } 29 | constexpr descr(char const (&s)[N+1]) : descr(s, make_index_sequence()) { } 30 | 31 | template 32 | constexpr descr(char const (&s)[N+1], index_sequence) : text{s[Is]..., '\0'} { } 33 | 34 | template 35 | constexpr descr(char c, Chars... cs) : text{c, static_cast(cs)..., '\0'} { } 36 | 37 | static constexpr std::array types() { 38 | return {{&typeid(Ts)..., nullptr}}; 39 | } 40 | }; 41 | 42 | template 43 | constexpr descr plus_impl(const descr &a, const descr &b, 44 | index_sequence, index_sequence) { 45 | return {a.text[Is1]..., b.text[Is2]...}; 46 | } 47 | 48 | template 49 | constexpr descr operator+(const descr &a, const descr &b) { 50 | return plus_impl(a, b, make_index_sequence(), make_index_sequence()); 51 | } 52 | 53 | template 54 | constexpr descr _(char const(&text)[N]) { return descr(text); } 55 | constexpr descr<0> _(char const(&)[1]) { return {}; } 56 | 57 | template struct int_to_str : int_to_str { }; 58 | template struct int_to_str<0, Digits...> { 59 | static constexpr auto digits = descr(('0' + Digits)...); 60 | }; 61 | 62 | // Ternary description (like std::conditional) 63 | template 64 | constexpr enable_if_t> _(char const(&text1)[N1], char const(&)[N2]) { 65 | return _(text1); 66 | } 67 | template 68 | constexpr enable_if_t> _(char const(&)[N1], char const(&text2)[N2]) { 69 | return _(text2); 70 | } 71 | 72 | template 73 | constexpr enable_if_t _(const T1 &d, const T2 &) { return d; } 74 | template 75 | constexpr enable_if_t _(const T1 &, const T2 &d) { return d; } 76 | 77 | template auto constexpr _() -> decltype(int_to_str::digits) { 78 | return int_to_str::digits; 79 | } 80 | 81 | template constexpr descr<1, Type> _() { return {'%'}; } 82 | 83 | constexpr descr<0> concat() { return {}; } 84 | 85 | template 86 | constexpr descr concat(const descr &descr) { return descr; } 87 | 88 | template 89 | constexpr auto concat(const descr &d, const Args &...args) 90 | -> decltype(std::declval>() + concat(args...)) { 91 | return d + _(", ") + concat(args...); 92 | } 93 | 94 | template 95 | constexpr descr type_descr(const descr &descr) { 96 | return _("{") + descr + _("}"); 97 | } 98 | 99 | NAMESPACE_END(detail) 100 | NAMESPACE_END(PYBIND11_NAMESPACE) 101 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/detail/typeid.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/detail/typeid.h: Compiler-independent access to type identifiers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #if defined(__GNUG__) 16 | #include 17 | #endif 18 | 19 | #include "common.h" 20 | 21 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 22 | NAMESPACE_BEGIN(detail) 23 | /// Erase all occurrences of a substring 24 | inline void erase_all(std::string &string, const std::string &search) { 25 | for (size_t pos = 0;;) { 26 | pos = string.find(search, pos); 27 | if (pos == std::string::npos) break; 28 | string.erase(pos, search.length()); 29 | } 30 | } 31 | 32 | PYBIND11_NOINLINE inline void clean_type_id(std::string &name) { 33 | #if defined(__GNUG__) 34 | int status = 0; 35 | std::unique_ptr res { 36 | abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free }; 37 | if (status == 0) 38 | name = res.get(); 39 | #else 40 | detail::erase_all(name, "class "); 41 | detail::erase_all(name, "struct "); 42 | detail::erase_all(name, "enum "); 43 | #endif 44 | detail::erase_all(name, "pybind11::"); 45 | } 46 | NAMESPACE_END(detail) 47 | 48 | /// Return a string representation of a C++ type 49 | template static std::string type_id() { 50 | std::string name(typeid(T).name()); 51 | detail::clean_type_id(name); 52 | return name; 53 | } 54 | 55 | NAMESPACE_END(PYBIND11_NAMESPACE) 56 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/eval.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/exec.h: Support for evaluating Python expressions and statements 3 | from strings and files 4 | 5 | Copyright (c) 2016 Klemens Morgenstern and 6 | Wenzel Jakob 7 | 8 | All rights reserved. Use of this source code is governed by a 9 | BSD-style license that can be found in the LICENSE file. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include "pybind11.h" 15 | 16 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 17 | 18 | enum eval_mode { 19 | /// Evaluate a string containing an isolated expression 20 | eval_expr, 21 | 22 | /// Evaluate a string containing a single statement. Returns \c none 23 | eval_single_statement, 24 | 25 | /// Evaluate a string containing a sequence of statement. Returns \c none 26 | eval_statements 27 | }; 28 | 29 | template 30 | object eval(str expr, object global = globals(), object local = object()) { 31 | if (!local) 32 | local = global; 33 | 34 | /* PyRun_String does not accept a PyObject / encoding specifier, 35 | this seems to be the only alternative */ 36 | std::string buffer = "# -*- coding: utf-8 -*-\n" + (std::string) expr; 37 | 38 | int start; 39 | switch (mode) { 40 | case eval_expr: start = Py_eval_input; break; 41 | case eval_single_statement: start = Py_single_input; break; 42 | case eval_statements: start = Py_file_input; break; 43 | default: pybind11_fail("invalid evaluation mode"); 44 | } 45 | 46 | PyObject *result = PyRun_String(buffer.c_str(), start, global.ptr(), local.ptr()); 47 | if (!result) 48 | throw error_already_set(); 49 | return reinterpret_steal(result); 50 | } 51 | 52 | template 53 | object eval(const char (&s)[N], object global = globals(), object local = object()) { 54 | /* Support raw string literals by removing common leading whitespace */ 55 | auto expr = (s[0] == '\n') ? str(module::import("textwrap").attr("dedent")(s)) 56 | : str(s); 57 | return eval(expr, global, local); 58 | } 59 | 60 | inline void exec(str expr, object global = globals(), object local = object()) { 61 | eval(expr, global, local); 62 | } 63 | 64 | template 65 | void exec(const char (&s)[N], object global = globals(), object local = object()) { 66 | eval(s, global, local); 67 | } 68 | 69 | template 70 | object eval_file(str fname, object global = globals(), object local = object()) { 71 | if (!local) 72 | local = global; 73 | 74 | int start; 75 | switch (mode) { 76 | case eval_expr: start = Py_eval_input; break; 77 | case eval_single_statement: start = Py_single_input; break; 78 | case eval_statements: start = Py_file_input; break; 79 | default: pybind11_fail("invalid evaluation mode"); 80 | } 81 | 82 | int closeFile = 1; 83 | std::string fname_str = (std::string) fname; 84 | #if PY_VERSION_HEX >= 0x03040000 85 | FILE *f = _Py_fopen_obj(fname.ptr(), "r"); 86 | #elif PY_VERSION_HEX >= 0x03000000 87 | FILE *f = _Py_fopen(fname.ptr(), "r"); 88 | #else 89 | /* No unicode support in open() :( */ 90 | auto fobj = reinterpret_steal(PyFile_FromString( 91 | const_cast(fname_str.c_str()), 92 | const_cast("r"))); 93 | FILE *f = nullptr; 94 | if (fobj) 95 | f = PyFile_AsFile(fobj.ptr()); 96 | closeFile = 0; 97 | #endif 98 | if (!f) { 99 | PyErr_Clear(); 100 | pybind11_fail("File \"" + fname_str + "\" could not be opened!"); 101 | } 102 | 103 | #if PY_VERSION_HEX < 0x03000000 && defined(PYPY_VERSION) 104 | PyObject *result = PyRun_File(f, fname_str.c_str(), start, global.ptr(), 105 | local.ptr()); 106 | (void) closeFile; 107 | #else 108 | PyObject *result = PyRun_FileEx(f, fname_str.c_str(), start, global.ptr(), 109 | local.ptr(), closeFile); 110 | #endif 111 | 112 | if (!result) 113 | throw error_already_set(); 114 | return reinterpret_steal(result); 115 | } 116 | 117 | NAMESPACE_END(PYBIND11_NAMESPACE) 118 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/functional.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/functional.h: std::function<> support 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template 19 | struct type_caster> { 20 | using type = std::function; 21 | using retval_type = conditional_t::value, void_type, Return>; 22 | using function_type = Return (*) (Args...); 23 | 24 | public: 25 | bool load(handle src, bool convert) { 26 | if (src.is_none()) { 27 | // Defer accepting None to other overloads (if we aren't in convert mode): 28 | if (!convert) return false; 29 | return true; 30 | } 31 | 32 | if (!isinstance(src)) 33 | return false; 34 | 35 | auto func = reinterpret_borrow(src); 36 | 37 | /* 38 | When passing a C++ function as an argument to another C++ 39 | function via Python, every function call would normally involve 40 | a full C++ -> Python -> C++ roundtrip, which can be prohibitive. 41 | Here, we try to at least detect the case where the function is 42 | stateless (i.e. function pointer or lambda function without 43 | captured variables), in which case the roundtrip can be avoided. 44 | */ 45 | if (auto cfunc = func.cpp_function()) { 46 | auto c = reinterpret_borrow(PyCFunction_GET_SELF(cfunc.ptr())); 47 | auto rec = (function_record *) c; 48 | 49 | if (rec && rec->is_stateless && 50 | same_type(typeid(function_type), *reinterpret_cast(rec->data[1]))) { 51 | struct capture { function_type f; }; 52 | value = ((capture *) &rec->data)->f; 53 | return true; 54 | } 55 | } 56 | 57 | // ensure GIL is held during functor destruction 58 | struct func_handle { 59 | function f; 60 | func_handle(function&& f_) : f(std::move(f_)) {} 61 | func_handle(const func_handle&) = default; 62 | ~func_handle() { 63 | gil_scoped_acquire acq; 64 | function kill_f(std::move(f)); 65 | } 66 | }; 67 | 68 | // to emulate 'move initialization capture' in C++11 69 | struct func_wrapper { 70 | func_handle hfunc; 71 | func_wrapper(func_handle&& hf): hfunc(std::move(hf)) {} 72 | Return operator()(Args... args) const { 73 | gil_scoped_acquire acq; 74 | object retval(hfunc.f(std::forward(args)...)); 75 | /* Visual studio 2015 parser issue: need parentheses around this expression */ 76 | return (retval.template cast()); 77 | } 78 | }; 79 | 80 | value = func_wrapper(func_handle(std::move(func))); 81 | return true; 82 | } 83 | 84 | template 85 | static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) { 86 | if (!f_) 87 | return none().inc_ref(); 88 | 89 | auto result = f_.template target(); 90 | if (result) 91 | return cpp_function(*result, policy).release(); 92 | else 93 | return cpp_function(std::forward(f_), policy).release(); 94 | } 95 | 96 | PYBIND11_TYPE_CASTER(type, _("Callable[[") + concat(make_caster::name...) + _("], ") 97 | + make_caster::name + _("]")); 98 | }; 99 | 100 | NAMESPACE_END(detail) 101 | NAMESPACE_END(PYBIND11_NAMESPACE) 102 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/iostream.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/iostream.h -- Tools to assist with redirecting cout and cerr to Python 3 | 4 | Copyright (c) 2017 Henry F. Schreiner 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 21 | NAMESPACE_BEGIN(detail) 22 | 23 | // Buffer that writes to Python instead of C++ 24 | class pythonbuf : public std::streambuf { 25 | private: 26 | using traits_type = std::streambuf::traits_type; 27 | 28 | const size_t buf_size; 29 | std::unique_ptr d_buffer; 30 | object pywrite; 31 | object pyflush; 32 | 33 | int overflow(int c) { 34 | if (!traits_type::eq_int_type(c, traits_type::eof())) { 35 | *pptr() = traits_type::to_char_type(c); 36 | pbump(1); 37 | } 38 | return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof(); 39 | } 40 | 41 | int sync() { 42 | if (pbase() != pptr()) { 43 | // This subtraction cannot be negative, so dropping the sign 44 | str line(pbase(), static_cast(pptr() - pbase())); 45 | 46 | { 47 | gil_scoped_acquire tmp; 48 | pywrite(line); 49 | pyflush(); 50 | } 51 | 52 | setp(pbase(), epptr()); 53 | } 54 | return 0; 55 | } 56 | 57 | public: 58 | 59 | pythonbuf(object pyostream, size_t buffer_size = 1024) 60 | : buf_size(buffer_size), 61 | d_buffer(new char[buf_size]), 62 | pywrite(pyostream.attr("write")), 63 | pyflush(pyostream.attr("flush")) { 64 | setp(d_buffer.get(), d_buffer.get() + buf_size - 1); 65 | } 66 | 67 | pythonbuf(pythonbuf&&) = default; 68 | 69 | /// Sync before destroy 70 | ~pythonbuf() { 71 | sync(); 72 | } 73 | }; 74 | 75 | NAMESPACE_END(detail) 76 | 77 | 78 | /** \rst 79 | This a move-only guard that redirects output. 80 | 81 | .. code-block:: cpp 82 | 83 | #include 84 | 85 | ... 86 | 87 | { 88 | py::scoped_ostream_redirect output; 89 | std::cout << "Hello, World!"; // Python stdout 90 | } // <-- return std::cout to normal 91 | 92 | You can explicitly pass the c++ stream and the python object, 93 | for example to guard stderr instead. 94 | 95 | .. code-block:: cpp 96 | 97 | { 98 | py::scoped_ostream_redirect output{std::cerr, py::module::import("sys").attr("stderr")}; 99 | std::cerr << "Hello, World!"; 100 | } 101 | \endrst */ 102 | class scoped_ostream_redirect { 103 | protected: 104 | std::streambuf *old; 105 | std::ostream &costream; 106 | detail::pythonbuf buffer; 107 | 108 | public: 109 | scoped_ostream_redirect( 110 | std::ostream &costream = std::cout, 111 | object pyostream = module::import("sys").attr("stdout")) 112 | : costream(costream), buffer(pyostream) { 113 | old = costream.rdbuf(&buffer); 114 | } 115 | 116 | ~scoped_ostream_redirect() { 117 | costream.rdbuf(old); 118 | } 119 | 120 | scoped_ostream_redirect(const scoped_ostream_redirect &) = delete; 121 | scoped_ostream_redirect(scoped_ostream_redirect &&other) = default; 122 | scoped_ostream_redirect &operator=(const scoped_ostream_redirect &) = delete; 123 | scoped_ostream_redirect &operator=(scoped_ostream_redirect &&) = delete; 124 | }; 125 | 126 | 127 | /** \rst 128 | Like `scoped_ostream_redirect`, but redirects cerr by default. This class 129 | is provided primary to make ``py::call_guard`` easier to make. 130 | 131 | .. code-block:: cpp 132 | 133 | m.def("noisy_func", &noisy_func, 134 | py::call_guard()); 136 | 137 | \endrst */ 138 | class scoped_estream_redirect : public scoped_ostream_redirect { 139 | public: 140 | scoped_estream_redirect( 141 | std::ostream &costream = std::cerr, 142 | object pyostream = module::import("sys").attr("stderr")) 143 | : scoped_ostream_redirect(costream,pyostream) {} 144 | }; 145 | 146 | 147 | NAMESPACE_BEGIN(detail) 148 | 149 | // Class to redirect output as a context manager. C++ backend. 150 | class OstreamRedirect { 151 | bool do_stdout_; 152 | bool do_stderr_; 153 | std::unique_ptr redirect_stdout; 154 | std::unique_ptr redirect_stderr; 155 | 156 | public: 157 | OstreamRedirect(bool do_stdout = true, bool do_stderr = true) 158 | : do_stdout_(do_stdout), do_stderr_(do_stderr) {} 159 | 160 | void enter() { 161 | if (do_stdout_) 162 | redirect_stdout.reset(new scoped_ostream_redirect()); 163 | if (do_stderr_) 164 | redirect_stderr.reset(new scoped_estream_redirect()); 165 | } 166 | 167 | void exit() { 168 | redirect_stdout.reset(); 169 | redirect_stderr.reset(); 170 | } 171 | }; 172 | 173 | NAMESPACE_END(detail) 174 | 175 | /** \rst 176 | This is a helper function to add a C++ redirect context manager to Python 177 | instead of using a C++ guard. To use it, add the following to your binding code: 178 | 179 | .. code-block:: cpp 180 | 181 | #include 182 | 183 | ... 184 | 185 | py::add_ostream_redirect(m, "ostream_redirect"); 186 | 187 | You now have a Python context manager that redirects your output: 188 | 189 | .. code-block:: python 190 | 191 | with m.ostream_redirect(): 192 | m.print_to_cout_function() 193 | 194 | This manager can optionally be told which streams to operate on: 195 | 196 | .. code-block:: python 197 | 198 | with m.ostream_redirect(stdout=true, stderr=true): 199 | m.noisy_function_with_error_printing() 200 | 201 | \endrst */ 202 | inline class_ add_ostream_redirect(module m, std::string name = "ostream_redirect") { 203 | return class_(m, name.c_str(), module_local()) 204 | .def(init(), arg("stdout")=true, arg("stderr")=true) 205 | .def("__enter__", &detail::OstreamRedirect::enter) 206 | .def("__exit__", [](detail::OstreamRedirect &self_, args) { self_.exit(); }); 207 | } 208 | 209 | NAMESPACE_END(PYBIND11_NAMESPACE) 210 | -------------------------------------------------------------------------------- /third_party/pybind11/include/pybind11/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/options.h: global settings that are configurable at runtime. 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | class options { 17 | public: 18 | 19 | // Default RAII constructor, which leaves settings as they currently are. 20 | options() : previous_state(global_state()) {} 21 | 22 | // Class is non-copyable. 23 | options(const options&) = delete; 24 | options& operator=(const options&) = delete; 25 | 26 | // Destructor, which restores settings that were in effect before. 27 | ~options() { 28 | global_state() = previous_state; 29 | } 30 | 31 | // Setter methods (affect the global state): 32 | 33 | options& disable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = false; return *this; } 34 | 35 | options& enable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = true; return *this; } 36 | 37 | options& disable_function_signatures() & { global_state().show_function_signatures = false; return *this; } 38 | 39 | options& enable_function_signatures() & { global_state().show_function_signatures = true; return *this; } 40 | 41 | // Getter methods (return the global state): 42 | 43 | static bool show_user_defined_docstrings() { return global_state().show_user_defined_docstrings; } 44 | 45 | static bool show_function_signatures() { return global_state().show_function_signatures; } 46 | 47 | // This type is not meant to be allocated on the heap. 48 | void* operator new(size_t) = delete; 49 | 50 | private: 51 | 52 | struct state { 53 | bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings. 54 | bool show_function_signatures = true; //< Include auto-generated function signatures in docstrings. 55 | }; 56 | 57 | static state &global_state() { 58 | static state instance; 59 | return instance; 60 | } 61 | 62 | state previous_state; 63 | }; 64 | 65 | NAMESPACE_END(PYBIND11_NAMESPACE) 66 | --------------------------------------------------------------------------------